Ir para conteúdo
Entre para seguir isso  
Mock

NPC Guarda [GS 1]

Recommended Posts

Mock    32
Mock

  • Nome: NPC guarda
  • Autor: Grupo de scripting, Kaotar, Mock, Dragonlorde
  • Versao: 1.0 rev 2746
  • Desenvolvido para: TFS 0.3.6 Possivelmente nao funciona em distros inferiores.

 

Oia eu dinovo!mais dessa vez o script nao foi apens meu, foi feito pelo grupo de scripting da otnet! (
), No caso eu fiz o autowalk do npc e o kaotar fez a maior parte, entao a maior parte dos creditoes é para ele! outros membros do grupo foram explulsos por nao mostrar o minimo interesse, e dragonlordzes apenas ajudou a testar, mais ajudou :yes:.

 

 

Como nosso script ficou bem grande entao ~so nescessarios 2 scripts, uma lib e o script em si, já que é um npc entao da para saber o por que do tamanho. Bom o npc quando criado você configura se ele vai ser guarda ou guarda-costas, no caso se guarda ele fica parado na cidade, quando ve algo ameaçador (um monstro ou um pk) ele vai atraz seguindo para matar, quando mata ele volta andando sosinho para onde ele estava (se for muito lonjue ele se teleporta), e no caso se guarda coisas pode vir oque for ele vai ficar parado, entao chega alguem e fala
hi
,
help
e ele começara a seguir o player matando qualquer monstro que estiver avista, para dispensar o NPC basta falar,
bye
ou
leave
, o npc ainda pode curar quano você fica com pouco HP e ele possue um sistema de pagamento que você configura quanto ele cobra por tempor de caça, 100 gps por minuto, por segundo, por hora, etc
:D

 

 

 

O npc tem uma config no começo, pode exclui-la se quiser pois ja existe configurações pré definidas mais são ruims.

 

Vamos instalar-lo.

O npc esta anexado ao topico no fim mais vou postar ele aqui de qualquer forma.

Crie em data/npc/scripts o arquivo guard lib.lua

e coloque isso:

--[[
       ==========================
       |                        |
       |   Guard system 1.0     |
       |    Author: GS TEAM     |
       |   Create to OTNET      |
       |   Mock and kaotar     |
       ==========================

1.0 Features:
       - Attack monsters and Pk players
]]

GUARD = 1
SELFGUARD = 2



Guard = {
       movingBack = false,
       move = {
           moving = false
       },
       config = {
           speed = 1000,
           changeFloor = false,
           moveType = GUARD,
           moveBack = true,
           playerExp = true,
           delay_attack = 0.5,
           exaustHeal=20,
           GPS=10,
           TIME=60,
       },
       focus={},
       combat = {
           min = 100,
           max = 200,
       },
       ignoreList = {
       }
}

function Guard:new()
       local tab = {}
       tab.combat = {}
       setmetatable(tab.combat, self.combat)
       tab.combat.__index = self.combat
       tab.ignoreList = {}
       setmetatable(tab.ignoreList, self.ignoreList)
       tab.ignoreList.__index = self.ignoreList
       tab.move = {}
       setmetatable(tab.move, self.move)
       tab.move.__index = self.move
       setmetatable (tab, self)
       self.__index = self
       return tab
end

function Guard:check(first)
   if (first) then
       if (self.config.moveType == 2 and self.player and isPlayer(self.player) == TRUE) then
           return false
               end
       end
       if not (self.cid) then
               return false
       end
       if not (self.firstPos) then
               self.firstPos = getThingPos(self.cid)
       end
       if (self:samePos(getThingPos(self.cid), self.firstPos)) then
               self.move.movingBack = false
       end
       if (self.config) then
               for i, v in pairs(Guard.config) do
                       if (tostring(self.config[i]) ~= "nil") then
                               if not (type(v) == type(self.config[i])) then
                                       print("Guard System - Config error:\n Variable ".. i .." is a not correct type.\n It's is setable a defaul value: "..   tostring(Guard.config[i]))
                                       self.config[i] = v
                               end
                       else
                               self.config[i] = v
                       end
               end
       end
       return true
end

