export default function RefuseCollector() { var State = false; var hasBinBag = false; var dumptruckIsFull = false; var blipDumptruck = null; var dumptruckMarker = null; var colshapeDumptruck = null; var blipBase = null; var markerBase = null; var colshapeBase = null; var vehRemoteID = null; var interval = null; var garbageToCollect = new Map(); mp.events.add('SERVER:MuellmannStatusTrue', () => { State = true; }); mp.events.add('SERVER:MuellmannStatusFalse', () => { State = false; }); mp.events.add('SERVER:MuellmannBCSErstellen', (jsonPosArr, veh: VehicleMp) => { let posArr = JSON.parse(jsonPosArr); vehRemoteID = veh.remoteId; for (var i = 0; i < posArr.length; i++) { let pos = new mp.Vector3(posArr[i].x, posArr[i].y, posArr[i].z - 1) 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); } 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', () => { garbageToCollect.forEach((colshape, blip) => { if (colshape && mp.colshapes.exists(colshape)) colshape.destroy(); if (blip && mp.blips.exists(blip)) blip.destroy(); }); 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)); 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', blip.getCoords()); hasBinBag = true; if (colshape) colshape.destroy(); if (blip) blip.destroy(); interval = setInterval(function () { createMarker(); }, 2); } else { mp.gui.chat.push("Der Müllwagen ist bereits voll! Fahre zur Base und lade ab!"); return; } }); mp.gui.chat.push("test"); if (currentShape == colshapeDumptruck) { if (!hasBinBag) { hasBinBag = false; mp.events.callRemote('CLIENT:MuellmannAddSack'); clearInterval(interval); if (blipDumptruck) blipDumptruck.destroy(); blipDumptruck = null; if (dumptruckMarker) dumptruckMarker.destroy(); dumptruckMarker = null; if (colshapeDumptruck) colshapeDumptruck.destroy(); colshapeDumptruck = null; } } else if (currentShape == colshapeBase) { blipBase.setRoute(false); mp.events.callRemote('CLIENT:MuellmannBaseSack'); dumptruckIsFull = false; } }); mp.events.add("MuellmannUpdateColshape", (vector3) => { let currBlip; garbageToCollect.forEach((colShape, blip) => { if (blip.getCoords == vector3) currBlip = blip; }); if (!garbageToCollect.has(currBlip)) return; var colShape = garbageToCollect.get(currBlip); if (currBlip && mp.blips.exists(currBlip)) currBlip.destroy(); if (colShape && mp.colshapes.exists(colShape)) colShape.destroy(); garbageToCollect.delete(currBlip); }); mp.events.add("SERVER:MuellmannZuBase", () => { blipBase.setRoute(true); blipBase.setRouteColour(5); dumptruckIsFull = true; }); function createMarker() { let vehicle; if (vehRemoteID) vehicle = mp.vehicles.atRemoteId(vehRemoteID); if (vehicle != null) { var boneIndex2 = vehicle.getBoneIndexByName("platelight"); var boneIndex1 = vehicle.getBoneIndexByName("chassis_dummy"); let posPlate = vehicle.getWorldPositionOfBone(boneIndex2); let posCentre = vehicle.getWorldPositionOfBone(boneIndex1); let plateVec = new mp.Vector3(posPlate.x, posPlate.y, posPlate.z); let lightVec = new mp.Vector3(posCentre.x, posCentre.y, posCentre.z); let posPL = lightVec.subtract(plateVec); let temp = new mp.Vector3(posPL.x * -1, posPL.y * -1, posPL.z * -1) let length = Math.sqrt((temp.x * temp.x) + (temp.y * temp.y) + (temp.z * temp.z)); let x = temp.x / length; let y = temp.y / length; let z = temp.z / length; temp = new mp.Vector3(x, y, z - 1); let pos = plateVec.add(temp); 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); } }; }