• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Bank NPC (Suzy) not working. Help!

tani

New Member
Joined
May 12, 2013
Messages
68
Reaction score
4
Im using OTHire Version 0.0.2


Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)



-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I work in this bank. I can change money for you."})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I am Suzy."})


function creatureSayCallback(cid, type, msg) msg = string.lower(msg)
---------------
-- deposit --
---------------
if(npcHandler.focus ~= cid) then
return false
end
amount = getCount(msg)
if amount > 1000000 then
npcHandler:say('this amount is too high!', 1)
return false
end
if msgcontains(msg, 'deposit all') then
PLAYERCURRENTMONEY = ((getPlayerItemCount(cid, ITEM_CRYSTAL_COIN) * 10000) + (getPlayerItemCount(cid, ITEM_PLATINUM_COIN) * 100) + getPlayerItemCount(cid, ITEM_GOLD_COIN))
npcHandler:say('would you like to deposit '.. PLAYERCURRENTMONEY ..' gold?', 1)
suzy_talk_state = 205

elseif msgcontains(msg, 'deposit') and getCount(msg) <= 0 then
npcHandler:say('How much would you like to deposit?', 1)
suzy_talk_state = 201

elseif msgcontains(msg, 'deposit') and getCount(msg) >= 1 then
DEPOSITMONEY = getCount(msg)
npcHandler:say('Would you like to deposit '.. DEPOSITMONEY ..' gold?', 1)
suzy_talk_state = 202

elseif suzy_talk_state == 201 then
TEXTMSG = msg
DEPOSITAMOUNT = getCount(msg)
if DEPOSITAMOUNT >= 1 then
npcHandler:say("would you like to deposit ".. DEPOSITAMOUNT .." gold?", 1)
else
npcHandler:say("I'm sorry, but you must give me an valid amount of how much you would like to deposit.", 1)
end
suzy_talk_state = 203

elseif suzy_talk_state == 203 and msgcontains(msg, 'yes') then

if DepositMoney(cid, DEPOSITAMOUNT) == TRUE then
npcHandler:say("You have added ".. DEPOSITAMOUNT .." gold to your bank account.", 1)
else
npcHandler:say("You don't have that much money!", 1)
end
suzy_talk_state = 0

elseif suzy_talk_state == 202 then

if DepositMoney(cid, DEPOSITMONEY) == TRUE then
npcHandler:say("You have added ".. DEPOSITMONEY .." gold to your bank account.", 1)
else
npcHandler:say("You don't have that much money!", 1)
end
suzy_talk_state = 0

elseif suzy_talk_state == 205 and msgcontains(msg, 'yes') then

if DepositMoney(cid, PLAYERCURRENTMONEY) == TRUE then
npcHandler:say("You have added ".. PLAYERCURRENTMONEY .." gold to your bank account.", 1)
else
npcHandler:say("Hey! where did you put the money?", 1)
end
suzy_talk_state = 0

end

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
---------------
-- Balance --
---------------
if(npcHandler.focus ~= cid) then
return false
end
if msgcontains(msg, 'balance') or msgcontains(msg, 'balance') then

if getPlayerBalance(cid) <= 4999 then
npcHandler:say("Your account balance is ".. getPlayerBalance(cid) .." gold.", 1)
suzy_talk_state = 0
elseif getPlayerBalance(cid) >= 5000 and getPlayerBalance(cid) <= 49999 then
npcHandler:say("Your account balance is ".. getPlayerBalance(cid) .." gold.", 1)
suzy_talk_state = 0
elseif getPlayerBalance(cid) >= 50000 and getPlayerBalance(cid) <= 99999 then
npcHandler:say("You certainly have made a pretty penny. Your account balance is ".. getPlayerBalance(cid) .." gold.", 1)
suzy_talk_state = 0
elseif getPlayerBalance(cid) >= 100000 then
npcHandler:say("You have really been successful with money! you account balance is ".. getPlayerBalance(cid) .." gold.", 1)
suzy_talk_state = 0
end
end

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
---------------
-- Withdraw --
---------------
if(npcHandler.focus ~= cid) then
return false
end
if msgcontains(msg, 'withdraw') and getCount(msg) >= 1 then
WITHDRAWAMOUNT = getCount(msg)
npcHandler:say('Would you like to withdraw '.. WITHDRAWAMOUNT ..' gold?', 1)
suzy_talk_state = 304

elseif msgcontains(msg, 'withdraw') then
npcHandler:say('How much would you like to withdraw?', 1)
suzy_talk_state = 301

