Primeiramente se já ouver o NPC GYM Misty Aqui no Forum Podem Fechar o Tópico.
Eae Galera Do XTibia Vou ensinar como Fazer o NPC GYM Misty.
No Final Explicarei Aonde Adcionar Mas Pokes.
Então Vamos lá:
Primeiro Passo: Vá em DATA/LIB/ e Crie Um Arquivo Chamado gymlib.lua (LUA) e Coloque isto Dentro.
funcpokemon = {2531, 2652, 2653, 2654, 2195} -- ID das pokebolas (o pokemon tem que estar vivo nessas IDs)
bpslot = CONST_SLOT_BACKPACK --em outros servers, pode ser que seja CONST_SLOT_AMMO o lugar onde fica a backpack no inventory
ginasios = {
["Misty"] = { storage = 992,
msgdefeat = "You lost! You aren't strong enough yet, don't come back until you get stronger!",
msgafk = "Go away if you don't have any pokemons!",
msgwin = "Congratulations, you were strong enough to win this battle fairly! Take this Water Badge as reward.",
[1] = { msggo = "Lets fight then! I choose you, Starmie!",
msgba = "That's enough, Starmie!",
pokem = "Misty Starmie",
nextp = "Misty Poliwrath"},
[2] = { msggo = "It's your turn, Poliwrath!",
msgba = "Come back, Poliwrath!",
pokem = "Misty Poliwrath",
nextp = "Misty Gyarados"},
[3] = { msggo = "Crush'em, Gyarados!",
msgba = "You did well, Gyarados!",
pokem = "Misty Gyarados",
nextp = "Misty Blastoise"},
[4] = { msggo = "Crush'em, Blastoise!",
msgba = "You did well, Blastoise!",
pokem = "Misty Blastoise",
nextp = "finish"}
}
}
function noPokeAtAll(cid, gympoke, npcname, msgafk)
if not isCreature(cid) then
return false
end
if not isCreature(gympoke) then
return false
end
if #getCreatureSummons(cid) == 0 and getPlayerStorageValue(cid, 992) == 0 and getPlayerStorageValue(cid, ginasios[npcname].storage) ~= 2 then
setPlayerStorageValue(cid, 992, -1)
doCreatureSay(getCreatureByName(npcname), msgafk, 1)
doSendMagicEffect(getThingPos(gympoke), 10)
setPlayerStorageValue(cid, ginasios[npcname].storage, 0)
doRemoveCreature(gympoke)
return true
end
end
function gymChecker(cid, duel, nb, npcname)
if not isCreature(cid) then
return true
end
if not isCreature(duel) then
doSendMagicEffect(getThingPos(cid), 10)
doRemoveCreature(cid)
return true
end
if getDistanceBetween(getThingPos(getCreatureByName(npcname)), getThingPos(duel)) >= 8 then
doSendMagicEffect(getThingPos(cid), 10)
doRemoveCreature(cid)
setPlayerStorageValue(duel, ginasios[npcname].storage, 0)
return true
end
if isCreature(duel) and getPlayerStorageValue(duel, 992) == 0 then
addEvent(noPokeAtAll, 6000, duel, cid, npcname, ginasios[npcname].msgafk)
end
if isCreature(duel) and getPlayerStorageValue(duel, 992) == -1 then
doSendMagicEffect(getThingPos(cid), 10)
doRemoveCreature(cid)
setPlayerStorageValue(duel, ginasios[npcname].storage, 0)
doCreatureSay(getCreatureByName(npcname), ginasios[npcname].msgdefeat, 1)
return true
end
if isCreature(duel) and not hasPokemon(duel) then
setPlayerStorageValue(duel, 992, -1)
end
if not isCreature(getCreatureTarget(cid)) then
if nb == 0 then
addEvent(gymChecker, 200, cid, duel, 1, npcname)
else
doSendMagicEffect(getThingPos(cid), 10)
doRemoveCreature(cid)
if isCreature(duel) then
setPlayerStorageValue(duel, ginasios[npcname].storage, 0)
end
end
return true
end
addEvent(gymChecker, 1000, cid, duel, 0, npcname)
end
function hasPokemon(cid)
if #getCreatureSummons(cid) >= 1 then
return true
end
if isInArray(funcpokemon, getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid) then
return true
end
local bp = getPlayerSlotItem(cid, bpslot)
for cc = 1, #funcpokemon do
if #getItemsInContainerById(bp.uid, funcpokemon[cc]) >= 1 then
return true
end
end
return false
end
function doGymBattle(npcname, gympoke, cid, turn)
doCreatureSay(getCreatureByName(npcname), ginasios[npcname][turn].msggo, 1)
local x = doSummonCreature(gympoke, getThingPos(getCreatureByName(npcname)))
registerCreatureEvent(x, "Gym1")
registerCreatureEvent(x, "Gym2")
registerCreatureEvent(x, "Gym3")
registerCreatureEvent(x, "Gym4")
setPlayerStorageValue(x, 201, ".")
setPlayerStorageValue(x, 201, npcname)
setPlayerStorageValue(x, 202, turn)
doSendMagicEffect(getThingPos(x), 10)
setPlayerStorageValue(x, ginasios[npcname].storage, 1)
addEvent(gymChecker, 1000, x, cid, 0, npcname)
end
--ex: doGymBattle("Misty", "Misty Starmie", cid, 1)
Segundo Passo:Vá em DATA/CREATURESCRIPTS/SCRIPTS e Crie Um Arquivo Chamado gym.lua (LUA) e Coloque isto Dentro:
function onDeath(cid, corpse)
doSendMagicEffect(getThingPos(cid), 10)
local npc = ""..getPlayerStorageValue(cid, 201)..""
local turn = getPlayerStorageValue(cid, 202)
local nturn = ((turn) + 1)
local nxt = ginasios[npc][turn].nextp
doCreatureSay(getCreatureByName(npc), ginasios[npc][turn].msgba, 1)
if nxt == "finish" then
local killer = getItemAttribute(corpse.uid, "corpseowner")
addEvent(doCreatureSay, 1200, getCreatureByName(npc), ginasios[npc].msgwin, 1)
setPlayerStorageValue(getCreatureMaster(killer), ginasios[npc].storage, 2)
--local item = getPlayerItemById(killer, true, 2307)
--doTransformItem(item.uid, 5924,1)
--doTransformItem(item.uid, 2160,100)
--doTransformItem(item.uid, 2160,100)
doRemoveCreature(cid)
return false
end
local function summonNext(poke, pos, gym, msg, cid)
local x = doSummonCreature(poke, pos)
addEvent(gymChecker, 1000, x, cid, 0)
doSendMagicEffect(getThingPos(x), 10)
doCreatureSay(getCreatureByName(gym), msg, 1)
end
local killer = getItemAttribute(corpse.uid, "corpseowner")
addEvent(doGymBattle, 1200, npc, ginasios[npc][turn].nextp, killer, nturn)
doRemoveCreature(cid)
return false
end
local fightconditionnn = createConditionObject(CONDITION_INFIGHT)
setConditionParam(fightconditionnn, CONDITION_PARAM_TICKS, 18 * 1000)
function onAttack(cid, target)
if getPlayerStorageValue(getCreatureMaster(target), ginasios[getPlayerStorageValue(cid, 201)].storage) ~= 1 then
doMonsterChangeTarget(cid)
doChangeSpeed(cid, -getCreatureSpeed(cid))
return true
end
if isPlayer(target) then
if #getCreatureSummons(target) == 0 then
doMonsterChangeTarget(cid)
doChangeSpeed(cid, -getCreatureSpeed(cid))
return true
end
if #getCreatureSummons(target) >= 1 then
doMonsterSetTarget(cid, getCreatureSummons(target)[1])
end
end
if getCreatureSpeed(cid) == 0 then
doChangeSpeed(cid, -getCreatureSpeed(cid))
doChangeSpeed(cid, 200)
end
doAddCondition(getCreatureMaster(target), fightconditionnn)
return true
end
function onCast(cid, target)
if isPlayer(target) then
return false
end
local targete = getCreatureTarget(cid)
if isPlayer(getCreatureMaster(targete)) and getPlayerStorageValue(getCreatureMaster(targete), ginasios[getPlayerStorageValue(cid, 201)].storage) ~= 1 then
return false
end
return true
end
function onDirection(cid, old, current)
if isCreature(getCreatureTarget(cid)) and not isPlayer(getCreatureTarget(cid)) and getPlayerStorageValue(getCreatureMaster(getCreatureTarget(cid)), ginasios[getPlayerStorageValue(cid, 201)].storage) == 1 then
return true
end
return false
end
Terceiro passo: Vá em DATA/CREATURESCRIPTS abra o Arquivo Creaturescripts.xml (XML) E Adcione Essas 4 Tags.
<event type="cast" name="Gym1" event="script" value="gym.lua"/>
<event type="attack" name="Gym2" event="script" value="gym.lua"/>
<event type="direction" name="Gym3" event="script" value="gym.lua"/>
<event type="death" name="Gym4" event="script" value="gym.lua"/>
Quarto passo: Vá em DATA/NPC/SCRIPTS e Crie um Arquivo Chamado Misty.lua (LUA) e Coloque isto Dentro.
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false
local talkState = {}
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye sir!')
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)
local msg = string.lower(msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if getPlayerStorageValue(cid, ginasios["Misty"].storage) >= 1 then
return true
end
if (msgcontains(msg, 'hi') and (focus == 0) and (focus ~= cid) and (getDistanceToCreature(cid) <= 4)) then
focus = cid
talkState[talkUser] = 1
selfSay("Welcome to the gym of Pewter City. My name is Misty and I am the leader of this gym. Would you like to battle me?")
elseif (msgcontains(msg, "no") or msgcontains(msg, "bye")) and focus == cid and talkState[talkUser] ~= 3 then
selfSay("Bye then, tell strong friends to come here and try to beat me!")
focus = 0
elseif (msgcontains(msg, "yes") or msgcontains(msg, "battle")) and focus == cid and talkState[talkUser] == 1 then
if not hasPokemon(cid) then
selfSay("You don't have any pokemon to battle me!")
focus = 0
return true
end
talkState[talkUser] = 3
doGymBattle("Misty", "Misty Starmie", cid, 1)
setPlayerStorageValue(cid, ginasios["Misty"].storage, 1)
setPlayerStorageValue(cid, 992, 0)
local function focusCheck(cid)
if not isCreature(cid) then
focus = 0
return true
end
if getPlayerStorageValue(cid, 992) == -1 then
focus = 0
return true
end
addEvent(focusCheck, 500, cid)
end
addEvent(focusCheck, 1000, cid)
end
end
function onThink()
if focus ~= 0 then
a, b, c = selfGetPosition()
if c ~= getThingPos(focus).z then
focus = 0
end
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 6 then
focus = 0
end
end
return true
end
Quinto Passo: Vá em DATA/NPC/ e Crie um Arquivo Chamado Misty.xml (XML) e Coloque isto Dentro.
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Misty" script="misty.lua" walkinterval="0" floorchange="0">
<health now="100" max="100"/>
<look type="176" head="0" body="0" legs="0" feet="0" addons="0"/>
</npc>
Abrindo o arquivo gymlib.lua, localizado em DATA/LIB/ você encontra essa tabela:
ginasios = {
["Misty"] = { storage = 992,
msgdefeat = "You lost! You aren't strong enough yet, don't come back until you get stronger!",
msgafk = "Go away if you don't have any pokemons!",
msgwin = "Congratulations, you were strong enough to win this battle fairly! Take this Water Badge as reward.",
[1] = { msggo = "Lets fight then! I choose you, Starmie!",
msgba = "That's enough, Starmie!",
pokem = "Misty Starmie",
nextp = "Misty Poliwrath"},
[2] = { msggo = "It's your turn, Poliwrath!",
msgba = "Come back, Poliwrath!",
pokem = "Misty Poliwrath",
nextp = "Misty Gyarados"},
[3] = { msggo = "Crush'em, Gyarados!",
msgba = "You did well, Gyarados!",
pokem = "Misty Gyarados",
nextp = "Misty Blastoise"},
[4] = { msggo = "Crush'em, Blastoise!",
msgba = "You did well, Blastoise!",
pokem = "Misty Blastoise",
nextp = "finish"}
}
}
Ali São Aonde Tem os Pokes o Finish Representa Acabou ou Terminou Que dizer Que não Haverá Mas Pokemons Depois de Blastoise.
Para Acrescentar Mas Pokemons Tire o Finish e Coloque o Nome do Pokemon Que você quiser e Coloque Mas isto:
[5] = { msggo = "Crush'em, Pokemon Que Você Quiser.!",
msgba = "You did well, Pokemon Que Você Quiser!",
pokem = "Misty Pokemon Que Você Quiser",
nextp = "finish"}
Ali em Preto é o Pokemon Que Você Quiser.
Mas Sempre que Você Não Quiser Mas Pokemons Depois Do Ultimo Coloque Finish no Final Depois de Nextp -.
Para o NPC Funcionar Você Terá que Criar os Pokes Com o Nome Misty Antes.
Por Exemplo: Misty Blastoise.
Ai Você Cria Todos os Pokemon Com o Nome (Misty Antes) e Adciona As Tags dos Pokemon no Monster.xml (XML)
Para Ver se o NPC Funcionou Você Fala no Seu Serve /n Misty.
Bom é isso Ai.
Valeu Galera espero Ter Ajudado Todos do XTibia.
Créditos: Bom 99% Fui eu Que fiz Mas Não Sei Exatamente Quem Fez o 1%. Mas Não Foi Aqui do Forum Mas Quando Achar eu Botarei Aqui.