RA

Npc Banker 8.0

Por Rafael Hamdan, 12 de ago. de 2007 em NPCs, monsters e raids

tibia
script
32
8.9k
12 de agosto de 2007 às 11:20

Fala galerinha!

 

Tenho uma boa notícia para vocês!

 

Consegui passar o "Npc Banker - By Colex", para 8.0, SEM NENHUM bug!!!

 

Isso mesmo!!

 

---------------------------------------------------

 

Créditos: Colex - 98%

Rafael Hamdan - 2%

 

---------------------------------------------------

 

Só 2% para mim, pois, pelo excelente e bem montado script do colex, creio que mereço só 2%, por editar seu begin, criação de variáveis, e fixação no focus.

 

Vamos logo com isso!!

 

Para instalar o script, vá na pasta npc/scripts, crie um arquivo chamado banker.lua, e coloque o seguinte código nele:

 

---------NPC Banker by Colex - Edited and Fixed by Rafael Hamdan (Testa) -----------

local focus = 0
local talk_start = 0
local target = 0
local dep = 0
local wit = 0
local trans = 0
local following = false
local attacking = false




--ALTERE DE ACORDO COM A SUA VERSÃO
-----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 = getCreatureName(cid)

--------------------------------------Begin----------------------------------------------

if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
		selfSay('Hello ' .. getCreatureName(cid) .. '! Welcome to the bank! What can I do for you? Deposit, Withdraw, Transfer or Balance?.')
		focus = cid
		talk_start = os.clock()

elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
	  selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')

  elseif focus == cid then
	talk_start = os.clock()


--------------------------------------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.')
 dep = 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
 rec = msg
 selfSay('Do you want to transfer '..quant..' gps to '..rec..'?')
 trans = 4
 talk_start = os.clock()  
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('Have a nice day Sir!')
	 focus = 0
	 dep = 0
 wit = 0
 trans = 0

   end
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

 

Agora, volte à pasta npc, crie um arquivo chamado banker.xml, e coloque o seguinte código nele:

 

<?xml version="1.0"?>

<npc name="Banker" script="data/npc/scripts/banker.lua" access="3" lookdir="1" autowalk="25">
<health now="1000" max="1000"/>
<look type="128" head="20" body="100" legs="50" feet="99"/>
</npc>

 

Agora, insira o nome "Banker" em seu mapeditor, e saia colocando ele em cada cidade!

 

Além dos fix bug's, o npc está estável, pois antes, você colocava 5 , 4 npc's no mesmo mapa, e bugava na hora de dizer "hi".

 

Todos os bug's fixados e funcionando PERFEITAMENTE para Tibia 8.0.

 

Testado em SVN - DevLand 8.0 (todas versões que sairam até hoje)!

 

Espero ter ajudado em galerinha! :p

 

//Rafael Hamdan;

Editado Agosto 12 por Rafael Hamdan

DekoooD
12 de agosto de 2007 às 11:23

Rox manow vlw ae pra vc trazer seus trabalhos pro XTibia, me ajudo mt e garanto que vai ajudar mts outros tambem ;)~

RoD LoKoR
12 de agosto de 2007 às 12:31

Cara, vou te dar um "beijo"... UAEHAUEHUEHUHEuHUEhUEHaUHEUHEUHEUhAUEhAUEHuAHEAU³

Mano, precisava muito disso ;)...

Parabéns pelo trabalho, obrigado por trazer para o Xtibia :)~

 

 

 

Abraços,

lucasbroL
12 de agosto de 2007 às 13:13

No Servfull 0.1 só está funcionando o deposit....

12 de agosto de 2007 às 13:19

O que está acontecendo? Essa versão do servfull já é 8.0?

 

//Rafael Hamdan;

lucasbroL
12 de agosto de 2007 às 15:41

É 8.0 sim, quando eu falo deposit e o numero, deposita, mais quando eu falo "yes" para pegar, tranferir, e quando falo "balance" o npc não fala nada, e aparece monte de linha da inicialização do otserver...

 

Vou testart no DevLand 8.0 agora... Vamos ver!

 

Edit

 

DevLand também não funcionou...

Editado Agosto 12 por lucasbro

12 de agosto de 2007 às 16:02

Engano seu, eu uso a última versão do DevLand, 0.96b eu acho. E funciona PERFEITAMENTE. Me passe as linhas do erro de qualquer maneira para que eu possa ver!

lucasbroL
12 de agosto de 2007 às 17:13

Vou passar um exemplo de quando eu falo "balance"

 

Lua Script Error: [Npc interface]

data/npc/scripts/banker.lua:onCreatureSay

 

data/npc/scripts/banker.lua:347: attempt to index global 'file' <a nil value>

 

É esse o erro

 

OBS: Também uso a ultima versão do DevLand (postada pelo JV Chequer)

Editado Agosto 12 por lucasbro

NostradamusN
12 de agosto de 2007 às 20:32

@lucasbro

Nunca postei versão do DevLand aqui no XTibia, você deve usar o NTS StarterKit.

lucasbroL
12 de agosto de 2007 às 21:33

Desculpe Nostradamus, eu errei o nome, eu queria dizer JV Chequer

13 de agosto de 2007 às 13:18

Lucasbro,

 

Descobri o erro. É simples: Quando se fala:

 

- hi - deposit xx

- hi - withdraw xx

 

O erro ocorre. Creio que devemos falar :

 

- hi - deposit - xx

- hi - withdraw - xx

 

Como estou sem tibia aqui no trabalho, não posso te dizer se este é EXATAMENTE o erro. Alguém pode testar para mim?

 

Logo arrumarei esse erro (se for isso mesmo), e postarei a versão 1.1.

 

//Rafael Hamdan;

Editado Agosto 13 por Rafael Hamdan

lucasbroL
13 de agosto de 2007 às 13:50

Eu criei a pasta Bank sim...

 

Vou ver agora se funciona "hi" "withdraw" "1000"...

 

edited

 

13:51 Dzojo [49]: hi

13:51 Banker: Hello Dzojo! Welcome to the bank! What can I do for you? Deposit, Withdraw, Transfer or Balance?.

13:52 Dzojo [49]: withdraw

13:52 Banker: How much do you wish to withdraw?

13:52 Dzojo [49]: 2600

13:52 Banker: Do you really want to withdraw 2600 gold pieces?

13:52 Dzojo [49]: yes

 

Depois que eu falo yes ele não fala mais nada....

Editado Agosto 13 por lucasbro

13 de agosto de 2007 às 14:22

Certo, e dá algum erro no console??

 

//Rafael Hamdan;

lucasbroL
13 de agosto de 2007 às 14:37
Lua Script Error: [Npc interface]

data/npc/scripts/banker.lua:onCreatureSay

 

data/npc/scripts/banker.lua:347: attempt to index global 'file' <a nil value>

 

Esse erro...

Editado Agosto 13 por lucasbro

13 de agosto de 2007 às 15:37

Lucasbro,

 

Cheguei em casa, testei tudo, com withdraw 100, withdraw - 100, todos estão funcioanando CORRETAMENTE sem nenhum BUG.

 

Não sei o que pode estar acontecendo ai. Tente trocar as partes que estão com getCreatureName e passe para creatureGetName.

 

//Rafael Hamdan;