elseif suzy_talk_state == 301 then
WITHDRAWMONEY = getCount(msg)
if WITHDRAWMONEY >= 1 then
npcHandler:say("would you like to withdraw ".. WITHDRAWMONEY .." gold?", 1)
suzy_talk_state = 303
else
npcHandler:say("I'm sorry, but you must give me an valid amount of how much you would like to withdraw.", 1)
suzy_talk_state = 0
end

elseif suzy_talk_state == 303 and msgcontains(msg, 'yes') or suzy_talk_state == 303 and msgcontains(msg, 'YES') then

if WithdrawMoney(cid, WITHDRAWMONEY) == TRUE then
npcHandler:say("There you go.. enjoy them!", 1)
else
npcHandler:say("You don't have that much money on your bank account!", 1)
end
suzy_talk_state = 0

elseif suzy_talk_state == 304 and msgcontains(msg, 'yes') or suzy_talk_state == 304 and msgcontains(msg, 'YES') then

if WithdrawMoney(cid, WITHDRAWAMOUNT) == TRUE then
npcHandler:say("There you go.. enjoy them!", 1)
else
npcHandler:say("You don't have that much money on your bank account!", 1)
end
suzy_talk_state = 0
end
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
---------------
--Change gold--
---------------
if(npcHandler.focus ~= cid) then
return false
end
if msgcontains(msg, 'change') then
npcHandler:say('Would you like to change gold, "platinum" or "crystal"?', 1)
suzy_talk_state = 401

elseif msgcontains(msg, 'gold') and suzy_talk_state == 401 then
npcHandler:say('How many platinum coins would you like to get?', 1)
suzy_talk_state = 402

----------
elseif msgcontains(msg, 'platinum') and suzy_talk_state == 401 then
npcHandler:say('would you like to change platinum to gold or "crystal"?', 1)
suzy_talk_state = 403
elseif msgcontains(msg, 'gold') and suzy_talk_state == 403 then
npcHandler:say('How many platinum coins would you like to change to gold?', 1)
suzy_talk_state = 404
elseif msgcontains(msg, 'crystal') and suzy_talk_state == 403 then
npcHandler:say('How many crystal coins would you like to get?', 1)
suzy_talk_state = 405
----------

elseif msgcontains(msg, 'crystal') and suzy_talk_state == 401 then
npcHandler:say('How many crystal coins would you like to change to platinum coins?', 1)
suzy_talk_state = 406



elseif suzy_talk_state == 402 then
TEXTMSG = msg
amount = getCount(msg)
if amount >= 1 then
if doPlayerRemoveItem(cid, 2148, (amount) * 100) == TRUE then
doPlayerAddItem(cid, 2152, amount)
npcHandler:say("Here's your ".. amount .." platinum coins.", 1)
suzy_talk_state = 0
else
npcHandler:say("You don't have that much money!", 1)
suzy_talk_state = 402
end
else
npcHandler:say("I'm sorry, but you must give me an valid amount.", 1)
suzy_talk_state = 402
end

elseif suzy_talk_state == 404 then
TEXTMSG = msg
amount = getCount(msg)
if amount >= 1 then
if doPlayerRemoveItem(cid, 2152, (amount)) == TRUE then
doPlayerAddItem(cid, 2148, (amount) * 100)
npcHandler:say("Here's your ".. (amount) * 100 .." gold coins.", 1)
suzy_talk_state = 0
else
npcHandler:say("You don't have that much money!", 1)
suzy_talk_state = 404
end
else
npcHandler:say("I'm sorry, but you must give me an valid amount.", 1)
suzy_talk_state = 404
end

elseif suzy_talk_state == 405 then
TEXTMSG = msg
amount = getCount(msg)
if amount >= 1 then
if doPlayerRemoveItem(cid, 2152, (amount) * 100) == TRUE then
doPlayerAddItem(cid, 2160, amount)
npcHandler:say("Here's your ".. amount .." crystal coins.", 1)
suzy_talk_state = 0
else
npcHandler:say("You don't have that much money!", 1)
suzy_talk_state = 405
end
else
npcHandler:say("I'm sorry, but you must give me an valid amount.", 1)
suzy_talk_state = 405
end

elseif suzy_talk_state == 406 then
TEXTMSG = msg
amount = getCount(msg)
if amount >= 1 then
if doPlayerRemoveItem(cid, 2160, (amount)) == TRUE then
doPlayerAddItem(cid, 2152, amount * 100)
npcHandler:say("Here's your ".. (amount) * 100 .." platinum coins.", 1)
suzy_talk_state = 0
else
npcHandler:say("You don't have that much money!", 1)
suzy_talk_state = 406
end
else
npcHandler:say("I'm sorry, but you must give me an valid amount.", 1)
suzy_talk_state = 406
end

end
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
---------------
 
