Please help, auto banking script/package

Post Reply
UmßraDivisio
Posts: 1
Joined: Fri Mar 29, 2024 12:00 am

Please help, auto banking script/package

Post by UmßraDivisio »

I need some assistance please, if possible, on setting up a package of triggers, variables, aliases, and or scripts that will do automated banking for a character when a threshold of money is accumulated. I've tried to make it work via just a bunch of triggers and an alias or two but I keep having issues with something not working and breaking the chain of triggers so it goes haywire and spams a zillion commands. I haven't found a way to view the table/database in this client visually like I'm used to with zmud so I'm having issues working with it. It needs to have ability for player to add and store/modify information into a table/database. My understanding of LUA is almost non-existant but I'm trying to learn, its just slow goings, making this whole process take that much longer for me to troubleshoot.

Things to prompt player for: Names of Citys (1-8), paths to and from Port and Bank in City(all are unique(to and froe are mirrored possible to only enter the to path?), all seperated via commas or something), an adjustable amount of gold(1-10000) the player can set(one to control when to deposit, one to control how much to deposit each time), and a collection of bank accounts(safes) identified via numbers(1-10 5 digit numbers).

Way it will hopefully work: Upon reaching a city it will trigger off the Citys name if the gold threshold was reached or if commanded by player(wait till City name is seen to start next part if activated by player(I think this is where my mass of triggers messes up the most)), path the unique path to the Bank(anywhere between 1 and 20 rooms apart), make a deposit into whichever account(s), then path back(this is another spot my system fails because it sees the City name again and I dont know how to stop it from reactivating), and then do some echo to announce completion.

Examples of things to trigger off of: the Kingdom of (.*), you have (.*) gold, puts (.*) gold in your safe, that safe is full.(progress to next safe number).

Jor'Mox
Posts: 1153
Joined: Wed Apr 03, 2013 2:19 am

Re: Please help, auto banking script/package

Post by Jor'Mox »

Okay, so let me try to break this down into discrete elements, and you can provide correction if necessary. These are the tasks any script/package would need to perform, as I understand it.

1) Detection of key events: gold carried by character, gold deposited in bank, arrival at city port.
2) Movement: from port to bank, and bank to port, using provided path info for each city.
3) Banking: attempt to deposit gold into bank accounts, rotate to next account if one is full, track gold carried.
4) User Direction: set deposit thresholds and amounts, account numbers, user triggered banking when automated banking not triggered.

This is a simple script I threw together that I think should do what you are asking, though you'd need to provide all the relevant triggers and aliases
Code: [show] | [select all] lua
Banking = Banking or {}

-- update these values via aliases/triggers / set default values in script
Banking.gold_carried = Banking.gold_carried or 0
Banking.deposit_threshold = Banking.deposit_threshold or 1
Banking.deposit_amount = Banking.deposit_amount or 1

-- add cities and directions to this table
local bank_directions = bank_directions or {["city 1"] = {'n','e','n','w'}, ["city 2"] = {'s','w','s','e','n'}}

-- add default account numbers to use here if desired
local account_numbers = account_numbers or {}

-- internal variables
local current_account = current_account or 1
local directions = directions or {}
local reverse_dirs = reverse_dirs or {}
local do_banking = do_banking or false

-- call via alias to manually trigger banking
function Banking.go_banking()
    do_banking = true
end

-- call via alias to add new account number
function Banking.add_account(num)
    num = tonumber(num)
    table.insert(account_numbers, num)
end

-- call via alias to remove account number from list
function Banking.remove_account(num)
    num = tonumber(num)
    local index
    for i,v in ipairs(account_numbers) do
        if v == num then
            index = i
            break
        end
    end
    if index then table.remove(account_numbers, index) end
end

-- call via trigger when arriving at port
function Banking.at_port(city)
    -- check if gold is over threshold
    local gold = tonumber(Banking.gold_carried)
    local threshold = tonumber(Banking.deposit_threshold)
    if gold >= threshold then do_banking = true end
    -- if needed, head off banking
    if do_banking then
        do_banking = false
        directions = bank_directions[city]
        reverse_dirs = {}
        -- walk to bank and create reverse_dirs table
        for i,v in ipairs(directions) do
            send(v)
            table.insert(reverse_dirs,1,v)
        end
        -- enable deposit triggers here
        enableTrigger("Failed Bank Deposit Trigger")
        enableTrigger("Successful Bank Deposit Trigger")
        -- perform bank deposit
        Banking.make_deposit(false)
    end
end

-- re-call this function via trigger that detects account full: Banking.make_deposit(true)
function Banking.make_deposit(account_full)
    -- use next account in list if account full
    if account_full then
        if current_account >= #account_numbers then
            -- wrap around to first account if end of list reached
            current_account = 1
        else
            -- switch to next account
            current_account = current_account + 1
        end
    end
    -- send command to make deposit
    send(string.format("deposit %d gold in account %d", deposit_amount, account_numbers[current_account]))
end

-- call via trigger upon successful deposit
function Banking.deposit_made(amount)
    amount = amount or deposit_amount
    -- update gold_carried
    amount = tunumber(amount)
    gold_carried = gold_carried - amount
    -- disable deposit triggers here
    disableTrigger("Failed Bank Deposit Trigger")
    disableTrigger("Successful Bank Deposit Trigger")
    -- walk back to port
    for i,v in ipairs(reverse_dirs) do
        send(v)
    end
end

Post Reply