Ir para conteúdo
  • 0

Npc que quando ver o player ataca automaticamente


AwakeGamer

Pergunta

Queria um npc que anda - se com o pokemon para fora e quando ele avista - se qualquer player ele atacaria esse player .

e se o player mata todos pokemon do npc pode matar o npc ele da loot . e depois de 2 min ele reaparece

Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

NPC.xml - Lembrando que o HP do npc você edita no arquivo do XML.

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

<npc name="NPC" script="npc.lua" walkinterval="0" floorchange="0" access="5" level="1" maglevel="6">

<health now="1500" max="1500"/>

<look type="1015" head="114" body="119" legs="114" feet="114" corpse="3058"/>

 

<parameters>

 

</parameters>

</npc>

 

 

 

NPC.lua

 

 

 

local target = 0

local prevTarget = 0

local origPos = 0

local max_distance = 15

local fighting = false

local challenger = 0

local battle_turn = 1 -- don't change

local challenger_turn = 0 -- don't change

---

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function doSummonGymPokemon(npc)

local this = npc

if not isCreature(this) or not ehNPC(this) then return true end --alterado v2.6

if #getCreatureSummons(this) >= 1 or target == 0 then return true end

local it = wildHunter[getPlayerStorageValue(this, 665471)][battle_turn]

if not it then return true end

doSummonMonster(this, it.name)

local summon = getCreatureSummons(this)[1]

if not summon then --alterado v2.6

print("Error in npc: "..getCreatureName(this)..", tring to execute function 'doSummonGymPokemon', poke: "..it.name)

battle_turn = battle_turn+1

return true

end

local balleffect = pokeballs["normal"].effect

if it.ball and pokeballs[it.ball] then

balleffect = pokeballs[it.ball].effect

end

doSendMagicEffect(getThingPos(summon), balleffect)

setPlayerStorageValue(summon, 10000, balleffect)

