GTX Posted March 23, 2012 Share Posted March 23, 2012 Hello, I don't know why this is but I got problem "attempt to concatenate a boolean value" function getRaceAlivePlayers() local result = {} local _getAlivePlayers = getElementsByType("player") for i, v in ipairs(_getAlivePlayers) do if getElementData(v, "state") == "alive" then table.insert(result, v) end end return result end function get() local ap = 0 local _getAlivePlayers = getElementsByType("player") for index, player in ipairs(_getAlivePlayers) do if getElementData(player, "state") == "alive" then ap = ap + 1 end end return ap end -- -- addEventHandler("onPlayerWasted", root, function() if get() == 1 then outputChatBox(getPlayerFromName(tostring(getRaceAlivePlayers()[1])) .. " has won") end end ) Thanks in advance Link to comment
-ffs-Sniper Posted March 23, 2012 Share Posted March 23, 2012 function getRaceAlivePlayers() local result = {} local _getAlivePlayers = getElementsByType("player") for i, v in ipairs(_getAlivePlayers) do if getElementData(v, "state") == "alive" then table.insert(result, v) end end return result end function get() local ap = 0 local _getAlivePlayers = getElementsByType("player") for index, player in ipairs(_getAlivePlayers) do if getElementData(player, "state") == "alive" then ap = ap + 1 end end return ap end -- -- addEventHandler("onPlayerWasted", root, function() if get() == 1 then outputChatBox(getPlayerName(getRaceAlivePlayers()[1]) .. " has won") end end ) Link to comment
Castillo Posted March 24, 2012 Share Posted March 24, 2012 1: Never call a function like a native MTA function. 2: Why do you need another function to count the alive players? you can just do: #table to count a table. 3: This should work: function getRaceAlivePlayers() local result = {} local _getAlivePlayers = getElementsByType("player") for i, v in ipairs(_getAlivePlayers) do if getElementData(v, "state") == "alive" then table.insert(result, v) end end return result end addEventHandler ( "onPlayerWasted", root, function ( ) if ( #getRaceAlivePlayers ( ) == 1 ) then outputChatBox ( getPlayerName ( getRaceAlivePlayers ( )[ 1 ] ) .. " has won" ) end end ) Link to comment
GTX Posted March 24, 2012 Author Share Posted March 24, 2012 Oh yes, I forgot to remove it. Thank you both! 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