Jump to content

Player's Money


Recommended Posts

Hey Guys, this script shows in chat the money of the player who write in chat !cash or !money.

i want to make the players can check other players money like: !cash [playerName]. i don't want to use the command handler.

How can i do that?

Server:

addEventHandler("onPlayerChat", getRootElement(), 
    function(msg) 
            if (msg == "!money" or msg == "!cash") then 
                cash = getPlayerMoney(source) 
                outputChatBox("#0188ff"..getPlayerName(source).." Has #ff8801$"..cash, getRootElement(), 255,255,255,true) 
            end 
    end 
) 
  
  

Link to comment

you can do this

addCommandHandler("money", getRootElement(), 
function(playerName) 
if playername then 
playername = getPlayerName () 
money = getPlayerMoney () 
outputChatBox ("The player"..playername.."have:"..money.."$", source, 255, 0, 255 ) 
else 
outputChatBox("Syntax : /money Playername", source, 255, 0, 255) 
end 
end)  

I do not know if it works but try

Link to comment
you can do this
addCommandHandler("money", getRootElement(), 
function(playerName) 
if playername then 
playername = getPlayerName () 
money = getPlayerMoney () 
outputChatBox ("The player"..playername.."have:"..money.."$", source, 255, 0, 255 ) 
else 
outputChatBox("Syntax : /money Playername", source, 255, 0, 255) 
end 
end)  

I do not know if it works but try

This is wrong .

Link to comment

You should use this to get player from name.

function getPlayerFromName( partialName ) 
    if partialName then 
        local matches = {} 
        for i, player in ipairs ( getElementsByType ( "player" ) ) do 
            if getPlayerName ( player ) == partialName then 
                return player 
            end 
            if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then 
                table.insert ( matches , player ) 
            end 
        end 
        if #matches == 1 then 
            return matches [ 1 ] 
        end 
    end 
    return false 
end 

Link to comment
addEventHandler("onPlayerChat", getRootElement(), 
function(msg) 
    if msg:find("!money ") or msg:find("!cash ") then 
        for i,v in ipairs(getElementsByType("player")) do 
            if msg:find(getPlayerName(v)) and getPlayerName(v) ~= false then 
                local player = getPlayerFromName(v) 
                local cash = getPlayerMoney(player) 
                outputChatBox("#0188ff"..getPlayerName(player).." Has #ff8801$"..cash, root, 255,255,255,true) 
            else 
                outputChatBox("Wrong player-name/syntax", source) 
            end 
        end 
    end 
end 
) 

I'm not sure of this, but it should work.

Link to comment
addEventHandler ( "onPlayerChat", getRootElement(), 
    function ( msg ) 
        local splittedMsg = split ( msg, " " ) 
        if ( type ( splittedMsg ) == "table" ) then 
            if ( splittedMsg [ 1 ] == "!money" or splittedMsg [ 1 ] == "!cash" ) then 
                local player = getPlayerFromName ( splittedMsg [ 2 ] ) 
                if ( player ) then 
                    local cash = getPlayerMoney ( player ) 
                    outputChatBox ( "#0188ff".. getPlayerName ( player ) .." Has #ff8801$".. cash, root, 255, 255, 255, true ) 
                else 
                    outputChatBox ( "Player not found!", source, 255, 0, 0 ) 
                end 
            end 
        end 
    end 
) 
  
function getPlayerFromName ( partialName ) 
    if partialName then 
        local matches = {} 
        for i, player in ipairs ( getElementsByType ( "player" ) ) do 
            if getPlayerName ( player ) == partialName then 
                return player 
            end 
            if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then 
                table.insert ( matches , player ) 
            end 
        end 
        if #matches == 1 then 
            return matches [ 1 ] 
        end 
    end 
    return false 
end 

Link to comment
addEventHandler ( "onPlayerChat", getRootElement(), 
    function ( msg ) 
        local splittedMsg = split ( msg, " " ) 
        if ( type ( splittedMsg ) == "table" ) then 
            if ( splittedMsg [ 1 ] == "!money" or splittedMsg [ 1 ] == "!cash" ) then 
                local player = getPlayerFromName ( splittedMsg [ 2 ] ) 
                if ( player ) then 
                    local cash = getPlayerMoney ( player ) 
                    outputChatBox ( "#0188ff".. getPlayerName ( player ) .." Has #ff8801$".. cash, root, 255, 255, 255, true ) 
                else 
                    outputChatBox ( "Player not found!", source, 255, 0, 0 ) 
                end 
            end 
        end 
    end 
) 
  
function getPlayerFromName ( partialName ) 
    if partialName then 
        local matches = {} 
        for i, player in ipairs ( getElementsByType ( "player" ) ) do 
            if getPlayerName ( player ) == partialName then 
                return player 
            end 
            if getPlayerName ( player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( partialName : lower ( ) ) then 
                table.insert ( matches , player ) 
            end 
        end 
        if #matches == 1 then 
            return matches [ 1 ] 
        end 
    end 
    return false 
end 

Thanks it's working, but can i make that if the player not found do not display "!cash" on chat.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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