Hi there,
I have a problem with my script for temporary cars. After leaving them, they should be gone and it's working fine, but when someone else create other temporary car, previous one doesn't disappear. I think that I must use tables, but I don't understand them. The tutorials aren't helping me. Here is the code:
function cmd_veh(plr, cmd, ...)
local vehicleName = table.concat({...}, " ")
local vehicleID = getVehicleModelFromName(vehicleName)
local x, y, z = getElementPosition(plr)
if isPedInVehicle(plr) then
outputChatBox ("#C80000✖ #E7D9B0Get out of the vehicle first.", plr, 255, 255, 255, true)
return end
if vehicleID then
newVehicle = createVehicle (vehicleID, x, y, z, 0, 0, 0)
warpPedIntoVehicle(plr, newVehicle)
outputChatBox ("#04B404✔ #E7D9B0You created a temporary vehicle named " .. vehicleName .. "#E7D9B0.", plr, 255, 255, 255, true)
end
end
addCommandHandler("veh", cmd_veh)
function deleteTempVeh(plr, seat, jacked)
if not (newVehicle) then return end
if (newVehicle) then
destroyElement(newVehicle)
end
end
addEventHandler("onVehicleExit", getRootElement(), deleteTempVeh)