O inicio deste meu tutorial era assim :
Descobri que esse NPC é do COLEXnosso amiguinho BlackHero fez tutorial de NPC Banqueiro.infelismente o NPC dele usava comandos que gerava erro na maioria dos servers
(mesmo os 8.0)
Descula COLEX por dar créditos errados.
COLEX <-- Vejam quem é COLEX
----------------------------------------------------------------------------------------------------------------------------------
Exclusivo para XTibia
favor não postar em outro forum
----------------------------------------------------------------------------------------------------------------------------------
Vai ae um NPC Banqueiro que não usa comandos especiais.
data\npc\scripts\Palmares.lua
local focus = 0 local talk_start = 0 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) if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then selfSay('Hello ' .. creatureGetName(cid) .. '! wellcome to OT Bank System.') 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.') elseif focus == cid then if msgcontains(msg, 'balance') then balance(cid) talk_state = 0 talk_start = os.clock() elseif msgcontains(msg, 'deposit') and getCount(msg) > 0 then value = getCount(msg) selfSay('Would you really like to deposit '..value..' gold?') talk_state = 2 talk_start = os.clock() elseif msgcontains(msg, 'deposit') then selfSay('Please tell me how much gold it is you would like to deposit.') talk_state = 1 talk_start = os.clock() elseif talk_state == 1 then value = getCount(msg) if value > 0 then selfSay('Would you really like to deposit '..value..' gold?') talk_state = 2 else talk_state = 0 end elseif msgcontains(msg, 'yes') and talk_state == 2 then deposit(cid, value) talk_state = 0 elseif msgcontains(msg, 'transfer') and getCount(msg) > 0 then value = getCount(msg) selfSay('What Player NAME you want to Transfer '..value..' gold?') talk_state = 5 talk_start = os.clock() elseif talk_state == 5 then xid = getPlayerByName(msg) if xid == 0 then selfSay('Player "'..msg..'" not found!!!') talk_state = 0 elseif xid == cid then selfSay('You canot transfer money to yourself!!!') talk_state = 0 else NomeDele = getPlayerName(xid) selfSay('Are you sure you wish to transfer '..value..' gold from your bank to '..NomeDele..' bank?') talk_state = 8 end elseif msgcontains(msg, 'transfer') then selfSay('Please tell me how much gold you would like to transfer?') talk_state = 7 talk_start = os.clock() elseif talk_state == 7 then value = getCount(msg) if value > 0 then selfSay('What Player NAME you want to Transfer '..value..' gold?') talk_state = 5 talk_start = os.clock() else talk_state = 0 end elseif msgcontains(msg, 'yes') and talk_state == 8 then transfer(cid, value, xid) talk_state = 0 elseif msgcontains(msg, 'withdraw') and getCount(msg) > 0 then value = getCount(msg) selfSay('Are you sure you wish to withdraw '..value..' gold from your bank account?') talk_state = 3 talk_start = os.clock() elseif msgcontains(msg, 'withdraw') then talk_state = 4 selfSay('Please tell me how much gold you would like to withdraw.') talk_start = os.clock() elseif talk_state == 4 then value = getCount(msg) if value > 0 then selfSay('Are you sure you wish to withdraw '..value..' gold from your bank account?') talk_state = 3 else talk_state = 0 end elseif msgcontains(msg, 'yes') and talk_state == 3 then withdraw(cid, value) talk_state = 0 elseif msgcontains(msg, 'no') and talk_state == 2 then selfSay('As you wish. Is there something else I can do for you?') talk_state = 0 elseif msgcontains(msg, 'no') and talk_state == 3 then selfSay('The customer is king! Come back anytime you want to if you wish to withdraw your money.') talk_state = 0 elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then selfSay('Bye bye ' .. creatureGetName(cid) .. ', come back anytime you want talk about money.') focus = 0 talk_start = 0 elseif msg ~= "" then selfSay('You are in a Bank! Talk about Bank thinks.') talk_state = 0 end end end function onCreatureChangeOutfit(creature) end function onThink() doNpcSetCreatureFocus(focus) if (os.clock() - talk_start) > 30 then if focus > 0 then selfSay('Next money owner Please...') end focus = 0 talk_start = 0 end if focus ~= 0 then if getDistanceToCreature(focus) > 5 then selfSay('Good bye then. Good talk with you about money.') focus = 0 talk_start = 0 end end end
Palmares é um amiguinho que pediu pra acertar este NPC
Em sua homenagem fiz com o nome dele.
Agora precisa a identificação do NPC
data\npc\Palmares.xml
<npc name="Palmares" script="data/npc/scripts/Banco.lua" access="3" lookdir="1" autowalk="200" speed="200"> <health now="100" max="100"/> <look type="134" head="57" body="59" legs="40" feet="76" corpse="2212"/> <parameters/> </npc>
Este NPC usa funções pré-estabelecidas que ficam no arquivo
data\npc\scripts\lib\npc.lua
-- Funçoes de BANCO function getCount(msg) b, e = string.find(msg, "%d+") if b == nil or e == nil then count = 1 else count = tonumber(string.sub(msg, b, e)) end if count > 100000 then count = 100000 elseif count == 0 then count = 1 end return count end function balance(cid) local storage = 666 local value = getPlayerStorageValue(cid, storage) if value > 0 then selfSay('Your account balance is '..value..' gold.') else setPlayerStorageValue(cid, storage, 0) selfSay('You don\'t have money in your bank account.') end end function withdraw(cid, value) local storage = 666 local balance = getPlayerStorageValue(cid, storage) if balance == -1 then -- Não tinha depositos ainda -> Iniciar com 0 setPlayerStorageValue(cid, storage, 0) end if value <= 0 then selfSay('You cannot withdraw invalid values.') elseif balance < value then selfSay('There is not enough gold on your account.') else selfSay('Here you are, '..value..' gold. Please let me know if there is something else I can do for you.') setPlayerStorageValue(cid, storage, balance-value) doPlayerAddMoney(cid,value) end end function deposit(cid, value) local storage = 666 local balance = getPlayerStorageValue(cid, storage) if balance == -1 then -- Não tinha depositos ainda -> Iniciar com 0 setPlayerStorageValue(cid, storage, 0) end if value < 0 then selfSay('You cannot deposit negative values.') elseif doPlayerRemoveMoney(cid,value) == TRUE then selfSay('Alright, we have added the amount of '..value..' gold to your balance. You can withdraw your money anytime you want to.') setPlayerStorageValue(cid, storage, balance + value) else selfSay('You do not have enough gold.') end end function transfer(cid, value, xid) local storage = 666 local balanceEu = getPlayerStorageValue(cid, storage) local balanceEle = getPlayerStorageValue(xid, storage) if value <= 0 then selfSay('You cannot transfer illegal values.') elseif balanceEu >= value then setPlayerStorageValue(cid, storage, balanceEu - value) setPlayerStorageValue(xid, storage, balanceEle + value) selfSay('Alright, we have transfered the amount of '..value..' gold from your balance to '..NomeDele..' balance.') doPlayerSendTextMessage(xid,4,'OT Bank System : '..getPlayerName(cid)..' transfered the amount of '..value..' gold to your balance.') selfSay(getPlayerName(xid)..' received confirmation about transfer.') else selfSay('You do not have enough gold.') end end function doPlayerGetMoney(cid) local gold = getPlayerItemCount(cid,2148) local platinum = getPlayerItemCount(cid,2152) local crystal = getPlayerItemCount(cid,2160) local total = gold + (platinum*100) + (crystal*10000) return total end
Caso não tenha , incluir no FIM do arquivo.
A grana fica guardada no Storage 666
Caso esse número já esteja sendo usado , substituir.
UpDates
Acharam um erro que foge à minha compreensão
Numa parte que nem é minha.
Eu só usei um recurso que JÁ VEM NO SERVER
Aqui : data\npc\scripts\lib\npc.lua <--- Já vem pronto no server
Estava assim :
elseif doPlayerRemoveMoney(cid,value) then
Troquei por :
elseif doPlayerRemoveMoney(cid,value) == TRUE then
Não entendi porque esse erro, mas o player depositava grana mesmo sem ter o valor.
TRANSFER
Função TRANSFER adicionada
sem os comandos de IO-OPEN só posso fazer TRANSFER pra player on-line
o player que ganhou esse TRANFER recebe a mensagem que houve uma transferência da grana para a conta dele.