Destroyer.- Posted January 17, 2016 Share Posted January 17, 2016 Hi, sorry for my bad english,I have a problem with this function, keyless if it works, but with no keys go, here I show you the code Working function elvehiculo(thePlayer) local x, y, z = getElementPosition(thePlayer) veh = createVehicle(400, x + 2, y, z) end addCommandHandler("veh",elvehiculo) function Explosion(player) if isElement(veh) then destroyElement( veh) veh = nil end end addEventHandler("onVehicleExplode", getRootElement(), Explosion) Not Working local veh = {} function elvehiculo(thePlayer) local x, y, z = getElementPosition(thePlayer) veh[thePlayer] = createVehicle(400, x + 2, y, z) end addCommandHandler("veh",elvehiculo) function Explosion(player) if isElement(veh[source]) then destroyElement( veh[source] ) veh[source] = nil end end addEventHandler("onVehicleExplode", getRootElement(), Explosion) Thanks Link to comment
#RooTs Posted January 17, 2016 Share Posted January 17, 2016 (edited) maybe try this local veh = {} function elvehiculo(source) local x, y, z = getElementPosition(source) veh[source] = createVehicle(400, x + 2, y, z) end addCommandHandler("veh",elvehiculo) function VehicleExplode() local isCreatedByPlayer = false; for k, v in pairs( veh ) do if ( v == source ) then isCreatedByPlayer = k; break; end end if ( isCreatedByPlayer ) then setTimer ( function( vehicle, owner ) destroyElement( vehicle ) veh[owner] = nil end , 5000, 1, source, isCreatedByPlayer ) end end addEventHandler("onVehicleExplode", root, VehicleExplode) Edited January 17, 2016 by Guest Link to comment
Noki Posted January 17, 2016 Share Posted January 17, 2016 (edited) local veh = {} function elvehiculo(thePlayer) local x, y, z = getElementPosition(thePlayer) veh[thePlayer] = createVehicle(400, x + 2, y, z) end addCommandHandler("veh",elvehiculo) function Explosion() for i, vehicle in pairs(veh) do if (vehicle == source) then destroyElement( veh[i] ) veh[i] = nil end end end addEventHandler("onVehicleExplode", getRootElement(), Explosion) Edited January 18, 2016 by Guest Link to comment
Destroyer.- Posted January 18, 2016 Author Share Posted January 18, 2016 Works, Thanks 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