..:D&G:.. Posted September 4, 2015 Share 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. Link to comment
ozulus Posted September 4, 2015 Share 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) Link to comment
..:D&G:.. Posted September 5, 2015 Author Share 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.. Link to comment
ozulus Posted September 5, 2015 Share Posted September 5, 2015 Well, check this out. https://forum.multitheftauto.com/viewtop ... 06#p351160 Link to comment
..:D&G:.. Posted September 5, 2015 Author Share 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) Link to comment
Moderators IIYAMA Posted September 6, 2015 Moderators Share 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) Link to comment
TAPL Posted September 6, 2015 Share 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) Link to comment
..:D&G:.. Posted September 7, 2015 Author Share 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) Link to comment
Moderators IIYAMA Posted September 7, 2015 Moderators Share 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. 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