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