Jump to content

Get Players Online


Norhy

Recommended Posts

    function deathMoney ( player ) 
        local reward = math.random(2000, 3000) 
        givePlayerMoney ( source, reward ) 
        outputChatBox ( "Zdochol si! Tvoja odmena za túto mapu je " .. reward .. "$!", getRootElement(), 0, 255, 0, true ) 
    end 
    addEventHandler ( "onPlayerWasted", getRootElement(), deathMoney ) 

This is my code which will give a player between 2k and 3k$. The problem is that the player gets it everytime. I want to make it possible only when there are atleast 2 players online, but don't know how. Any functions?

Link to comment
  • Moderators

Use the following:

if getPlayerCount() >= 2 then ... end 

Example:

function deathMoney ( player ) 
    if getPlayerCount() >= 2 then 
        local reward = math.random(2000, 3000) 
        givePlayerMoney ( source, reward ) 
        outputChatBox ( "Zdochol si! Tvoja odmena za túto mapu je " .. reward .. "$!", getRootElement(), 0, 255, 0, true ) 
    end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), deathMoney ) 

Link to comment
    function deathMoney ( player ) 
        if (getPlayerCount < 2) then 
            outputChatBox ( "Na serveri nie je dostatok (2) hráčov aby si získal odmenu!", getRootElement(), 0, 255, 0, true ) 
        else 
            local reward = math.random(2000, 3000) 
            givePlayerMoney ( source, reward ) 
            outputChatBox ( "Zdochol si! Tvoja odmena za túto mapu je " .. reward .. "$!", getRootElement(), 0, 255, 0, true ) 
        end 
    end 
    addEventHandler ( "onPlayerWasted", getRootElement(), deathMoney ) 

Tried this, doesn't work.

Link to comment
You can get the amount of players online in the client side too by getting the length of the table returned by getElementsByType:
#getElementsByType 'player' 

He doesn't want it client side, because he's using server side event... think...

    function deathMoney ( player ) 
        if (getPlayerCount < 2) then 
            outputChatBox ( "Na serveri nie je dostatok (2) hráčov aby si získal odmenu!", getRootElement(), 0, 255, 0, true ) 
        else 
            local reward = math.random(2000, 3000) 
            givePlayerMoney ( source, reward ) 
            outputChatBox ( "Zdochol si! Tvoja odmena za túto mapu je " .. reward .. "$!", getRootElement(), 0, 255, 0, true ) 
        end 
    end 
    addEventHandler ( "onPlayerWasted", getRootElement(), deathMoney ) 

Tried this, doesn't work.

You're trying to compare function with number... just add () to call the getPlayerCount. So it will be getPlayerCount()

Link to comment
You can get the amount of players online in the client side too by getting the length of the table returned by getElementsByType:
#getElementsByType 'player' 

He doesn't want it client side, because he's using server side event... think...

    function deathMoney ( player ) 
        if (getPlayerCount < 2) then 
            outputChatBox ( "Na serveri nie je dostatok (2) hráčov aby si získal odmenu!", getRootElement(), 0, 255, 0, true ) 
        else 
            local reward = math.random(2000, 3000) 
            givePlayerMoney ( source, reward ) 
            outputChatBox ( "Zdochol si! Tvoja odmena za túto mapu je " .. reward .. "$!", getRootElement(), 0, 255, 0, true ) 
        end 
    end 
    addEventHandler ( "onPlayerWasted", getRootElement(), deathMoney ) 

Tried this, doesn't work.

You're trying to compare function with number... just add () to call the getPlayerCount. So it will be getPlayerCount()

I was answering to the guy above, in case you didn't saw.

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