• 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 Help me to fix my bank NPC

Code:
if msgcontains(msg, 'deposit all') then
   n = getPlayerMoney(cid)
   selfSay('Do you want deposit '..n..' golds ?', cid)
   talkState[talkUser] = 2
else
   n = getNumber(msg)
   selfSay('Do you want deposit '..n..' golds ?', cid)
   talkState[talkUser] = 2
end
 
If you have more than 1 vocation in rook then you can always use isInArray with not in front of it.
Example
Code:
elseif msgcontains(msg, 'transfer') and not isInArray({0, 13, 14}, getPlayerVocation(cid)) then
 
If you have more than 1 vocation in rook then you can always use isInArray with not in front of it.
Example
Code:
elseif msgcontains(msg, 'transfer') and not isInArray({0, 13, 14}, getPlayerVocation(cid)) then

Its not what i want pall... cid is player who say transfer

- I want rookers transfer money, but only to rookers
- I want mainlanders cant transfer money to rookers

Like this part of code I made but not work
Code:
elseif talkState[talkUser] == 6 then
  p = msg
  if(getPlayerVocation(cid) ~= 0 and getPlayerVocation(cid) ~= 13 and getPlayerVocation(cid) ~= 14) then
  if(getPlayerVocation(p) == 0 or getPlayerVocation(p) == 13 or getPlayerVocation(p) == 14) then
  selfSay('You can not transfer to player from Rookgaard.', cid)
  talkState[talkUser] = 0
  end
  end
  selfSay('So you would like to transfer '..n..' gold to '..p..'?', cid)
  talkState[talkUser] = 7


Code:
if msgcontains(msg, 'deposit all') then
   n = getPlayerMoney(cid)
   selfSay('Do you want deposit '..n..' golds ?', cid)
   talkState[talkUser] = 2
else
   n = getNumber(msg)
   selfSay('Do you want deposit '..n..' golds ?', cid)
   talkState[talkUser] = 2
end


I tried what u said, but not work

When i saw: hi, deposit all... NPC ask me how many money i want deposit :mad:
Code:
01:26 Captain Cold: deposit all
01:26 Banker: Please tell me how much gold it is you would like to deposit.

script
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

--------------------MESSAGES------------------------------------------------------------------------------
if msgcontains(msg, 'deposit') then
selfSay('Please tell me how much gold it is you would like to deposit.', cid)
talkState[talkUser] = 1

elseif msgcontains(msg, 'deposit all') then
n = getPlayerMoney(cid)
selfSay('Do you want deposit '..n..' golds ?', cid)
talkState[talkUser] = 2

elseif msgcontains(msg, 'withdraw') then
selfSay('Please tell me how much gold you would like to withdraw.', cid)
talkState[talkUser] = 3

elseif msgcontains(msg, 'transfer') then
selfSay('Please tell me the amount of gold coins you would like to transfer.', cid)
talkState[talkUser] = 5

elseif msgcontains(msg, 'balance') then
n = getPlayerBalance(cid)
selfSay('Your balance are '..n..' golds.', cid)
talkState[talkUser] = 0


----------------------DEPOSIT-------------------------------------------------------
elseif talkState[talkUser] == 1 then
if msgcontains(msg, 'all') then
  n = getPlayerMoney(cid)
  selfSay('Do you want deposit '..n..' golds ?', cid)
  talkState[talkUser] = 2
else
  n = getNumber(msg)
  selfSay('Do you want deposit '..n..' golds ?', cid)
  talkState[talkUser] = 2
end

elseif talkState[talkUser] == 2 then
if msgcontains(msg, 'yes') then
if getPlayerMoney(cid) >= n then
  doPlayerDepositMoney(cid,n)
  selfSay('Sucessfull. Now your balance account is ' ..getPlayerBalance(cid)..' golds.', cid)
  talkState[talkUser] = 0
else
  selfSay('You don\'t have money.', cid)
end
else
  selfSay('Ok then', cid)
end

----------------------WITHDRAW-------------------------------------------------------------------------------------

elseif talkState[talkUser] == 3 then
if msgcontains(msg, 'all') then
n = getPlayerBalance(cid)
selfSay('Do you want withdraw '..n..' golds ?', cid)
talkState[talkUser] = 4
else
n = getNumber(msg)
selfSay('Do you want withdraw '..n..' golds ?', cid)
talkState[talkUser] = 4
end

