Jump to content

Simple Pay Script


shaio

Recommended Posts

Well this is a small server-side payment script that lets players pay each other, unfortunately my 'money checker' doesn't work, no matter how much money you have, it says you don't have enough. I have no idea why it is doing this..

function payScript(player,cmd,other,amount) 
local money = getPlayerMoney(player) 
local otherPlayer = getPlayerFromName(other) 
    if not other then 
        outputChatBox("Syntax: /pay (playerName) (amount)",player,0,255,255) 
    else 
        if not amount then 
            outputChatBox("Syntax: /pay (playerName) (amount)",player,0,255,255) 
        else 
            if ((money - amount) < money) then 
                outputChatBox("You do not have enough money!",player,0,255,255) 
                return 
            else 
                setPlayerMoney(otherPlayer,getPlayerMoney(otherPlayer) + amount) 
                setPlayerMoney(player,money - amount) 
                outputChatBox("$"..amount.." has been sent to "..other.."!",player,0,255,255) 
                outputChatBox("You have received $"..amount.." from "..getPlayerName(player).."!",otherPlayer,0,255,255) 
            end 
        end 
    end 
end 
addCommandHandler("pay",payScript) 

Link to comment

Use this.

function payScript(player,cmd,other,amount) 
local money = getPlayerMoney(player) 
local otherPlayer = getPlayerFromName(other) 
    if not other then 
        outputChatBox("Syntax: /pay (playerName) (amount)",player,0,255,255) 
    else 
        if not amount then 
            outputChatBox("Syntax: /pay (playerName) (amount)",player,0,255,255) 
        else 
            if ((money - amount) < 0) then 
                outputChatBox("You do not have enough money!",player,0,255,255) 
                return 
            else 
                setPlayerMoney(otherPlayer,getPlayerMoney(otherPlayer) + amount) 
                setPlayerMoney(player,money - amount) 
                outputChatBox("$"..amount.." has been sent to "..other.."!",player,0,255,255) 
                outputChatBox("You have received $"..amount.." from "..getPlayerName(player).."!",otherPlayer,0,255,255) 
            end 
        end 
    end 
end 
addCommandHandler("pay",payScript) 

Link to comment

By the way, since you had the same outputChatBox for both 'if not other then' and 'if not amount then', you can merge them to one line:

  
if not other or not amount then 
     outputChatBox("Syntax: /pay (playerName) (amount)",player,0,255,255) 
end 
  

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