LabiVila Posted July 22, 2015 Share Posted July 22, 2015 local all = getAlivePlayers () if (#all == 1) then local player1 = all[1] local p1Account = getPlayerAccount (player1) if p1Account and not isGuestAccount (p1Account) then local points = points + everyone outputChatBox ("You got "..points.." points for finishing first.", player1, 255, 255, 255) setAccountData (p1Account, "DMpoints", getAccountData (p1Account, "DMpoints") + points) else outputChatBox ("You are not logged in.", player1, 255, 255, 255) end end if (#all == 2) then local player2 = all[2] local p2Account = getPlayerAccount (player2) if p2Account and not isGuestAccount (p2Account) then local points = points + everyone - 1 outputChatBox ("You got "..points.." points for finishing second.", player2, 255, 255, 255) setAccountData (p2Account, "DMpoints", getAccountData (p2Account, "DMpoints") + points) else outputChatBox ("You are not logged in.", player2, 255, 255, 255) end end Hey, thanks for taking time. So I recently got stuck in a problem, everything works fine but the outputchatBoxs. outputChatBox ("You got "..points.." points for finishing second.", player2, 255, 255, 255) - this outputs in the wrong time, it outputs when two players are alive, not when second players is dead. I want it like when player 2 dies, it outputs him the message, not when player 3 dies and two are alive, it outputs a random player between the two alive ones. Thanks Link to comment
GTX Posted July 22, 2015 Share Posted July 22, 2015 Do you mean when second player dies, it outputs him message? Link to comment
Arnold-1 Posted July 22, 2015 Share Posted July 22, 2015 You showed us the useless part, we need the event, and the event triggering function. Link to comment
LabiVila Posted July 22, 2015 Author Share Posted July 22, 2015 Yea should've placed the event tho; addEventHandler ("onPlayerWasted", getRootElement(), who) and it's not triggered anyhow. I've also got this; function onLogin () local account = getPlayerAccount (source) if account then local points = getAccountData (account, "DMpoints") outputChatBox ("Your statistics have been loaded successfully."..points) end end addEventHandler ("onPlayerLogin", getRootElement(), onLogin) it saves the points, nothing else Link to comment
Arnold-1 Posted July 22, 2015 Share Posted July 22, 2015 Add a little delay, like 5 seconds, maybe the player is removed from the alive player list a little bit after onPlayerWasted is triggered. Link to comment
LabiVila Posted July 22, 2015 Author Share Posted July 22, 2015 It won't be very useful as you can't determine the time the player dies. Is there any other way I can do it? I can erase the whole script if needed Link to comment
Arnold-1 Posted July 22, 2015 Share Posted July 22, 2015 i said add a little delay, add a little delay before you check how many players are alive, because as you know, after the player is wasted, it takes him a few seconds before he actually dies, his body remains on the ground, so add a little delay. Link to comment
LabiVila Posted July 23, 2015 Author Share Posted July 23, 2015 No it doesn't help it, the message still goes to one of two alive players (but just after 5 seconds now), any other way you suggest? Link to comment
Army@1 Posted July 23, 2015 Share Posted July 23, 2015 Try change check for first player alive to: #all == 0 and for second player alive to: #all == 1 If I understand the function correctly, it should work. Link to comment
Arnold-1 Posted July 23, 2015 Share Posted July 23, 2015 WAIT, i just got your problem... You should output that after the second dies,so, here's how it will go: function output (player) all = getAlivePlayers() if #all == 1 then outputChatBox("You won as first",all[1]) outputChatBox("You won as second",player) end end addEventHandler("onPlayerWasted",root,output) sorry, but i didn't read your script well earlier. 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