Ir para conteúdo
  • Cadastre-se

Posts Recomendados

Hello, before everything, if i made this topic in wrong section i apologies.

Now, i made NPC Duplica that sell ditto for 10 diamonds and exchange ditto +50 + 350 diamonds into shiny ditto.

Everything work good but there is some errors that i dont know to fix :(

 

duplica.lua

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function doBuyPokemonWithCasinoCoins(cid, poke) npcHandler:onSellpokemon(cid) end
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
 
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
 
------------------------------------------------------------
local function buyPoke(cid, pokemon, price)             
if not pokes[pokemon] then return false end
 
local btype = "normal"
local happy = 250
 
if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then 
   item = doCreateItemEx(11826)
else
    item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, 11826, 1)   
end
 
doItemSetAttribute(item, "poke", pokemon)
doItemSetAttribute(item, "hp", 1)
doItemSetAttribute(item, "happy", happy)
doItemSetAttribute(item, "description", "Contains a "..pokemon..".")
doItemSetAttribute(item, "Icone", "yes")
 
if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then 
   doPlayerSendMailByName(getCreatureName(cid), item, 1)
   selfSay("Your pokemon was sent to Pokemon Center!", cid)
end
end
 
local pokes = {
["ditto"] = {poke = "Ditto", price = 10},
}
local msg = tonumber(msg) and msg or msg:lower()
------------------------------------------------------------------------------
if msgcontains(msg, 'ditto') or msgcontains(msg, 'buy') then
   pokemon = pokes[msg]
   selfSay("Are you sure you want buy an "..pokemon.poke.." for ".. pokemon.price .." diamonds?", cid)
   talkState[cid] = 1
   return true
   
elseif (msgcontains(msg, "yes") or msgcontains(msg, "Yes")) and talkState[cid] == 1 then
   if getPlayerItemCount(cid, 2145) >= pokemon.price then
      selfSay("Here you are! You have just bought an "..pokemon.poke.." for "..pokemon.price.." diamonds!", cid)
      buyPoke(cid, pokemon.poke, pokemon.price)
 doPlayerRemoveItem(cid, 2145, pokemon.price)
      talkState[cid] = 0
      return true
   else
      selfSay("You don't have enought diamonds, bye", cid)
      talkState[cid] = 0
      return true 
   end
end
 
 
if (msgcontains(msg, "no") or msgcontains(msg, "nao")) then
   selfSay("Ok then, come back if you want something...", cid)
   talkState[cid] = 0
   return true     
end
 
 
----------- make shiny -----------
 
 
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
if (msgcontains(msg, 'Shiny') or msgcontains(msg, 'shiny')) then
selfSay("Do you want to transform your Ditto in Shiny Ditto? You need Ditto +50 and 350 diamonds.", cid)
talkState[talkUser] = 3
elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'Yes')) and talkState[talkUser] == 3 then
if getPlayerSlotItem(cid, 8).uid <= 0 then
selfSay("Sorry, you are not with the pokemon in the slot!", cid)
talkState[talkUser] = 0
return true
end 
if #getCreatureSummons(cid) >= 1 then
selfSay("Pull your pokemon to Pokeball!", cid)
talkState[talkUser] = 0
return true
end
local pb = getPlayerSlotItem(cid, 8).uid
 
if getItemAttribute(pb, "poke") ~= "Ditto" then
selfSay("Place your Ditto + 50 in slot please!", cid)
talkState[talkUser] = 0
return true
end
 
if not getItemAttribute(pb, "boost") or getItemAttribute(pb, "boost") < 50 then
selfSay("Sorry your Ditto is not +50!", cid)
talkState[talkUser] = 0
return true
end
 
           if doPlayerRemoveItem(cid, 2145, 350) == true then
              selfSay("So there is it! Enjoy!", cid)
              doItemSetAttribute(pb, "hp", 1)
              doItemSetAttribute(pb, "poke", "Shiny Ditto")
     doItemSetAttribute(pb, "description", "Contains a Shiny Ditto.")
     doItemEraseAttribute(pb, "boost")
     doTransformItem(getPlayerSlotItem(cid, 7).uid, fotos["Shiny Ditto"])
 
doItemSetAttribute(pb, "Icone", "yes")
doTransformItem(pb, icons[getItemAttribute(pb, "poke")].on)
 
     if useKpdoDlls then
       doCreatureExecuteTalkAction(cid, "/pokeread")
         end
     talkState[talkUser] = 0
     return true
     else
         selfSay("You do not have enough diamonds!", cid)
         talkState[talkUser] = 0
         return true
          end
        end
 
