update ragemp-c types for 1.1

This commit is contained in:
kookroach
2021-04-04 20:24:29 +02:00
parent f7423b24fc
commit 6ed6916f00
2 changed files with 71 additions and 225 deletions

View File

@@ -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;
} }

View File

@@ -16,121 +16,52 @@ export default function attachmentManager(game: IGame) {
{ {
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);
let object = mp.objects.new(attInfo.model, entity.position);
while (object.handle === 0) {
await mp.game.waitAsync(0);
}
var bone = (typeof (attInfo.boneName) === 'string') ? entityRage.getBoneIndexByName(attInfo.boneName) : entityRage.getBoneIndex(attInfo.boneName) object.__attMgrData = {
targetEntity: entity.handle,
let attachmentData = { bone: (typeof (attInfo.boneName) === 'string') ? entity.getBoneIndexByName(attInfo.boneName) : entity.getBoneIndex(attInfo.boneName),
targetEntity: entity.id,
bone: bone,
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) { 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 (e.__attachmentObjects.hasOwnProperty(id)) {
let obj = e.__attachmentObjects[id];
if (mp.objects.exists(obj)) {
obj.destroy(); obj.destroy();
delete e.__attachmentObjects[id];
}
},
initFor: function (entityRage) {
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 != null) {
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,
@@ -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,34 +133,9 @@ 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 = game.players.at(entityRage.remoteId);
} else if (entityRage.type === "vehicle") {
entity = game.vehicles.at(entityRage.remoteId);
}
if (entityRage.tye === "object") { //if is object
game.wait(200);
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( entity.attachTo(
targetEntity, bone, targetEntity, bone,
@@ -240,125 +143,61 @@ export default function attachmentManager(game: IGame) {
rotation.x, rotation.y, rotation.z, rotation.x, rotation.y, rotation.z,
false, false, false, false, 2, true false, false, false, false, 2, true
); );
return;
} }
let e = game.attachments.get(entity); //if player or vehicle if (entity.__attachments) {
if (e != null) { attachmentMngr.initFor(entity);
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); mp.events.add("playerReady", () => {
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.
InitAttachmentsOnJoin(); InitAttachmentsOnJoin();
}); });
} }