[+] Add Gangwar System (bugs incl.)

This commit is contained in:
Lukas Moungos
2020-01-13 21:43:55 +01:00
parent 3b0189807e
commit e8321e3ec3
10 changed files with 246 additions and 85 deletions

View File

@@ -56,12 +56,15 @@
_timerCheck;
edit: boolean;
attackBlip: BlipMp;
leaderBlip: BlipMp;
leaderBlipVector: Vector3Mp;
leaderColShape: MarkerMp;
constructor(name, id, x, y, range, color, rot, owner, edit) {
this._setup(name, id, x, y, range, color, rot, owner, edit);
constructor(name, id, x, y, range, color, rot, owner, edit, vector) {
this._setup(name, id, x, y, range, color, rot, owner, edit, vector);
}
_setup(name, id, x, y, range, color, rot, owner, edit) {
_setup(name, id, x, y, range, color, rot, owner, edit, vector) {
var self = this;
self.name = name;
@@ -82,6 +85,14 @@
self.edit = edit;
self.loadArea();
self.attackBlip = null;
self.leaderBlip = null;
if (vector != null) {
self.leaderBlipVector = JSON.parse(vector);
} else {
self.leaderBlipVector = null;
}
self.leaderColShape = null;
}
setColor(owner) {
@@ -133,6 +144,8 @@
}
if (self._status == "attack" || self.edit == true) {
if (self._colshape) {
if (mp.game.gameplay.getDistanceBetweenCoords(mp.players.local.position.x, mp.players.local.position.y, 0, self.x, self.y, 0, true) < self.range * 1.5) {
@@ -182,6 +195,8 @@
}
}
if (self.isInsideArea()) {
mp.game.graphics.drawText(self.name, [self.x, self.y, mp.players.local.position.z + 20], {
font: 7,
@@ -190,14 +205,49 @@
outline: true,
centre: true
});
}
}
}
if (self.leaderBlipVector != null) {
let dist = mp.game.gameplay.getDistanceBetweenCoords(mp.players.local.position.x, mp.players.local.position.y, mp.players.local.position.z, self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z, false);
if (self.isInsideArea() && self._status != "attack" && dist <= 3) {
if (self.leaderBlipVector != null) {
mp.game.graphics.drawText(self.name + "\n~y~Gang: ~s~" + self.owner + "\n~y~Wert: ~s~$~g~187", [self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z], {
font: 7,
color: [255, 255, 255, 185],
scale: [0.4, 0.4],
outline: true,
centre: true
});
}
}
}
}
private delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async startGangWar() {
var self = this;
await this.delay(1000);
if (self._status == "normal") {
let dist = mp.game.gameplay.getDistanceBetweenCoords(mp.players.local.position.x, mp.players.local.position.y, 0, self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z, false);
if (dist <= 3) {
mp.events.callRemote("SERVER:StartGangwar");
}
}
}
updateArea(status, ...args) {
var self = this;
if (status == "attack") {
if (self.leaderColShape != null) {
self.leaderColShape.destroy();
self.leaderColShape = null;
}
self._status = "attack";
self.attacker = args[1];
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, true);
@@ -216,6 +266,7 @@
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, false);
self.setColor(self.owner)
mp.game.invoke(Natives.SET_BLIP_COLOUR, self.blip, self.color);
self.setLeaderColShape();
return;
}
}
@@ -223,7 +274,7 @@
setAttackBlip(bool) {
var self = this;
if (bool) {
self.attackBlip = mp.game.ui.addBlipForRadius(self.x, self.y, 1, 60);
self.attackBlip = mp.game.ui.addBlipForCoord(self.x, self.y, 0);
mp.game.invoke(Natives.SET_BLIP_SPRITE, self.attackBlip, 378);
mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, self.attackBlip, false);
@@ -232,6 +283,36 @@
}
}
setLeaderBlip(bool) {
var self = this;
if (bool) {
self.leaderBlipVector = mp.players.local.position;
mp.events.callRemote("SERVER:Turf_SetNewLeaderPoint", JSON.stringify(self.leaderBlipVector), JSON.stringify(self.id));
self.setLeaderColShape();
return;
}
if (self.leaderBlipVector != null) {
self.leaderBlip = mp.game.ui.addBlipForRadius(self.leaderBlipVector.x, self.leaderBlipVector.y, 1, 60);
self.setLeaderColShape();
mp.game.invoke(Natives.SET_BLIP_SPRITE, self.leaderBlip, 437);
mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, self.leaderBlip, false);
}
}
setLeaderColShape() {
var self = this;
let newVector = new mp.Vector3(self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z - 2)
self.leaderColShape = mp.markers.new(1, newVector, 2, {
color: [255, 255, 255, 150],
visible: true,
dimension: 0
});
}
isTurfArea(shape) {
return (shape == this._colshape)
}
@@ -384,6 +465,11 @@
last_attackBlip = mp.game.invoke(Natives.GET_NEXT_BLIP_INFO_ID, 378);
}
let last_leaderBlip = mp.game.invoke(Natives.GET_FIRST_BLIP_INFO_ID, 437);
while (mp.game.invoke(Natives.DOES_BLIP_EXIST, last_leaderBlip)) {
mp.game.ui.removeBlip(last_leaderBlip);
last_leaderBlip = mp.game.invoke(Natives.GET_NEXT_BLIP_INFO_ID, 437);
}
}
mp.events.add('GangAreas:Create', (turfsJSON) => {
@@ -396,7 +482,7 @@
gangturfs = [];
turfs.forEach(function (turf) {
if (turf.Id != undefined) {
gangturfs[gangturfs.length] = new Gangturf(turf.Name, turf.Id, turf.X, turf.Y, turf.Range, turf.Color, turf.Rotation, turf.Owner, false);
gangturfs[gangturfs.length] = new Gangturf(turf.Name, turf.Id, turf.X, turf.Y, turf.Range, turf.Color, turf.Rotation, turf.Owner, false, turf.Vector);
}
});
}
@@ -404,7 +490,7 @@
mp.events.add('ADMIN:CreateTurf', (rangeJSON) => {
var range = JSON.parse(rangeJSON);
gangturfs[gangturfs.length] = new Gangturf("Reload For Name", -1, mp.players.local.position.x, mp.players.local.position.y, range, 0, mp.players.local.getHeading(), "Neutral", true);
gangturfs[gangturfs.length] = new Gangturf("Reload For Name", -1, mp.players.local.position.x, mp.players.local.position.y, range, 0, mp.players.local.getHeading(), "Neutral", true, null);
});
mp.events.add('ADMIN:SetTurf', (name) => {
@@ -446,5 +532,31 @@
});
});
mp.events.add('CLIENT:Turf_LoadLeaderBlip', () => {
gangturfs.forEach(function (turf) {
if (turf.Id != undefined) {
turf.setLeaderBlip(false);
}
});
});
mp.events.add('ADMIN:Turf_CreateLeaderBlip', () => {
gangturfs.forEach(function (turf) {
if (turf._entered == true) {
if (turf.leaderColShape != null) {
turf.leaderColShape.destroy();
turf.leaderColShape = null;
}
turf.setLeaderBlip(true);
}
});
});
mp.events.add('CLIENT:StartGangwar', () => {
gangturfs.forEach(function (turf) {
if (turf._entered == true) {
turf.startGangWar();
}
});
});
}