Last edited:
Code:
-- Transfer --
---------------
if(npcHandler.focus ~= cid) then
return false
end
if msgcontains(msg, 'transfer') and getCount(msg) >= 1 or suzy_talk_state == 501 and getCount(msg) >= 1 then
TRANSFERAMOUNT = getCount(msg)
npcHandler:say('Who would you like to transfer the money to?', 1)
suzy_talk_state = 504

elseif msgcontains(msg, 'transfer') then
npcHandler:say('How much would you like to transfer?', 1)
suzy_talk_state = 501



elseif suzy_talk_state == 504 then

TRANSFERTO = msg
newmsg = string.upper(string.sub(msg, 0, 1)) .. string.sub(msg, 2)
UPPERCASETRANSFERTO = newmsg

npcHandler:say("Would you like to transfer ".. TRANSFERAMOUNT .." gold to ".. UPPERCASETRANSFERTO .."?", 1)
suzy_talk_state = 505

elseif suzy_talk_state == 505 and msgcontains(msg, 'yes') then
if getPlayerGUIDByName(TRANSFERTO) > 0 then
checkcharexist = mysqlQuery("SELECT `id`, `money_balance`, `vocation` FROM `players` WHERE `players`.`name` = '" .. TRANSFERTO .. "' AND `players`.`world_id` = '" .. getConfigValue("WorldID") .. "'", "id, money_balance, vocation")
GETVALIDCHAR = getCount(checkcharexist.id)
if GETVALIDCHAR >= 1 then
if GETVALIDCHAR == getPlayerGUIDByName(getPlayerName(cid)) then
npcHandler:say("Haha, sending money to yourself, good joke!", 1)
else
notinrook = getCount(checkcharexist.vocation)
if notinrook == 0 or notinrook == 9 then
npcHandler:say("You cannot send money to rookgaard!", 1)
else
if getPlayerVocation(cid) == 0 or getPlayerVocation(cid) == 9 then
npcHandler:say("I'm sorry, but you're not allowed to transfer money yet.", 1)
else
BALANCEOFTRANSFERTO = getCount(checkcharexist.money_balance)
resultdb = mysqlQuery("SELECT `money_balance` FROM `players` WHERE `players`.`name` = '" .. getPlayerName(cid) .. "'", "money_balance")
getbalance = getCount(resultdb.money_balance)
if getbalance >= TRANSFERAMOUNT then
mysqlQuery("UPDATE `players` SET `players`.`money_balance`=\"".. BALANCEOFTRANSFERTO+TRANSFERAMOUNT .."\" WHERE `players`.`name` = \"" .. TRANSFERTO .. "\"", 'UPDATE')
mysqlQuery("UPDATE `players` SET `players`.`money_balance`=\"".. getbalance-TRANSFERAMOUNT .."\" WHERE `players`.`name` = \"" .. getPlayerName(cid) .. "\"", 'UPDATE')
npcHandler:say("You have transfered ".. TRANSFERAMOUNT .." gold to ".. UPPERCASETRANSFERTO ..".", 1)
else
npcHandler:say("You don't have that much money!", 1)
end
end
end
end
else
npcHandler:say("There's no such player in this world!", 1)
end
else
npcHandler:say("There's no such player in this world!", 1)
end
suzy_talk_state = 0

end
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------

end


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
This script is giving me this Error:

Lua Script Error: [Npc interface]
data/npc/scripts/Suzy.lua:eek:nCreatureSay

data/npc/scripts/Suzy.lua:24: attempt to call global 'getCount' <a nil value>
stack traceback:
data/npc/scripts/Suzy.lua:24: in function 'callback'
data/npc/scripts/lib/npcsystem/npchandler.lua:299: in function 'onCreatureSay'
data/npc/scripts/Suzy.lua:10: in function <data/npc/scripts/Suzy.lua:10>


please don't make double threads. I've already commented in your other thread.
ye Sorry somehow it got double posted. But this is the main.
 
Last edited by a moderator:
Code:
amount = getCount(msg)
at line 24.
the function getCount() does not exist. It needs to be added. It should have been included with the NPC. If not, try a different NPC as this one is incomplete.
 
Help please! :)

Code:
amount = getCount(msg)
at line 24.
the function getCount() does not exist. It needs to be added. It should have been included with the NPC. If not, try a different NPC as this one is incomplete.
How can I add the function, and where?
 
Last edited by a moderator:
depending on how the function is supposed to work, it may simply convert msg to a number value, but it may need to actually do checks on msg if it contains things other than the number. so it's hard to say for sure exactly what it's supposed to be. I can't just write a function because I have no idea what it needs to do. If you can find that function wherever you got your NPC from, just add it somewhere at the top of the script. If you edit your first post with distro and datapack versions, you may get better assistance from those who know them better.
 
