Jump to content

[Solved] Take money command


Eshtiz

Recommended Posts

Posted (edited)

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
Posted

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 ]

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

Posted
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) 

Posted

Doesn't work, no syntax, no command, no money ;S

Error message:

ERROR: admin-system/Player/s_player_commands.lua:1791: attempt to concaenate local 'money'(a nil value)

Posted

Yeh, I'm back to page one. Only shows the syntax and doesn't hand out any money ;/

and yeh, I'm using it ServerSide & I have similar scripts to this one ServerSided, why wouldn't it work on ServerSide?

Posted

Eshtiz: Don't listen to Evil-Codr, he's a newbie, this is server side, not client side.

And it should work, I don't know much about Valhalla Scripts.

Posted

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.

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

Posted

That one works well, but isn't it the same as the old one? (if it is, I guess I got an old one while you edited previous posts) >,<

How do I edit the font style for it and any fonts for similar texts? can you link me something?

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