elseif talkState[talkUser] == 4 then
if msgcontains(msg, 'yes') then
if getPlayerBalance(cid) >= n then
doPlayerWithdrawMoney(cid, n)
selfSay('Here you are, '..n..' gold. Now your balance account is ' ..getPlayerBalance(cid)..' golds.', cid)
talkState[talkUser] = 0
else
selfSay('There is not enough gold on your account', cid)
end
else
selfSay('Ok then', cid)
end

----------------------TRANSFER----------------------------------------------------------------------------------------

elseif talkState[talkUser] == 5 then
if msgcontains(msg, 'all') then
n = getPlayerBalance(cid)
selfSay('Who would you like transfer '..n..' gold to?', cid)
talkState[talkUser] = 6
else
n = getNumber(msg)
selfSay('Who would you like transfer '..n..' gold to?', cid)
talkState[talkUser] = 6
end

elseif talkState[talkUser] == 6 then
  p = msg
  if(getPlayerVocation(cid) ~= 0 and getPlayerVocation(cid) ~= 13 and getPlayerVocation(cid) ~= 14) then
  if(getPlayerVocation(p) == 0 or getPlayerVocation(p) == 13 or getPlayerVocation(p) == 14) then
  selfSay('You can not transfer to player from Rookgaard.', cid)
  talkState[talkUser] = 0
  end
  end
  selfSay('So you would like to transfer '..n..' gold to '..p..'?', cid)
  talkState[talkUser] = 7
elseif talkState[talkUser] == 7 then
if msgcontains(msg, 'yes') then
  if getPlayerBalance(cid) >= n then
  if doPlayerTransferMoneyTo(cid, p, n) == TRUE then
  selfSay('You have transferred '..n..' gold to '..p..' and your account balance is '..getPlayerBalance(cid)..' golds.', cid)
  talkState[talkUser] = 0
  else
  selfSay('This player does not exist. Please tell me a valid name!', cid)
  talkState[talkUser] = 0
  end
  else
  selfSay('There is not enough gold on your account', cid)
  talkState[talkUser] = 0
  end
else
  selfSay('Ok then', cid)
  talkState[talkUser] = 0
end


end

end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



-- function maded by Gesior--
function getNumber(txt) --return number if its number and is > 0, else return 0
x = string.gsub(txt,"%a","")
x = tonumber(x)
if x ~= nill and x > 0 then
return x
else
return 0
end
end
 
Got some errors
Code:
[14:31:37.497] [Error - NpcScript Interface]
[14:31:37.497] data/npc/scripts/bank.lua:onCreatureSay
[14:31:37.497] Description:
[14:31:37.497] data/npc/scripts/bank.lua:34: attempt to compare number with boolean
[14:31:37.498] stack traceback:
[14:31:37.498]    data/npc/scripts/bank.lua:34: in function 'callback'
[14:31:37.498]    data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
[14:31:37.498]    data/npc/scripts/bank.lua:8: in function <data/npc/scripts/bank.lua:8>

[14:31:41.635] [Error - NpcScript Interface]
[14:31:41.635] data/npc/scripts/bank.lua:onCreatureSay
[14:31:41.635] Description:
[14:31:41.635] data/npc/scripts/bank.lua:24: attempt to compare number with boolean
[14:31:41.635] stack traceback:
[14:31:41.635]    data/npc/scripts/bank.lua:24: in function 'callback'
[14:31:41.635]    data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
[14:31:41.635]    data/npc/scripts/bank.lua:8: in function <data/npc/scripts/bank.lua:8>

[14:31:44.367] [Error - NpcScript Interface]
[14:31:44.368] data/npc/scripts/bank.lua:onCreatureSay
[14:31:44.368] Description:
[14:31:44.368] data/npc/scripts/bank.lua:24: attempt to compare number with boolean
[14:31:44.368] stack traceback:
[14:31:44.368]    data/npc/scripts/bank.lua:24: in function 'callback'
[14:31:44.368]    data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
[14:31:44.368]    data/npc/scripts/bank.lua:8: in function <data/npc/scripts/bank.lua:8>


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

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 creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

--------------------MESSAGES------------------------------------------------------------------------------
if msgcontains(msg, 'deposit') then
  if msgcontains(msg, 'deposit') and msgcontains(msg, 'all') then
  n = getPlayerMoney(cid)
  selfSay('Do you want deposit '..n..' golds ?', cid)
  talkState[talkUser] = 2
  elseif msgcontains(msg, 'deposit') and msgcontains(msg, '') > 0 then
  n = getNumber(msg)
  selfSay('Do you want deposit '..n..' golds ?', cid)
  talkState[talkUser] = 2
  else
  selfSay('Please tell me how much gold it is you would like to deposit.', cid)
  talkState[talkUser] = 1
  end