setPlayerStorageValue(summon, 10001, gobackmsgs[math.random(#gobackmsgs)].back:gsub("doka", it.nick ~= "" and it.nick or it.name))

setPlayerStorageValue(summon, 1007, it.nick ~= "" and it.nick or it.name)

doSetMonsterGym(summon, target)

local name = it.nick ~= "" and it.nick or getCreatureName(this).."s "..it.name --alterado v1.3

setWildPokemonLevel(summon, it.optionalLevel, getPokemonStatus(it.name, it.optionalLevel), name, 1.5)

doCreatureSay(this, gobackmsgs[math.random(#gobackmsgs)].go:gsub("doka", getPlayerStorageValue(summon, 1007)), 1)

fighting = true

battle_turn = battle_turn + 1

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function goToOrigPos()

target = 0

selfFollow(0)

fighting = false

challenger = 0

challenger_turn = 0

if #getCreatureSummons(getNpcCid()) >= 1 then

setPlayerStorageValue(getCreatureSummons(getNpcCid())[1], 1006, 0)

doCreatureAddHealth(getCreatureSummons(getNpcCid())[1], -getCreatureMaxHealth(getCreatureSummons(getNpcCid())[1]))

end

doChangeSpeed(getNpcCid(), -getCreatureSpeed(getNpcCid()))

doTeleportThing(getNpcCid(), origPos)

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function updateTarget()

if(target == 0) then

local list = getSpectators(getNpcPos(), 9, 9, false)

for i = 1, table.getn(list) do

local _target = list

if(_target ~= 0) then

if isPlayer(_target) and not getTileInfo(getThingPos(_target)).protection then --alterado v2.8

selfSay(hunterTalks[math.random(#hunterTalks)])

doNpcSetCreatureFocus(_target)

target = _target

prevTarget = target

break

end

end

end

end

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

function onCreatureAppear(cid)

end

 

function onCreatureDisappear(cid)

end

 

function onCreatureMove(creature, oldPos, newPos)

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

function onThink()

if not isCreature(getNpcCid()) then return false end --alterado v2.6

if origPos == 0 then

origPos = getNpcPos()

end

if getPlayerStorageValue(getNpcCid(), 665471) <= 0 then

setPlayerStorageValue(getNpcCid(), 665471, math.random(1, 5))

randOutfit(getNpcCid())

end

updateTarget()

------------------------------------------------------

if getDistanceBetween(getNpcPos(), origPos) >= max_distance or (isCreature(target) and getTileInfo(getThingPos(target)).protection) then --alterado v2.8

goToOrigPos()

end

------------------------------------------------------

if(target == 0) then

if getPlayerStorageValue(getNpcCid(), 154788) <= 0 then

setPlayerStorageValue(getNpcCid(), 154788, 1)

doChangeSpeed(getNpcCid(), -getCreatureSpeed(getNpcCid()))

addEvent(randWalk, 2000, getNpcCid(), 1000, getPlayerStorageValue(getNpcCid(), 154788))

end

return true

end

------------------------------------------------------

local playerPos = getThingPosWithDebug(target) --alterado v12.6

local myPos = getNpcPos()

------------------------------------------------------

if(myPos.z ~= playerPos.z) then

goToOrigPos()

battle_turn = battle_turn == 1 and battle_turn or battle_turn-1

return

end

------------------------------------------------------

if getDistanceBetween(playerPos, myPos) > max_distance then

goToOrigPos()

battle_turn = battle_turn == 1 and battle_turn or battle_turn-1

return

end

------------------------------------------------------

if getDistanceBetween(playerPos, myPos) >= 5 then

if getPlayerStorageValue(getNpcCid(), 154788) >= 1 then

setPlayerStorageValue(getNpcCid(), 154788, -1)

doRegainSpeed(getNpcCid())

if isCreature(target) then

selfFollow(target)

end

end

end

------------------------------------------------------

if getDistanceBetween(playerPos, myPos) <= 3 then

if getPlayerStorageValue(getNpcCid(), 154788) <= 0 then

setPlayerStorageValue(getNpcCid(), 154788, 1)

doChangeSpeed(getNpcCid(), -getCreatureSpeed(getNpcCid()))

addEvent(randWalk, 2000, getNpcCid(), 1000, getPlayerStorageValue(getNpcCid(), 154788))

end

end

------------------------------------------------------

if getDistanceBetween(playerPos, myPos) <= 5 then

challenger = target

addEvent(doSummonGymPokemon, 850, getNpcCid())

---

local change = false

 

if not isCreature(target) then

target = 0

battle_turn = battle_turn == 1 and battle_turn or battle_turn-1

return true

end

 

if fighting then

 

if not isCreature(getCreatureTarget(getNpcCid())) then

if #getCreatureSummons(challenger) >= 1 then

selfAttackCreature(getCreatureSummons(challenger)[1])

change = true

else

if change then

change = false

challenger_turn = challenger_turn + 1

end

end

end

 

if #getCreatureSummons(getNpcCid()) == 0 and isCreature(target) then

if battle_turn > #wildHunter[getPlayerStorageValue(getNpcCid(), 665471)] then

addEvent(doCreateNpc, 300000, ".aHunter", myPos)

local outfit = getCreatureOutfit(getNpcCid())

doRemoveCreature(getNpcCid())

----------------------------------------

if outfit.lookType == 1016 then --verifica se o npc eh female.. ;p

monster = doCreateMonster("aHunterFemale", myPos)

else

monster = doCreateMonster("aHunter", myPos)

end

----------------------------------------

doCloneOut(monster, outfit)

addEvent(beDrunk, 100, monster)

end

addEvent(doSummonGymPokemon, 1000, getNpcCid())

end

 

if #getCreatureSummons(challenger) <= 0 then

selfAttackCreature(challenger)

end

end

end

end

 

 

Link para o comentário
Compartilhar em outros sites

  • 0

Karl aonde eu configuro os pokemons que io npc vai ter ? ( Que vai usar )

Ele fica com o pokemon para fora da ball ?

Ele ve o player e ja ataca ?

 

Testeio npc

 

Primeiro erro na distro

 

 

[29/04/2013 23:12:37] [Error - Npc interface]

[29/04/2013 23:12:37] In a timer event called from:

[29/04/2013 23:12:37] data/npc/scripts/melhorcorrer.lua:onThink

[29/04/2013 23:12:37] Description:

[29/04/2013 23:12:37] data/npc/scripts/melhorcorrer.lua:24: attempt to index field 'normal' (a nil value)

[29/04/2013 23:12:37] stack traceback:

[29/04/2013 23:12:37] data/npc/scripts/melhorcorrer.lua:24: in function <data/npc/scripts/melhorcorrer.lua:11>

 

 

Segundo : O npc nao me ataca so fica andando com o pokemon pra fora !

 

Terceiro : Quando mato pokemon dele ele fala - 1 e envoc mais um clefable e nunca acaba e infinito !

Link para o comentário
Compartilhar em outros sites

  • 0

teste esse ...NPC.xml

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

<npc name="NPC" script="NPC.lua" walkinterval="0" floorchange="0" access="5" level="100" maglevel="1">

<health now="15" max="15"/>

<look type="1015" head="114" body="119" legs="114" feet="114" corpse="3058"/>

 

<parameters>

 

</parameters>

</npc>

 

 

 

NPC.lua

 

 

 

local target = 0

local prevTarget = 0

local origPos = 0

local max_distance = 15

local fighting = false

local challenger = 0

local battle_turn = 1 -- don't change

local challenger_turn = 0 -- don't change

---

local pbs = {11826, 11829, 11835, 11832, 11737, 11740, 11743, 11746}

local ball = {

[11826] = "normal",

[11829] = "ultra",

[11835] = "super",

[11832] = "great",

[11737] = "normal",

[11740] = "great",

[11743] = "super",

[11746] = "ultra",

}

 

local pokemons = { }

 

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function doClone(cid, npc)

local o = getCreatureOutfit(cid)

 

local npcname = getCreatureName(cid)

local health, maxHealth = getCreatureHealth(cid), getCreatureMaxHealth(cid)

local npcoutfit = {lookType = o.lookType, lookHead = o.lookHead, lookBody = o.lookBody, lookLegs = o.lookLegs, lookFeet = o.lookFeet}

 

doSetCreatureOutfit(npc, npcoutfit, -1)

doCreatureSetNick(npc, npcname)

setCreatureMaxHealth(npc, maxHealth)

doCreatureAddHealth(npc, health)

------------

if isNpc(npc) then

local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)

local a = 1

 

----------

bUID = getPlayerSlotItem(cid, 8)

 

if bUID.itemid ~= 0 then

local nome = getItemAttribute(bUID.uid, "poke")

local sexy = getItemAttribute(bUID.uid, "gender")

local boost = getItemAttribute(bUID.uid, "boost") or 0

local nick = getItemAttribute(bUID.uid, "nick") or ""

local balls = ball[bUID.itemid]

local levell = getItemAttribute(bUID.uid, "level")

local extraLvl = 50

local aura = getItemAttribute(bUID.uid, "aura")

pokemons[a] = {name = nome, level = levell, extralevel = extraLvl, sex = sexy, nick = nick, ball = balls, boost = boost, aura = aura}

a = a+1

end

----------

for i = 1, 8 do

local items = getItemsInContainerById(bp.uid, pbs)

if #items >= 1 then

for _, uid in pairs(items) do

local nome2 = getItemAttribute(uid, "poke")

local sexy2 = getItemAttribute(uid, "gender")

local boost2 = getItemAttribute(uid, "boost") or 0

local nick2 = getItemAttribute(uid, "nick") or ""

local balls2 = ball[pbs]

local levell = getItemAttribute(bUID.uid, "level")

local extraLvl = 50 --lvl extra

local aura2 = getItemAttribute(uid, "aura")

pokemons[a] = {name = nome2, level = levell, extralevel = extraLvl, sex = sexy2, nick = nick2, ball = balls2, boost = boost2, aura = aura2}

a = a+1

end

end

end

end

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function doSummonGymPokemon(npc)

local this = npc

if not isCreature(this) or not ehNPC(this) then return true end --alterado v2.6

if #getCreatureSummons(this) >= 1 or target == 0 then return true end

local it = pokemons[battle_turn]

if not it then return true end

doSummonMonster(this, it.name)

local summon = getCreatureSummons(this)[1]

local balleffect = pokeballs["normal"].effect

if it.ball and pokeballs[it.ball] then

balleffect = pokeballs[it.ball].effect

end

doSendMagicEffect(getThingPos(summon), balleffect)

setPlayerStorageValue(summon, 10000, balleffect)

setPlayerStorageValue(summon, 10001, gobackmsgs[math.random(#gobackmsgs)].back:gsub("doka", it.nick ~= "" and it.nick or it.name))

setPlayerStorageValue(summon, 1007, it.nick ~= "" and it.nick or it.name)

doSetMonsterGym(summon, target)

local name = it.nick ~= "" and it.nick or getCreatureName(this).."s "..it.name --alterado v1.3

setWildPokemonLevel(summon, it.level, getPokemonStatus(it.name, it.level+it.extralevel), name, 2)

---

doCreatureSetNick(summon, it.nick ~= "" and it.nick or it.name)

if it.boost == 50 then

sendAuraEffect(summon, auraSyst[it.aura])

end

doCreatureSetSkullType(summon, it.gender)

---

doCreatureSay(this, gobackmsgs[math.random(#gobackmsgs)].go:gsub("doka", getPlayerStorageValue(summon, 1007)), 1)

fighting = true

battle_turn = battle_turn + 1

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function goToOrigPos()

target = 0

selfFollow(0)

fighting = false

challenger = 0

challenger_turn = 0

battle_turn = 1

if #getCreatureSummons(getNpcCid()) >= 1 then

setPlayerStorageValue(getCreatureSummons(getNpcCid())[1], 1006, 0)

doCreatureAddHealth(getCreatureSummons(getNpcCid())[1], -getCreatureMaxHealth(getCreatureSummons(getNpcCid())[1]))

end

doChangeSpeed(getNpcCid(), -getCreatureSpeed(getNpcCid()))

doTeleportThing(getNpcCid(), origPos)

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

local function updateTarget()

if(target == 0) then

local list = getSpectators(getNpcPos(), 9, 9, false)

for i = 1, table.getn(list) do

local _target = list

if(_target ~= 0) then

if isPlayer(_target) and not getTileInfo(getThingPos(_target)).protection then --alterado v2.8

selfSay("You will be killed by yourself.. o.O")

doClone(_target, getNpcCid())

doNpcSetCreatureFocus(_target)

target = _target

prevTarget = target

break

end

end

end

end

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

function onCreatureAppear(cid)

end

function onCreatureDisappear(cid)

end

function onCreatureMove(creature, oldPos, newPos)

end

--/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--

function onThink()

if not isCreature(getNpcCid()) then return false end --alterado v1.6

if origPos == 0 then

origPos = getNpcPos()

end

updateTarget()

---------------------------------------------------

if getDistanceBetween(getNpcPos(), origPos) > max_distance or (isCreature(target) and getTileInfo(getThingPos(target)).protection) then --alterado v2.8

goToOrigPos()

end

------------------------------------------------------

if(target == 0) then

if getPlayerStorageValue(getNpcCid(), 154788) <= 0 then

setPlayerStorageValue(getNpcCid(), 154788, 1)

doChangeSpeed(getNpcCid(), -getCreatureSpeed(getNpcCid()))

addEvent(randWalk, 2000, getNpcCid(), 1000, getPlayerStorageValue(getNpcCid(), 154788))

end

return true

end

-----------------------------------------------------

local playerPos = getThingPosWithDebug(target) --alterado v1.6

local myPos = getNpcPos()

-----------------------------------------------------

if(myPos.z ~= playerPos.z) then

goToOrigPos()

return

end

-----------------------------------------------------

if getDistanceBetween(playerPos, myPos) > max_distance then

goToOrigPos()

return

end

-----------------------------------------------------

if getDistanceBetween(playerPos, myPos) >= 5 then

if getPlayerStorageValue(getNpcCid(), 154788) >= 1 then

setPlayerStorageValue(getNpcCid(), 154788, -1)

doRegainSpeed(getNpcCid())

if isCreature(target) then

selfFollow(target)

end

end

end

------------------------------------------------------

if getDistanceBetween(playerPos, myPos) <= 3 then

if getPlayerStorageValue(getNpcCid(), 154788) <= 0 then

setPlayerStorageValue(getNpcCid(), 154788, 1)

doChangeSpeed(getNpcCid(), -getCreatureSpeed(getNpcCid()))

addEvent(randWalk, 2000, getNpcCid(), 1000, getPlayerStorageValue(getNpcCid(), 154788))

end

end

------------------------------------------------------

if getDistanceBetween(playerPos, myPos) <= 5 then

challenger = target

addEvent(doSummonGymPokemon, 850, getNpcCid())

---

local change = false

 

if not isCreature(target) then

target = 0

return true

end

 

if fighting then

 

if not isCreature(getCreatureTarget(getNpcCid())) then

if #getCreatureSummons(challenger) >= 1 then

selfAttackCreature(getCreatureSummons(challenger)[1])

change = true

else

if change then

change = false

challenger_turn = challenger_turn + 1

end

end

end

 

if #getCreatureSummons(getNpcCid()) == 0 and isCreature(target) then

if battle_turn > #pokemons then

addEvent(doCreateNpc, 300000, ".aClone", myPos) --alterado v2.5

doRemoveCreature(getNpcCid())

local monster = doCreateMonster("aClone", myPos)

addEvent(beDrunk, 100, monster)

addEvent(doClone, 100, target, monster)

end

addEvent(doSummonGymPokemon, 1000, getNpcCid())

end

 

if #getCreatureSummons(challenger) <= 0 then

selfAttackCreature(challenger)

end

end

end

end

 

 

Link para o comentário
Compartilhar em outros sites

  • 0

Da essro quando mata o pokemon dele

 

 

[30/04/2013 13:50:22] [Error - Npc interface]

[30/04/2013 13:50:22] In a timer event called from:

[30/04/2013 13:50:22] data/npc/scripts/melhorcorrer.lua:onThink

[30/04/2013 13:50:22] Description:

[30/04/2013 13:50:22] data/npc/scripts/melhorcorrer.lua:85: attempt to index field 'normal' (a nil value)

[30/04/2013 13:50:22] stack traceback:

[30/04/2013 13:50:22] data/npc/scripts/melhorcorrer.lua:85: in function <data/npc/scripts/melhorcorrer.lua:77>

 

ele envoca o pokemon so que quando ele me ve so solta o pokemon e nao ataca so solta !

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...