Jump to content

[HELP] Unlimited Money


koviak98

Recommended Posts

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 by Keiichi1
Link to comment
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
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 by KillerX
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...