@name AutoGunShop
@inputs Entity:entity
@persist Owner:entity

if (first() | dupefinished())
{
    function entity randomPlayer()
    {
        local Found = noentity()
        foreach (Index, Player:entity=players())
        {
                if (Player != Owner)
                {
                    Found = Player
                    break
                }
        }

        return Found                
    }

    Owner = owner()
    runOnChat(1)
}

elseif (inputClk())
{
    if (Entity:isValid())
    {
        if (Entity:isMoneyDrop() | Entity:isChequeDrop())
        {
            absorbMoney(Entity)
        }
    }
}

elseif (chatClk(Owner))
{
    local Text = lastSaid():lower()
    if (Text == "drop_money")
    {
        if (canAfford(500))
        {
            dropMoney(500, Owner:eyeTrace():position())
        }
    }

    elseif (Text == "drop_cheque")
    {
        if (canAfford(500))
        {
            dropCheque(500, Owner, Owner:eyeTrace():position())
        }
    }

    elseif (Text == "check_money")
    {
        print(_HUD_PRINTTALK, select(Owner:aimEntity():isMoneyDrop() + 1, "Not a money drop.", "Is a money drop."))
    }

    elseif (Text == "check_cheque")
    {
        print(_HUD_PRINTTALK, select(Owner:aimEntity():isChequeDrop() + 1, "Not a cheque drop.", "Is a cheque drop."))
    }

    elseif (Text == "get_money")
    {
        print(_HUD_PRINTTALK, Owner:aimEntity():getMoneyAmount())
    }

    elseif (Text == "get_signer")
    {
        print(_HUD_PRINTTALK, Owner:aimEntity():getSigner())
    }

    elseif (Text == "get_recipient")
    {
        print(_HUD_PRINTTALK, Owner:aimEntity():getRecipient())
    }

    elseif (Text == "give_money")
    {
        local Found = randomPlayer()
        if (Found:isValid())
        {
            if (canAfford(500))
            {
                print(_HUD_PRINTTALK, "Gave " + Found:name() + " $500.")
                giveMoney(500, Found)
            }
        }
    }
}
