Jump to content

[Porblem]Give-money


//_Dragon

Recommended Posts

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) 

Link to comment

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 

Link to comment

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) 

Link to comment
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)  

Link to comment
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) 

Link to comment

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 

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...