Fix Job RefuseCollector Client Side

This commit is contained in:
2021-04-05 17:17:18 +02:00
parent 492154e3ec
commit 2ddeb289f4
2 changed files with 32 additions and 25 deletions

View File

@@ -13,7 +13,7 @@
var interval = null; var interval = null;
var garbageToCollect = new Map<BlipMp, ColshapeMp>(); var garbageToCollect = new Map<number, { blip: BlipMp, colshape: ColshapeMp }>();
mp.events.add('SERVER:MuellmannStatusTrue', () => { mp.events.add('SERVER:MuellmannStatusTrue', () => {
State = true; State = true;
@@ -34,7 +34,7 @@
newBlip.setFlashTimer(2000); newBlip.setFlashTimer(2000);
garbageToCollect.set(newBlip, newColShape); garbageToCollect.set(i, { blip: newBlip, colshape: newColShape });
} }
blipBase = mp.blips.new(1, new mp.Vector3(-442.3999, -1701.5234, 18.933002 - 1), { name: 'Recylinganlage', color: 5, shortRange: false }); blipBase = mp.blips.new(1, new mp.Vector3(-442.3999, -1701.5234, 18.933002 - 1), { name: 'Recylinganlage', color: 5, shortRange: false });
@@ -42,7 +42,9 @@
colshapeBase = mp.colshapes.newSphere(-442.3999, -1701.5234, 18.933002 - 1, 10); colshapeBase = mp.colshapes.newSphere(-442.3999, -1701.5234, 18.933002 - 1, 10);
}); });
mp.events.add('SERVER:MuellmannBCSEntfernen', () => { mp.events.add('SERVER:MuellmannBCSEntfernen', () => {
garbageToCollect.forEach((colshape, blip) => { garbageToCollect.forEach((collection, index) => {
let { blip, colshape } = collection;
if (colshape && mp.colshapes.exists(colshape)) if (colshape && mp.colshapes.exists(colshape))
colshape.destroy(); colshape.destroy();
if (blip && mp.blips.exists(blip)) if (blip && mp.blips.exists(blip))
@@ -69,14 +71,16 @@
mp.events.add("playerEnterColshape", (currentShape, player) => { mp.events.add("playerEnterColshape", (currentShape, player) => {
//mp.events.callRemote('CLIENT:ImShape', JSON.stringify(Shape)); //mp.events.callRemote('CLIENT:ImShape', JSON.stringify(Shape));
garbageToCollect.forEach((colshape, blip) => { let i = getIndex(currentShape);
if (!colshape || colshape != currentShape) { return; }
if (garbageToCollect.has(i)) {
let { blip, colshape } = garbageToCollect.get(i);
if (mp.players.local.vehicle) { mp.events.call("renderTextOnScreen", "Steige aus dem Müllwagen aus um den Müllsack zu entnehmen."); return; } if (mp.players.local.vehicle) { mp.events.call("renderTextOnScreen", "Steige aus dem Müllwagen aus um den Müllsack zu entnehmen."); return; }
if (hasBinBag) { mp.gui.chat.push("Du trägst bereits einen Müllsack!"); return; } if (hasBinBag) { mp.gui.chat.push("Du trägst bereits einen Müllsack!"); return; }
if (!dumptruckIsFull) { if (!dumptruckIsFull) {
mp.events.callRemote('CLIENT:MuellmannImShape', blip.getCoords()); mp.events.callRemote('CLIENT:MuellmannImShape', i);
hasBinBag = true; hasBinBag = true;
if (colshape) if (colshape)
@@ -84,13 +88,15 @@
if (blip) if (blip)
blip.destroy(); blip.destroy();
garbageToCollect.delete(i);
interval = setInterval(function () { createMarker(); }, 2); interval = setInterval(function () { createMarker(); }, 2);
} }
else { else {
mp.gui.chat.push("Der Müllwagen ist bereits voll! Fahre zur Base und lade ab!"); mp.gui.chat.push("Der Müllwagen ist bereits voll! Fahre zur Base und lade ab!");
return; return;
} }
}); }
if (currentShape == colshapeDumptruck) { if (currentShape == colshapeDumptruck) {
if (hasBinBag) { if (hasBinBag) {
@@ -113,28 +119,20 @@
dumptruckIsFull = false; dumptruckIsFull = false;
} }
}); });
mp.events.add("MuellmannUpdateColshape", (vector3) => { mp.events.add("MuellmannUpdateColshape", (index) => {
let currBlip; if (!garbageToCollect.has(index)) return;
garbageToCollect.forEach((colShape, blip) => {
if (blip.getCoords() == vector3) currBlip = blip;
});
if (!garbageToCollect.has(currBlip)) return; let { blip, colshape } = garbageToCollect.get(index);
mp.gui.chat.push("Has Blip.");
var colShape = garbageToCollect.get(currBlip); if (blip && mp.blips.exists(blip)) {
blip.destroy();
if (currBlip && mp.blips.exists(currBlip)) {
mp.gui.chat.push("Delete Blip.");
currBlip.destroy();
} }
if (colShape && mp.colshapes.exists(colShape)) { if (colshape && mp.colshapes.exists(colshape)) {
mp.gui.chat.push("Delete Colshape."); colshape.destroy();
colShape.destroy();
} }
garbageToCollect.delete(currBlip); garbageToCollect.delete(index);
}); });
mp.events.add("SERVER:MuellmannZuBase", () => { mp.events.add("SERVER:MuellmannZuBase", () => {
@@ -143,6 +141,15 @@
dumptruckIsFull = true; dumptruckIsFull = true;
}); });
function getIndex(shape: ColshapeMp): number {
let i = -1;
garbageToCollect.forEach((collection, index) => {
let { blip, colshape } = collection;
if (shape == colshape) i = index;
});
return i;
}
function createMarker() { function createMarker() {
let vehicle; let vehicle;
if (vehRemoteID) if (vehRemoteID)

View File

@@ -209,13 +209,13 @@ namespace ReallifeGamemode.Server.Job
} }
[RemoteEvent("CLIENT:MuellmannImShape")] [RemoteEvent("CLIENT:MuellmannImShape")]
public void MuellmannImShape(Player player, Vector3 blipCoords) public void MuellmannImShape(Player player, int index)
{ {
foreach (var data in muellmanData) foreach (var data in muellmanData)
{ {
if (data.getDataFromClient(player) == null) continue; if (data.getDataFromClient(player) == null) continue;
Player target = data.getPartnerClient(player); Player target = data.getPartnerClient(player);
if (target != null) target.TriggerEvent("MuellmannUpdateColshape", blipCoords); if (target != null) target.TriggerEvent("MuellmannUpdateColshape", index);
player.TriggerEvent("renderTextOnScreen", "Wirf den Müllsack in den Müllwagen."); player.TriggerEvent("renderTextOnScreen", "Wirf den Müllsack in den Müllwagen.");
player.AddAttachment("binbag", false); player.AddAttachment("binbag", false);
return; return;