Jump to content

Problem with onVehicleExplode


Destroyer.-

Recommended Posts

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 :cry:

Link to comment

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 by Guest
Link to comment
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 by Guest
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...