Npc Banker (update)

colex
Por colex
em NPCs, monsters e raids

colex

Serviços Prestados a Comunidade
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 03/10/05Posts: 301Gênero: Masculino

Olá,

Este NPC foi feito pro mim, tentei fazer igual ao do Tibia e este foi o resultado, espero que gostem!

As Funções deste NPC são:

- Deposit (depositar dinheiro)

- Withdraw (retirar dinheiro)

- Balance (ver quanto dinheiro tem na conta)

-TRANSFER (transferir dinheiro entre players) <-- UPDATE

No "withdraw" o NPC da ao jogador crystal, platinum e gold quando necssário

10110 <- neste exemplo o NPC daria 1 crystal, 1 platinum e 10 gold

Aqui esta o script:

 

---------NPC Banker by Colex-----------focus = 0talk_start = 0target = 0dep = 0wit = 0trans = 0following = falseattacking = false--ALTERE DE ACORDO COM A SUA VERSÃO-----IDs----gold_id = 2148plat_id = 2152crys_id = 2160function onThingMove(creature, thing, oldpos, oldstackpos)endfunction onCreatureAppear(creature)endfunction onCreatureDisappear(cid, pos) 	 if focus == cid then          selfSay('Good bye then.')          focus = 0          talk_start = 0 	 endendfunction onCreatureTurn(creature)endfunction msgcontains(txt, str) 	 return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))endfunction 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.')   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  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('Have a nice day Sir!')          focus = 0          dep = 0   wit = 0   trans = 0           endendfunction onCreatureChangeOutfit(creature)endfunction 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  endendfunction getNumber(txt)x = string.gsub(txt,"%a","")x = tonumber(x)if x ~= nill and x > 0 thenreturn xelsereturn 0endendfunction getMoney(name)file = io.open("data/bank/"..name..".dat", "r")x = file:read("*number")file:close()return xendfunction newAccount(name)file = io.open("data/bank/"..name..".dat", "w")file:write("0")file:close()return 1endfunction addMoney(name,money)file = io.open("data/bank/"..name..".dat", "r")x = file:read("*number")x = x + moneyfile:close()file = io.open("data/bank/"..name..".dat", "w")file:write(x)file:close()return 1endfunction takeMoney(name,money)file = io.open("data/bank/"..name..".dat", "r")x = file:read("*number")x = x - moneyfile:close()file = io.open("data/bank/"..name..".dat", "w")file:write(x)file:close()return 1endfunction Transfer(name1,name2,money)takeMoney(name1,money)addMoney(name2,money)return 1end

 

----------Novo update lançado--------

Agora o NPC tem sistema de transferencia de dinheiro entre players

necessário a criação de uma pasta com nome "bank" dentro da pasta "data"

ficando "data\bank"

o sistema de transferencia poderá não funcionar bem em servidores SQL então daqui a pouco eu edito e coloco para download uma versão para servidores SQL.

#bugfix no withdraw -- obrigado por me avisar GM Dudu

Aproveitem o NPC mas não tirem os creditos

Atenciosamente,

Colex

tibiaa4e

Ex amante de Tibia
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 18/12/05Posts: 912Gênero: MasculinoChar no Tibia: Kohzete

ja postei no otfans

+ aki tbm vou denovo

100% funfando

só no xikeot 0.6.2 num funfa ainda :p

muito bom

igualzim o do tibia

aprabens

por isso sous eu fã:D

vlws

flws :bye:

Aposentado de OTserver e Tibia

Meus melhores tutoriais
Enciclopédia Pasta Data
Tutorial de quest

colex

Serviços Prestados a Comunidade
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 03/10/05Posts: 301Gênero: Masculino

Obrigado pro dar a opinião.

depois eu baixo essa versão e arrumo para funcionar nele tambem

Abraços,

Colex

tibiaa4e

Ex amante de Tibia
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 18/12/05Posts: 912Gênero: MasculinoChar no Tibia: Kohzete

essa versão ta mto bugada

ate saiu de download

axo q na + antiga funfa

daki a poko eu testo e t falo

Aposentado de OTserver e Tibia

Meus melhores tutoriais
Enciclopédia Pasta Data
Tutorial de quest

colex

Serviços Prestados a Comunidade
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 03/10/05Posts: 301Gênero: Masculino
e em 7.6 pega?

 

 

 

