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) 

CiTLh.png
Posted

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

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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 
  
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

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?

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

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 
) 
  
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

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

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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