Jump to content

how to give player that i choose money


TroyBoy

Recommended Posts

Server.

function findPlayer( namepart ) 
    local player = getPlayerFromName( namepart ) 
    if player then 
        return player 
    end 
    for _,player in pairs( getElementsByType 'player' ) do 
        if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then 
            return player 
        end 
    end 
    return false 
end 
  
addCommandHandler( 'givemoney', 
    function( source,_,player,amount ) 
        local find = findPlayer( player ) 
        if find then 
            if amount then 
                givePlayerMoney( find,tonumber( amount ) ) 
                outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 ) 
            else 
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
            end  
        else 
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
        end 
    end 
)    

Updated.

Link to comment
function findPlayer( namepart ) -- 1 argument is string 
    local player = getPlayerFromName( namepart ) 
    if player then -- if player found 
        return player -- return player element 
    end 
    -- So if not found with getPlayerFromName then find player with loop. 
    for _,player in pairs( getElementsByType 'player' ) do -- loop table players 
        if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then -- find player by pattern  
            return player -- return player element 
        end 
    end 
    return false -- return false if not found  
end 
  
addCommandHandler( 'givemoney', -- add command handler 
    function( source,_,player,amount ) -- 1 argument is source ( element player ) ( who use type this command ) , 2 argument is command name but we not need use this and we create 'upvalue' ( frozen variable that will not be used ) , 3 argument is player nick name ( string ) , 4 argument is amount 
        local find = findPlayer( player ) -- So call function findPlayer in argument use nick name ( string ) 
        if find then -- If player founded then 
            if amount then -- If player type amount ( full command /givemoney [nickname][amount] ) 
                givePlayerMoney( find,tonumber( amount ) ) -- give money for player 
                outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 ) -- write in chat box 
            else -- player not type full command ( /givemoney [nickname][amount] )  
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) -- write in chat box 
            end  
        else -- player not found  
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) -- write in chat box 
        end 
    end 
)    

Updated again.

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...