KidMoppuc Posted July 9, 2015 Share Posted July 9, 2015 What would be the easiest way to set a time for this function? (Also, if you spot any errors feel free to point them out!) This script works, however when I add a timer, it gives me errors that it couldn't find the 'source' element. Whereas it works without the timer! function revivePlayer() local money = getPlayerMoney(source) spawnPlayer(source, x, y, z) setCameraTarget(source, source) fadeCamera(source, true) outputChatBox("You have been killed, a fee of $100 has been deducted from your account.", source) setPlayerMoney(source, (tostring(money) - 100)) end addEventHandler("onPlayerWasted", root, revivePlayer) Thanks Link to comment
Bonsai Posted July 9, 2015 Share Posted July 9, 2015 What did you try? setTimer(spawnPlayer, 1000, 1, source, x, y, z) That doesn't work? Link to comment
KidMoppuc Posted July 9, 2015 Author Share Posted July 9, 2015 Something like this; function revivePlayer() setTimer( function() spawnPlayer(source, x, y, z) setCameraTarget(source, source) fadeCamera(source, true) outputChatBox("You have been killed, a fee of $100 has been deducted from your account.", source) setPlayerMoney(source, (getPlayerMoney(source) - 100)) end, 3000, 1) end addEventHandler("onPlayerWasted", root, revivePlayer) Link to comment
Calculador Posted July 9, 2015 Share Posted July 9, 2015 Something like this; function revivePlayer() setTimer( function() spawnPlayer(source, x, y, z) setCameraTarget(source, source) fadeCamera(source, true) outputChatBox("You have been killed, a fee of $100 has been deducted from your account.", source) setPlayerMoney(source, (getPlayerMoney(source) - 100)) end, 3000, 1) end addEventHandler("onPlayerWasted", root, revivePlayer) Yes, any error? Link to comment
KidMoppuc Posted July 10, 2015 Author Share Posted July 10, 2015 That 'source' is nil. However it works without the timer?? Link to comment
Gr0x Posted July 10, 2015 Share Posted July 10, 2015 function revivePlayer(player) if player then if isElement(player) then spawnPlayer(player, x, y, z) setCameraTarget(player, player) fadeCamera(player, true) outputChatBox("You have been killed, a fee of $100 has been deducted from your account.", player) setPlayerMoney(player, (getPlayerMoney(player) - 100)) return end end if source then setTimer(revivePlayer,3000,1,source) end end addEventHandler("onPlayerWasted", root, revivePlayer) Kind of an ugly workaround, no idea why the timer in the previous comments are not working. Try this one Link to comment
KidMoppuc Posted July 10, 2015 Author Share Posted July 10, 2015 Okay, I've changed it up again! But nothing happens at all now... function JoinHandler (player) if player then if isElement(player) then spawnPlayer(player, x, y, z) setCameraTarget(player, player) fadeCamera(player, true) outputChatBox("Welcome to our newest server, unfortunately, it is still under development. Please visit later.", player) return end end end function settheTimer() setTimer ( JoinHandler, 1000, 1 ) end addEventHandler("onPlayerJoin", root, settheTimer) Link to comment
Gr0x Posted July 10, 2015 Share Posted July 10, 2015 Pass the player argument too. setTimer(JoinHandler,1000,1,source) Link to comment
KidMoppuc Posted July 10, 2015 Author Share Posted July 10, 2015 Ahh, it works! Thank you! Why didn't it work without that? Link to comment
Gr0x Posted July 12, 2015 Share Posted July 12, 2015 No problem. You need to send the player element who joined the game as the first argument to the other function too, so it knows which player should be spawned, that's why it didnt work. 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