Postado Abril 7, 2018 7 anos Base: OTX 1.3 Boa noite, o NPC que eu procuro é um guarda que funciona da seguinte maneira: >> Ataca qualquer tipo de pk (branco, vermelho e preto), - Tipos de ataque : meele e distance "shot e effect", - Com possibilidade de configuração similar ao xml de um monstro, >> Ao falar "Hi" pra ele, ele responde uma mensagem simples. Ex. "Salve o rei", >> Colocar falas automáticas. Ex. "Como vai o seu dia?", "Como está quente hoje.", "Ouvi rumores que alguém importante foi enterrado perto do deserto.", >> Com possibilidade de repetir o NPC. Ex. "Carlin Guard", "Thais Guard", "Venore Guard", Editado Abril 7, 2018 7 anos por martimtiburcio (veja o histórico de edições)
Postado Abril 9, 2018 7 anos vamo lá. npc.xml <?xml version="1.0" encoding="UTF-8"?> <npc name="Guard" script="guard.lua" walkinterval="0" floorchange="0"> <health now="100" max="100" /> <look type="139" head="20" body="39" legs="45" feet="7" addons="0" /> </npc> guard.lua local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end local config = { attackRadius = {x = 7, y = 5, targetDistance = 2, walkDistance = 7}, attackPK = {value = true, skulls = {SKULL_WHITE, SKULL_RED}}, attackMonster = {value = true, ignore = {"Rat", "Cave Rat"}, ignoreSummon = true}, damageValue = {min = 10, max = 20} } -- Do not touch local targetId = 0 local masterPosition function Creature.isAttackable(self) if not self:isNpc() then if self:isPlayer() and not self:getGroup():getAccess() then if config.attackPK.value and isInArray(config.attackPK.skulls, self:getSkull()) then return true end end if self:isMonster() and config.attackMonster.value then local master = self:getMaster() if (config.attackMonster.ignoreSummon and master and not master:isPlayer()) or not isInArray(config.attackMonster.ignore, self:getName()) then return true end end end return false end function Npc.searchTarget(self) local attackRadius = config.attackRadius for _, spectator in ipairs(Game.getSpectators(self:getPosition(), false, false, attackRadius.x, attackRadius.x, attackRadius.y, attackRadius.y)) do if spectator:isAttackable() then targetId = spectator:getId() end end end function onThink() local npc = Npc() local target = Creature(targetId) -- If we have not a target, then we shall search for one if not target then npc:searchTarget() return end -- Let's get target offset position local npcPosition = npc:getPosition() local targetPosition = target:getPosition() local offsetX = npcPosition.x - targetPosition.x local offsetY = npcPosition.y - targetPosition.y -- Target is out of reach, search for new one local radius = config.attackRadius if math.abs(offsetX) > radius.x or math.abs(offsetY) > radius.y then npc:searchTarget() return end -- Back to spawn position if npcPosition:getDistance(masterPosition) >= radius.walkDistance then npcPosition:sendMagicEffect(CONST_ME_TELEPORT) npc:teleportTo(masterPosition) return end -- If target is found local npcId = npc:getId() doTargetCombatHealth(npcId, targetId, COMBAT_FIREDAMAGE, -config.damageValue.min, -config.damageValue.max, CONST_ME_HITBYFIRE) npcPosition:sendDistanceEffect(targetPosition, CONST_ANI_FIRE) doNpcSetCreatureFocus(targetId) -- Follow Target local distance = radius.targetDistance local path = npc:getPathTo(targetPosition, 0, distance, true, true) if path and npcPosition:getDistance(targetPosition) > distance then doMoveCreature(npcId, path[1]) end npcHandler:onThink() end function onCreatureAppear(self) if self == Npc() and not masterPosition then masterPosition = self:getPosition() end npcHandler:onCreatureAppear(self) end
Postado Abril 11, 2018 7 anos Em 09/04/2018 em 04:22, Jobs disse: vamo lá. npc.xml <?xml version="1.0" encoding="UTF-8"?> <npc name="Guard" script="guard.lua" walkinterval="0" floorchange="0"> <health now="100" max="100" /> <look type="139" head="20" body="39" legs="45" feet="7" addons="0" /> </npc> guard.lua local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end local config = { attackRadius = {x = 7, y = 5, targetDistance = 2, walkDistance = 7}, attackPK = {value = true, skulls = {SKULL_WHITE, SKULL_RED}}, attackMonster = {value = true, ignore = {"Rat", "Cave Rat"}, ignoreSummon = true}, damageValue = {min = 10, max = 20} } -- Do not touch local targetId = 0 local masterPosition function Creature.isAttackable(self) if not self:isNpc() then if self:isPlayer() and not self:getGroup():getAccess() then if config.attackPK.value and isInArray(config.attackPK.skulls, self:getSkull()) then return true end end if self:isMonster() and config.attackMonster.value then local master = self:getMaster() if (config.attackMonster.ignoreSummon and master and not master:isPlayer()) or not isInArray(config.attackMonster.ignore, self:getName()) then return true end end end return false end function Npc.searchTarget(self) local attackRadius = config.attackRadius for _, spectator in ipairs(Game.getSpectators(self:getPosition(), false, false, attackRadius.x, attackRadius.x, attackRadius.y, attackRadius.y)) do if spectator:isAttackable() then targetId = spectator:getId() end end end function onThink() local npc = Npc() local target = Creature(targetId) -- If we have not a target, then we shall search for one if not target then npc:searchTarget() return end -- Let's get target offset position local npcPosition = npc:getPosition() local targetPosition = target:getPosition() local offsetX = npcPosition.x - targetPosition.x local offsetY = npcPosition.y - targetPosition.y -- Target is out of reach, search for new one local radius = config.attackRadius if math.abs(offsetX) > radius.x or math.abs(offsetY) > radius.y then npc:searchTarget() return end -- Back to spawn position if npcPosition:getDistance(masterPosition) >= radius.walkDistance then npcPosition:sendMagicEffect(CONST_ME_TELEPORT) npc:teleportTo(masterPosition) return end -- If target is found local npcId = npc:getId() doTargetCombatHealth(npcId, targetId, COMBAT_FIREDAMAGE, -config.damageValue.min, -config.damageValue.max, CONST_ME_HITBYFIRE) npcPosition:sendDistanceEffect(targetPosition, CONST_ANI_FIRE) doNpcSetCreatureFocus(targetId) -- Follow Target local distance = radius.targetDistance local path = npc:getPathTo(targetPosition, 0, distance, true, true) if path and npcPosition:getDistance(targetPosition) > distance then doMoveCreature(npcId, path[1]) end npcHandler:onThink() end function onCreatureAppear(self) if self == Npc() and not masterPosition then masterPosition = self:getPosition() end npcHandler:onCreatureAppear(self) end Primeiramente muito obrigado pela sua atenção meu amigo!!! E desculpa pela demora OBS: estou respondendo pela conta do meu irmão, pois não estou em casa. NPC funcionou perfeitamente!! Eu adorei o lance dos monstros e dele voltar pra posição inicial, apos ultrapassar o limite de SQM configurável. Só observei alguns detalhes que são: NPC esta atacando mesmo quando eu desço ou subo uma cave, escada etc... Se eu ainda estiver no range ele continua atacando independente da posição Z. __________________________________________________________________________________________________________________________________________________________________________ Apos perde o target ele fica parado ao invés de voltar a andar novamente, mesmo depois de colocar no XML dele >>>> speed="500" walkinterval="2000" <<<<<< __________________________________________________________________________________________________________________________________________________________________________ o mesmo vale ao matar monstro ele fica parado sem se mexer ate o próximo alvo aparecer. __________________________________________________________________________________________________________________________________________________________________________ Quando o player esta Red skull ou black o npc ataca o player mesmo dentro da protection zone ou da house. __________________________________________________________________________________________________________________________________________________________________________ Os ataques do npc não estão respeitando o "blockwalls" (serve para bloquear ataques quando o alvo esta atras de parede, pilares, portas fechadas, janelas fechadas etc..) __________________________________________________________________________________________________________________________________________________________________________ Tambem gostaria de saber se e possível colocar ele pra quando alguém dizer "hi" ele responder pelo menos o que esta no XML dele. atualmente eu testei e não deu em nada. __________________________________________________________________________________________________________________________________________________________________________ E por ultimo mesmo deixando a opção "true" ativada ele continua atacando o summon. OBS: eu fiz o summon a partir do comando do GM /summon nome do monstros. agradeço mais uma vez pela atenção. :D Editado Abril 11, 2018 7 anos por emmanuel111111111111 (veja o histórico de edições)
Postado Abril 19, 2018 7 anos Autor Em 11/04/2018 em 18:42, emmanuel111111111111 disse: Primeiramente muito obrigado pela sua atenção meu amigo!!! E desculpa pela demora OBS: estou respondendo pela conta do meu irmão, pois não estou em casa. NPC funcionou perfeitamente!! Eu adorei o lance dos monstros e dele voltar pra posição inicial, apos ultrapassar o limite de SQM configurável. Só observei alguns detalhes que são: NPC esta atacando mesmo quando eu desço ou subo uma cave, escada etc... Se eu ainda estiver no range ele continua atacando independente da posição Z. __________________________________________________________________________________________________________________________________________________________________________ Apos perde o target ele fica parado ao invés de voltar a andar novamente, mesmo depois de colocar no XML dele >>>> speed="500" walkinterval="2000" <<<<<< __________________________________________________________________________________________________________________________________________________________________________ o mesmo vale ao matar monstro ele fica parado sem se mexer ate o próximo alvo aparecer. __________________________________________________________________________________________________________________________________________________________________________ Quando o player esta Red skull ou black o npc ataca o player mesmo dentro da protection zone ou da house. __________________________________________________________________________________________________________________________________________________________________________ Os ataques do npc não estão respeitando o "blockwalls" (serve para bloquear ataques quando o alvo esta atras de parede, pilares, portas fechadas, janelas fechadas etc..) __________________________________________________________________________________________________________________________________________________________________________ Tambem gostaria de saber se e possível colocar ele pra quando alguém dizer "hi" ele responder pelo menos o que esta no XML dele. atualmente eu testei e não deu em nada. __________________________________________________________________________________________________________________________________________________________________________ E por ultimo mesmo deixando a opção "true" ativada ele continua atacando o summon. OBS: eu fiz o summon a partir do comando do GM /summon nome do monstros. agradeço mais uma vez pela atenção. :D @xWhiteWolf heeeelp.
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.