EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Custom (https://www.eqemulator.org/forums/forumdisplay.php?f=671)
-   -   LUA Bucket Shared Banker (https://www.eqemulator.org/forums/showthread.php?t=42359)

rudeboy88 03-12-2019 03:24 PM

LUA Bucket Shared Banker
 
Hey everyone,

Put this one together as part of some NPCs I've been working at here and there for a casino. This one is simply a banker that converts your platinum to a Data Bucket Value based on your Account ID, so it doubles up as a shared bank.

note: With LUA I think you may need to either add a clause to give players the bucket referenced here or add it somewhere else before players can use it.

Code:

function event_say(e)
        if (e.message:findi("hail")) then
                e.other:Message(315, "Hail and well met mighty adventurer!  If you would like to [" .. eq.say_link("exchange",false,"exchange") .. "] platinum for credit, cash [" .. eq.say_link("out",false,"out") .. "], or know how much [" .. eq.say_link("credit",false,"credit") .. "] you have, I can help you with that.");
        end
       
        if (e.message:findi("exchange")) then
                e.other:Message(315,"If you hand me platinum, I will convert it into credit.  Your money will be safe with me, but you can always cash out if you'd like.");
        end
       
        if (e.message:findi("credit")) then
                local k = eq.get_data(e.other:AccountID() .. "_Casino");
                e.other:Message(315,"Currently your balance is " .. k ..".");
        end
       
        if (e.message:findi("out")) then
                local cashout = eq.get_data(e.other:AccountID() .. "_Casino");
                e.other:GiveCash(0, 0, 0, tonumber(cashout));
                eq.set_data(e.other:AccountID() .. "_Casino", '0');
                e.other:Message(315,"Your balance has been cleared.  Enjoy the rest of your stay!");
        end
end

function event_trade(e)
        local item_lib = require("items");
        if(e.trade.platinum ~= 0 and e.trade.platinum ~= nil) then
                local c2 = e.trade.platinum;
                local c3 = eq.get_data(e.other:AccountID() .. "_Casino");
                local c4 = c2 + c3;
                eq.set_data(e.other:AccountID() .. "_Casino", tostring(c4));
                e.other:Message(315,"Your platinum has been credited to your account.  Your current balance is: " .. eq.get_data(e.other:AccountID() .. "_Casino") .. ".");
        end
        item_lib.return_items(e.self, e.other, e.trade);
end

I tend to use global_player.pl for connection-based checks for my LUA docs/Buckets since it's a convenient way to add em for all chars, if you'd like that then add this to your global_player.pl:

Code:

sub EVENT_CONNECT
{
        $key = $client->AccountID() . "_Casino";
        if($client->AccountID() . "_Casino" == '')
        {
    quest::set_data($key, 0);
        }
}


rudeboy88 03-26-2019 07:40 PM

Did a little cleanup today same script just a little shorter:

Code:

function event_say(e)
        if (e.message:findi("hail")) then
                e.other:Message(315, "Hail and well met mighty adventurer!  If you would like to [" .. eq.say_link("exchange",false,"exchange") .. "] platinum for credit, cash [" .. eq.say_link("out",false,"out") .. "], or know how much [" .. eq.say_link("credit",false,"credit") .. "] you have, I can help you with that.");
        elseif (e.message:findi("exchange")) then
                e.other:Message(315,"If you hand me platinum, I will convert it into credit.  Your money will be safe with me, but you can always cash [" .. eq.say_link("out",false,"out") .. "] if you'd like.");
        elseif (e.message:findi("credit")) then
                local a = eq.get_data(e.other:AccountID() .. "_Casino");
                e.other:Message(315,"Your current balance is " .. a ..".");
        elseif (e.message:findi("out")) then
                local b = eq.get_data(e.other:AccountID() .. "_Casino");
                e.other:GiveCash(0, 0, 0, tonumber(b));
                eq.set_data(e.other:AccountID() .. "_Casino", '0');
                e.other:Message(315,"Your balance has been cleared.  Enjoy the rest of your stay!");
        end
end

function event_trade(e)
        local item_lib = require("items");
        if(e.trade.platinum ~= 0 and e.trade.platinum ~= nil) then
                local c = e.trade.platinum;
                local d = eq.get_data(e.other:AccountID() .. "_Casino");
                local e = c + d;
                eq.set_data(e.other:AccountID() .. "_Casino", tostring(e));
                e.other:Message(315,"Your platinum has been credited to your character.  Current Balance: " .. eq.get_data(e.other:AccountID() .. "_Casino") .. ".");
        end
        item_lib.return_items(e.self, e.other, e.trade);
end


rudeboy88 03-28-2019 10:21 AM

Just noticed the revised script is having issues with naming the variables c, d, and e, replaced with OP function_trade

Code:

function event_trade(e)
        local item_lib = require("items");
        if(e.trade.platinum ~= 0 and e.trade.platinum ~= nil) then
                local c2 = e.trade.platinum;
                local c3 = eq.get_data(e.other:AccountID() .. "_Casino");
                local c4 = c2 + c3;
                eq.set_data(e.other:AccountID() .. "_Casino", tostring(c4));
                e.other:Message(315,"Your platinum has been credited to your account.  Your current balance is: " .. eq.get_data(e.other:AccountID() .. "_Casino") .. ".");
        end
        item_lib.return_items(e.self, e.other, e.trade);
end



All times are GMT -4. The time now is 11:48 PM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.