Jump to content

Give money to all players-Not Yourself


Admigo

Recommended Posts

Posted
function giveMoney(thePlayer, cmd, amount) 
    local amount = tonumber(amount) 
    if (amount) then 
        for index, player in ipairs(getElementsByType("player")) do 
            if (player ~= thePlayer) then 
                givePlayerMoney(player, amount) 
                outputChatBox(getPlayerName(thePlayer) .." gave you $".. amount .."!",player,0,255,0) 
            end 
        end 
    end 
end 
addCommandHandler("givecash",giveMoney) 

Do you mean that?

Posted

No ,i mean like if you make a command like:/giveallmoney1000.

So you give everyone on the server 1000 money but not your self.

I hope that possible. Or a code for GiveAllCash or something like that.

Posted (edited)

Command: /givemoney

Function: Gives specified amount (see "local cash") of money to all online players with a specified amount of cooldown.

local cash = 1000 -- Cash amount 
local cooldown = false 
local cooldowntime = 1 -- Seconds before cooldown ends 
  
addCommandHandler("givemoney", 
     function(player, cmd) 
          if cooldown then 
               for i,v in ipairs(getElementsByType("player")) do 
                    if player ~= v then 
                         givePlayerMoney(v, tonumber(cash)) 
                         cooldown = true 
                         outputChatBox(getPlayerName(player) .. " has given you $" .. tonumber(cash), v, 220, 220, 0, false) 
                         setTimer(function() 
                              cooldown = false 
                         end, tonumber(cooldowntime) * 1000, 1) 
                    end 
               end 
               outputChatBox("Gave " .. tonumber(cash) .. " to all online players.", player, 0, 255, 0, false) 
          else 
               outputChatBox("Cooldown in effect! You need to wait before giving money again.", player, 255, 0, 0, false) 
          end 
     end 
) 

Command: /givemoney

Function: Gives specified amount (amount value in /givemoney) of money to all online players with a specified amount of cooldown.

local cooldown = false 
local cooldowntime = 1 -- Seconds before cooldown ends 
  
addCommandHandler("givemoney", 
     function(player, cmd, amount) 
          if amount then 
               if tonumber(amount) and tonumber(amount) > 0 then 
                    if cooldown then 
                         for i,v in ipairs(getElementsByType("player")) do 
                              if player ~= v then 
                                   givePlayerMoney(v, tonumber(amount)) 
                                   cooldown = true 
                                   outputChatBox(getPlayerName(player) .. " has given you $" .. tonumber(amount), v, 220, 220, 0, false) 
                                   setTimer(function() 
                                        cooldown = false 
                                   end, tonumber(cooldowntime) * 1000, 1) 
                              end 
                         end 
                         outputChatBox("Gave " .. tonumber(amount) .. " to all online players.", player, 0, 255, 0, false) 
                    else 
                         outputChatBox("Cooldown in effect! You need to wait before giving money again.", player, 255, 0, 0, false) 
                    end 
               else 
                    outputChatBox("Money amount must be over 0.", player, 255, 0, 0, false) 
               end 
          else 
               outputChatBox("Syntax: /givemoney ", player, 220, 220, 0, false) 
          end 
     end 
) 

Edited by Guest
Posted

That code is giving 1 player money with an amount.

I just want make a command like that i give everyone in server 1000 money. Not a command with amount.

So just a code like /giveeveryonecash- gives everyone in server 1000 money.

Posted
local amount = 1000 
  
function giveMoney(thePlayer) 
    for index, player in ipairs(getElementsByType("player")) do 
        if (player ~= thePlayer) then 
            givePlayerMoney(player, amount) 
            outputChatBox(getPlayerName(thePlayer) .." gave you $".. amount .."!",player,0,255,0) 
        end 
    end 
end 
addCommandHandler("giveallcash",giveMoney) 

Posted
local amount = 1000 
  
function giveMoney(thePlayer) 
    for index, player in ipairs(getElementsByType("player")) do 
        if (player ~= thePlayer) then 
            givePlayerMoney(player, amount) 
            outputChatBox(getPlayerName(thePlayer) .." gave you $".. amount .."!",player,0,255,0) 
        end 
    end 
end 
addCommandHandler("giveallcash",giveMoney) 

server side or client side?

I placed at client:S error:attempt to concatente a boolean amount.

Posted

It's server-side, and it needs to be server-side if your service scripts are using MTA money server-side. Client-side given money will not work in server-side.

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...