//_Dragon Posted January 24, 2016 Posted January 24, 2016 I have problem in this script When some one give to other player money , all players can see in chatbox what he gave [DR]Dragon gave to [DR]Fedex 5555$ & i add something in script for fixe the problem but still when i give money to player , nothen happened ----[u][b]Before changing[/b][/u] function giveSomeoneMoney(player, cmd, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromName(target) amount = tonumber(amount) if targetplayer then if money >= amount and amount >= 250 then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox(getPlayerName(player).." give "..amount.." to "..getPlayerName(targetplayer), getRootElement(), 0, 165, 0, true) else outputChatBox("• You don't have enought money!", player, 255, 0, 0) end else outputChatBox("• Player not found", player, 255, 0, 0) end else outputChatBox("• Error: /gm [player name] [amount]", player, 255, 0, 0) end else outputChatBox("• Error: /gm [player name] [amount]", player, 255, 0, 0) end end addCommandHandler("gm", giveSomeoneMoney) addCommandHandler("givemoney", giveSomeoneMoney) ----[b][u]Atfter adding[/u][/b] function giveSomeoneMoney(player, cmd, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromParticalName(target) -------new local r,g,b = getPlayerNametagColor(player) -------new amount = tonumber(amount) if targetplayer then if money >= amount and amount >= 250 then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox("You Were Given #00FF00$"..tostring(amount).." #006400 From #FF0000"..getPlayerName(player) , targetplayer, 0, 100, 0, true) -------new outputChatBox("You Gave #00FF00$"..tostring(amount).."#006400 To #FF0000"..getPlayerName(targetplayer), player, 0, 100, 0, true) ------new else outputChatBox("• You don't have enought money!", player, 255, 0, 0) end else outputChatBox("• Player not found", player, 255, 0, 0) end else outputChatBox("• Error: /gm [player name] [amount]", player, 255, 0, 0) end else outputChatBox("• Error: /gm [player name] [amount]", player, 255, 0, 0) end end addCommandHandler("gm", giveSomeoneMoney) addCommandHandler("givemoney", giveSomeoneMoney)
Castillo Posted January 24, 2016 Posted January 24, 2016 The second code is right, and it should work. What do you mean by "nothing happened"? is the money being sent to the player?
//_Dragon Posted January 24, 2016 Author Posted January 24, 2016 The second code is right, and it should work.What do you mean by "nothing happened"? is the money being sent to the player? yes nothen happened ,
//_Dragon Posted January 24, 2016 Author Posted January 24, 2016 Check debugscript for errors. Error : Gmoney\script.lua:5: attempt to call global 'getPlayerFromParticalName' (a nit value)
Castillo Posted January 24, 2016 Posted January 24, 2016 That's because getPlayerFromParticalName is not defined. Add this function to the end of the script: function getPlayerFromParticalName (name) -- BY TAPL local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end
//_Dragon Posted January 24, 2016 Author Posted January 24, 2016 thanks work but i've a little problem i want getplayercolorname outputChatBox("You Were Given #00FF00$"..tostring(amount).." #006400 From #FF0000"..getPlayerName(player) , targetplayer, 0, 100, 0, true) outputChatBox("You Gave #00FF00$"..tostring(amount).."#006400 To #FF0000"..getPlayerName(targetplayer), player, 0, 100, 0, true)
//_Dragon Posted January 24, 2016 Author Posted January 24, 2016 What do you mean? I mean like ur nametag color is : Solidsnake14 i must see in chatbox you get were given 2222$ from Solidsnake14 --- ur color you gave 2222$ to Oussez--Color blue
Castillo Posted January 24, 2016 Posted January 24, 2016 Use getPlayerNametagColor and this useful function (REMEMBER TO COPY SOURCE CODE): https://wiki.multitheftauto.com/wiki/RGBToHex
Castillo Posted January 24, 2016 Posted January 24, 2016 Try to do it, if it doesn't work, post here what you tried.
//_Dragon Posted January 24, 2016 Author Posted January 24, 2016 Try to do it, if it doesn't work, post here what you tried. 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(thePlayer) ---- local r, g, b local fromHex = string.format("#%.2X%.2X%.2X", r, g, b) -- converts R, G, B to HEX value local hex = string.format("#%.2X%.2X%.2X", r, g, b) -- converts R, G, B to HEX value amount = tonumber(amount) if targetplayer then if money >= amount and amount >= 250 then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox("You Were Given from " ..fromHex.. getPlayerName(player) .. " #00FF00$"..tostring(amount).." , targetplayer, 0, 100, 0, true) outputChatBox("You Gave to " ..toHex.. getPlayerName(targetplayer) .. " #00FF00$"..tostring(amount)..", player, 0, 100, 0, true)
1LoL1 Posted January 24, 2016 Posted January 24, 2016 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(thePlayer) ---- local r, g, b local hex = string.format("#%.2X%.2X%.2X", r, g, b) -- converts R, G, B to HEX value amount = tonumber(amount) if targetplayer then if money >= amount and amount >= 250 then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox("You Were Given from "..hex..getPlayerName(player).." #00FF00$"..tostring(amount).."", targetplayer, 0, 100, 0, true) outputChatBox("You Gave to "..hex..getPlayerName(targetplayer).." #00FF00$"..tostring(amount).."", player, 0, 100, 0, true) end end end end end addCommandHandler("give", giveSomeoneMoney)
KariiiM Posted January 24, 2016 Posted January 24, 2016 You both repeated the same errors, and btw your code is totally messy you forgot about 5 ends, Plus there're some arguments typed and not defined. Try that, It should works function giveSomeoneMoney(player, _, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromParticalName(target) local r, g, b = getPlayerNametagColor(targetplayer) local pr, pg, pb = getPlayerNametagColor(player) local hex = string.format("#%.2X%.2X%.2X", r, g, b) local fromHex = string.format("#%.2X%.2X%.2X", pr, pg, pb) local amount = tonumber(amount) if targetplayer then if money >= amount and amount >= 250 then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox("You Were Given from " ..fromHex .. getPlayerName(player).. " #00FF00$"..tostring(amount).."" , targetplayer, 0, 100, 0, true) outputChatBox("You Gave to "..hex..getPlayerName(targetplayer).." #00FF00$"..tostring(amount).."", player, 0, 100, 0, true) end end end end end addCommandHandler("give", giveSomeoneMoney) function getPlayerFromParticalName (name) -- BY TAPL local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end
Recommended Posts