Jump to content

Problem with destroying spawned vehicles...


Recommended Posts

Hello all,

I have another problem, again I can't seem to solve it... It's this problem:

I have a server which is not yet done, so I'm oftenly messing around with the other co-admins and they with me. With vehicles. :D

Problem is: when refreshing, they don't disappear. After a while, they don't disappear... They don't disappear until a whole server restart. So I made a small piece of code made out of other pieces of code and it... Doesn't work...

function initWreckageDestroy(source) 
    setTimer("destroyElement",41000,1,source) 
end 
addEventHandler("onVehicleExplode", getRootElement(), initWreckageDestroy) 
  
function killWreckageDestroyTimer() 
    timers = getTimers(1000) 
    for timerKey, timerValue in ipairs(timers) do 
        killTimer(timerValue) 
    end 
end 
addEventHandler("onVehicleRespawn", getRootElement(), killWreckageDestroyTimer) 

So I'm asking for some advice. I still need to learn scripting so don't fix the script completely, just explain a bit how to fix it. ;)

Edit: Forgot the error message...

WARNING: script.lua: Bad argument @ 'setTimer' Line: 322

Thanks in advance,

Gamesnert.

Link to comment

Well every time a vehicle respawns you're killing every timer you've created in the last second, regardless of what they're connected with. So you could stop timers that weren't meant to destroy the vehicle for one. So you when you create your timer you need to save this and associate it with the vehicle it's designed to destroy - so you can handle only it's timer when it respawns.

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