Npc Gym Misty

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

Npc Gym Misty

Mensagem por Matheus em Sab Jun 11, 2011 2:04 pm

Olá poketibianos, vou ensiná-los a colocar a líder Misty no seu ot, funcionando completamente.

Vá em data/lib, crie um arquivo chamado gymlib.lua e coloque isto dentro:
Spoiler:
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)

Agora vá em data/creaturescripts/scripts, crie um arquivo chamado gym.lua e coloque isto dentro:
Spoiler:
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

Depois vá em data/creaturescripts, abra o arquivo creaturescripts.xml e adcione estas 4 tags:
Spoiler:
<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"/>



Agora vá em data/npc/scripts e crie um arquivo chamado misty.lua e coloque isto dentro:
Spoiler:
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

Vá em data/npc e crie um arquivo chamado misty.xml e coloque isto dentro:
Spoiler:
<?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>


EXPLICANDO

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, quer dizer que não haverá mais pokemons depois de blastoise.

Pro npc funcionar você deverá criar os pokémons separadamente, com o nome Misty antes.

Exemplo:
Normal - Blastoise
Gináso - Misty Blastoise

Para ver se seu npc funcionou diga /n Misty no seu server.

80% dos créditos são ao GMRaphael e 20% são meus apenas pela criação do tópico.
CYA!
avatar
Matheus
Administrador
Administrador

Mensagens : 61
Placar : 207
Data de inscrição : 25/04/2011
Idade : 21
Localização : Campinas - SP

Ver perfil do usuário http://pokescript.forumeiros.com

Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo


 
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum