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 ) Please do not PM me with scripting related question nor support, use the forums instead.
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 Please do not PM me with scripting related question nor support, use the forums instead.
Max+ Posted April 15, 2013 Posted April 15, 2013 Why Using getPlayerCount ? Just Use This , https://wiki.multitheftauto.com/wiki/Ge ... rs_(Client) - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
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 I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
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() Lua Scripter Owner of mshost.cz MTA portal.
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. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
MIKI785 Posted April 15, 2013 Posted April 15, 2013 No, I didn't . Lua Scripter Owner of mshost.cz MTA portal.
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