xbenny2506x Posted September 7, 2009 Share Posted September 7, 2009 HI! I have make a script when the ped is death the ped respawn in 5000 ms. But the problem is, when i start the server and come in the server all 5000ms is see a new ped And when i restart the resource "pedfun" the script work! The server create then only one ped and not all 5sec a new one. Can someone help me with that problem!? function pedspawn ( thePlayer ) function pedcreate () ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) end setTimer ( pedcreate, 5000, 1 ) function peddestroy ( thePlayer ) if ( isPedDead (ped1) ) then outputChatBox ( "Ped is death", thePlayer ) setTimer ( destroyElement, 5000, 1, ped1) end end addEventHandler("onPedWasted", getRootElement(), peddestroy ) function pednewadeath( thePlayer ) if ( isPedDead (ped1) ) then function pedrespawnafterdeath () ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) end setTimer ( pedrespawnafterdeath, 5000, 1 ) outputChatBox ( "Ped Respawn work!", thePlayer ) end end addEventHandler("onPedWasted", getRootElement(), pednewadeath ) end addEventHandler("onResourceStart", getRootElement(), pedspawn ) Link to comment
subenji99 Posted September 8, 2009 Share Posted September 8, 2009 You've nested all your functions inside each other, making it very difficult to follow the code. Try this, and report the results back function pedcreate () ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) pedanim = setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) --added variable here, to help clean up timers end function peddestroy ( thePlayer ) if ( isPedDead (ped1) ) then outputChatBox ( "Ped is death", thePlayer ) killTimer( pedanim ) --stop ped anim timer when destroying the ped destroyElement( ped1 ) --removed timer here, to prevent your code conflicting with the ped's respawn end end addEventHandler("onPedWasted", getRootElement(), peddestroy ) function pedrespawnafterdeath () ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) pedanim = setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) --again, define timer variable end function pednewadeath( thePlayer ) if ( isPedDead (ped1) ) then setTimer ( pedrespawnafterdeath, 5000, 1 ) outputChatBox ( "Ped Respawn work!", thePlayer ) end end addEventHandler("onPedWasted", getRootElement(), pednewadeath ) function pedspawn ( thePlayer ) setTimer ( pedcreate, 5000, 1 ) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), pedspawn ) --changed to resource root element - attaching to root element would trigger a new ped on every new resource starting Link to comment
xbenny2506x Posted September 8, 2009 Author Share Posted September 8, 2009 yh its not a so good script But with your help i have fix something and now the script work! THX for the help!! 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