Jump to content

destroyElement not work


#RooTs

Recommended Posts

hello friends, I made a function to destroy the vehicle after 5 seconds. most did not succeed.

I've tried with and without loop the loop

function VehicleExplode() 
        for k, v in pairs(vehicles) do 
                if v == source then 
                        setTimer(function() 
                        destroyElement(vehicles[source]) 
                        vehicles[source] = nil 
                        end, 5000, 1, vehicles[source]) 
                end 
        end 
end 
addEventHandler("onVehicleExplode", root, VehicleExplode) 

Edited by Guest
Link to comment
local vehicle = {   } 
local markers = { 
    { 1560.77563, -1605.14966, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1584.11853, -1604.97534, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1604.44885, -1622.20142, 12.51332, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1653, 30, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1697, 30, "cylinder", 2, 0, 0, 255, 35 }, 
} 
  
for _,v in ipairs ( markers ) do 
    createMarker ( v [ 1 ], v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ], v [ 6 ], v [ 7 ], v [ 8 ], v [ 9 ] ) 
end 
  
addEvent ( "CreVehicePv", true ) 
addEventHandler ( "CreVehicePv", root, 
    function (  id  ) 
        if ( isElement ( vehicle [ client ] ) ) then destroyElement ( vehicle [ client ] ) end 
        local x, y, z = getElementPosition ( client ) 
        vehicle [ client ] = createVehicle ( tostring ( id ) or 411, x + 2, y, z ) 
        warpPedIntoVehicle ( client, vehicle [ client ] ) 
    end 
) 
  
addEventHandler ( "onMarkerHit", resourceRoot, 
    function (  hitPlayer   ) 
        if ( getElementType ( hitPlayer ) == "player" ) and not ( isPedInVehicle ( hitPlayer ) ) then 
            if ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "Policia" ) ) or ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "SWAT" ) ) then 
                triggerClientEvent ( hitPlayer, "showGUIpv", hitPlayer ) 
            else 
                triggerClientEvent ( hitPlayer, "failvehcop", hitPlayer ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            destroyElement ( vehicle [ source ] ) 
            vehicle [ source ] = nil 
        end 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function (  ) 
        if ( isElement ( vehicle [ source ] ) ) then 
            destroyElement ( vehicle [ source ] ) 
            vehicle [ source ] = nil 
        end 
    end 
) 

Edited by Guest
Link to comment
local vehicle = {   } 
local markers = { 
    { 1560.77563, -1605.14966, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1584.11853, -1604.97534, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1604.44885, -1622.20142, 12.51332, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1653, 30, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1697, 30, "cylinder", 2, 0, 0, 255, 35 }, 
} 
  
for _,v in ipairs ( markers ) do 
    createMarker ( v [ 1 ], v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ], v [ 6 ], v [ 7 ], v [ 8 ], v [ 9 ] ) 
end 
  
addEvent ( "CreVehicePv", true ) 
addEventHandler ( "CreVehicePv", root, 
    function (  id  ) 
        if ( isElement ( vehicle [ source ] ) ) then destroyElement ( vehicle [ source ] ) end 
        local x, y, z = getElementPosition ( client ) 
        vehicle [ client ] = createVehicle ( tostring ( id ) or 411, x + 2, y, z ) 
        warpPedIntoVehicle ( client, vehicle [ client ] ) 
    end 
) 
  
addEventHandler ( "onMarkerHit", resourceRoot, 
    function (  hitPlayer   ) 
        if ( getElementType ( hitPlayer ) == "player" ) and not ( isPedInVehicle ( hitPlayer ) ) then 
            if ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "Policia" ) ) or ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "SWAT" ) ) then 
                triggerClientEvent ( hitPlayer, "showGUIpv", hitPlayer ) 
            else 
                triggerClientEvent ( hitPlayer, "failvehcop", hitPlayer ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            destroyElement ( vehicle [ source ] ) 
            vehicle [ source ] = nil 
        end 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function (  ) 
        if ( isElement ( vehicle [ source ] ) ) then 
            destroyElement ( vehicle [ source ] ) 
            vehicle [ source ] = nil 
        end 
    end 
) 

:o:o:o Thanks, my friend

Link to comment

add setTimer in

addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            destroyElement ( vehicle [ source ] ) 
            vehicle [ source ] = nil 
        end 
    end 
) 

5 seconds, please

Link to comment
addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            setTimer ( 
                function (  ) 
                    destroyElement ( vehicle [ source ] ) 
                    vehicle [ source ] = nil 
                end, 5000, 1, source 
            ) 
        end 
    end 
) 

Link to comment
function VehicleExplode() 
        for k, v in pairs(vehicles) do 
                if v == source then 
                        setTimer(function() 
                        destroyElement(vehicles[source]) 
                        vehicles[source] = nil 
                        end, 5000, 1) 
                end 
        end 
end 
addEventHandler("onVehicleExplode", root, VehicleExplode) 

Link to comment
function VehicleExplode() 
        for k, v in pairs(vehicles) do 
                if v == source then 
                        setTimer(function() 
                        destroyElement(vehicles[source]) 
                        vehicles[source] = nil 
                        end, 5000, 1) 
                end 
        end 
end 
addEventHandler("onVehicleExplode", root, VehicleExplode) 