function Guard:doMove()
       if (not self.move.moving and self.move.movingBack or self.target and isCreature(self.target) == TRUE and not self.move.moving) then
               if (self.config.changeFloor or self.move.movingBack or getThingPos(self.target).z == getThingPos(self.cid).z) then
                       if (not self.move.movingBack and getThingPos(self.target).z ~= getThingPos(self.cid).z) then
                               doTeleportThing(self.cid, getThingPos(self.config.moveType == 2 and self.player or self.target), TRUE)
                       end
                       if (self.move.movingBack or self.player == self.target and getDistanceBetween(getThingPos(self.cid), getThingPos(self.target)) > 2 or self.target ~= self.player and getDistanceBetween(getThingPos(self.cid), getThingPos(self.target)) > 1) then
                               if (self.move.movingBack and self.config.moveBack and getDistanceBetween(getThingPos(self.cid), self.firstPos) >= 50) then
                                       doTeleportThing(self.cid, self.firstPos)
                                       self.player = nil
                                       self.target = nil
                                       self.move.movingBack = nil
                                       self.move.moving = nil
                                       return false
                               end
                               local q = self:findDir(getThingPos(self.cid), self.move.movingBack == false and getThingPos(self.target) or self.firstPos)
                               local x = 0
                               while (not q and x <= 1) do
                                       q = self:findDir(getThingPos(self.cid), self.move.movingBack == false and getThingPos(self.target) or self.firstPos)
                                       if not (self.player == self.target) then
                                               break
                                       end
                                       x = x+1
                               end
                               if (q) then
                                       self:doMoving(true, q)
                                       for i = 1, #q do
                                               addEvent(eventMove, i*self.config.speed, self,  q[i])
                                       end
                               else
                                       if (self.player and self.player ~= self.target and not self.move.movingBack) then
                                               self.ignoreList[#self.ignoreList+1] = {self.target, os.clock()}
                                               self.target = self.player
                                       elseif (self.player == self.target and not self.move.movingBack) then
                                               doCreatureSay(self.cid, "I'm sorry, but I'm lost", 3)
                                               self.player = nil
                                               self.move.moving = true
                                               addEvent(function (var) var.target, self.move.moving = nil, false end, 3000, self)
                                       elseif (self.move.movingBack) then
                                               doTeleportThing(self.cid, self.firstPos)
                                       end
                               end
                       end
               else
                       doCreatureSay(self.cid, "I'm sorry, but I'm lost", 3)
                       self.player = nil
                       self.target = nil
               end
       elseif (self.target == nil or isCreature(self.target) == FALSE) then
               if (self.config.moveType == 2 and isPlayer(self.player) == TRUE) then
                       self.target = self.player
               elseif (self.config.moveType == 2 and isPlayer(self.player) == FALSE) then
                       self.player = nil
                       self.target = nil
                       if (self.config.changeFloor and self.config.moveBack) then
                               doTeleportThing(self.cid, self.firstPos)
                       elseif (not self.config.changeFloor and self.config.moveBack) then
                               self.move.movingBack = true
                       end
               elseif (self.config.moveType == 1 and self.config.changeFloor and self.config.moveBack) then
                       doTeleportThing(self.cid, self.firstPos)
               elseif (self.config.moveType == 1 and not self.config.changeFloor and self.config.moveBack) then
                       if (not self:samePos(getThingPos(self.cid), self.firstPos) and not self.moving) then
                               self.move.movingBack = true
                               self.target = nil
                       end
               else
                       self.player = nil
                       self.target = nil
               end
       elseif (self.move.moving and self.moveType == 2) then
               if (self:samePos(getThingPos(self.cid), self.move.lastPos or {x=0, y=0})) then
                       if (self.move.lastPos[2] and os.clock()-self.move.lastPos[2] >= 5) then
                               self.move.moving = false
                       else
                               return true
                       end
               else
                       self.move.lastPos = {getThingPos(self.cid), os.clock()}
               end
       end
end


function Guard:doMoving(bool, tab)
       if (bool and tab) then
               self.move.moveTable = tab
               self.move.moving = true
       else
               if (self.move.moveTable and #self.move.moveTable > 0) then
                       table.remove(self.move.moveTable, 1)
                       if (#self.move.moveTable == 0) then
                               self.move.moving = false
                               self.move.moveTable = nil
                               if (self.move.movingBack) then
                                       self.move.movingBack = false
                               end
                       end
               else
                       self.move.moving = false
                       self.move.moveTable = nil
               end
       end
end


function eventMove(var, dir)
       var:doMoving()
       if (isWalkable(getPosByDir(getCreaturePosition(var.cid), dir), true) == true) then
               doMoveCreature(var.cid, dir)
       end
end

function Guard:isNext()
       local dir
       if (self:samePos(getThingPos(self.target), getThingPos(self.cid))) then
               return true
       end
       for dir = 0, 7 do
               local pos = self:getPosByDir(getThingPos(self.cid), dir)
               if (self:samePos(getThingPos(self.target), pos)) then
                       return true
               end
       end
       return false
end

function Guard:doCheckAttack()
       local isIgnore = function(tableIgnore, uid)
               if not (#tableIgnore == 0) then
                       for i, v in pairs(tableIgnore) do
                               if (v[1] == uid) then
                                       return true
                               end
                       end
               end
               return false
       end
       if (self.ignoreList) then
               for i, v in pairs(self.ignoreList) do
                       if (type(v) == "table" and v[2] and os.clock()-v[2] >= 15) then
                               table.remove(self.ignoreList, i)
                       end
               end
       end
       if (self.config.moveType == 2 and isPlayer(self.player) == FALSE) then
               return false
       end
       battlelist = getSpectators(getThingPos(self.config.moveType == 2 and self.player or self.cid), 7, 8, false)
       if (type(battlelist) == "table" and #battlelist > 0) then
               if (self.config.moveType == 2 and isInArray(battlelist, self.player) == FALSE or isInArray(battlelist, self.cid) == FALSE) then
                       self.target = self.player
                       return false
               end
               for i = 1, #battlelist do
                       if (battlelist[i] ~= self.cid and battlelist[i] ~= self.player and not isIgnore(self.ignoreList, battlelist[i])) then
                               if (isMonster(battlelist[i]) == TRUE or isNpc(battlelist[i]) == FALSE and getCreatureSkullType(battlelist[i]) > 1 and isPlayerPzLocked(battlelist[i]) == TRUE) then
                                       if (self.target ~= self.player and isInArray(battlelist, self.target) == TRUE) then
                                               self:doAttack()
                                               break
                                       else
                                               self.target = battlelist[i]
                                               self:doAttack()
                                               break
                                       end
                               end
                       elseif (isIgnore(self.ignoreList, battlelist[i])) then
                               self:doMoving()
                       end
               end
       end
end

function Guard:doAttack()
       if (self:isNext() == true) then
               if not (self.combat.min or self.combat.max) then
                       error("GUARD SYSTEM: Can not found min or max value for attack")
                       return false
               end
               if (self.combat.min > self.combat.max) then
                       error("GUARD SYSTEM: Combat min value is greater of max")
                       return false
               end
               if (self.config.playerExp) then
                       doTargetCombatHealth(self.config.moveType == SELFGUARD and self.player or self.cid, self.target, COMBAT_PHYSICALDAMAGE, -self.combat.min, -self.combat.max, CONST_ME_DRAWBLOOD)
               else
                       doTargetCombatHealth(self.cid, self.target, COMBAT_PHYSICALDAMAGE, -self.combat.min, -self.combat.max, CONST_ME_DRAWBLOOD)
               end
       end
end

function  Guard:cash()
   if self.player then
       if isPlayer(self.player)   then
                       self.last_ =  self.last_ or os.time()
                       if  self.last_ <= os.time() then
                               if  getPlayerMoney(self.player) >= self.config.GPS then
                                       doPlayerRemoveMoney(self.player,self.config.GPS)
                                       doPlayerSendTextMessage(self.player,12,'You paid  '..self.config.GPS..'  now left '..getPlayerMoney(self.player)..',  you can hunt arond   '..((getPlayerMoney(self.player)/self.config.GPS)*self.config.TIME)..'   seconds yet.')
               else
                   selfSay('You  dont  have enghout money, bye!',self.player)
                                       self.player =  nil
                   self.target =  nil
               end
                               self.last_ =  os.time()+self.config.TIME
                       end
       else
                       self.player = nil
           self.target = nil
       end
   end
end
function Guard:runAttack()
   self.config.time = self.config.time or os.clock()
   if self.config.time <= os.clock() then
               self:doCheckAttack()
               self.config.time = os.clock()+self.config.delay_attack
   end
end

-- Mock Lib(Auto Walk)
function Guard:isPos(p1, q)
       for i, p2 in pairs(q) do
               if (p1.x == p2.x and p1.y == p2.y) then
                       return true
               end
       end
end

function Guard:getDir(start, finish, walked)
       local menor = getDistanceBetween(start, finish)+10
       local dir = nil
       for i=0,7 do
               ae = self:getPosByDir(start, i)
               if (isWalkable(ae, TRUE) == TRUE and self:isPos(ae, walked) == nil) then
                       if (getDistanceBetween(ae, finish) < menor) then
                               menor = getDistanceBetween(ae, finish)
                               dir = i
                       end
               end
       end
       return dir
end

function Guard:findDir(start, finish)
       local q = 0
   local walked = {}
       local go = {}
       local distance = getDistanceBetween(start, finish)
       local moves = self.move.movingBack and getDistanceBetween(start, finish) + 1 or getDistanceBetween(start, finish)
       while (moves > 1) do
               table.insert(walked, 1, start)
               local dir = self:getDir(start, finish, walked)
               if (not dir or q >= 25+distance) then
                       return false
               end
               start = self:getPosByDir(start, dir)
               if (self:samePos(start, finish) == true and not self.move.movingBack) then
                       break
               end
               table.insert(go, dir)
               q = q+1
               moves = getDistanceBetween(start, finish)
       end
       return go
end

function Guard:getPosByDir(position, direction, size)
       local n = size or 1
       local pos = position
       if(direction == NORTH) then
               return {x=pos.x, y=pos.y-1, z=pos.z}
       elseif(direction == SOUTH) then
               return {x=pos.x, y=pos.y+1, z=pos.z}
       elseif(direction == WEST) then
               return {x=pos.x-1, y=pos.y, z=pos.z}
       elseif(direction == EAST) then
               return {x=pos.x+1, y=pos.y, z=pos.z}
       elseif(direction == NORTHWEST) then
               return {x=pos.x-1, y=pos.y-1, z=pos.z}
       elseif(direction == SOUTHWEST) then
               return {x=pos.x-1, y=pos.y+1, z=pos.z}
       elseif(direction == NORTHEAST) then
               return {x=pos.x+1, y=pos.y-1, z=pos.z}
       elseif(direction == SOUTHEAST) then
               return {x=pos.x+1, y=pos.y+1, z=pos.z}
       end
end

function Guard:samePos(p1,p2)
       if (p1.x == p2.x and p1.y == p2.y) then
               return true
       end
end

function isWalkable(pos, creature, proj, pz)-- by Nord
       if hasSqm(pos) == false then return false end
       if isCreature(getThingFromPos({x=pos.x,y=pos.y,z=pos.z,stackpos=255}).uid) and creature then return false end
       if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
       if getTileInfo(pos).protection and pz then return false, true end
       local n = not proj and 3 or 2
       for i = 0, 255 do
               pos.stackpos = i
               local tile = getTileThingByPos(pos)
               if tile.itemid == 459 then
                       return true
               end
               if tile.itemid ~= 0 and not isCreature(tile.uid) then
                       if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                               return false
                       end
               end
       end
       return true
end

function hasSqm(pos)-- by Mock
   return getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid ~= 0
end

 

Salve e crie o guard.lua e coloque isso dentro:

dofile('data/npc/scripts/guard lib.lua')
local guarda = Guard:new()
guarda.config = {
       moveType=SELFGUARD,
       speed = 400,
       changeFloor = false,
       playerExp = false,
       delay_attack=1,
       exaustHeal=20,
       --- Payment
       GPS=100, --- Pagar 100 GPS a X de tempo
       TIME=60, --- Pagar a quantia acima a cada X segundos, no caso 60
}
guarda.focus={}

guarda.combat = {
   min = 10,
   max = 20
}


function onCreatureAppear(cid)
 guarda.cid = getNpcId()
end

function onCreatureDisappear(cid)
end

function onCreatureSay(cid, tsype, msg)
       msg = msg:lower()
       if msg == 'hi' and isInArray(guarda.focus,cid) == false and getDistanceBetween(getThingPos(cid), getThingPos(getNpcCid())) <= 5 then
           table.insert(guarda.focus,1,cid)
           selfSay("Hello!",cid)
       end
       if isInArray(guarda.focus,cid) and getDistanceBetween(getThingPos(cid), getThingPos(getNpcCid())) <= 5  then
           if msg:find('help') then
               if (guarda:check(true)) then
                   if (guarda.config.moveType == SELFGUARD) then
                           selfSay('It will cost '..guarda.config.GPS..' each '..guarda.config.TIME..' seconds.',cid)
                           selfSay('I will help you '..getCreatureName(cid)..'!',cid)
                           guarda.cid = getNpcId()
                           guarda.player = cid
                           guarda.target = cid
                   else
                       selfSay('Sorry but i cant help.',cid)
                   end
               else
                   if guarda.player == cid then
                       selfSay('I am helping you.',cid)
                   else
                       selfSay('Sorry i am busy.',cid)
                   end
               end
           elseif msg:find('heal') then
               local percent = (getCreatureHealth(cid)/getCreatureMaxHealth(cid))*100
               if percent <= 15 then
                   if getPlayerStorageValue(cid,15001) >= os.time() then
                       if not isPlayerPzLocked(cid) then
                           doCreatureAddHealth(cid,(getCreatureMaxHealth(cid)*(percent-15))/100)
                           setPlayerStorageValue(cid,15001,os.time()+ guarda['config']['exaustHeal'] )
                           selfSay('Oh my god! you are verry bad! i can heal you now.',cid)
                       else
                           selfSay('I cant heal you now.',cid)
                       end
                   else
                       selfSay('I am retired, i cant heal you now.',cid)
                   end
               else
                   selfSay('You aren\'t too bad.',cid)
               end
           elseif msg:find('leave') then
               if not (guarda:check(true)) then
                   if (guarda.config.moveType == SELFGUARD) then
                       if guarda.player == cid then
                           guarda.player = nil
                           guarda.target = nil
                           selfSay('Okay, i will stay here.',cid)
                       end
                   end
               end
           elseif msg:find('job') then
               selfSay('I am guard.',cid)
           elseif msg == 'bye' then
               for i,b in pairs(guarda.focus) do
                   if b == cid then
                       table.remove(guarda.focus,i)
                   end
               end
               if guarda.player and guarda.player == cid then
                   guarda.player = nil
                   guarda.target = nil
               end
               selfSay('Okay, bye',cid)
           end
       end
end

function onPlayerCloseChannel(cid)
end

function onPlayerEndTrade(cid)
end




function onThink()
   guarda:cash()
   if (guarda:check()) then
       guarda:runAttack()
       guarda:doMove() -- A ordem dos fatores altera o resultado
   end
   for i,b in pairs(guarda.focus) do
       if not isPlayer( then
           table.remove(guarda.focus,i)
       elseif getDistanceBetween(getThingPos(, getThingPos(getNpcCid())) > 5 and guarda.player ~= b then
           table.remove(guarda.focus,i)
           selfSay('Then bye...',
       end
   end
end

Salve, agora crie um XML com o nome que você quiser dar para seu guarda e coloque isso dentro:

<?xml version="1.0" encoding="UTF-8"?>
<npc name="guard" script="guard.lua" walkinterval="0" floorchange="0">
   <health now="150" max="150"/>
   <look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
</npc>

Não se esqueça que speed, dano maximo minimo e outras coisas ~sao configuradas no script, o nome e outfit do npc são no xml acima

 

 

Obrigado, o script sim ainda terá bugs entao reportar pro favor!

Editado por Black Ice

Compartilhar este post


Link para o post
pejuge2    1
pejuge2

Caramba, até agora ninguém comentou uma coisa dessa ^^. Estou lendo ainda, mas parabens à equipe.

Compartilhar este post


Link para o post
Notorious    1
Notorious

Muito bom o script, ótimo uso de metodos, nao li tudo ainda claro, mas o que li ta otimo

Só tem duas linhas que acho que estão erradas:

setPlayerStorageValue(cid,os.time()+guarda.config.  exaustHeal)
if getPlayerStorageValue(cid) >= os.time() then

Compartilhar este post


Link para o post
Mock    32
Mock

sim, ja ajeitei

Compartilhar este post


Link para o post
carlinhogta    0
carlinhogta

como eu ponho ele de guarda ou guarda costas?

Compartilhar este post


Link para o post
Mock    32
Mock

@carlinho

muda:

moveType=SELFGUARD,

pra

moveType=GUARD,

Compartilhar este post


Link para o post
MatheusBB    0
MatheusBB

Parabéns mock ele é muito bom...eu tava pensando...da pra faze um sistema de PET desse modo :)

Compartilhar este post


Link para o post
pejuge2    1
pejuge2

Ficaria legal se colocasse um sistema de chingamento, como coloquei no meu MoG.

 

DIFAMES = {"fuck", "ass", "dick", "pussy", "suck", "retard", "bastard", "idiot", "craw"} 

if isInArray(DIFAMES, msg) then
  selfSay("What is yours? Idiot!", cid)
  ... -- > não terminado
end

 

Neste caso, utilizaria um sistema de não ajudar, quando falasse algma coisa, teria que verificar o tempo da StorageValue e comparar com o atual, pra verificar se é menor ou igual a ao de espera após o chingamento. Eu faria mas bateu uma preguiça :-O.

Compartilhar este post


Link para o post
dragonlorde    0
dragonlorde

È nois do GS :D

Eu ajudei poco :S

Mas nos testes adorei como fico o npc...

Compartilhar este post


Link para o post
GustavoMassa    1
GustavoMassa

Muito bom o script, parabens ;D

 

Bugs: Na linha 198 e na linha 407 está com espacos amais, é so corrigir na hora de copiar.

Eu uso TFS 0.3.4 e encontrei problemas na função getNpcId() - Nil value no guard.lua

Então substitui pela função getNpcCid(), queria saber se tem como usar outra função ou se tem como arrumar a getNpcId().

 

Obrigado.

Compartilhar este post


Link para o post
Mock    32
Mock

@gustavo

sim é por causa q o script e grande e essa formatação do forum zoa ele

Compartilhar este post


Link para o post
Watson    0
Watson

ow da pra arruma pro player pega o serviço de um so npc?

 

Que eu testei ake com 2 uma foi pra um lado o outro fiko lezadao se der ajuda ae ;D

 

Tava doido por um npc anti-pk parabens ae equip, se for possivel, é q eu quero espalha os npc pela city principal do meu ot ae os lek pode pega mais de npc ae da bagunça

 

desculpa pedido mas é util vlw.

Editado por Watson

Compartilhar este post


Link para o post
blitzkrieng123    0
blitzkrieng123

bomm .. qnd eu coloquei ele no meu ot deu uns errinhos ... o primeiro foi que assim .. ele tava como guarda costas, e nem sempre me seguia, eu tinha que voltar até ele pra ele começar a me seguir, tipo, eu andava, ele dava um passo, ai eu ja tava longe pakas, ai eu tinha q voltar até ele pra ele dar mais um passo, segundo é que ele nem sempre ataca os bixos, só as vezes, =S e uma dica, vc poderia botar pra ele mandar magias legais criadas por vc de preferencia, acho q seria legal , vlw

Compartilhar este post


Link para o post
Dean    1
Dean

Parabéns!Um dos melhores scripts aqui do fórum, não deu para testar ainda mas parece ser muito bom.

Compartilhar este post


Link para o post
Hilton    0
Hilton

e se eu quiser colocar ele para ser um Npc parado na cidade, pra ataca pk e bixo, oq eu tiro ou coloco?

 

NoMore~~

Compartilhar este post


Link para o post
Le588    0
Le588

Legal o script!

 

Não consigo testar porque não tenho mais o meu OT, mas fiquei em dúvida numa coisa:

 

Se o player "contrata" um NPC de guarda costas, ele pode convocar mais?

Seria legal configurar um número X de guarda costas que cada player pode ter, porque senão pode ter players com muitos guardas costas :S

Compartilhar este post


Link para o post
blitzkrieng123    0
blitzkrieng123

po , vc poderia colocar pra esse npc atacar com magia que ficaria legal .. vlw

Compartilhar este post


Link para o post
Conde2    0
Conde2

@Mock

Script muito bom mesmo um dos melhores npcs do forum se não o melhor

Porem dava pra melhorar e muito =)

 

A função isNext() poderia ser substituida por:

 


function isNext()
   local playerPos = getCreaturePosition(self.target)
   local myPos = getCreaturePosition(self.cid)

if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
       return true
   end
       return false
end

 

 

E a função doMove que você teve um trabalhão pra fazer pode ser substituida por:

 

function selfMoveToCreature(id)
   if(not id or id == 0) then
       return
   end

   local t = getCreaturePosition(id)
   if(not t.x or t.x == nil) then
       return
   end

   selfMoveTo(t.x, t.y, t.z)
   return
end

 

 

De qualquer forma não se pode desvalorizar esse code tão fod@ digamos assim =)

 

 

De resto está perfeito essas foram as coisas que ac

Compartilhar este post


Link para o post
Kaotar    5
Kaotar

A função next realmente pode ser substituída por isso ai mesmo, já a função doMove não por mais de um motivo que so irei citar 1, a função selfMoveTo só funciona dentro do script do npc, fora dele pode conflitar ou simplesmente não funcionar

Compartilhar este post


Link para o post
Super Heros    0
Super Heros

AFFFFFFFFFFF

 

 

perfeito!!!!!!

 

Valeu

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×