Jump to content

givemoney function


Recommended Posts

Posted

I did this function:

function DaiSoldi(player,quantita) 
    quantita=tonumber(quantita) 
    givePlayerMoney(player, quantita) 
    outputChatBox("|Uso:| /givemoney [giocatore]",player) 
    end 
end 
  
addCommandHandler("givemoney", DaiSoldi) 

but doesn't happen anything. Why?

Posted

You have an extra 'end'

function DaiSoldi(player,quantita) 
    quantita=tonumber(quantita) 
    givePlayerMoney(player, quantita) 
    outputChatBox("|Uso:| /givemoney [giocatore]",player) 
end 
  
addCommandHandler("givemoney", DaiSoldi) 

Posted

I changed to this:

function DaiSoldi(player,cmd,source,quantita) 
    quantita=tonumber(quantita) 
    if(quantita) then 
    givePlayerMoney(source, quantita) 
    else 
    outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) 
    end 
end 
  
addCommandHandler("givemoney", DaiSoldi) 

but it says: "Bad argument @ 'givePlayerMoney'"

Posted
function DaiSoldi(player, cmd, quantita, soldi) 
    local soldi = tonumber(soldi) 
    local quantita = getPlayerFromName(quantita) 
    if (soldi) and (isElement(quantita) then 
        givePlayerMoney(quantita, soldi) 
    else 
        outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) 
    end 
end 
addCommandHandler("givemoney", DaiSoldi) 

Posted

try with this

Server

  
addCommandHandler("givemoney", 
    function(player, cmd, quantita, soldi) 
        local soldi = tonumber(soldi) 
        local quantita = findPlayerByName(tostring(quantita)) 
        if soldi and quantita then 
            givePlayerMoney(quantita, soldi) 
        else 
            outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) 
        end 
    end 
) 
  
  
function findPlayerByName (playerPart ) 
    local players = getPlayerFromName(playerPart) 
    if ( players ) then return players end 
    local matches = {} 
    for id, players in ipairs ( getElementsByType ( "player" ) ) do 
        if ( string.find ( string.upper ( getPlayerName ( players ) ), string.upper ( playerPart ), 1, true ) ) then 
            table.insert(matches,players) 
        end 
    end 
    if #matches == 0 then 
        return false 
    elseif #matches == 1 then 
        return matches[1] 
    else 
        return false 
    end 
end 
  
  

Posted
That code will only look for the player element with the exact name you write.

I written the exact name but it doesn't work.

With color codes?

Posted
That code will only look for the player element with the exact name you write.

I written the exact name but it doesn't work.

With color codes?

Maybe he used without color code

Posted
  
function getPlayerFromNamePart(name) 
    if name then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
            end 
        end 
    end 
    return false 
end 
  
addCommandHandler("givemoney", 
    function(player, cmd, quantita, soldi) 
        local soldi = tonumber(soldi) 
        local quantita = getPlayerFromNamePart(tostring(quantita)) 
        if soldi and quantita then 
            givePlayerMoney(quantita, soldi) 
        else 
            outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) 
        end 
    end 
) 
  
  

Posted
  
function getPlayerFromNamePart(name) 
    if name then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
            end 
        end 
    end 
    return false 
end 
  
addCommandHandler("givemoney", 
    function(player, cmd, quantita, soldi) 
        local soldi = tonumber(soldi) 
        local accountname = getAccountName(getPlayerAccount(player)) 
        local quantita = getPlayerFromNamePart(tostring(quantita)) 
        if soldi and quantita then 
            if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" )) then 
                   givePlayerMoney(quantita, soldi) 
             end 
        else 
            outputChatBox("|Uso:| /givemoney [giocatore] [soldi]",player) 
        end 
    end 
) 
  
  

try with this

Posted

@scienziato-pazzo, your script was a complete mess.

About the player ID, how do you get it/store it? There's no magical way to get a player ID because simply there's no such thing in MTA, player ID should be scripted by the programmers.

Posted
@scienziato-pazzo, your script was a complete mess.

About the player ID, how do you get it/store it? There's no magical way to get a player ID because simply there's no such thing in MTA, player ID should be scripted by the programmers.

Yes, but how to do what I want? It's possible?

Posted
About the player ID, how do you get it/store it?

Would be faster if you read everything people say.

And what people say?

Are you kidding? I already quoted what I said two times.

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