CastorFlynn
Member
- Joined
- Aug 29, 2021
- Messages
- 100
- Reaction score
- 15
The bank script does not have a check for free slots in the player's container. When withdrawing amounts that occupy more slots, items are thrown to the floor.
Apparently there is no specific function in TFS for this, how could this check be done before handing over the gold to the player?
Nekiro Downgrade 1.3+
Bank.lua:
Apparently there is no specific function in TFS for this, how could this check be done before handing over the gold to the player?
Nekiro Downgrade 1.3+
Bank.lua:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local count = {}
local transfer = {}
function onCreatureAppear(cid)
npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
npcHandler:onThink()
end
function rtrim(s)
local n = #s
while n > 0 and s:find("^%s", n) do n = n - 1 end
return s:sub(1, n)
end
local function greetCallback(cid)
count[cid], transfer[cid] = nil, nil
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
---------------------------- balance ------------------------
if msgcontains(msg, 'balance') then
npcHandler.topic[cid] = 0
if player:getBankBalance() >= 100000000 then
npcHandler:say('I think you must be one of the richest inhabitants in the world! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
elseif player:getBankBalance() >= 10000000 then
npcHandler:say('You have made ten millions and it still grows! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
elseif player:getBankBalance() >= 1000000 then
npcHandler:say('Wow, you have reached the magic number of a million gp!!! Your account balance is ' .. player:getBankBalance() .. ' gold!', cid)
return true
elseif player:getBankBalance() >= 100000 then
npcHandler:say('You certainly have made a pretty penny. Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
else
npcHandler:say('Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
end
---------------------------- deposit ---------------------
elseif msgcontains(msg, 'deposit') then
count[cid] = player:getMoney()
if count[cid] < 1 then
npcHandler:say('You do not have enough gold.', cid)
npcHandler.topic[cid] = 0
return false
end
if msgcontains(msg, 'all') then
count[cid] = player:getMoney()
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
npcHandler.topic[cid] = 2
return true
else
if string.match(msg,'%d+') then
count[cid] = getMoneyCount(msg)
if count[cid] < 1 then
npcHandler:say('You do not have enough gold.', cid)
npcHandler.topic[cid] = 0
return false
end
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
npcHandler.topic[cid] = 2
return true
else
npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
npcHandler.topic[cid] = 1
return true
end
end
if not isValidMoney(count[cid]) then
npcHandler:say('Sorry, but you can\'t deposit that much.', cid)
npcHandler.topic[cid] = 0
return false
end
elseif npcHandler.topic[cid] == 1 then
count[cid] = getMoneyCount(msg)
if isValidMoney(count[cid]) then
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
npcHandler.topic[cid] = 2
return true
else
npcHandler:say('You do not have enough gold.', cid)
npcHandler.topic[cid] = 0
return true
end
elseif npcHandler.topic[cid] == 2 then
if msgcontains(msg, 'yes') then
if player:depositMoney(count[cid]) then
npcHandler:say('Alright, we have added the amount of ' .. count[cid] .. ' gold to your {balance}. You can {withdraw} your money anytime you want to.', cid)
else
npcHandler:say('You do not have enough gold.', cid)
end
elseif msgcontains(msg, 'no') then
npcHandler:say('As you wish. Is there something else I can do for you?', cid)
end
npcHandler.topic[cid] = 0
return true
---------------------------- withdraw --------------------
elseif msgcontains(msg, 'withdraw') then
if string.match(msg,'%d+') then
count[cid] = getMoneyCount(msg)
if isValidMoney(count[cid]) then
npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
npcHandler.topic[cid] = 7
else
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
end
return true
else
npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
npcHandler.topic[cid] = 6
return true
end
elseif npcHandler.topic[cid] == 6 then
count[cid] = getMoneyCount(msg)
if isValidMoney(count[cid]) then
npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
npcHandler.topic[cid] = 7
else
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
end
return true
elseif npcHandler.topic[cid] == 7 then
if msgcontains(msg, 'yes') then
if player:getFreeCapacity() >= getMoneyWeight(count[cid]) then
if not player:withdrawMoney(count[cid]) then
npcHandler:say('There is not enough gold on your account.', cid)
else
npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
end
else
npcHandler:say('Whoah, hold on, you have no room in your inventory to carry all those coins. I don\'t want you to drop it on the floor, maybe come back with a cart!', cid)
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, 'no') then
npcHandler:say('The customer is king! Come back anytime you want to if you wish to {withdraw} your money.', cid)
npcHandler.topic[cid] = 0
end
return true
---------------------------- transfer --------------------
elseif msgcontains(msg, 'transfer') then
npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
npcHandler.topic[cid] = 11
elseif npcHandler.topic[cid] == 11 then
count[cid] = getMoneyCount(msg)
if player:getBankBalance() < count[cid] then
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
return true
end
if isValidMoney(count[cid]) then
npcHandler:say('Who would you like transfer ' .. count[cid] .. ' gold to?', cid)
npcHandler.topic[cid] = 12
else
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 12 then
transfer[cid] = rtrim(msg)
if player:getName() == transfer[cid] then
npcHandler:say('Fill in this field with person who receives your gold!', cid)
npcHandler.topic[cid] = 0
return true
end
if playerExists(transfer[cid]) then
local arrayDenied = {"accountmanager", "rooksample", "druidsample", "sorcerersample", "knightsample", "paladinsample"}
if isInArray(arrayDenied, string.gsub(transfer[cid]:lower(), " ", "")) then
npcHandler:say('This player does not exist.', cid)
npcHandler.topic[cid] = 0
return true
end
npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold to ' .. transfer[cid] .. '?', cid)
npcHandler.topic[cid] = 13
else
npcHandler:say('This player does not exist.', cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 13 then
if msgcontains(msg, 'yes') then
if not player:transferMoneyTo(transfer[cid], count[cid]) then
npcHandler:say('You cannot transfer money to this account.', cid)
else
npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. transfer[cid] ..'.', cid)
transfer[cid] = nil
end
elseif msgcontains(msg, 'no') then
npcHandler:say('Alright, is there something else I can do for you?', cid)
end
npcHandler.topic[cid] = 0
end
return true
end
npcHandler:setMessage(MESSAGE_GREET, "Yes? What may I do for you, |PLAYERNAME|? Bank business, perhaps?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Have a nice day.")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())