Norhy Posted April 15, 2013 Posted April 15, 2013 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?
DNL291 Posted April 15, 2013 Posted April 15, 2013 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 )
Norhy Posted April 15, 2013 Author Posted April 15, 2013 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.
DNL291 Posted April 15, 2013 Posted April 15, 2013 Obviously will not work, because it's wrong. Use the following: if getPlayerCount() >= 2 then ... end
Max+ Posted April 15, 2013 Posted April 15, 2013 Why Using getPlayerCount ? Just Use This , https://wiki.multitheftauto.com/wiki/Ge ... rs_(Client)
iPrestege Posted April 15, 2013 Posted April 15, 2013 Why Using getPlayerCount ?Just Use This , https://wiki.multitheftauto.com/wiki/Ge ... rs_(Client) This function returns all the alive players by a client side, so you can store them into a Gridlist or something like that, faster.
ixjf Posted April 15, 2013 Posted April 15, 2013 (edited) Retrieving the number of players in-game is possible in the client-side, but I wouldn't recommend it for servers with too many players: #getElementsByType 'player' Edited April 28, 2013 by Guest
MIKI785 Posted April 15, 2013 Posted April 15, 2013 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()
ixjf Posted April 15, 2013 Posted April 15, 2013 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.
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