Jump to content

[HELP]Respawn ped after death


Black2

Recommended Posts

Hi,how i can do for the ped respawn after death ?

I try it but don't work

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 
subenji99 
Trick 
  
Posts: 226 
Joined: Sat Jan 03, 2009 8:48 pm 
  

Link to comment

this should work

  
  ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) 
    pedanim = setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) 
  
     
function peddestroy ( thePlayer ) 
    if ( isPedDead (ped1) ) then 
        outputChatBox ( "Ped is dead", 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" )   
    end 
    addEventHandler ( "onPedWasted", ped1, pedrespawnafterdeath ) 

The rest that you did is totally useless, this will make your ped respawn after death

Link to comment
 ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) 
    pedanim = setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) 
  
    
function peddestroy ( thePlayer ) 
    if ( isPedDead (ped1) ) then 
        outputChatBox ( "Ped is dead", 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" )   
    end 
    addEventHandler ( "onPedWasted", ped1, pedrespawnafterdeath ) 

this work,but if i kill ped 2 times he don't respawn why :( ?

Link to comment
local pedanim 
addEventHandler("onResourceStart",resourceRoot, 
function() 
    local ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) 
    pedanim = setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) 
    addEventHandler("onPedWasted", ped1, onPedWasted) 
end 
) 
  
function onPedWasted() 
    outputChatBox ( "Ped is dead", root) 
    killTimer(pedanim) 
    removeEventHandler("onPedWasted",source,onPedWasted) -- just because 
    destroyElement(source) 
    ped1 = createPed(56, -2225.376953125, 2333.6584472656, 7.546875) 
    pedanim = setTimer ( setPedAnimation, 5000, 0, ped1, "ped", "SEAT_idle" ) 
    addEventHandler("onPedWasted", ped1, onPedWasted) 
end 

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