Jump to content

I'm confused..


GTX

Recommended Posts

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

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

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