return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Now, problems: (I'm using PDA)

1. when i buy ditto it show in inventory, but it is in normal (poke) ball, and i got icon system. after i relog everything is normal.

    if i try open pokeball before relog i get error:

[14/04/2015 16:40:07] [Error - Npc interface] 
[14/04/2015 16:40:07] data/npc/scripts/duplica.lua:onCreatureSay
[14/04/2015 16:40:07] Description: 
[14/04/2015 16:40:07] data/npc/scripts/duplica.lua:49: attempt to index global 'pokemon' (a nil value)
[14/04/2015 16:40:07] stack traceback:
[14/04/2015 16:40:07] data/npc/scripts/duplica.lua:49: in function 'callback'
[14/04/2015 16:40:07] data/npc/lib/npcsystem/npchandler.lua:391: in function 'onCreatureSay'

 

[14/04/2015 16:40:07] data/npc/scripts/duplica.lua:9: in function <data/npc/scripts/duplica.lua:9>

 

2. If pokeslot is empty i get this whenever i log in:

[14/04/2015 16:45:51] [Error - CreatureScript Interface] 
[14/04/2015 16:45:51] data/creaturescripts/scripts/login.lua:onLogin
[14/04/2015 16:45:51] Description: 
[14/04/2015 16:45:51] (luaGetItemAttribute) Item not found

Editado por dbs86 (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

O tópico foi movido para a área correta, preste mais atenção da próxima vez!

Leia as regras do fórum: http://tibiaking.com/forum/topic/1281-regras-gerais/?p=7680

Este tópico foi movido:

De: "OTServSuporte OTServSuporte de Scripts"

Para: "OTServSuporte OTServSuporte de Servidores Derivados"

Se quiser sua dúvida tirada, mande PM com os links, e não com a dúvida (outros podem ter a mesma dúvida, e o fórum serve para ser usado).

 

Tópicos:


 

yNlhRVC.png

 

55px-Judo_yellow_belt.svg.png

Link para o post
Compartilhar em outros sites

Resolved on other way by me  :D

 

Script work on PDA.. 

 

data/npc/scripts/duplica.lua

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function doBuyPokemonWithCasinoCoins(cid, poke) npcHandler:onSellpokemon(cid) end
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
 
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
 
local msg = tonumber(msg) and msg or msg:lower()
------------------------------------------------------------------------------
if msgcontains(msg, 'ditto') or msgcontains(msg, 'buy') then
   pokemon = pokes[msg]
   selfSay("Are you sure you want buy an Ditto for 15 diamonds?", cid)
   talkState[cid] = 1
   return true
   
elseif (msgcontains(msg, "yes") or msgcontains(msg, "Yes")) and talkState[cid] == 1 then
   if getPlayerItemCount(cid, 2145) >= 15 then
      selfSay("Here you are! You have just bought an Ditto for 15 diamonds!", cid)
      doPlayerAddItem(cid,1738,1)
 doPlayerRemoveItem(cid, 2145, 15)
      talkState[cid] = 0
      return true
   else
      selfSay("You don't have enought diamonds, bye", cid)
      talkState[cid] = 0
      return true 
   end
end
 
 
if (msgcontains(msg, "no") or msgcontains(msg, "nao")) then
   selfSay("Ok then, come back if you want something...", cid)
   talkState[cid] = 0
   return true     
end
 
 
----------- make shiny -----------
 
 
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
if (msgcontains(msg, 'Shiny') or msgcontains(msg, 'shiny')) then
selfSay("Do you want to transform your Ditto in Shiny Ditto? You need Ditto +50 and 300 diamonds.", cid)
talkState[talkUser] = 3
elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'Yes')) and talkState[talkUser] == 3 then
if getPlayerSlotItem(cid, 8).uid <= 0 then
selfSay("Sorry, you are not with the pokemon in the slot!", cid)
talkState[talkUser] = 2
return true
end 
if #getCreatureSummons(cid) >= 1 then
selfSay("Pull your pokemon to Pokeball!", cid)
talkState[talkUser] = 2
return true
end
local pb = getPlayerSlotItem(cid, 8).uid
 
if getItemAttribute(pb, "poke") ~= "Ditto" then
selfSay("Place your Ditto + 50 in slot please!", cid)
talkState[talkUser] = 2
return true
end
 
if not getItemAttribute(pb, "boost") or getItemAttribute(pb, "boost") < 50 then
selfSay("Sorry your Ditto is not +50!", cid)
talkState[talkUser] = 2
return true
end
 
           if doPlayerRemoveItem(cid, 2145, 300) == true then
              selfSay("So there is it! Enjoy!", cid)
              doItemSetAttribute(pb, "hp", 1)
              doItemSetAttribute(pb, "poke", "Shiny Ditto")
     doItemSetAttribute(pb, "description", "Contains a Shiny Ditto.")
     doItemEraseAttribute(pb, "boost")
     doTransformItem(getPlayerSlotItem(cid, 7).uid, fotos["Shiny Ditto"])
 
doItemSetAttribute(pb, "Icone", "yes")
doTransformItem(pb, icons[getItemAttribute(pb, "poke")].on)
 
     if useKpdoDlls then
       doCreatureExecuteTalkAction(cid, "/pokeread")
         end
     talkState[talkUser] = 2
     return true
     else
         selfSay("You do not have enough diamonds!", cid)
         talkState[talkUser] = 2
         return true
          end
        end
 
return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

data/actions/actions.xml

<action itemid="1738" event="script" value="box_ditto.lua"/>

 

data/actions/scripts/box_ditto.lua

local a = {
[1738] = {pokemons = {"Ditto"}}
}
        
local happy = 1000 
         
function onUse(cid, item, frompos, item2, topos)
         local b = a[item.itemid]                                    
               if not b then return true end
         local pokemon = b.pokemons[math.random(#b.pokemons)]
               if not pokes[pokemon] then return true end  
if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then 
end
         doPlayerSendTextMessage(cid, 27, "You opened a pokemon box!")
     doPlayerSendTextMessage(cid, 27, "The prize pokemon was a "..pokemon..", congratulations!")
     doSendMagicEffect(getThingPos(cid), 29)
               
         addPokeToPlayer(cid, pokemon, 0, nil, btype)                                              
         doRemoveItem(item.uid, 1)
                   if useOTClient then
       doCreatureExecuteTalkAction(cid, "/save")
    end
 
return true
end

Editado por dbs86 (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo