kewizzle Posted June 17, 2022 Share Posted June 17, 2022 This script is nearly complete works great but there are some bugs, just wanna see if anyone can point out why it spawns multiple elements each time i complete the warehouse, ill complete it once it spawns 1 truck then the second time it spawns 2 trucks. Also any improvement ideas would be nice. Client: warehouseR = createRadarArea ( 2535, 2795, 80, 50, 255, 0, 0, 75) warehouseCol = createColRectangle ( 2535, 2795, 80, 50 ) createBlip ( 2577, 2820, 11, 22 ) gpt = getElementData(localPlayer, "timer") local screenW, screenH = guiGetScreenSize() timerT = guiCreateLabel((screenW - 600) / 2, (screenH - 52) / 2, 600, 52, "Defend Warehouse: 300", false) guiSetFont(timerT, "sa-gothic") guiLabelSetColor(timerT, 48, 218, 36) guiSetVisible(timerT, false) addEventHandler("onClientColShapeHit", warehouseCol, function(theElement) if isElementWithinColShape ( localPlayer, warehouseCol ) then setElementData(localPlayer, "timer", 300) guiSetVisible(timerT, true) theTimer = setTimer ( function ( ) gpt = getElementData(localPlayer, "timer") setElementData(localPlayer, "timer", gpt-1) guiSetText(timerT, "Defend Warehouse: "..gpt) end, 1000, 300 ) addEventHandler("onClientColShapeLeave", warehouseCol, function() killTimer(theTimer) setElementData(localPlayer, "timer", 300) guiSetText(timerT, "Defend Warehouse: "..gpt) guiSetVisible(timerT, false) end) addEventHandler("onClientElementDataChange", localPlayer, function() if getElementData(localPlayer, "timer") == -2 then outputChatBox ( "Deliver The Supply Truck!", 0, 255, 0 ) triggerServerEvent ( "spawnSupplies", localPlayer, "spawnSupplies" ) end end) end end) Server: function supplySpawn () supplytruck = createVehicle ( 498, 2525, 2810, 11.2, 0, 0, 180 ) warpPedIntoVehicle ( source, supplytruck) stb = createBlipAttachedTo ( supplytruck, 51, 2, 255, 0, 0, 255, 0, 65535 ) dropoff = createMarker(285.5, 2498.8000488281, 16.5, "cylinder", 10, 255, 0, 255, 255, source) dob = createBlipAttachedTo ( dropoff, 35, 2, 255, 0, 0, 255, 0, 65535, source ) addEventHandler("onMarkerHit", dropoff, function() if isElementWithinMarker ( supplytruck, dropoff ) then destroyElement(dropoff) destroyElement(supplytruck) destroyElement(stb) destroyElement(dob) outputChatBox ( "Supply Truck Delivered Successfully! Rewards Recieved!", thePlayer, 0, 255, 0 ) givePlayerMoney(root, math.random(1000,5000)) giveWeapon(root, math.random(1, 46), math.random(0,100)) giveWeapon(root, math.random(1, 46), math.random(0,100)) giveWeapon(root, math.random(1, 46), math.random(0,100)) end end) addEventHandler("onVehicleExplode", supplytruck, function() outputChatBox ( "Supply Truck Destroyed! MISSION FAILED!", thePlayer, 255, 0, 0 ) destroyElement(supplytruck) destroyElement(dropoff) destroyElement(stb) destroyElement(dob) end) end addEvent( "spawnSupplies", true ) addEventHandler( "spawnSupplies", root, supplySpawn ) Link to comment
Z4Zy Posted June 17, 2022 Share Posted June 17, 2022 (edited) I noticed that in client code, you added the event "onClientElementDataChange" inside "onClientColShapeHit" event. so, each time when player enter the colshape new "onClientElementDataChange" event is created. This will cause the trigger server event each time +1. Edited June 17, 2022 by Z4Zy Link to comment
kewizzle Posted June 17, 2022 Author Share Posted June 17, 2022 (edited) 6 hours ago, Z4Zy said: I noticed that in client code, you added the event "onClientElementDataChange" inside "onClientColShapeHit" event. so, each time when player enter the colshape new "onClientElementDataChange" event is created. This will cause the trigger server event each time +1. so i should removeEventHandler each time Edit actually i can probably just call that outside Edited June 17, 2022 by kewizzle Link to comment
kewizzle Posted June 17, 2022 Author Share Posted June 17, 2022 actually cancel this lol i found my old script i dont have to rewrite completely now HAHA Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now