#RooTs Posted January 11, 2016 Share Posted January 11, 2016 (edited) 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 January 11, 2016 by Guest Link to comment
AboShanab Posted January 11, 2016 Share Posted January 11, 2016 (edited) 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 January 11, 2016 by Guest Link to comment
#RooTs Posted January 11, 2016 Author Share Posted January 11, 2016 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 ) Thanks, my friend Link to comment
#RooTs Posted January 11, 2016 Author Share Posted January 11, 2016 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
AboShanab Posted January 11, 2016 Share Posted January 11, 2016 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
Army@1 Posted January 11, 2016 Share Posted January 11, 2016 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
AboShanab Posted January 11, 2016 Share Posted January 11, 2016 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
Army@1 Posted January 11, 2016 Share Posted January 11, 2016 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
AboShanab Posted January 11, 2016 Share Posted January 11, 2016 Ah, didn't check thoroughly. I guess source doesn't need a table unless he created one. Your code didn't work and it's wrong, try it. Link to comment
AboShanab Posted January 11, 2016 Share Posted January 11, 2016 I just edit the code to fix some typo, try it now. Link to comment
#RooTs Posted January 11, 2016 Author Share Posted January 11, 2016 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
#RooTs Posted January 11, 2016 Author Share Posted January 11, 2016 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
KariiiM Posted January 11, 2016 Share Posted January 11, 2016 Try that, local vehicle = {} addEventHandler("onVehicleExplode",resourceRoot,function () if ( isElement( vehicle[source] ) ) then setTimer (function() destroyElement ( vehicle [source] ) vehicle [source] = nil end, 5000, 1, source) end end) Link to comment
Army@1 Posted January 12, 2016 Share Posted January 12, 2016 (edited) 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 January 12, 2016 by Guest Link to comment
Sasu Posted January 12, 2016 Share Posted January 12, 2016 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
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