No loop needed, just show my way.

Link to comment
function VehicleExplode() 
        for k, v in pairs(vehicles) do 
                if v == source then 
                        setTimer(function() 
                        destroyElement(vehicles[source]) 
                        vehicles[source] = nil 
                        end, 5000, 1) 
                end 
        end 
end 
addEventHandler("onVehicleExplode", root, VehicleExplode) 

No loop needed, just show my way.

Ah, didn't check thoroughly. I guess source doesn't need a table unless he created one.

Link to comment

some error ?

local vehicle = {   } 
local markers = { 
    { 1560.77563, -1605.14966, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1584.11853, -1604.97534, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1604.44885, -1622.20142, 12.51332, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1653, 30, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1697, 30, "cylinder", 2, 0, 0, 255, 35 }, 
} 
  
for _,v in ipairs ( markers ) do 
    createMarker ( v [ 1 ], v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ], v [ 6 ], v [ 7 ], v [ 8 ], v [ 9 ] ) 
end 
  
addEvent ( "CreVehicePv", true ) 
addEventHandler ( "CreVehicePv", root, 
    function (  id  ) 
        if ( isElement ( vehicle [ client ] ) ) then destroyElement ( vehicle [ client ] ) end 
        local x, y, z = getElementPosition ( client ) 
        vehicle [ client ] = createVehicle ( tostring ( id ) or 411, x + 2, y, z ) 
        warpPedIntoVehicle ( client, vehicle [ client ] ) 
    end 
) 
  
addEventHandler ( "onMarkerHit", resourceRoot, 
    function (  hitPlayer   ) 
        if ( getElementType ( hitPlayer ) == "player" ) and not ( isPedInVehicle ( hitPlayer ) ) then 
            if ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "Policia" ) ) or ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "SWAT" ) ) then 
                triggerClientEvent ( hitPlayer, "showGUIpv", hitPlayer ) 
            else 
                triggerClientEvent ( hitPlayer, "failvehcop", hitPlayer ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            setTimer ( 
                function (  ) 
                    destroyElement ( vehicle [ source ] ) 
                    vehicle [ source ] = nil 
                end, 5000, 1, source 
            ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function (  ) 
        if ( isElement ( vehicle [ source ] ) ) then 
            destroyElement ( vehicle [ source ] ) 
            vehicle [ source ] = nil 
        end 
    end 
) 

Link to comment

not work

addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            setTimer ( 
                function (  ) 
                    destroyElement ( vehicle [ source ] ) 
                    vehicle [ source ] = nil 
                end, 5000, 1, source 
            ) 
        end 
    end 
) 

Link to comment
  
local vehicles = {   } 
local markers = { 
    { 1560.77563, -1605.14966, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1584.11853, -1604.97534, 12.38281, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1604.44885, -1622.20142, 12.51332, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1653, 30, "cylinder", 2, 0, 0, 255, 35 }, 
    { 1559, -1697, 30, "cylinder", 2, 0, 0, 255, 35 }, 
} 
  
for _,v in ipairs ( markers ) do 
    createMarker ( v [ 1 ], v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ], v [ 6 ], v [ 7 ], v [ 8 ], v [ 9 ] ) 
end 
  
addEvent ( "CreVehicePv", true ) 
addEventHandler ( "CreVehicePv", root, 
    function (  id  ) 
        if ( isElement ( vehicles [ client ] ) ) then destroyElement ( vehicles [ client ] ) end 
        local x, y, z = getElementPosition ( client ) 
        vehicles [ client ] = createVehicle ( tostring ( id ) or 411, x + 2, y, z ) 
        warpPedIntoVehicle ( client, vehicles [ client ] ) 
    end 
) 
  
addEventHandler ( "onMarkerHit", resourceRoot, 
    function (  hitPlayer   ) 
        if ( getElementType ( hitPlayer ) == "player" ) and not ( isPedInVehicle ( hitPlayer ) ) then 
            if ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "Policia" ) ) or ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "SWAT" ) ) then 
                triggerClientEvent ( hitPlayer, "showGUIpv", hitPlayer ) 
            else 
                triggerClientEvent ( hitPlayer, "failvehcop", hitPlayer ) 
            end 
        end 
    end 
) 
  
addEventHandler("onVehicleExplode", root,  
    function ( ) 
        for k, v in pairs ( vehicles ) do 
            if v == source then 
                    setTimer ( function ( ) 
                    destroyElement ( source ) 
                    vehicles [ k ] = nil 
                    end, 5000, 1, source ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        if ( isElement ( vehicles [ source ] ) ) then 
            destroyElement ( vehicles [ source ] ) 
            vehicles [ source ] = nil 
        end 
    end 
) 
  

Edit: Replaced 'vehicle' with 'vehicles' as reminded by Sasu.

Edited by Guest
Link to comment
addEventHandler ( "onVehicleExplode", root, 
    function (  ) 
        if ( vehicle [ source ] ) then 
            setTimer ( 
                function ( source ) 
                    destroyElement ( source ) 
                    vehicle [ source ] = nil 
                end, 5000, 1, source 
            ) 
        end 
    end 
) 

Also, your table is 'vehicles' and not 'vehicle', isn't it?

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...