depending on how the function is supposed to work, it may simply convert msg to a number value, but it may need to actually do checks on msg if it contains things other than the number. so it's hard to say for sure exactly what it's supposed to be. I can't just write a function because I have no idea what it needs to do. If you can find that function wherever you got your NPC from, just add it somewhere at the top of the script. If you edit your first post with distro and datapack versions, you may get better assistance from those who know them better.
Ok but you cant help me with this error by making the function? Sorry I forgot mention but Im using OTHire Version 0.0.2
 
I know nothing about othire and without knowing what the function is supposed to do, I can't make it.
Alright I tried this:


Code:
function getCount(msg)
    b, e = string.find(msg, "%d+")
  
    if b == nil or e == nil then
        count = 1
    else
        count = tonumber(string.sub(msg, b, e))
    end  
    return count
end

I put that into the NPC script and the error went gone , but now when I write "balance" there comes new error. When I say "withdraw" it says , do you want to withdraw 1 gold? And nothing happends. The function might be wrong. Hah
 
Last edited:
I generally know what it does, but I don't know exactly. It's designed to get a number from the player's message, but it also appears to get a value from other things, so I don't know what it does enough to recreate it. Check with whoever releases the distro.
 
I generally know what it does, but I don't know exactly. It's designed to get a number from the player's message, but it also appears to get a value from other things, so I don't know what it does enough to recreate it. Check with whoever releases the distro.
But This NPC I took it from another server.
 
Then that's your problem. It's likely a global function and there's probably others missing as well. Check the global.lua and lib folder (if it has one) in the other server, and see if you can find the functions in there.
 
Then that's your problem. It's likely a global function and there's probably others missing as well. Check the global.lua and lib folder (if it has one) in the other server, and see if you can find the functions in there.


Saying "balance" works now, but theres another error and you cant withdraw or deposit money. This is the error:

Code:
Lua Script Error: [Npc interface]

data/npc/scripts/Suzy.lua:onCreatureSay

data/npc/scripts/Suzy.lua:80: attempt to call global 'DepositMoney' (a nil value
)
stack traceback:
        data/npc/scripts/Suzy.lua:80: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:299: in function 'onCreatu
reSay'
        data/npc/scripts/Suzy.lua:10: in function <data/npc/scripts/Suzy.lua:10>


And this is the"depositmoney" function:

Code:
function DepositMoney(cid, amount)
if getConfigValue("WorldID") == 1 then
    if doPlayerRemoveMoney(cid, amount) == TRUE then
    mysqlQuery("UPDATE `players` SET `players`.`money_balance`=\"".. getPlayerBalance(cid)+amount .."\" WHERE `players`.`name` = \"" .. getPlayerName(cid) .. "\"", 'UPDATE')
    return 1
    end
end
end


Help pls!:)
 
Last edited:
Well, the error basically states that DepositMoney doesn't exist, so just make sure it's added just like the getCount function. Ther also could be an error with the query. money_balance may not exist in your database on the player table. If not, replace money_balance with whatever field represents balance in your database table called players. I'm also not familiar with whether your server is able to call mysqlQuery. But I guess we'll get to that if it errors.
 
Well, the error basically states that DepositMoney doesn't exist, so just make sure it's added just like the getCount function. Ther also could be an error with the query. money_balance may not exist in your database on the player table. If not, replace money_balance with whatever field represents balance in your database table called players. I'm also not familiar with whether your server is able to call mysqlQuery. But I guess we'll get to that if it errors.
Ok thanks for the reply! I will try the things you said. I think mysqlQuery should be replaced with db.query. But not sure :)
 
Okey now Im getting this error:


Code:
Lua Script Error: [Npc interface]

data/npc/scripts/Suzy.lua:onCreatureSay

data/npc/scripts/Suzy.lua:18: attempt to call global 'mysqlQuery' (a nil value)
stack traceback:
        data/npc/scripts/Suzy.lua:18: in function 'getPlayerBalance'
        data/npc/scripts/Suzy.lua:126: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:299: in function 'onCreatu
reSay'
        data/npc/scripts/Suzy.lua:10: in function <data/npc/scripts/Suzy.lua:10>


help please!!
 
thought so. mysqlQuery doesn't exist. I believe db.query is what it should be, as you said.
Well I just fixed the whole bank NPC by taking another NPC and it works now perfect. But do you know how to fix so server shuts down at around 5 in the morning and it says "Server is saving game in 5 minutes. Please come back in 10 minutes." For example. Would like to have that! :D Ty for answer
 
Back
Top