koviak98 Posted April 4, 2019 Share Posted April 4, 2019 (edited) Hi My first question: How can i set max money on the server? By default the maximum is 99999999. Second question: How can i make that if i set money for a player show him how much he got. Edited April 4, 2019 by koviak98 Link to comment
Keiichi1 Posted April 4, 2019 Share Posted April 4, 2019 (edited) You can't set the player's money over that value. Use ElementData. Code (server): -- When this script starts set every players' 'money' elementdata to 0, if they haven't got one already. for _, player in ipairs(getElementsByType("player")) do if not getElementData(player, "money") then setElementData(player, "money", 0) end end -- When a player joins set the 'money' elementdata to 0. addEventHandler("onPlayerJoin", getRootElement(), function() setElementData(source, "money", 0) end) addCommandHandler("givemoney", function(thePlayer, cmd, targetName, amount) if targetName and tonumber(amount) then local target = getPlayerFromName(targetName) if target then setElementData(target, "money", getElementData(target, "money") + tonumber(amount)) outputChatBox("You gave $"..amount.." to "..targetName.."!", thePlayer, 0, 200, 0) outputChatBox("You got $"..amount.."!", target, 0, 200, 0) else outputChatBox("Player not found.", thePlayer, 255, 0, 0) end else outputChatBox("Usage: /givemoney [playername] [amount]", thePlayer, 255, 255, 255) end end) Edited April 4, 2019 by Keiichi1 Link to comment
koviak98 Posted April 10, 2019 Author Share Posted April 10, 2019 On 04/04/2019 at 20:33, Keiichi1 said: You can't set the player's money over that value. Use ElementData. Code (server): -- When this script starts set every players' 'money' elementdata to 0, if they haven't got one already. for _, player in ipairs(getElementsByType("player")) do if not getElementData(player, "money") then setElementData(player, "money", 0) end end -- When a player joins set the 'money' elementdata to 0. addEventHandler("onPlayerJoin", getRootElement(), function() setElementData(source, "money", 0) end) addCommandHandler("givemoney", function(thePlayer, cmd, targetName, amount) if targetName and tonumber(amount) then local target = getPlayerFromName(targetName) if target then setElementData(target, "money", getElementData(target, "money") + tonumber(amount)) outputChatBox("You gave $"..amount.." to "..targetName.."!", thePlayer, 0, 200, 0) outputChatBox("You got $"..amount.."!", target, 0, 200, 0) else outputChatBox("Player not found.", thePlayer, 255, 0, 0) end else outputChatBox("Usage: /givemoney [playername] [amount]", thePlayer, 255, 255, 255) end end) Thanks, but how can i to get the player money, because this not working: local Money = getPlayerMoney(localPlayer) Link to comment
KillerX Posted April 10, 2019 Share Posted April 10, 2019 (edited) local MaximumValue = 500 -- replace 500 with your Value setTimer( function( ) local Players = getElementsByType( 'player' ) for index = 1 , #Players do if( getPlayerMoney( Players[ index ] ) > MaximumValue ) then setPlayerMoney( Players[ index ] , MaximumValue ) end end end , 1000 , 0 ) 2 - SetPlayerMoney = setPlayerMoney function setPlayerMoney( plr , amount ) if( isElement( plr ) and getElementType( plr ) == 'player' and tonumber( amount ) ) then outputChatBox( 'you got ' .. amount .. 'dollars' , plr) SetPlayerMoney( plr , amount ) end end Edited April 10, 2019 by KillerX 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