Sizaro
Advanced OT User
I dont take the credits.
Anyways.
NPC.
Script.
:thumbup:
Anyways.
NPC.
Code:
<npc name="Tony" script="data/npc/scripts/bank.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
<parameters>
</parameters>
</npc>
Script.
Code:
focus = 0
talk_start = 0
target = 0
dep = 0
wit = 0
trans = 0
following = false
attacking = false
<!--Ids--!>
gold_id = 2148
plat_id = 2152
crys_id = 2160
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye then.')
focus = 0
talk_start = 0
end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
function onCreatureSay(cid, type, msg)
msg = string.lower(msg)
nome = creatureGetName(cid)
--------------------------------------Begin----------------------------------------------
if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello')) and (focus == 0) and getDistanceToCreature(cid) < 4 then
if io.open("data/bank/"..nome..".dat", "r") then
io.close();
else
newAccount(nome)
end
dep = 0
wit = 0
trans = 0
selfSay('Hello ' .. nome .. '! Well come to the local bank, what do you want to do? here you can access your bank account saying (deposit, withdraw, balance, transfer).')
focus = cid
talk_start = os.clock()
elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
end
--------------------------------------Deposit----------------------------------------------
if dep == 0 then
if (msgcontains(msg, 'deposit')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('How much do you wish to deposit?')
dep = 1
wit = 0
trans = 0
talk_start = os.clock()
end
end
if dep == 1 then
if (focus == cid) and getDistanceToCreature(cid) < 4 then
n = getNumber(msg)
if n ~= 0 then
talk_start = os.clock()
selfSay('Do you really want to deposit '..n..' gold pieces?')
dep = 2
end
end
end
if dep == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (msgcontains(msg, 'yes')) then
dep = 0
talk_start = os.clock()
if pay(cid,n) then
addMoney(nome,n)
selfSay('Deposit Succesful!')
else
selfSay('Sorry, you dont have enought money!')
end
end
if (msgcontains(msg, 'no')) then
selfSay('Ok then.')
dep = 0
talk_start = os.clock()
end
end
-------------------------------------------Withdraw---------------------------------------
if wit == 0 then
if (msgcontains(msg, 'withdraw')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('How much do you wish to withdraw?')
dep = 0
trans = 0
wit = 1
talk_start = os.clock()
end
end
if wit == 1 then
if (focus == cid) and getDistanceToCreature(cid) < 4 then
n = getNumber(msg)
if n ~= 0 then
talk_start = os.clock()
selfSay('Do you really want to withdraw '..n..' gold pieces?')
wit = 2
end
end
end
if wit == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (msgcontains(msg, 'yes')) then
wit = 0
talk_start = os.clock()
if n <= getMoney(nome) then
takeMoney(nome,n)
gold = n
plat = 0
crys = {}
crys[1] = 0
i = 1
repeat
if gold >= 100 then
plat = plat + 1
gold = gold - 100
end
until gold < 100
repeat
if plat >= 100 then
if crys[i] == 100 then
i = i + 1
crys[i] = 0
end
crys[i] = crys[i] + 1
plat = plat - 100
end
until plat < 100
if crys[1] > 0 then
repeat
buy(cid,crys_id,crys[i],0)
i = i-1
until i == 0
end
if plat > 0 then
buy(cid,plat_id,plat,0)
end
if gold > 0 then
buy(cid,gold_id,gold,0)
end
selfSay('withdraw successful!')
else
selfSay('Sorry, you dont have enought money in your account!')
end
end
if (msgcontains(msg, 'no')) then
selfSay('Ok then.')
wit = 0
talk_start = os.clock()
end
end
-------------------------------------------Balance---------------------------------------
if (msgcontains(msg, 'balance')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('You have got '..getMoney(nome)..' gold pieces in your bank account.')
dep = 0
wit = 0
trans = 0
talk_start = os.clock()
end
-------------------------------------------Transfer---------------------------------------
if trans == 4 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if io.open("data/bank/"..rec..".dat", "r") then
io.close();
else
newAccount(rec)
end
if (msgcontains(msg, 'yes')) then
Transfer(nome,rec,quant)
selfSay('The money was successfuly transfered!')
trans = 0
talk_start = os.clock()
elseif (msgcontains(msg, 'no')) then
selfSay('Ok then!')
trans = 0
talk_start = os.clock()
end
end
if trans == 3 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if io.open("data/players/"..msg..".xml", "r") then
io.close();
rec = msg
selfSay('Do you want to transfer '..quant..' gps to '..rec..'?')
trans = 4
talk_start = os.clock()
else
selfSay('This name does not exist!')
trans = 0
talk_start = os.clock()
end
end
if trans == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (msgcontains(msg, 'yes')) then
if getMoney(nome) >= quant then
selfSay('Who do you want to trasnfer the money to?')
trans = 3
talk_start = os.clock()
else
selfSay('Sorry, you do not have enough money!')
trans = 0
talk_start = os.clock()
end
elseif (msgcontains(msg, 'no')) then
selfSay('Ok then!')
talk_start = os.clock()
trans = 0
end
end
if trans == 1 and (focus == cid) and getDistanceToCreature(cid) < 4 then
quant = getNumber(msg)
if quant > 0 then
selfSay('Do you really want to transfer '..quant..' gold pieces?')
trans = 2
talk_start = os.clock()
end
end
if trans == 0 then
if (msgcontains(msg, 'transfer')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('How much do you want to transfer?')
dep = 0
wit = 0
trans = 1
talk_start = os.clock()
end
end
-------------------------------------------End--------------------------------------------
if (msgcontains(msg, 'bye')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('Bye bye!')
focus = 0
dep = 0
wit = 0
trans = 0
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
dep = 0
wit = 0
trans = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
dep = 0
wit = 0
trans = 0
end
end
end
function getNumber(txt)
x = string.gsub(txt,"%a","")
x = tonumber(x)
if x ~= nill and x > 0 then
return x
else
return 0
end
end
function getMoney(name)
file = io.open("data/bank/"..name..".dat", "r")
x = file:read("*number")
file:close()
return x
end
function newAccount(name)
file = io.open("data/bank/"..name..".dat", "w")
file:write("0")
file:close()
return 1
end
function addMoney(name,money)
file = io.open("data/bank/"..name..".dat", "r")
x = file:read("*number")
x = x + money
file:close()
file = io.open("data/bank/"..name..".dat", "w")
file:write(x)
file:close()
return 1
end
function takeMoney(name,money)
file = io.open("data/bank/"..name..".dat", "r")
x = file:read("*number")
x = x - money
file:close()
file = io.open("data/bank/"..name..".dat", "w")
file:write(x)
file:close()
return 1
end
function Transfer(name1,name2,money)
takeMoney(name1,money)
addMoney(name2,money)
return 1
end
:thumbup: