Tails Posted August 6, 2012 Posted August 6, 2012 So I want the player to respawn automatically after he dies, on the same position. function deathCheck(source) local x,y,z = getElementPosition(source) if (isPedDead(source)) then spawnPlayer(source, x,y,z) end end addEventHandler("onPlayerWasted", deathCheck) What am I doing wrong? Also, how do I attach a timer to the respawn? Thanks in advance
Castillo Posted August 6, 2012 Posted August 6, 2012 'source' shouldn't be defined at the function name, there: function deathCheck(source)
Tails Posted August 6, 2012 Author Posted August 6, 2012 Huh, so what do I need to do? This is what I have: function respawn(source) local x,y,z = getElementPosition(source) spawnPlayer(source, x, y, z) setPedSkin (source, mySkin) end addCommandHandler("respawn", respawn) function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then spawnPlayer(source, x,y,z) end end addEventHandler("onPlayerWasted", deathCheck) function killcommand(source) killPed (source, source) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) end addCommandHandler("kill", killcommand)
Tails Posted August 6, 2012 Author Posted August 6, 2012 local mySkin = 50 I just did this to see if it would work. The script doesn't let me respawn when I die or type /kill /respawn works.
Castillo Posted August 6, 2012 Posted August 6, 2012 Try this: function respawn ( thePlayer ) if ( isPedDead ( thePlayer ) ) then local x, y, z = getElementPosition ( thePlayer ) spawnPlayer ( thePlayer, x, y, z ) setElementModel ( thePlayer, mySkin ) end end addCommandHandler ( "respawn", respawn ) function deathCheck ( ) local x, y, z = getElementPosition ( source ) spawnPlayer ( source, x, y, z ) end addEventHandler ( "onPlayerWasted", root, deathCheck ) function killcommand ( thePlayer ) killPed ( thePlayer, thePlayer) outputChatBox ( "Type /respawn to respawn immediately.", thePlayer, 255, 0, 0, true ) end addCommandHandler ( "kill", killcommand )
Tails Posted August 6, 2012 Author Posted August 6, 2012 Nope , doesn't work. Only thing that lets me respawn is by typing /respawn I want the respawn to happen automatically after I die. Edit: This is the full script maybe that helps: local spawnX, spawnY, spawnZ = 1713.02, 917.98, 10.80 local mySkin = 50 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPedSkin ( source, mySkin ) outputChatBox("Welcome to My Server", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) function respawn(source) local x,y,z = getElementPosition(source) spawnPlayer(source, x, y, z) setPedSkin (source, mySkin) end addCommandHandler("respawn", respawn) function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then spawnPlayer(source, x,y,z) end end addEventHandler("onPlayerWasted", deathCheck) function killcommand(source) killPed (source, source) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) end addCommandHandler("kill", killcommand) -- retrieve a table with all flag elements local flagElements = getElementsByType ( "tdm" ) -- loop through them for key, value in pairs(flagElements) do -- get our info local posX = getElementData ( value, "posX" ) local posY = getElementData ( value, "posY" ) local posZ = getElementData ( value, "posZ" ) end
Castillo Posted August 6, 2012 Posted August 6, 2012 Found the problem, you have missing 'root' at addEventHandler of 'onPlayerWasted'. addEventHandler ( "onPlayerWasted", root, deathCheck )
Tete omar Posted August 6, 2012 Posted August 6, 2012 use ' setElementPosition ' much better than ' spawnPlayer ' try this local spawnX, spawnY, spawnZ = 1713.02, 917.98, 10.80 local mySkin = 50 function joinHandler() setElementPosition(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPedSkin ( source, mySkin ) outputChatBox("Welcome to My Server", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) function respawn(source) local x,y,z = getElementPosition(source) setElementPosition(source, x, y, z) setPedSkin (source, mySkin) end addCommandHandler("respawn", respawn) function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then setElementPosition(source, x,y,z) end end addEventHandler ("onPlayerWasted", root, deathCheck) function killcommand(source) killPed (source, source) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) end addCommandHandler("kill", killcommand) -- retrieve a table with all flag elements local flagElements = getElementsByType ( "tdm" ) -- loop through them for key, value in pairs(flagElements) do -- get our info local posX = getElementData ( value, "posX" ) local posY = getElementData ( value, "posY" ) local posZ = getElementData ( value, "posZ" ) end Found the problem, you have missing 'root' at addEventHandler of 'onPlayerWasted'. addEventHandler ( "onPlayerWasted", root, deathCheck ) fixed
Tails Posted August 6, 2012 Author Posted August 6, 2012 Thank you guys. @Teteomar, the setElementPosition did not work, the ped got stuck and the respawn didn't work. I changed it back to spawnPlayer and it worked.
Tete omar Posted August 6, 2012 Posted August 6, 2012 spawnPlayer is same as setElementPosition( the player element , x, y, z ) weird ...
Tails Posted August 6, 2012 Author Posted August 6, 2012 spawnPlayer is same as setElementPosition( the player element , x, y, z )weird ... Maybe because my element was dead?
Tails Posted August 6, 2012 Author Posted August 6, 2012 Sorry for the many questions, (I am such a noob), but can you help me figure out how to put a respawn timer in the script below? function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then spawnPlayer(source, x,y,z) setPedSkin (source, mySkin) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) setTimer ( spawnPlayer, 2500, 1, source) end end addEventHandler ("onPlayerWasted", root, deathCheck)
Booo Posted August 6, 2012 Posted August 6, 2012 Sorry for the many questions, (I am such a noob), but can you help me figure out how to put a respawn timer in the script below? function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then spawnPlayer(source, x,y,z) setPedSkin (source, mySkin) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) setTimer ( spawnPlayer, 2500, 1, source) end end addEventHandler ("onPlayerWasted", root, deathCheck) function deathCheck() local x,y,z = getElementPosition(source) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) setTimer ( function() spawnPlayer(source, x,y,z) setElementAlpha(source, 0) end , 2500, 1) end addEventHandler ("onPlayerWasted", root, deathCheck)
Castillo Posted August 6, 2012 Posted August 6, 2012 Sorry for the many questions, (I am such a noob), but can you help me figure out how to put a respawn timer in the script below? function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then spawnPlayer(source, x,y,z) setPedSkin (source, mySkin) outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) setTimer ( spawnPlayer, 2500, 1, source) end end addEventHandler ("onPlayerWasted", root, deathCheck) Yours is half fine, you should remove the first spawnPlayer, setPedSkin and fill the arguments in the timer. function deathCheck() local x,y,z = getElementPosition(source) if (isPedDead(source)) then outputChatBox("Type /respawn to respawn immediately.", getRootElement(), 255,0,0,true) setTimer ( spawnPlayer, 2500, 1, source, x, y, z, 0, mySkin ) end end addEventHandler ("onPlayerWasted", root, deathCheck)
Tails Posted August 6, 2012 Author Posted August 6, 2012 Thanks you guys. I appreciate the help so much. I learn something new every time when I'm here!
Tails Posted August 6, 2012 Author Posted August 6, 2012 Another question, what exactly is the 0 standing for in this line: setTimer ( spawnPlayer, 2500, 1, source, x, y, z, 0, mySkin ) ?
TAPL Posted August 6, 2012 Posted August 6, 2012 Another question, what exactly is the 0 standing for in this line: setTimer ( spawnPlayer, 2500, 1, source, x, y, z, 0, mySkin ) ? rotation: rotation of the player on spawn.
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