Refactor Code in RefuseCollector.ts

This commit is contained in:
2021-04-05 15:32:48 +02:00
parent 53f46d28c8
commit 8043f3c35b
2 changed files with 104 additions and 104 deletions

View File

@@ -1,20 +1,19 @@
export default function RefuseCollector() {
var State = false;
var Traegt = false;
var HintenVoll = false;
var hasBinBag = false;
var dumptruckIsFull = false;
var BlipTonneHinten = null;
var CheckpointTonneHinten = null;
var ShapeTonneHinten = null;
var BlipTonneBase = null;
var CheckpointTonneBase = null;
var ShapeTonneBase = null;
var blipDumptruck = null;
var dumptruckMarker = null;
var colshapeDumptruck = null;
var blipBase = null;
var markerBase = null;
var colshapeBase = null;
var vehicle = null;
var interval = null;
var BlipTonne = [];
var ShapeTonne = [];
var garbageToCollect = new Map<BlipMp, ColshapeMp>();
mp.events.add('SERVER:MuellmannStatusTrue', () => {
State = true;
@@ -29,53 +28,61 @@
vehicle = veh;
for (var i = 0; i < posArr.length; i++) {
let pos = new mp.Vector3(posArr[i].x, posArr[i].y, posArr[i].z - 1)
BlipTonne.push(mp.blips.new(1, new mp.Vector3(pos.x, pos.y, 1000), { name: 'Mülltonne', color: 45, shortRange: false }));
BlipTonne[i].setFlashTimer(2000);
ShapeTonne.push(mp.colshapes.newSphere(posArr[i].x, posArr[i].y, posArr[i].z + 0.5, 1.75));
let newBlip = mp.blips.new(1, new mp.Vector3(pos.x, pos.y, 1000), { name: 'Mülltonne', color: 45, shortRange: false });
let newColShape = mp.colshapes.newSphere(posArr[i].x, posArr[i].y, posArr[i].z + 0.5, 1.75);
newBlip.setFlashTimer(2000);
garbageToCollect.set(newBlip, newColShape);
}
BlipTonneBase = mp.blips.new(1, new mp.Vector3(-442.3999, -1701.5234, 18.933002 - 1), { name: 'Recylinganlage', color: 5, shortRange: false });
CheckpointTonneBase = mp.markers.new(1, new mp.Vector3(-442.3999, -1701.5234, 18.933002 - 1), 10, { direction: new mp.Vector3(-235.5747, -1685.475, 32.7207), color: [255, 255, 0, 150], visible: true, dimension: 0 });
ShapeTonneBase = mp.colshapes.newSphere(-442.3999, -1701.5234, 18.933002 - 1, 10);
blipBase = mp.blips.new(1, new mp.Vector3(-442.3999, -1701.5234, 18.933002 - 1), { name: 'Recylinganlage', color: 5, shortRange: false });
markerBase = mp.markers.new(1, new mp.Vector3(-442.3999, -1701.5234, 18.933002 - 1), 10, { direction: new mp.Vector3(-235.5747, -1685.475, 32.7207), color: [255, 255, 0, 150], visible: true, dimension: 0 });
colshapeBase = mp.colshapes.newSphere(-442.3999, -1701.5234, 18.933002 - 1, 10);
});
mp.events.add('SERVER:MuellmannBCSEntfernen', () => {
for (var i = 0; i < BlipTonne.length; i++) {
if (BlipTonne[i] == null) continue;
if (ShapeTonne[i] == null) continue;
BlipTonne[i].destroy();
ShapeTonne[i].destroy();
}
BlipTonne = [];
ShapeTonne = [];
if (BlipTonneHinten) BlipTonneHinten.destroy();
BlipTonneHinten = null;
if (CheckpointTonneHinten) CheckpointTonneHinten.destroy();
CheckpointTonneHinten = null;
if (ShapeTonneHinten) ShapeTonneHinten.destroy();
ShapeTonneHinten = null;
if (BlipTonneBase) BlipTonneBase.destroy();
BlipTonneBase = null;
if (CheckpointTonneBase) CheckpointTonneBase.destroy();
CheckpointTonneBase = null;
if (ShapeTonneBase) ShapeTonneBase.destroy();
ShapeTonneBase = null;
Traegt = false;
garbageToCollect.forEach((colshape, blip) => {
if (colshape)
colshape.destroy();
if (blip)
blip.destroy();
});
mp.events.add("playerEnterColshape", (Shape, player) => {
garbageToCollect.clear();
if (blipDumptruck) blipDumptruck.destroy();
blipDumptruck = null;
if (dumptruckMarker) dumptruckMarker.destroy();
dumptruckMarker = null;
if (colshapeDumptruck) colshapeDumptruck.destroy();
colshapeDumptruck = null;
if (blipBase) blipBase.destroy();
blipBase = null;
if (markerBase) markerBase.destroy();
markerBase = null;
if (colshapeBase) colshapeBase.destroy();
colshapeBase = null;
hasBinBag = false;
});
mp.events.add("playerEnterColshape", (currentShape, player) => {
//mp.events.callRemote('CLIENT:ImShape', JSON.stringify(Shape));
for (var i = 0; i < ShapeTonne.length; i++) {
if (Shape != ShapeTonne[i]) continue;
if (!mp.players.local.vehicle) {
if (!Traegt) {
if (!HintenVoll) {
mp.events.callRemote('CLIENT:MuellmannImShape', i);
Traegt = true;
BlipTonne[i].destroy();
BlipTonne[i] = null;
ShapeTonne[i].destroy();
ShapeTonne[i] = null;
garbageToCollect.forEach((colshape, blip) => {
if (!colshape || colshape != currentShape) 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 (!dumptruckIsFull) {
mp.events.callRemote('CLIENT:MuellmannImShape', JSON.stringify(blip));
hasBinBag = true;
if (colshape)
colshape.destroy();
if (blip)
blip.destroy();
interval = setInterval(function () { createMarker(); }, 2);
}
@@ -83,50 +90,47 @@
mp.gui.chat.push("Der Müllwagen ist bereits voll! Fahre zur Base und lade ab!");
return;
}
}
else {
mp.gui.chat.push(`Du trägst bereits einen Müllsack!`);
return;
}
}
else {
mp.events.call("renderTextOnScreen", "Steige aus dem Müllwagen aus um den Müllsack zu entnehmen.");
}
}
if (Shape == ShapeTonneHinten) {
if (Traegt) {
Traegt = false;
});
if (currentShape == colshapeDumptruck) {
if (!hasBinBag) {
hasBinBag = false;
mp.events.callRemote('CLIENT:MuellmannAddSack');
clearInterval(interval);
if (BlipTonneHinten) BlipTonneHinten.destroy();
BlipTonneHinten = null;
if (CheckpointTonneHinten) CheckpointTonneHinten.destroy();
CheckpointTonneHinten = null;
if (ShapeTonneHinten) ShapeTonneHinten.destroy();
ShapeTonneHinten = null;
if (blipDumptruck) blipDumptruck.destroy();
blipDumptruck = null;
if (dumptruckMarker) dumptruckMarker.destroy();
dumptruckMarker = null;
if (colshapeDumptruck) colshapeDumptruck.destroy();
colshapeDumptruck = null;
}
}
else if (Shape == ShapeTonneBase) {
BlipTonneBase.setRoute(false);
else if (currentShape == colshapeBase) {
blipBase.setRoute(false);
mp.events.callRemote('CLIENT:MuellmannBaseSack');
HintenVoll = false;
dumptruckIsFull = false;
}
});
mp.events.add("MuellmannUpdateColshape", (index) => {
if (BlipTonne[index] != null)
BlipTonne[index].destroy();
BlipTonne[index] = null;
if (ShapeTonne[index] != null)
ShapeTonne[index].destroy();
ShapeTonne[index] = null;
mp.events.add("MuellmannUpdateColshape", (jsonIdentifier) => {
var blip = JSON.parse(jsonIdentifier);
if (!garbageToCollect.has(blip)) return;
var colShape = garbageToCollect.get(blip);
if (blip)
blip.destroy();
if (colShape)
colShape.destroy();
garbageToCollect.delete(blip);
});
mp.events.add("SERVER:MuellmannZuBase", () => {
BlipTonneBase.setRoute(true);
BlipTonneBase.setRouteColour(5);
HintenVoll = true;
blipBase.setRoute(true);
blipBase.setRouteColour(5);
dumptruckIsFull = true;
});
function createMarker() {
@@ -154,15 +158,15 @@
let pos = plateVec.add(temp);
if (BlipTonneHinten) BlipTonneHinten.destroy();
BlipTonneHinten = null;
if (CheckpointTonneHinten) CheckpointTonneHinten.destroy();
CheckpointTonneHinten = null;
if (ShapeTonneHinten) ShapeTonneHinten.destroy();
ShapeTonneHinten = null;
BlipTonneHinten = mp.blips.new(318, pos, { name: 'Müllmann', color: 24, shortRange: false });
CheckpointTonneHinten = mp.markers.new(1, pos, 1, { direction: new mp.Vector3(-235.5747, -1685.475, 32.7207), color: [0, 255, 0, 255], visible: true, dimension: 0 });
ShapeTonneHinten = mp.colshapes.newSphere(pos.x, pos.y, pos.z, 2);
if (blipDumptruck) blipDumptruck.destroy();
blipDumptruck = null;
if (dumptruckMarker) dumptruckMarker.destroy();
dumptruckMarker = null;
if (colshapeDumptruck) colshapeDumptruck.destroy();
colshapeDumptruck = null;
blipDumptruck = mp.blips.new(318, pos, { name: 'Müllmann', color: 24, shortRange: false });
dumptruckMarker = mp.markers.new(1, pos, 1, { direction: new mp.Vector3(-235.5747, -1685.475, 32.7207), color: [0, 255, 0, 255], visible: true, dimension: 0 });
colshapeDumptruck = mp.colshapes.newSphere(pos.x, pos.y, pos.z, 2);
}
};
}

View File

@@ -19,7 +19,7 @@ namespace ReallifeGamemode.Server.Job
public override bool NeedVehicleToStart => false;
const int MAX_BAG = 40;
private const int MAX_BAG = 40;
public RefuseCollectorJob()
{
@@ -157,7 +157,6 @@ namespace ReallifeGamemode.Server.Job
new Vector3(-921.0493774414062, -1095.1513671875, 2.1503124237060547),
new Vector3(-942.0684204101562, -1077.1378173828125, 2.1503121852874756),
new Vector3(-951.5316772460938, -1078.955078125, 2.1503100395202637),
}.AsReadOnly();
[RemoteEvent("CLIENT:MuellmannJobStarten")]
@@ -165,7 +164,6 @@ namespace ReallifeGamemode.Server.Job
{
if (vehicle.Model == (uint)Types.VehicleModel.Trash || vehicle.Model == (uint)Types.VehicleModel.Trash2)
{
Vehicle veh;
foreach (var data in muellmanData)
{
@@ -192,7 +190,7 @@ namespace ReallifeGamemode.Server.Job
if (data.hasFreePlace())
{
if(data.vehicle != null)
if (data.vehicle != null)
data.vehicle.GetServerVehicle().Spawn(data.vehicle);
muellmanData.Remove(data);
return;
@@ -211,13 +209,13 @@ namespace ReallifeGamemode.Server.Job
}
[RemoteEvent("CLIENT:MuellmannImShape")]
public void MuellmannImShape(Player player, int colshapeIndex)
public void MuellmannImShape(Player player, string jsonIdentifier)
{
foreach (var data in muellmanData)
{
if (data.getDataFromClient(player) == null) continue;
Player target = data.getPartnerClient(player);
if (target != null) target.TriggerEvent("MuellmannUpdateColshape", colshapeIndex);
if (target != null) target.TriggerEvent("MuellmannUpdateColshape", jsonIdentifier);
player.TriggerEvent("renderTextOnScreen", "Wirf den Müllsack in den Müllwagen.");
player.AddAttachment("binbag", false);
return;
@@ -260,19 +258,17 @@ namespace ReallifeGamemode.Server.Job
}
player.TriggerEvent("SERVER:MuellmannZuBase");
}
else if(data.getTrashCount() > MAX_BAG)
else if (data.getTrashCount() > MAX_BAG)
{
data.setTrashCount(MAX_BAG);
ChatService.ErrorMessage((Player)player, "Der Müllwagen ist schon voll.");
}
else
{
if (target != null)
{
user1.Wage += 25;
user2.Wage += 25;
}
else
{