elseif msgcontains(msg, 'withdraw') then
  if msgcontains(msg, 'withdraw') and msgcontains(msg, '') > 0 then
  n = getNumber(msg)
  selfSay('Do you want withdraw '..n..' golds ?', cid)
  talkState[talkUser] = 4
  else
  selfSay('Please tell me how much gold you would like to withdraw.', cid)
  talkState[talkUser] = 3
  end

elseif msgcontains(msg, 'transfer') then
  selfSay('Please tell me the amount of gold coins you would like to transfer.', cid)
  talkState[talkUser] = 5

elseif msgcontains(msg, 'balance') then
  n = getPlayerBalance(cid)
  selfSay('Your balance are '..n..' golds.', cid)
  talkState[talkUser] = 0


----------------------DEPOSIT-------------------------------------------------------
elseif talkState[talkUser] == 1 then
if msgcontains(msg, 'all') then
  n = getPlayerMoney(cid)
  selfSay('Do you want deposit '..n..' golds ?', cid)
  talkState[talkUser] = 2
else
  n = getNumber(msg)
  selfSay('Do you want deposit '..n..' golds ?', cid)
  talkState[talkUser] = 2
end

elseif talkState[talkUser] == 2 then
if msgcontains(msg, 'yes') then
if getPlayerMoney(cid) >= n then
  doPlayerDepositMoney(cid,n)
  selfSay('Sucessfull. Now your balance account is ' ..getPlayerBalance(cid)..' golds.', cid)
  talkState[talkUser] = 0
else
  selfSay('You don\'t have money.', cid)
end
else
  selfSay('Ok then', cid)
end

----------------------WITHDRAW-------------------------------------------------------------------------------------

elseif talkState[talkUser] == 3 then
if msgcontains(msg, 'all') then
n = getPlayerBalance(cid)
selfSay('Do you want withdraw '..n..' golds ?', cid)
talkState[talkUser] = 4
else
n = getNumber(msg)
selfSay('Do you want withdraw '..n..' golds ?', cid)
talkState[talkUser] = 4
end

elseif talkState[talkUser] == 4 then
if msgcontains(msg, 'yes') then
if getPlayerBalance(cid) >= n then
doPlayerWithdrawMoney(cid, n)
selfSay('Here you are, '..n..' gold. Now your balance account is ' ..getPlayerBalance(cid)..' golds.', cid)
talkState[talkUser] = 0
else
selfSay('There is not enough gold on your account', cid)
end
else
selfSay('Ok then', cid)
end

----------------------TRANSFER----------------------------------------------------------------------------------------

elseif talkState[talkUser] == 5 then
if msgcontains(msg, 'all') then
n = getPlayerBalance(cid)
selfSay('Who would you like transfer '..n..' gold to?', cid)
talkState[talkUser] = 6
else
n = getNumber(msg)
selfSay('Who would you like transfer '..n..' gold to?', cid)
talkState[talkUser] = 6
end

elseif talkState[talkUser] == 6 then
  p = msg
  selfSay('So you would like to transfer '..n..' gold to '..p..'?', cid)
  talkState[talkUser] = 7
elseif talkState[talkUser] == 7 then
if msgcontains(msg, 'yes') then
  if(getPlayerVocation(cid) ~= 0 and getPlayerVocation(cid) ~= 13 and getPlayerVocation(cid) ~= 14) then
  if(getPlayerVocation(p) == 0 or getPlayerVocation(p) == 13 or getPlayerVocation(p) == 14) then
  selfSay('You can not transfer to player from Rookgaard.', cid)
  talkState[talkUser] = 0
  end
  end
  if getPlayerBalance(cid) >= n then
  if doPlayerTransferMoneyTo(cid, p, n) == TRUE then
  selfSay('You have transferred '..n..' gold to '..p..' and your account balance is '..getPlayerBalance(cid)..' golds.', cid)
  talkState[talkUser] = 0
  else
  selfSay('This player does not exist. Please tell me a valid name!', cid)
  talkState[talkUser] = 0
  end
  else
  selfSay('There is not enough gold on your account', cid)
  talkState[talkUser] = 0
  end
else
  selfSay('Ok then', cid)
  talkState[talkUser] = 0
end


end

end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



-- function maded by Gesior--
function getNumber(txt) --return number if its number and is > 0, else return 0
x = string.gsub(txt,"%a","")
x = tonumber(x)
if x ~= nill and x > 0 then
return x
else
return 0
end
end

[/code]
 
Last edited:
Back
Top