Negriukas Posted July 3, 2014 Share Posted July 3, 2014 Hi, When i try to send someone money it doesnt output in chat box the text for the local player, but the target player can see the output, It suppose to write in chatbox ("You gave "..money.." to "..getPlayerName(targetPlayer)", source, r, g, b) The problem is that the target player can recieve the text of the money but who send money it doesnt output nothing, here is the code function giveSomeoneMoney(player, cmd, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromParticalName(target) local r,g,b = getPlayerNametagColor(source) amount = tonumber(amount) if targetplayer then if money >= amount then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox("You have been given #00FF00$"..amount.." #0096FF from #FFFFFF"..getPlayerName(player) , targetplayer, 0, 81, 255, true) outputChatBox("You gave #00FF00$"..amount.."#0096FF to #FFFFFF"..getPlayerName(target), player, 0, 81, 255, true) else outputChatBox("You don't have enought money!", player, 255, 0, 0) end else outputChatBox("Error: Player not found", player, 255, 0, 0) end else outputChatBox("Error: /givemoney [player name] [amount]", player, 255, 0, 0) end else outputChatBox("Error: /givemoney [player name] [amount]", player, 255, 0, 0) end end addCommandHandler("givemoney", giveSomeoneMoney) function getPlayerFromParticalName(thePlayerName) local thePlayer = getPlayerFromName(thePlayerName) if thePlayer then return thePlayer end for _,thePlayer in ipairs(getElementsByType("player")) do if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then return thePlayer end end return false end Link to comment
MTA Team botder Posted July 3, 2014 MTA Team Share Posted July 3, 2014 outputChatBox("You gave #00FF00$"..amount.."#0096FF to #FFFFFF"..getPlayerName(target) getPlayerName(target) Use targetplayer instead of target, because you pass the command parameter name to the function: Example usage: /givemoney Franklin234 500 That line produces the following code: outputChatBox("You gave #00FF00$".."500".."#0096FF to #FFFFFF"..getPlayerName("Franklin234") Link to comment
Negriukas Posted July 5, 2014 Author Share Posted July 5, 2014 Another problem is showing up, I guess it's the second argument of outputChatBox in line 13 Link to comment
Negriukas Posted July 5, 2014 Author Share Posted July 5, 2014 amount = tonumber(amount) Link to comment
SkittlesAreFalling Posted July 5, 2014 Share Posted July 5, 2014 But you cannot set a string with a number in Lua, you must convert the number to string: outputChatBox("You gave #00FF00$"..tostring(amount).."#0096FF to #FFFFFF"..getPlayerName(target)); Do not argue just test it before being naive. Link to comment
MTA Team botder Posted July 5, 2014 MTA Team Share Posted July 5, 2014 outputChatBox("You gave #00FF00$"..tostring(amount).."#0096FF to #FFFFFF"..getPlayerName(target)) Again the wrong variable: outputChatBox("You gave #00FF00$"..tostring(amount).."#0096FF to #FFFFFF"..getPlayerName(targetplayer)) Link to comment
-.Paradox.- Posted July 5, 2014 Share Posted July 5, 2014 But you cannot set a string with a number in Lua, you must convert the number to string:outputChatBox("You gave #00FF00$"..tostring(amount).."#0096FF to #FFFFFF"..getPlayerName(target)); Do not argue just test it before being naive. Line 12 is working fine for target player Without converting it, The problem is that it doesnt show for the player who sent the money.... Link to comment
SkittlesAreFalling Posted July 5, 2014 Share Posted July 5, 2014 (edited) I just copied and pasted the code you had and edited the problem I saw for you. As long as it's fixed now: outputChatBox("You gave #00FF00$"..tostring(amount).."#0096FF to #FFFFFF"..getPlayerName(targetplayer), player, 0, 81, 255, true); Edited July 5, 2014 by Guest Link to comment
-.Paradox.- Posted July 5, 2014 Share Posted July 5, 2014 Try changing player argument Link to comment
Negriukas Posted July 15, 2014 Author Share Posted July 15, 2014 No not working, pls help Link to comment
Et-win Posted July 15, 2014 Share Posted July 15, 2014 function giveSomeoneMoney(player, cmd, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromParticalName(target) local r,g,b = getPlayerNametagColor(player) amount = tonumber(amount) if targetplayer then if money >= amount then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox("You have been given #00FF00$"..tostring(amount).." #0096FF from #FFFFFF"..getPlayerName(player) , targetplayer, 0, 81, 255, true) outputChatBox("You gave #00FF00$"..tostring(amount).."#0096FF to #FFFFFF"..getPlayerName(targetplayer), player, 0, 81, 255, true) else outputChatBox("You don't have enought money!", player, 255, 0, 0) end else outputChatBox("Error: Player not found", player, 255, 0, 0) end else outputChatBox("Error: /givemoney [player name] [amount]", player, 255, 0, 0) end else outputChatBox("Error: /givemoney [player name] [amount]", player, 255, 0, 0) end end addCommandHandler("givemoney", giveSomeoneMoney) function getPlayerFromParticalName(thePlayerName) local thePlayer = getPlayerFromName(thePlayerName) if thePlayer then return thePlayer end for _,thePlayer in ipairs(getElementsByType("player")) do if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then return thePlayer end end return false end Did everything what they said with your script and it works. EDIT: Edited it after forgetting to change a line back to normal. 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