em 7.6 pega com certeza, alias eu fiz esse NPC numa versão de ot 7.6

se voce for ver os IDs são 7.6

abraços,

Colex

soulblaster

avatar
Cavaleiro
Cavaleiro

INFOS

Grupo: CavaleiroRegistrado: 22/10/05Posts: 196

aeee =]

boaaa colex ;D

mto bom esse npc em? ^^

vou ate add no meu server ;]

é por essas e outras razoes que adimiro seu trabalho cada vez mais =]

cya... :bye:

EDITED:

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

vc colocou nill + num é nil (sem um L) num? =]

cya... :bye:

Assinatura feita por Kilerzinhow:
untitled3mg3.jpg
| Wey.Ctba | Wey.Ctba | Rafix | UnderNight | Xedegux |

colex

Serviços Prestados a Comunidade
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 03/10/05Posts: 301Gênero: Masculino

@soulblaster

nill funcionou na mesma

por isso acho que nem vale a pena mudar se ficou correto

mas mostar que voce leu o code

Abraços,

Colex

Kenzo

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 08/10/06Posts: 131Char no Tibia: Kenzo Phoenix

Cara eu te Love

Como vc consegue?^^

Simplesmente EXCELENTE

//Kenzo

Visite a melhor parte do Fórum XTibia! Basta você apenas clicar aqui e deixar sua opinião sobre qualquer um dos assuntos!

Está com dúvidas no Tibia? Quer dicas de como melhorar seu character? Mande uma PM e lhe responderei a medida do possível.

"Tonight
I'm gonna have myself a real good time
I feel alive
And the world is turning inside out
Yeah!
And floating around in ecstasy

So don't stop me now
Don't stop me
'Cause I'm having a good time
I'm having a good time

I'm a shooting star leaping through the sky
Like a tiger defying the laws of gravity
I'm a racing car passing by like Lady Godiva
I'm gonna go go go
There's no stopping me...
"

Dont Stop me Now - McFly

soulblaster

avatar
Cavaleiro
Cavaleiro

INFOS

Grupo: CavaleiroRegistrado: 22/10/05Posts: 196

colex,

acabo de ver no tibia real, que vc pode transferir seu dinheiro para alguem do server...

estou tentando faser isso, mas por enquanto não deu em nada =X

vc que intende mais, poderia tentar faser isso , num? ;]

a conversa seria assim:

hi - transfer - (gold) - yes/no - (pessoa) - [verificar se a pessoa existe] - yes/no

(gold) = quantidade de dinheiro que a pessoa tranferiria

(pessoa) = nome do player que vai transferir o dinheiro

[verificar se a pessoa existe] = (num sei desse novo .lua + no antigo vc usaria algo assim)

if io.open("data/players/"..msg..".xml" , "r") == nil then

^^'

se vc conseguir faser, ficarei mto grato ;]

cya... :bye:

Assinatura feita por Kilerzinhow:
untitled3mg3.jpg
| Wey.Ctba | Wey.Ctba | Rafix | UnderNight | Xedegux |

colex

Serviços Prestados a Comunidade
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 03/10/05Posts: 301Gênero: Masculino

@soulblaster

eu ja tava trabalhando nisso e vou aproveitar e ja acrescentar outras coisas.

Abraços,

Colex

Sky Hunter

avatar
Banidos
Banidos

INFOS

Grupo: BanidosRegistrado: 03/10/06Posts: 227

o0 lol³, vou testar aqui pra ver, se ficar parecido com o real tá massa.

[Usuário banido por comportamento destrutivo]

Conde do Monte Cristo

Eu sempre vou ser o Conde. =)
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 16/09/06Posts: 464Gênero: MasculinoChar no Tibia: Yonlu

te amo colex! O melhor de tudo: FUNCIONA EM 7.6

^^

Te falar, sinto saudade de quando eu era jovem, muita saudade.

colex

Serviços Prestados a Comunidade
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 03/10/05Posts: 301Gênero: Masculino

UPDATE chegou, agora com o sistema de transfer como o soulblaster havia pedido.

não se esqueçam de criar a pasta bank dentro da pasta data caso contrário o NPC não funcionará

nota: como foi dito no tópico, daqui a pouco eu edito com o sistema transfer funcionando em servidores SQL (não vai ficar tão bom como em servidores XML)

Atenciosamente,

Colex