CTCCoco Posted February 21, 2010 Posted February 21, 2010 I don't know what to do to give money to a specific connected player. Please help me. function ComandoDinero(thePlayer, comando, thePlayerQ, dinero) if(thePlayerQ) then givePlayerMoney(thePlayerQ, dinero) outputChatBox ( ""..getPlayerName(thePlayer).." te ha dado " .. dinero .." dolares", thePlayerQ) else outputChatBox ( "Usa /dardinero <nombrejugador> <cantidad>", thePlayerQ ) end end addCommandHandler("dardinero", ComandoDinero)
Callum Posted February 21, 2010 Posted February 21, 2010 Try this: function giveCommand ( source, command, playerToGive, moneyToGive ) if ( playerToGive ) then if ( moneyToGive ) then local givingPlayer = getPlayerName ( source ) local thePlayer = getPlayerFromName ( playerToGive ) if ( thePlayer ~= false ) then local moneyToGive = tonumber ( moneyToGive ) local playersMoney = getPlayerMoney ( source ) if ( playersMoney >= moneyToGive ) then takePlayerMoney ( source, moneyToGive ) givePlayerMoney ( thePlayer, moneyToGive ) outputChatBox ( givingPlayer .. " has given you $" .. moneyToGive .. ".", thePlayer, 255, 255, 0 ) outputChatBox ( "You have given " .. playerToGive .. " $" .. moneyToGive .. ".", source, 255, 255, 0 ) else outputChatBox ( "You do not have enough money.", source, 255, 255, 0 ) end else outputChatBox ( thePlayer .. " does not exist.", source, 255, 255, 0 ) end else outputChatBox ( "Please specify an amount to give the player!", source, 255, 255, 0 ) end else outputChatBox ( "Please specify which player to give the money to!", source, 255, 255, 0 ) end end addCommandHandler ( "give", giveCommand )
Aibo Posted February 21, 2010 Posted February 21, 2010 oops, while i was typing answer was already posted well here's fun trick for you: try giving a negative amount of money (like -999999) there and see what happens anyway here's my part with a couple more checks: addCommandHandler("dardinero", function (thePlayer, theCommand, theTarget, amount) if theTarget then local giveTo = getPlayerFromName(theTarget) end if amount then amount = tonumber(amount) end if giveTo and amount then amount = math.floor(amount) if giveTo == thePlayer then outputChatBox("Error: You can't give money to yourself", thePlayer) elseif amount < 1 then outputChatBox("Error: You can't give nothing", thePlayer) elseif getPlayerMoney(thePlayer) < amount then outputChatBox("Error: You don't have $" .. amount, thePlayer) else takePlayerMoney(thePlayer, amount) givePlayerMoney(giveTo, amount) outputChatBox(getPlayerName(thePlayer) .. " gave you $" .. amount, giveTo) outputChatBox("You gave $" .. amount .. " to " .. theTarget, thePlayer) end else outputChatBox("Type /" .. theCommand .. " ", thePlayer) end end )
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