Jump to content

[Solved] Take money command


Eshtiz

Recommended Posts

I've been trying to make a command that takes money from a specific player ID/name

here's what I got so far (I've checked wiki, didn't work well):

function takeMoney(thePlayer, commandName, target, money) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
        if not (target) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Partial Player Nick] [Money]", thePlayer, 255, 194, 14) 
        else 
            local username = getPlayerName(thePlayer) 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick(thePlayer, target) 
             
            if targetPlayer then 
                        local adminTitle = exports.global:getPlayerAdminTitle(thePlayer) 
                exports.logs:logMessage("[GIVE] " .. getPlayerName(thePlayer):gsub("_", " ") .. " gave " .. targetPlayerName .. " to $" .. money, 23) 
                exports.global:sendMessageToAdmins("AdmCmd: " .. getPlayerName(thePlayer) .. " gave " .. targetPlayerName .. " " .. money .. " dollars.") 
                exports.global:takeMoney(targetPlayer, money) 
                outputChatBox("Random text " .. targetPlayerName .. " $" .. money .. ".", thePlayer) 
                outputChatBox("Admin " .. username .. " has taken  $" .. money .. ".", targetPlayer) 
                    outputChatBox(" " .. tostring(adminTitle) .. " " .. getPlayerName(thePlayer) .. " took " .. targetPlayerName .. " " .. money .. " dollars.", getRootElement(), 255, 0, 51) 
            end 
        end 
    end 
end 

I reversed it from a 'givemoney' script/command and hoped for it to work, but doesn't, any suggestionss on how to?

I checked this: https://wiki.multitheftauto.com/wiki/TakePlayerMoney

didn't really work either.

Edited by Guest
Link to comment

Server side.

