colex 8 Postado Dezembro 17, 2006 Share Postado Dezembro 17, 2006 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 Link para o comentário Compartilhar em outros sites More sharing options...
tibiaa4e 86 Postado Dezembro 17, 2006 Share Postado Dezembro 17, 2006 ja postei no otfans + aki tbm vou denovo 100% funfando só no xikeot 0.6.2 num funfa ainda muito bom igualzim o do tibia aprabens por isso sous eu fã vlws flws Link para o comentário Compartilhar em outros sites More sharing options...
colex 8 Postado Dezembro 17, 2006 Autor Share Postado Dezembro 17, 2006 Obrigado pro dar a opinião. depois eu baixo essa versão e arrumo para funcionar nele tambem Abraços, Colex Link para o comentário Compartilhar em outros sites More sharing options...
tibiaa4e 86 Postado Dezembro 17, 2006 Share Postado Dezembro 17, 2006 essa versão ta mto bugada ate saiu de download axo q na + antiga funfa daki a poko eu testo e t falo Link para o comentário Compartilhar em outros sites More sharing options...
Gm Dudu 0 Postado Dezembro 17, 2006 Share Postado Dezembro 17, 2006 e em 7.6 pega? Link para o comentário Compartilhar em outros sites More sharing options...
colex 8 Postado Dezembro 17, 2006 Autor Share Postado Dezembro 17, 2006 e em 7.6 pega? <{POST_SNAPBACK}> 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 Link para o comentário Compartilhar em outros sites More sharing options...
soulblaster 0 Postado Dezembro 17, 2006 Share Postado Dezembro 17, 2006 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... 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... Link para o comentário Compartilhar em outros sites More sharing options...
colex 8 Postado Dezembro 18, 2006 Autor Share Postado Dezembro 18, 2006 @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 Link para o comentário Compartilhar em outros sites More sharing options...
Kenzo 0 Postado Dezembro 18, 2006 Share Postado Dezembro 18, 2006 Cara eu te Love Como vc consegue?^^ Simplesmente EXCELENTE //Kenzo Link para o comentário Compartilhar em outros sites More sharing options...
Gm Dudu 0 Postado Dezembro 18, 2006 Share Postado Dezembro 18, 2006 aaaa blz ! vou por la no x-treme... e vou add uma linha com os crditos ! elseif (msgcontains(msg, 'creditos')) then selfSay('Todos os creditos a Colex Pelo otimo trabalho feito no http://xtibia.com/forum.') Link para o comentário Compartilhar em outros sites More sharing options...
soulblaster 0 Postado Dezembro 19, 2006 Share Postado Dezembro 19, 2006 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... Link para o comentário Compartilhar em outros sites More sharing options...
colex 8 Postado Dezembro 19, 2006 Autor Share Postado Dezembro 19, 2006 @soulblaster eu ja tava trabalhando nisso e vou aproveitar e ja acrescentar outras coisas. Abraços, Colex Link para o comentário Compartilhar em outros sites More sharing options...
Sky Hunter 0 Postado Dezembro 19, 2006 Share Postado Dezembro 19, 2006 o0 lol³, vou testar aqui pra ver, se ficar parecido com o real tá massa. Link para o comentário Compartilhar em outros sites More sharing options...
Conde do Monte Cristo 0 Postado Dezembro 19, 2006 Share Postado Dezembro 19, 2006 te amo colex! O melhor de tudo: FUNCIONA EM 7.6 ^^ Link para o comentário Compartilhar em outros sites More sharing options...
colex 8 Postado Dezembro 19, 2006 Autor Share Postado Dezembro 19, 2006 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 Link para o comentário Compartilhar em outros sites More sharing options...
Posts Recomendados