Admigo Posted March 7, 2012 Share Posted March 7, 2012 Heey all, How can i make a command that i give all other players(not myself) of server 1000 dollar ? Thanks Admigo Link to comment
Castillo Posted March 7, 2012 Share Posted March 7, 2012 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? Link to comment
Admigo Posted March 7, 2012 Author Share Posted March 7, 2012 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. Link to comment
Castillo Posted March 7, 2012 Share Posted March 7, 2012 That command will give everyone but you the X amount of money. Link to comment
Admigo Posted March 7, 2012 Author Share Posted March 7, 2012 I will exlain in a lua code: givePlayerMoney ( all players who are online in server(dont count me), 1000 ) Link to comment
Castillo Posted March 7, 2012 Share Posted March 7, 2012 Have you even tested my script? it'll do that. Link to comment
myonlake Posted March 7, 2012 Share Posted March 7, 2012 (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 March 7, 2012 by Guest Link to comment
Admigo Posted March 7, 2012 Author Share Posted March 7, 2012 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. Link to comment
Castillo Posted March 7, 2012 Share Posted March 7, 2012 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) Link to comment
Admigo Posted March 7, 2012 Author Share Posted March 7, 2012 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. Link to comment
myonlake Posted March 7, 2012 Share Posted March 7, 2012 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. Link to comment
Admigo Posted March 7, 2012 Author Share Posted March 7, 2012 Thanks Social and Solid,codes works great! Link to comment
Castillo Posted March 7, 2012 Share Posted March 7, 2012 Thanks Social and Solid,codes works great! You're welcome . 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