function takeMoney( thePlayer, commandName, target, money ) 
    if exports.global:isPlayerLeadAdmin( thePlayer ) then 
        if not target then 
            outputChatBox( "SYNTAX: /" .. commandName .. " [Partial Player Nick] [Money]", thePlayer, 255, 194, 14 ) 
        else 
            local username = getPlayerName(thePlayer) 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick( thePlayer, target ) 
             
            if targetPlayer then 
                local adminTitle = exports.global:getPlayerAdminTitle( thePlayer ) 
                exports.logs:logMessage( "[GIVE] " .. getPlayerName(thePlayer):gsub("_", " ") .. "\ 
                gave " .. targetPlayerName .. " to $" .. money, 23 ) 
                exports.global:sendMessageToAdmins( "AdmCmd: " .. getPlayerName( thePlayer ) .. "\ 
                gave " .. targetPlayerName .. " " .. money .. " dollars." ) 
                exports.global:takeMoney( targetPlayer, tonumber( money ) ) 
                outputChatBox( "Random text " .. targetPlayerName .. " $" .. money .. ".", thePlayer ) 
                outputChatBox( "Admin " .. username .. " has taken  $" .. money .. ".", targetPlayer ) 
                outputChatBox( " " .. tostring( adminTitle ) .. "\ 
                " .. getPlayerName( thePlayer ) .. " took " .. targetPlayerName .. "\ 
                " .. money .. " dollars.", root, 255, 0, 51 ) 
            end 
        end 
    else 
        outputChatBox( ' not isPlayerLeadAdmin' ) 
    end 
end 
addCommandHandler( 'takemoney',takeMoney ) 

cmd /takemoney [player][ money ]

Link to comment
You're not a lead admin then, Esh.

I am, but as Solidsnake said, I forgot the command handler, stupid of me, sorry for wasting time.

but I got something else , I'm trying to make the /givemoney command "globaly" remove the ID and give everyone online an amount of money.

this is what I got so far:

function giveAllMoney(thePlayer, commandName, money) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
        if not (target) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Money]", thePlayer, 255, 194, 14) 
        else 
            local username = getPlayerName(thePlayer) 
             
            if targetPlayer then 
                        local adminTitle = exports.global:getPlayerAdminTitle(thePlayer) 
                exports.logs:logMessage("[GIVE] " .. getPlayerName(thePlayer):gsub("_", " ") .. " gave " .. targetPlayerName .. " to $" .. money, 23) 
                exports.global:sendMessageToAdmins("AdmCmd: " .. getPlayerName(thePlayer) .. " gave all players online " .. money .. " dollars.") 
                outputChatBox("You have given  $" .. money .. " to all players ", thePlayer) 
                outputChatBox("Admin " .. username .. " has given you $" .. money .. ".", targetPlayer) 
                    outputChatBox(" " .. tostring(adminTitle) .. " " .. getPlayerName(thePlayer) .. " gave all players online " .. money .. " dollars.", getRootElement(), 255, 0, 51) 
            end 
        end 
    end 
end 
addCommandHandler("giveallmoney", giveAllMoney, false, false) 

Only syntax shows but doesn't give money to anyone when it's supposed to give ALL online players.

Link to comment
function giveAllMoney(thePlayer, commandName, money) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
        if (not money) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Money]", thePlayer, 255, 194, 14) 
        else 
            local username = getPlayerName(thePlayer) 
            local adminTitle = exports.global:getPlayerAdminTitle(thePlayer) 
            exports.global:sendMessageToAdmins("AdmCmd: " .. getPlayerName(thePlayer) .. " gave all players online " .. money .. " dollars.") 
            outputChatBox("You have given  $" .. money .. " to all players ", thePlayer) 
            for index, player in ipairs(getElementsByType("player")) do 
                exports.global:giveMoney( player, tonumber( money ) ) 
                outputChatBox("Admin " .. username .. " has given you $" .. money .. ".", player) 
            end 
            outputChatBox(" " .. tostring(adminTitle) .. " " .. getPlayerName(thePlayer) .. " gave all players online " .. money .. " dollars.", getRootElement(), 255, 0, 51) 
        end 
    end 
end 
addCommandHandler("giveallmoney", giveAllMoney, false, false) 

Link to comment

Ah, I see, well I have this givemoney script/command directed for an(specific) ID/player.

If it helps,

function giveMoney(thePlayer, commandName, target, money) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
        if not (target) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Partial Player Nick] [Money]", thePlayer, 255, 194, 14) 
        else 
            local username = getPlayerName(thePlayer) 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick(thePlayer, target) 
             
            if targetPlayer then 
                        local adminTitle = exports.global:getPlayerAdminTitle(thePlayer) 
                exports.logs:logMessage("[GIVE] " .. getPlayerName(thePlayer):gsub("_", " ") .. " gave " .. targetPlayerName .. " to $" .. money, 23) 
                exports.global:sendMessageToAdmins("AdmCmd: " .. getPlayerName(thePlayer) .. " gave " .. targetPlayerName .. " " .. money .. " dollars.") 
                exports.global:giveMoney(targetPlayer, money) 
                outputChatBox("You have given " .. targetPlayerName .. " $" .. money .. ".", thePlayer) 
                outputChatBox("Admin " .. username .. " has given you $" .. money .. ".", targetPlayer) 
                    outputChatBox(" " .. tostring(adminTitle) .. " " .. getPlayerName(thePlayer) .. " gave " .. targetPlayerName .. " " .. money .. " dollars.", getRootElement(), 255, 0, 51) 
            end 
        end 
    end 
end 
addCommandHandler("givemoney", giveMoney, false, false) 
  

if not I'll try myself again :D people have been giving a lot of suggestions etc, nothing worked yet.

anyways, there it is, might help to complete the giveallmoney script.

Link to comment
function giveAllMoney(thePlayer, commandName, money) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
        if (not money) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [Money]", thePlayer, 255, 194, 14) 
        else 
            local username = getPlayerName(thePlayer) 
            local adminTitle = exports.global:getPlayerAdminTitle(thePlayer) 
            exports.global:sendMessageToAdmins("AdmCmd: " .. getPlayerName(thePlayer) .. " gave all players online " .. money .. " dollars.") 
            outputChatBox("You have given  $" .. money .. " to all players ", thePlayer) 
            for index, player in ipairs(getElementsByType("player")) do 
                exports.global:giveMoney( player, tonumber( money ) ) 
                outputChatBox("Admin " .. username .. " has given you $" .. money .. ".", player) 
            end 
            outputChatBox(" " .. tostring(adminTitle) .. " " .. getPlayerName(thePlayer) .. " gave all players online " .. money .. " dollars.", getRootElement(), 255, 0, 51) 
        end 
    end 
end 
addCommandHandler("giveallmoney", giveAllMoney, false, false) 

I tested it and seems to work.

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