SkrillexX Posted March 3, 2014 Share Posted March 3, 2014 Greetings , this script i've tried to make consists on checking the player's money when he types /money. If the player's money is less then 0 , The message would be written in red , If it's more then 0 or 0 , It would be written in green function mamoney(thePlayer ,cmd) money = getPlayerMoney(thePlayer) if ( money >= 0) then outputChatBox( "Your current money is "..money ,0 ,250 ,0) else outputChatBox( "Your current money is "..money ,250 ,0 ,0) end end addCommandHandler ("money" ,mamoney) Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Well, your code is right, but I would add some corrects: function mamoney (thePlayer, cmd) local money = getPlayerMoney(thePlayer) if ( money >= 0) then outputChatBox( "Your current money is "..money, thePlayer, 0, 255, 0) else outputChatBox( "Your current money is "..money, thePlayer, 255, 0, 0) end end addCommandHandler ("money", mamoney) What have I done? Firstly, I added local in your variable. For what? It is better to use local inside function, if you won't use this variable in other functions local money = getPlayerMoney(thePlayer) And after I added 'thePlayer' on 2nd argument in outputChatBox function, why? Then it will output this message for player, who execute this command, otherwise this message would be shown for all players in server. outputChatBox( "Your current money is "..money, thePlayer, 0, 255, 0) Finally I changed colors. The maximal amount of colors in r, g, b is 255. Link to comment
Dealman Posted March 3, 2014 Share Posted March 3, 2014 function mamoney (thePlayer, cmd) local money = getPlayerMoney(thePlayer) if(money < 0) then outputChatBox("Your current money is -$"..tostring(money), thePlayer, 250, 0, 0) elseif(money >= 0) then outputChatBox("Your current money is $"..tostring(money), thePlayer, 0, 250, 0) end end addCommandHandler("money", mamoney, false) Try something like that. You don't need to specify a player element if you're using this client-side. However, it is suggested to set a player's money server-side or it won't be synced. The false inside the command handler simply makes it non-case-sensitive. Tostring converts any type into a string. You were trying to concatenate an integer, which is probably why it didn't work. Remember to use Debugscript when coding for MTA, it will make your life a whole lot easier. Link to comment
SkrillexX Posted March 4, 2014 Author Share Posted March 4, 2014 Thanks a lot , i appreciate. I'll take your advice into consideration. 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