..:D&G:.. Posted September 4, 2015 Posted September 4, 2015 Hello guys, I am making an insurance system, and I got some problems with the respawn function on which I use onVehicleExplode. The vehicle respawns, but it explodes, and it keeps respawning and exploding... Any ideas? function onInsuredVehicleExplode() local dbid = tonumber(getElementData(source, "dbid")) if (dbid) then local thePlayer = getVehicleOwnerByDBid(dbid) if (getElementData(source, "insured") == 1) then respawnVehicle(source) fixVehicle(source) else destroyElement(source) end end end addEventHandler("onVehicleExplode", getRootElement(), onInsuredVehicleExplode) Thanks. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
ozulus Posted September 4, 2015 Posted September 4, 2015 You should use that function onInsuredVehicleDamage(loss) -- The source of this event is the vehicle that got damaged. local dbid = tonumber(getElementData(source, "dbid")) if (dbid) then local thePlayer = getVehicleOwnerByDBid(dbid) -- why you used that idk if (getElementData(source, "insured") == 1) then if getElementHealth(source) < 250 then -- if the health gets to 250 the vehicle gets on fire fixVehicle(source) end end end end addEventHandler("onVehicleDamage", getRootElement(), onInsuredVehicleDamage)
..:D&G:.. Posted September 5, 2015 Author Posted September 5, 2015 You should use that function onInsuredVehicleDamage(loss) -- The source of this event is the vehicle that got damaged. local dbid = tonumber(getElementData(source, "dbid")) if (dbid) then local thePlayer = getVehicleOwnerByDBid(dbid) -- why you used that idk if (getElementData(source, "insured") == 1) then if getElementHealth(source) < 250 then -- if the health gets to 250 the vehicle gets on fire fixVehicle(source) end end end end addEventHandler("onVehicleDamage", getRootElement(), onInsuredVehicleDamage) That has nothing to do with what I want... I want to respawn the vehicle when the vehicle explodes, I want it to respawn, that just fixes the vehicle when it gets under 250 health... Thanks for trying to help tho.. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
ozulus Posted September 5, 2015 Posted September 5, 2015 Well, check this out. https://forum.multitheftauto.com/viewtop ... 06#p351160
..:D&G:.. Posted September 5, 2015 Author Posted September 5, 2015 I tried this but the vehicle keeps exploding and respawning -.- function testRespawn() respawnVehicle(source) end function getElementsOnExplode() setTimer ( testRespawn(source), 1000, 1 ) end addEventHandler("onVehicleExplode", getRootElement(), getElementsOnExplode) MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Moderators IIYAMA Posted September 6, 2015 Moderators Posted September 6, 2015 Did you checked your debug? Because there were warnings, knowing just by looking at your code. local respawnTimers = {} function testRespawn(vehicle) respawnTimers[vehicle] = nil respawnVehicle(vehicle) end function getElementsOnExplode() if not respawnTimers[source] then respawnTimers[source] = setTimer ( testRespawn, 1000, 1,source ) end end addEventHandler("onVehicleExplode", root, getElementsOnExplode) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TAPL Posted September 6, 2015 Posted September 6, 2015 It's a simple code even available on the wiki example: https://wiki.multitheftauto.com/wiki/RespawnVehicle function respawnExplodedVehicle() setTimer(respawnVehicle, 5000, 1, source) end addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle)
..:D&G:.. Posted September 7, 2015 Author Posted September 7, 2015 It's a simple code even available on the wiki example:https://wiki.multitheftauto.com/wiki/RespawnVehicle function respawnExplodedVehicle() setTimer(respawnVehicle, 5000, 1, source) end addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) Thanks for help everyone, but I managed to find a solution myself I forgot to say it in the topic as well (I used setTimer as TAPL did) MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Moderators IIYAMA Posted September 7, 2015 Moderators Posted September 7, 2015 Just for the info. With the normal code on wiki, you will get problems with helicopters and planes that don't stop exploding. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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