update ragemp-c types for 1.1
This commit is contained in:
@@ -15,6 +15,13 @@ class RageEntity implements IEntity {
|
|||||||
return this.entity.id;
|
return this.entity.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get attachments(): number {
|
||||||
|
var color = this.entity.getVariable("nametagColor");
|
||||||
|
if (!color)
|
||||||
|
return 0;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
get handle() {
|
get handle() {
|
||||||
return this.entity.handle;
|
return this.entity.handle;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,125 +12,56 @@ export default function attachmentManager(game: IGame) {
|
|||||||
attachmentMngr.register("weapondeal2", "w_sg_pumpshotgun", "weapondeal2w_sg_pumpshotgun", new mp.Vector3(0.4, 1.6, 0.62), new mp.Vector3(90, 0, 180));
|
attachmentMngr.register("weapondeal2", "w_sg_pumpshotgun", "weapondeal2w_sg_pumpshotgun", new mp.Vector3(0.4, 1.6, 0.62), new mp.Vector3(90, 0, 180));
|
||||||
});
|
});
|
||||||
|
|
||||||
const attachmentMngr =
|
const attachmentMngr =
|
||||||
{
|
{
|
||||||
attachments: {},
|
attachments: {},
|
||||||
|
|
||||||
addFor: function (entityRage, id) {
|
addFor: async function (entity, id) {
|
||||||
|
|
||||||
if (!entityRage) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
let entity: IEntity;
|
|
||||||
if (entityRage.type === "player") {
|
|
||||||
var player = game.players.at(entityRage.remoteId);
|
|
||||||
entity = player;
|
|
||||||
|
|
||||||
} else if (entityRage.type === "vehicle") {
|
|
||||||
var vehicle = game.vehicles.at(entityRage.remoteId);
|
|
||||||
entity = vehicle;
|
|
||||||
var realName = mp.game.ui.getLabelText(mp.game.vehicle.getDisplayNameFromVehicleModel(entityRage.model));
|
|
||||||
} else if (entityRage.type === "object") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let e = game.attachments.get(entity);
|
|
||||||
|
|
||||||
if (this.attachments.hasOwnProperty(id)) {
|
if (this.attachments.hasOwnProperty(id)) {
|
||||||
|
if (!entity.__attachmentObjects.hasOwnProperty(id)) {
|
||||||
|
|
||||||
if (!e.__attachmentObjects) { e.__attachmentObjects = []; }
|
|
||||||
|
|
||||||
|
|
||||||
if (!e.__attachmentObjects.hasOwnProperty(id)) {
|
|
||||||
|
|
||||||
|
|
||||||
let attInfo = this.attachments[id];
|
let attInfo = this.attachments[id];
|
||||||
let rageObject = mp.objects.new(attInfo.model, entityRage.position);
|
|
||||||
|
|
||||||
|
|
||||||
var bone = (typeof (attInfo.boneName) === 'string') ? entityRage.getBoneIndexByName(attInfo.boneName) : entityRage.getBoneIndex(attInfo.boneName)
|
let object = mp.objects.new(attInfo.model, entity.position);
|
||||||
|
while (object.handle === 0) {
|
||||||
|
await mp.game.waitAsync(0);
|
||||||
|
}
|
||||||
|
|
||||||
let attachmentData = {
|
object.__attMgrData = {
|
||||||
targetEntity: entity.id,
|
targetEntity: entity.handle,
|
||||||
bone: bone,
|
bone: (typeof (attInfo.boneName) === 'string') ? entity.getBoneIndexByName(attInfo.boneName) : entity.getBoneIndex(attInfo.boneName),
|
||||||
offset: attInfo.offset,
|
offset: attInfo.offset,
|
||||||
rotation: attInfo.rotation
|
rotation: attInfo.rotation
|
||||||
};
|
};
|
||||||
|
|
||||||
game.objects.setData(rageObject, attachmentData); // hier hakt es mein freund
|
object.notifyStreaming = true;
|
||||||
|
entity.__attachmentObjects[id] = object;
|
||||||
let object = game.objects.at(rageObject.remoteId);
|
|
||||||
|
|
||||||
//DEBUG MSG
|
|
||||||
mp.gui.chat.push(`ATTACH: ${attachId} - bone = ${bone}`)
|
|
||||||
|
|
||||||
//rageObject.notifyStreaming = true;
|
|
||||||
mp.gui.chat.push("Notified Stream.");
|
|
||||||
game.wait(200);
|
|
||||||
|
|
||||||
//DEBUG MSG
|
|
||||||
mp.gui.chat.push(`ATTACH: ${attachId} - Attaching ${JSON.stringify(attInfo)}`);
|
|
||||||
e.__attachmentObjects[id] = rageObject;;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* else {
|
else {
|
||||||
mp.game.graphics.notify(`Static Attachments Error: ~r~Unknown Attachment Used: ~w~0x${id.toString(16)}`);
|
mp.game.graphics.notify(`Static Attachments Error: ~r~Unknown Attachment Used: ~w~0x${id.toString(16)}`);
|
||||||
} */
|
|
||||||
},
|
|
||||||
|
|
||||||
removeFor: function (entityRage, id) {
|
|
||||||
let entity;
|
|
||||||
if (entityRage.type === "player") {
|
|
||||||
entity = game.players.at(entityRage.remoteId);
|
|
||||||
} else if (entityRage.type === "vehicle") {
|
|
||||||
entity = game.vehicles.at(entityRage.remoteId);
|
|
||||||
}
|
|
||||||
let e = game.attachments.get(entity);
|
|
||||||
|
|
||||||
if (e.__attachmentObjects.hasOwnProperty(id)) {
|
|
||||||
let obj = e.__attachmentObjects[id];
|
|
||||||
|
|
||||||
obj.destroy();
|
|
||||||
delete e.__attachmentObjects[id];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initFor: function (entityRage) {
|
removeFor: function (entity, id) {
|
||||||
let entity;
|
if (entity.__attachmentObjects.hasOwnProperty(id)) {
|
||||||
if (entityRage.type === "player") {
|
let obj = entity.__attachmentObjects[id];
|
||||||
entity = game.players.at(entityRage.remoteId);
|
delete entity.__attachmentObjects[id];
|
||||||
} else if (entityRage.type === "vehicle") {
|
|
||||||
entity = game.vehicles.at(entityRage.remoteId);
|
|
||||||
}
|
|
||||||
|
|
||||||
let e = game.attachments.get(entity);
|
if (mp.objects.exists(obj)) {
|
||||||
if (e != null) {
|
obj.destroy();
|
||||||
for (let attachment of e.__attachments) {
|
|
||||||
attachmentMngr.addFor(entityRage, attachment);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
shutdownFor: function (entityRage) {
|
initFor: function (entity) {
|
||||||
let entity;
|
for (let attachment of entity.__attachments) {
|
||||||
if (entityRage.type === "player") {
|
attachmentMngr.addFor(entity, attachment);
|
||||||
entity = game.players.at(entityRage.remoteId);
|
|
||||||
} else if (entityRage.type === "vehicle") {
|
|
||||||
entity = game.vehicles.at(entityRage.remoteId);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
let e = game.attachments.get(entity);
|
shutdownFor: function (entity) {
|
||||||
if (e != null) {
|
for (let attachment in entity.__attachmentObjects) {
|
||||||
for (let attachment of e.__attachments) {
|
attachmentMngr.removeFor(entity, attachment);
|
||||||
attachmentMngr.removeFor(entityRage, attachment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -146,7 +77,6 @@ export default function attachmentManager(game: IGame) {
|
|||||||
if (!this.attachments.hasOwnProperty(id)) {
|
if (!this.attachments.hasOwnProperty(id)) {
|
||||||
if (mp.game.streaming.isModelInCdimage(model)) {
|
if (mp.game.streaming.isModelInCdimage(model)) {
|
||||||
this.attachments[id] =
|
this.attachments[id] =
|
||||||
|
|
||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
model: model,
|
model: model,
|
||||||
@@ -156,7 +86,7 @@ export default function attachmentManager(game: IGame) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mp.game.graphics.notify(`Static Attachments Error: ~r~Invalid Model(0x${model.toString(16)})`);
|
mp.game.graphics.notify(`Static Attachments Error: ~r~Invalid Model (0x${model.toString(16)})`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -179,10 +109,9 @@ export default function attachmentManager(game: IGame) {
|
|||||||
attachmentName = mp.game.joaat(attachmentName);
|
attachmentName = mp.game.joaat(attachmentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
let entity = game.players.local;
|
let entity = mp.players.local;
|
||||||
let e = game.attachments.get(entity);
|
|
||||||
|
|
||||||
if (!e.__attachments || e.__attachments.indexOf(attachmentName) === -1) {
|
if (!entity.__attachments || entity.__attachments.indexOf(attachmentName) === -1) {
|
||||||
mp.events.callRemote("staticAttachments.Add", attachmentName.toString(36));
|
mp.events.callRemote("staticAttachments.Add", attachmentName.toString(36));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -192,10 +121,9 @@ export default function attachmentManager(game: IGame) {
|
|||||||
attachmentName = mp.game.joaat(attachmentName);
|
attachmentName = mp.game.joaat(attachmentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
let entity = game.players.local;
|
let entity = mp.players.local;
|
||||||
let e = game.attachments.get(entity);
|
|
||||||
|
|
||||||
if (e.__attachments && e.__attachments.indexOf(attachmentName) !== -1) {
|
if (entity.__attachments && entity.__attachments.indexOf(attachmentName) !== -1) {
|
||||||
mp.events.callRemote("staticAttachments.Remove", attachmentName.toString(36));
|
mp.events.callRemote("staticAttachments.Remove", attachmentName.toString(36));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -205,160 +133,71 @@ export default function attachmentManager(game: IGame) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mp.events.add("entityStreamIn", (entityRage) => {
|
mp.events.add("entityStreamIn", (entity) => {
|
||||||
if (entityRage.type === "player" || entityRage.type === "vehicle") {
|
if (entity.__attMgrData) {
|
||||||
let entity;
|
const { targetEntity, bone, offset, rotation } = entity.__attMgrData;
|
||||||
|
|
||||||
if (entityRage.type === "player") {
|
entity.attachTo(
|
||||||
entity = game.players.at(entityRage.remoteId);
|
targetEntity, bone,
|
||||||
} else if (entityRage.type === "vehicle") {
|
offset.x, offset.y, offset.z,
|
||||||
entity = game.vehicles.at(entityRage.remoteId);
|
rotation.x, rotation.y, rotation.z,
|
||||||
}
|
false, false, false, false, 2, true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (entityRage.tye === "object") { //if is object
|
if (entity.__attachments) {
|
||||||
game.wait(200);
|
attachmentMngr.initFor(entity);
|
||||||
|
|
||||||
mp.gui.chat.push("object streamed");
|
|
||||||
entity = game.objects.at(entityRage.remoteId);
|
|
||||||
|
|
||||||
game.wait(200);
|
|
||||||
mp.gui.chat.push("object try get data");
|
|
||||||
game.wait(200);
|
|
||||||
|
|
||||||
|
|
||||||
const { targetEntity, bone, offset, rotation } = entity.__attachmentData;
|
|
||||||
game.wait(200);
|
|
||||||
|
|
||||||
+
|
|
||||||
mp.gui.chat.push(targetEntity + "," + bone + "," + offset + "," + rotation);
|
|
||||||
game.wait(200);
|
|
||||||
|
|
||||||
|
|
||||||
entity.attachTo(
|
|
||||||
targetEntity, bone,
|
|
||||||
offset.x, offset.y, offset.z,
|
|
||||||
rotation.x, rotation.y, rotation.z,
|
|
||||||
false, false, false, false, 2, true
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let e = game.attachments.get(entity); //if player or vehicle
|
|
||||||
if (e != null) {
|
|
||||||
if (e.__attachments) {
|
|
||||||
attachmentMngr.initFor(entityRage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mp.events.add("entityStreamOut", (entityRage) => {
|
mp.events.add("entityStreamOut", (entity) => {
|
||||||
if (entityRage == mp.players.local.vehicle) {
|
if (entity.__attachmentObjects) {
|
||||||
return;
|
attachmentMngr.shutdownFor(entity);
|
||||||
}
|
|
||||||
if (entityRage.type === "player" || entityRage.type === "vehicle") {
|
|
||||||
let e = game.attachments.at(entityRage.remoteId);
|
|
||||||
|
|
||||||
if (e != null) {
|
|
||||||
if (e.__attachmentObjects) {
|
|
||||||
//game.wait(2500);
|
|
||||||
attachmentMngr.shutdownFor(entityRage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mp.events.addDataHandler("attachmentsData", (entityRage, data) => {
|
mp.events.addDataHandler("attachmentsData", (entity, data) => {
|
||||||
let newAttachments = (data != null) ? data.split('|').map(att => parseInt(att, 36)) : [];
|
let newAttachments = (data.length > 0) ? data.split('|').map(att => parseInt(att, 36)) : [];
|
||||||
|
|
||||||
if (entityRage.handle !== 0) {
|
if (entity.handle !== 0) {
|
||||||
let entity;
|
let oldAttachments = entity.__attachments;
|
||||||
if (entityRage.type === "player") {
|
|
||||||
entity = game.players.at(entityRage.remoteId);
|
|
||||||
} else if (entityRage.type === "vehicle") {
|
|
||||||
entity = game.vehicles.at(entityRage.remoteId);
|
|
||||||
}
|
|
||||||
let e = game.attachments.get(entity);
|
|
||||||
if (e == null) {
|
|
||||||
let __attachments = [];
|
|
||||||
let __attachmentObjects = [];
|
|
||||||
e = game.attachments.set(entity, __attachments, __attachmentObjects);
|
|
||||||
}
|
|
||||||
|
|
||||||
let oldAttachments = e.__attachments;
|
|
||||||
|
|
||||||
if (!oldAttachments) {
|
if (!oldAttachments) {
|
||||||
oldAttachments = [];
|
oldAttachments = [];
|
||||||
e.__attachmentObjects = [];
|
entity.__attachmentObjects = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// process outdated first
|
// process outdated first
|
||||||
for (let attachment of oldAttachments.keys()) {
|
for (let attachment of oldAttachments) {
|
||||||
var obj = oldAttachments[attachment];
|
if (newAttachments.indexOf(attachment) === -1) {
|
||||||
if (newAttachments.indexOf(obj) === -1) {
|
attachmentMngr.removeFor(entity, attachment);
|
||||||
attachmentMngr.removeFor(entityRage, obj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// then new attachments
|
// then new attachments
|
||||||
for (let attachment of newAttachments) {
|
for (let attachment of newAttachments) {
|
||||||
if (oldAttachments.indexOf(attachment) === -1) {
|
if (oldAttachments.indexOf(attachment) === -1) {
|
||||||
attachmentMngr.addFor(entityRage, attachment);
|
attachmentMngr.addFor(entity, attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.__attachments = newAttachments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entity.__attachments = newAttachments;
|
||||||
});
|
});
|
||||||
|
|
||||||
function InitAttachmentsOnJoin() {
|
function InitAttachmentsOnJoin() {
|
||||||
game.players.forEach(_player => {
|
mp.players.forEach(_player => {
|
||||||
let player = mp.players.at(_player.remoteId);
|
let data = _player.getVariable("attachmentsData");
|
||||||
|
|
||||||
if (!player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let e = game.attachments.get(_player);
|
|
||||||
if (e == null) {
|
|
||||||
let __attachments = [];
|
|
||||||
let __attachmentObjects = [];
|
|
||||||
e = game.attachments.set(_player, __attachments, __attachmentObjects);
|
|
||||||
}
|
|
||||||
let data = player.getVariable("attachmentsData");
|
|
||||||
|
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
let atts = data.split('|').map(att => parseInt(att, 36));
|
let atts = data.split('|').map(att => parseInt(att, 36));
|
||||||
e.__attachments = atts;
|
_player.__attachments = atts;
|
||||||
e.__attachmentObjects = [];
|
_player.__attachmentObjects = {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
game.vehicles.forEach(_veh => {
|
|
||||||
let vehicle = mp.vehicles.at(_veh.remoteId);
|
|
||||||
|
|
||||||
if (!vehicle) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let e = game.attachments.get(_veh);
|
|
||||||
if (e == null) {
|
|
||||||
let __attachments = [];
|
|
||||||
let __attachmentObjects = [];
|
|
||||||
e = game.attachments.set(_veh, __attachments, __attachmentObjects);
|
|
||||||
}
|
|
||||||
let data = vehicle.getVariable("attachmentsData");
|
|
||||||
|
|
||||||
if (data && data.length > 0) {
|
|
||||||
let atts = data.split('|').map(att => parseInt(att, 36));
|
|
||||||
e.__attachments = atts;
|
|
||||||
e.__attachmentObjects = [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
mp.events.add("playerReady", () => { //player finished doenloading assets from server.
|
|
||||||
|
mp.events.add("playerReady", () => {
|
||||||
InitAttachmentsOnJoin();
|
InitAttachmentsOnJoin();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user