Its just a small think, just add a check balance after withdraw money to Lucas lib.
EDIT:
-- @name depositerbank
-- [MENTION=28084]desc[/MENTION] Deal with talk operations to deposit and withdraw the money needed for supplies.
-- @param category The supply category to check. (optional)
-- @param extragold The an extra amount of gold to withdraw. (optional)
-- @param logoutifnocash If set to true, it will make your character logout if you have no cash in the bank. (optional)
-- @returns boolean
function depositerbank(supplycategory, extragold, logoutifnocash)
extragold = extragold or 0
local npccount = 0
foreach creature m 'ns' do
if m.dist <= 3 then
npccount = npccount + 1
end
end
if npccount == 0 then
printerror('Unable to find a NPC close to you')
return
end
local currentnpcmsg = $lastnpcmsg
local tries = 0
local maxtries = math.random(3, 5)
repeat
if not ischannel('NPCs') then
say('hi')
else
npcsay('hi')
end
local t = $timems
while $timems - t <= 2500 and currentnpcmsg == $lastnpcmsg do wait(100) end
tries = tries + 1
until $lastnpcmsg ~= currentnpcmsg or tries > maxtries
npcsay('deposit all') wait(500,1000)
npcsay('yes') wait(500,1000)
-- check balance
repeat
npcsay('balance')
until waitmessage('', 'Your account balance is %d+', 2000, true, MSG_NPC)
-- withdraw needed money
local towithdraw = moneytowithdraw(supplycategory) + extragold
if towithdraw == 0 then
return
end
local success = false
repeat
if $balance >= towithdraw then
repeat
npcsay('withdraw '..towithdraw) wait(500,1000)
npcsay('yes')
success = waitmessage('', 'Here you are, '..towithdraw..' gold. Please let me know if there is something else I can do for you.', 2000, false, MSG_NPC)
until success
else
if (logoutifnocash) then
printerror('Your character has logged out because you don\'t have enough money in bank.')
xlog(true)
setcavebot('off')
return
end
playsoundflash('monster.wav') wait(1000)
end
until success
end