Jump to content

lilwayn

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by lilwayn

  1. local theVehicles = {} local spamTick = 0 function findVehsToRob(player) local vehicle = getNearestElement(player, "vehicle", 100) if (getTickCount() - spamTick < 100000) then outputChatBox("You are robbing a vehicle already", player, 255, 0, 0) return false end spamTick = getTickCount() if (vehicle) then local x, y, z = getElementPosition(vehicle) local rx, ry, rz = getElementRotation(vehicle) local model = getElementModel(vehicle) robVeh = createVehicle(model, x, y, z) destroyElement(vehicle) setElementRotation(robVeh, rx, ry, rz) setVehicleLocked(robVeh, true) theVehicles[#theVehicles + 1] = robVeh outputChatBox("You're attempting to steal this vehicle, complete your tasks !", player, 0, 128, 0) triggerClientEvent(player, "sendTableToClient", player, theVehicles) addEventHandler("onVehicleStartEnter", robVeh, startRobbery) addEventHandler("onVehicleEnter", robVeh, taskOnEnter) else outputChatBox("There is no nearby vehicle to steal", player, 255, 255, 255) end end addCommandHandler("robvehicle", findVehsToRob) How to edit this code so when the player types the command once again, he stops robbing the vehicle? idk what is the check that checks if the player has typed the command once again.
  2. I’ve tried already, but it says always in the addEventHandler that it requires an element and it got nil
  3. Hello thank you guys for assisting me, it's now working Sorry for being a bit inquirer. I'm facing another thing, i did find a solution for it tho but it's not very good. Lemme show you local helic = {} function startM() if (not isElement(source) and getElementType(source) == "player") then return false end if (not isPedInVehicle(source)) then return false end local heli = createVehicle(501, 2625.53247, 733.39642, 10.82031) table.insert(helic, heli) warpPedIntoVehicle(source, heli) setElementAlpha(source, 0) bindKey(source, "h", "down", attachBomb) for i, k in ipairs(Bombs) do Bomb1[i] = createObject(1654, Bombs[i][1], Bombs[i][2], Bombs[i][3] - 0.5) Bomb2[i] = Bomb1[i] setElementCollisionsEnabled(Bomb1[i], false) end addEventHandler("onVehicleExit", heli, onExit) ---triggerClientEvent(source, "clientPed", source, startM) end addEvent("startMission", true) addEventHandler("startMission", root, startM) function onHit(player) if (#m > 0 and #b > 0) then destroyElement(m[1]) destroyElement(b[1]) table.remove(m, 1) table.remove(b, 1) end if (not helic[1]) then return false end local lmnt = getAttachedElements(helic[1]) if (not lmnt) then return false end for i, k in ipairs(lmnt) do if (getElementType(lmnt[i]) == "object" and isElementAttached(lmnt[i])) then detachElements(lmnt[i], helic[1]) plantedBombs = plantedBombs + 1 if (plantedBombs == 1) then outputChatBox("Congratulations, you have passed the mission and got $50,000 as a reward!", root, 34, 139, 34) else outputChatBox("Bomb has been successfully installed, Do the same with the rest!", root, 34, 139, 34) outputChatBox(plantedBombs) end end end triggerClientEvent(player, "updatePlantedBombs", root, plantedBombs) if (plantedBombs == 1) then triggerEvent("stopMission", root, onHit) triggerClientEvent(resourceRoot, "stopM", resourceRoot, onHit) end end I've created a vehicle inside a function, if i knew from the start how to use the variable in other functions when it's inside a function, i wouldn't add it inside a table, i wanna use sometimes the vehicle is client but sadly i couldn't. Can anyone tell me what should i exactly do (Please dont tell me to put the variable global, as i dont want to cause setting it as global will create the vehicle once when the resource start and i dont wanna that) Also, the getAttachedElements(helic[1]) is sending a warning saying that it requires an argument. i guess it's because i'm using helic[1] as an argument. Help me, please. i'm new into lua and i wanna create my first working script
  4. Hello, i've tried your idea. When i printed the variable in server, it worked completely fine, but in client it doesnt seem to be working as everytime i try printing it keeps giving me a 0 I've added this in shared.lua plantedBombs = 0 this in server.lua function onHit(player) if (#m > 0 and #b > 0) then destroyElement(m[1]) destroyElement(b[1]) table.remove(m, 1) table.remove(b, 1) end for i, k in ipairs(Bomb2) do if (isElementAttached(Bomb2[i])) then detachElements(Bomb2[i], helic[1]) plantedBombs = plantedBombs + 1 outputChatBox("Bomb has been successfully installed, Do the same with the rest!", root, 34, 139, 34) outputChatBox(plantedBombs) ---- This returns what it should return end end if (plantedBombs == 5) then triggerEvent("stopMission", root, onHit) givePlayerMoney(player, 50000) outputChatBox("Congratulations, you have passed the mission and got $50,000 as a reward!", root, 34, 139, 34) end end This in client.lua function renderTimer() local white = tocolor(255, 255, 255, 255) if (isTimer(startTimer)) then local remaining = getTimerDetails(startTimer) local remaining = remaining / 1000 outputChatBox(plantedBombs) ---- Keeps printing a zero dxDrawText("Delievered Bombs : "..plantedBombs.."", 1162, 654, screenW, 711, white, 1.3, "default-bold", "right", "bottom") dxDrawText("Time Remaining : "..math.floor(remaining / 60)..":"..math.floor(remaining % 60).."", 1228, 725, screenW, 740, white, 1.3, "default-bold", "right", "bottom") end end Any solution?
  5. Hello @alex17" thanks for replying back. I've fixed that problem, but i'm facing another issue. I wanna know how to trigger a variable from server to client, i tried alot but i couldnt make it working. is there any solution for that?
  6. I'm confused about something, how to add the vehicle in the event handler argument when the vehicle is created inside another function? Cause whenever I type the vehicle’s variable name, it returns that it doesnt exist.
×
×
  • Create New...