Ir para conteúdo

Featured Replies

Postado

estou com o seguinte problema no headbutt, dou move no pokémon ele vai até a arvore mas nada acontece, e aparece o seguinte erro no tfs:

Spoiler

image.thumb.png.a33d9a53af2075e2ec52c8485d062339.png

 

meu main functions:

Spoiler

--// Edicioes DarkXPoke \\-
farwayPos = {x = 2, y = 1, z = 15}

function doSendUpdatesOnlineToADM()
    local player = getPlayerByNameWildcard("[ADM] One")
    if player == nil then return true end
    doGetPlayersOnToADM(player)
end

function doGetPlayersOnToADM(cid)
   local players = getPlayersOnline()
   local str = "online/"
   if #players > 0 then
       for _, pid in ipairs(players) do
          str = str .. getCreatureName(pid) .. "," .. getPlayerLevel(pid) .. "/"
       end
   end
   doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_PLAYER_SHOW_ONLINE, str)
   return str
end

function getExpByMoreDano(cid)
if not isCreature(cid) then return "" end
local listPlayers = ""
local life = getCreatureMaxHealth(cid)
local str = getPlayerStorageValue(cid, storages.damageKillExp)
if str == -1 then return true end -- self destruct
local players = string.explode(str, "|")

    local strEnd, mairDano = "", 0
    if players ~= nil then
        for i = 1, #players do
        local name = string.explode(players, "/")[1]
        local dano = string.explode(players, "/")[2]
              listPlayers = listPlayers .. name .. "/" .. (dano * 100 / life) .. "|"
        end
    end
    return listPlayers
end

function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
if not isCreature(cid) then return false end
if isWatchingTv(cid) then return false end
local name = getCreatureName(cid)
local transform = false
--- nao retirar item que estao no slot 8 e sao uniques
if fromPos.x ~= 0 and toContainer.uid == 0 and fromContainer.uid == 0 and toPos.x == 65535 and getPlayerSlotItem(cid, 8).uid ~= 0 then
    doPlayerSendCancel(cid, MSG_NAO_E_POSSIVEL)
    return false
end

local itemID = item.itemid
if itemID >= 14795 and itemID <= 14879 or pokeballs[getPokeballType(itemID)] and (itemID ==  pokeballs[getPokeballType(itemID)].use and (#getCreatureSummons(cid) > 0 or isRiderOrFlyOrSurf(cid))) then
   doPlayerSendCancel(cid, "You cant move this.")
   return false
end

if isFly(cid) and (getTileThingByPos(toPos).itemid == 460 or getTileThingByPos(toPos).itemid == 12171 or getTileThingByPos(toPos).itemid == 12172 or (toContainer.uid == 0 and getThingPos(cid).z ~= toPos.z)) then
    doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTTHROW)
    return false
end

if isInArray({2589, 15446, 15447, 15448, 15449, 12355}, toContainer.itemid)then -- nao fazer nada no cp
   return true
end    

local pos =  toPos
local items = getItemsfromPos(pos)
for i = 1, #items do
    local name = getItemInfo(items.itemid).name
    if string.find(name, "fainted") or string.find(name, "defeated") then
       doSendMsg(cid, "Don't throw this.")
       return false
    end       
end

    if isPokeball(item.itemid) and toPos.x == 65535 then
        if not getItemAttribute(item.uid, "unique") and getPlayerFreeCap(cid) > 1 then
             doTransformPokeballIcon(cid, item, count, toContainer, fromContainer, fromPos, toPos)
        end
    else
          if not getItemAttribute(item.uid, "unique") and not getItemAttribute(item.uid, "torneio") then
             doTransformPokeballIcon(cid, item, count, toContainer, fromContainer, fromPos, toPos)
          end
    end


if isPokeball(item.itemid) or isContainer(item.uid) then
if hasSqm(toPos) then

  if isContainer(item.uid) then

   local itens = getItensUniquesInContainer(item.uid)
   local sendMsg = false
    if #itens >= 1 then
       doSendMsg(cid, #itens.." item"..(#itens < 2 and "" or "s").." in this container "..(#itens < 2 and "is exclusive" or "are exclusive")..". You can't throw it"..(#itens < 2 and "" or "s").." away!")
       return false
    end
   
  else

   if getItemAttribute(item.uid, "unique") or getItemAttribute(item.uid, "torneio") then
      doSendMsg(cid, "This is a unique item, you can not throw it away!")
      return false
   end  
  end
 
elseif isContainer(toContainer.uid) and (isPokeball(item.itemid) or isContainer(item.uid)) then

   if toContainer.itemid == getPlayerSlotItem(cid, 3).itemid then -- nao fazer nada na poke bag principal
      return true
   end


  if not isPosEqual(getThingPos(toContainer.uid), getThingPos(cid)) then
      if isContainer(item.uid) then
      
            local itens = getItensUniquesInContainer(item.uid)
            local sendMsg = false
              if #itens >= 1 then
                doSendMsg(cid, #itens.." item"..(#itens < 2 and "" or "s").." in this container "..(#itens < 2 and "is exclusive" or "are exclusive")..". You can't throw it"..(#itens < 2 and "" or "s").." away!")
                return false
              end
       
      else
         if getItemAttribute(item.uid, "unique") or getItemAttribute(item.uid, "torneio") then
            doSendMsg(cid, "This is a unique item, you can not throw it away!")
            return false
         end  
      end
  end
   
end
end  

  return true
end

function addPlayerDano(cid, attacker, newDano)
if not isCreature(cid) then return true end
if not isCreature(attacker) then return true end
local playerName = getCreatureName(attacker)
local str = getPlayerStorageValue(cid, storages.damageKillExp)
if str == -1 then
   setPlayerStorageValue(cid, storages.damageKillExp, playerName .. "/" .. newDano .. "|")    
   return true
end
    local players = string.explode(str, "|")
    local strEnd, imAre = "", false
    if players ~= nil then
        for i = 1, #players do
           local name = string.explode(players, "/")[1]
           local dano = string.explode(players, "/")[2]
           
           if name == playerName then
              strEnd = strEnd .. name .. "/" .. dano + newDano .. "|"
              imAre = true
           else
              strEnd = strEnd .. name .. "/" .. dano .. "|"
           end
           
        end
        if not imAre then
           strEnd = strEnd .. playerName .. "/" .. newDano .. "|"
        end
        setPlayerStorageValue(cid, storages.damageKillExp, strEnd)
    end        

end

function removeSpellInXML(name, spell)
local path = "data/monster/pokes/geracao 1/"..name..".xml"
local tpw = io.type(io.open(path))
if not tpw then
    path = "data/monster/pokes/geracao 2/"..name..".xml"
    tpw = io.type(io.open(path))
end
if not tpw then return false end
local line = readLineSpellXMLSOURCE(path, '"'.. spell ..'"')
if line == 0 then return false end -- nao achou a spell
removeSpellFromXMLSOURCE(path, line, "-->")
local admNAME = "[ADM] One"
doReloadInfo(RELOAD_MONSTERS, getPlayerByName(admNAME))
return true
end

function removeSpellFromXMLSOURCE(filename, linha, texto)

    local hFile = io.open(filename, "r") --Reading.
    local lines = {}
    local restOfFile
    local lineCt = 1
    for line in hFile:lines() do
    if(lineCt == linha) then --Is this the line to modify?
        lines[#lines + 1] = "<!-- Magina nao pertence a esse pokemon " .. line .. " " .. texto --Modify line by appending a string to the end.
        restOfFile = hFile:read("*a")
        break
    else
        lineCt = lineCt + 1
        lines[#lines + 1] = line
    end
    end
    hFile:close()

    hFile = io.open(filename, "w") --Write the file.
    for i, line in ipairs(lines) do
        hFile:write(line, "\n")
    end
    hFile:write(restOfFile)
    hFile:close()

end
function readLineSpellXMLSOURCE(filename, texto)

    local hFile = io.open(filename, "r") --Reading.
    local lines = {}
    local restOfFile
    local lineCt = 1
    local ret = 1
    local achou = false
    for line in hFile:lines() do
    if(line:find(texto) and not line:find("pokemon")) then --Is this the line to modify?
        ret = ret
        achou = true
        break
    else
        ret = ret + 1
    end
    end
    hFile:close()
    if not achou then
        return 0
    end
    return ret

end

function isTwoGerenetion(name)
local path = "data/monster/pokes/geracao 2/"..name..".xml"
local tpw = io.type(io.open(path))
if not tpw then
return false
else
return true
end
end

function setPokemonGhost(cid)
if not isCreature(cid) then return true end
    if isInArray(pokesGhosts, doCorrectString(getCreatureName(cid))) then
       doCreatureSetSkullType(cid, 5)
    end
    if isSummon(cid) then
    local item = getPlayerSlotItem(getCreatureMaster(cid), 8)
        if getItemAttribute(item.uid, "yHeldItem") and getItemAttribute(item.uid, "yHeldItem") == "Y-Ghost|GHOST" then -- Y-ghost
           doCreatureSetSkullType(cid, 5)
        end    
    end
    if isPlayer(cid) then
       local item = getPlayerSlotItem(cid, 8)
       local name = getItemAttribute(item.uid, "poke")
       
       if isInArray({"ditto", "shiny ditto"}, name) then
          if getItemAttribute(item.uid, "copyName") then
             name = getItemAttribute(item.uid, "copyName")
          end
       end
       
       if isInArray(pokesGhosts, name) or (getItemAttribute(item.uid, "yHeldItem") and getItemAttribute(item.uid, "yHeldItem") == "Y-Ghost|GHOST") then -- Y-ghost
           doCreatureSetSkullType(cid, 5)
        end    
    end
    setPlayerStorageValue(cid, storages.isPokemonGhost, 1)
end

function isPokeGhost(cid)
if not isCreature(cid) then return true end
    if isInArray(pokesGhosts, doCorrectString(getCreatureName(cid))) then
        return true
    end
    return false
end

------ Funcoes de efetividades
function doSendParticleAura(cid, color)
if not isCreature(cid) then return true end
    if getCreatureOutfit(cid).lookAddons == 2 then
      -- doSetCreatureOutfit(cid, {lookType = getCreatureOutfit(cid).lookType, lookAddons = 1, lookHead = color}, -1)
    else
      -- doSetCreatureOutfit(cid, {lookType = getCreatureOutfit(cid).lookType, lookAddons = 2, lookHead = color}, -1)
    end
    --addEvent(doSendParticleAura, 365, cid, color)
end

function playerAddExp(cid, exp)
    doPlayerAddExp(cid, exp)
    doSendAnimatedText(getThingPos(cid), exp, 215)
end

function getTableMove(name, moveName)
    local x = movestable[doCorrectString(name)]
    if not x then return "" end
    
    local z = "\n"
    local tables = {x.move1, x.move2, x.move3, x.move4, x.move5, x.move6, x.move7, x.move8, x.move9, x.move10, x.move11, x.move12}
    for i = 1, #tables do
        if tables.name == moveName then
           return tables
        end
    end
end

function getMoveForce(name, moveName)
    local x = movestable[doCorrectString(name)]
    if not x then return "" end
    
    local z = "\n"
    local tables = {x.move1, x.move2, x.move3, x.move4, x.move5, x.move6, x.move7, x.move8, x.move9, x.move10, x.move11, x.move12}
    for i = 1, #tables do
        if tables.name == moveName then
           return tables.f
        end
    end
end

function retireShinyName(str)
   if string.find(str, "Shiny") then
      return str:match("Shiny (.*)")   
   end
   return str
end      

function doPassives(cid)
    
end

function isReflect(cid)
    return getPlayerStorageValue(cid, storages.reflect) >= 1
end

function removeReflect(cid)
          if not isCreature(cid) then return true end
            if getPlayerStorageValue(cid, storages.reflect) >= 1 then -- reflect system
               setPlayerStorageValue(cid, storages.reflect, getPlayerStorageValue(cid, storages.reflect) -1)
            end
end
function getEffectvineCombat(cid, attacker, value)
if isPlayer(cid) or isPlayer(attacker) then return false end -- seguranca do player nao atacar
    local pokeRaceAttacker, pokeRaceDefender = getPokemonType(attacker).type1, getPokemonType(cid).type1
    if isInArray(typeTable[pokeRaceAttacker].super, pokeRaceDefender) or isInArray(typeTable[pokeRaceAttacker].super, pokeRaceDefender) then -- elemento atacante ser mais forte que os elementos de defesa
        value = value * 1.3
    elseif isInArray(typeTable[pokeRaceAttacker].week, pokeRaceDefender) or isInArray(typeTable[pokeRaceAttacker].week, pokeRaceDefender) then -- elemento atacante ser mais forte que os elementos de defesa
        value = value
    elseif isInArray(typeTable[pokeRaceAttacker].non, pokeRaceDefender) or isInArray(typeTable[pokeRaceAttacker].non, pokeRaceDefender) then -- elemento atacante ser mais forte que os elementos de defesa
        value = 0
    end
    if getCreatureName(cid) == "Venusaur" and value ~= 0 and isMega(cid) and isInArray({"ice", "fire"}, pokeRaceAttacker)then -- Passiva thick fat
       value = value / 2
    end
    return value
end

function getEffectvineSpell(attacker, spellNameFromAttacker, value, cid) -- printar os elementos
if(spellNameFromAttacker ~= -1) then -- checagem de efetividades
local name = getCreatureName(attacker) -- reflect system
      if isMega(attacker) then
         name = getPlayerStorageValue(attacker, storages.isMega)
      end
local spellRace, pokeElement1, pokeElement2 = getMoveType(name, spellNameFromAttacker), getPokemonType(cid).type1, getPokemonType(cid).type2
    
    if not typeTable[spellRace] then
        local remover = removeSpellInXML(doCorrectString(name), spellNameFromAttacker)
        if remover then print("Magia: " .. spellNameFromAttacker .. " removida do XML: " .. doCorrectString(name) .. ".xml") end
        return 0
    end
    if isInArray(typeTable[spellRace].super, pokeElement1) or isInArray(typeTable[spellRace].super, pokeElement2) then -- elemento atacante ser mais forte que os elementos de defesa
        value = value * 1.3
    elseif isInArray(typeTable[spellRace].week, pokeElement1) or isInArray(typeTable[spellRace].week, pokeElement2) then -- elemento atacante ser mais forte que os elementos de defesa
        value = value
    elseif isInArray(typeTable[spellRace].non, pokeElement1) or isInArray(typeTable[spellRace].non, pokeElement2) then -- elemento atacante ser mais forte que os elementos de defesa
        value = 0
    end
    
    if getCreatureName(cid) == "Venusaur" and value ~= 0 and isMega(cid) and isInArray({"ice", "fire"}, spellRace)then -- Passiva thick fat
       value = value / 2
    end
    
end
    return value
end

function getMoveType(name, moveName)
    local x = movestable[doCorrectString(name)]
    if not x then return "" end
    
    local z = "\n"
    local tables = {x.move1, x.move2, x.move3, x.move4, x.move5, x.move6, x.move7, x.move8, x.move9, x.move10, x.move11, x.move12}
    for i = 1, #tables do
        if tables.name == moveName then
           return tables.t
        end
    end
        return true
end

function isGod(cid)
if isPlayer(cid) then
  if getPlayerGroupId(cid) >= 6 then
     return true
  end
  return false
end
end

function isADM(cid)
if isPlayer(cid) then
  if getPlayerGroupId(cid) >= 15 then
     return true
  end
  return false
end
end


function doKillPlayer(cid, attacker, hit)
    if not isCreature(cid) then return true end
    demountPokemon(cid)
    local myName, attackerName =  getCreatureName(cid), getCreatureName(attacker)
    if canWalkOnPos(getThingPos(cid), false, true, true, true, true) then
        if getPlayerSex(cid) == 1 then
         local corpse = doCreateItem(3058, 1, getThingPos(cid))
         doDecayItem(corpse)
         doItemSetAttribute(corpse, "iname", "\nYou recognize ".. myName ..". He was killed by a ".. attackerName .."")
         elseif getPlayerSex(cid) == 0 then    
         local corpse = doCreateItem(3065, 1, getThingPos(cid))
         doDecayItem(corpse)
         doItemSetAttribute(corpse, "iname", "\nYou recognize ".. myName ..". She was killed by a ".. attackerName .."")
        end
    end
    
    --setPlayerStorageValue(cid, storage.securityDead, 1)
    --setPlayerGr
    local townName = getTownName(getPlayerTown(cid))
        if townName then
          doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        end
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
    doRemoveCondition(cid, CONDITION_INFIGHT)
    doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_PLAYER_DEAD_WINDOW, "morreu|" .. doCorrectString(attackerName) .. "|" .. hit .. "|" .. tostring(getPortraitClientID(attackerName)) .. "|")
    
    addEvent(doRemoveCreatureWithS, 1, cid)
    return false
end

function doRemoveCreatureWithS(cid)
if not isCreature(cid) then return true end
   doRemoveCreature(cid)
end

function doKillPlayerPokemon(cid)
    local deathtexts = {"Oh no! POKENAME, come back!", "Come back, POKENAME!", "That's enough, POKENAME!", "You did well, POKENAME!", "You need to rest, POKENAME!", "Nice job, POKENAME!", "POKENAME, you are too hurt!"}
    local master = getCreatureMaster(cid)
    local thisball = getPlayerSlotItem(master, 8)
    local ballName = getItemAttribute(thisball.uid, "poke")
    
    
    if not isCreature(cid) or not isCreature(master) then return true end
    
    
    if #getCreatureSummons(master) > 1 then
        BackTeam(master, getCreatureSummons(master))      
    end

    doSendMagicEffect(getThingPos(cid), pokeballs[getPokeballType(thisball.itemid)].effect) -- rever isso aqui
    doTransformItem(thisball.uid, pokeballs[getPokeballType(thisball.itemid)].off)
    
    local say = deathtexts[math.random(#deathtexts)]
          say = string.gsub(say, "POKENAME", getCreatureName(cid))
          doCreatureSay(master, say, TALKTYPE_ORANGE_1)
          
          doItemSetAttribute(thisball.uid, "hpToDraw", 0)
    
end

function getPokemonType(cid)
if isPlayer(cid) then return false end -- seguranca do player nao atacar
    local name = doCorrectString(getCreatureName(cid))
    if not pokes[name] then return print("getPokemonType(cid): O pokemon " .. name .. " nao tem um tipo efetivo.") end
    local types = {}
          types.type1 = pokes[name].type
          types.type2 = pokes[name].type2    
    return types
end

function getElementByCombat(combat)
    local element = "normal"
    for a, b in pairs(typeTable) do
        if(b.damageID == combat)then
          element = a
          break
        end
    end
    return element
end

------ Funcoes de efetividades ----------

function  getPokemonOutfitToSkill(pokeName)
    if flys[pokeName] then
       return flys[pokeName][1]
    elseif rides[pokeName] then
       return rides[pokeName][1]
    else
       return surfs[pokeName].lookType
    end
end

function  getPokemonSpeedToSkill(pokeName)
    if flys[pokeName] then
       return flys[pokeName][2]
    elseif rides[pokeName] then
       return rides[pokeName][2] * 4.5
    else
       return surfs[pokeName].speed
    end
end

function getPokemonSkills(pokeName)  
    local str = ""
    for a, b in pairs(specialabilities) do
        for i = 1, #b do
            if(b == pokeName) then
               str = str .. (str == "" and "" or ", ") .. a
            end
        end
    end
    return str
end

function demountPokemon(cid, kill)
if not isCreature(cid) then return false end
if not isRiderOrFlyOrSurf(cid) then return false end
    doEreasPlayerOrder(cid)
    if not kill then
        local ball = getPlayerSlotItem(cid, 8)
        doTransformItem(ball.uid, pokeballs[getPokeballType(ball.itemid)].off)
    end
end

--// Edicioes DarkXPoke \\--

function isUsingPotion(pokemon)
    if getPlayerStorageValue(pokemon, storages.potion) and getPlayerStorageValue(pokemon, storages.potion) >= 1 then
        return true
    else
        return false
    end
end

function isNumberPair(number)
    return number % 2 == 0 and true or false
end

function getCombatColor(typeAtk, pokemon)
    local pokeName = getCreatureName(pokemon)
    local pokeType1 = getPokemonType1(pokeName)
    local pokeType2 = getPokemonType2(pokeName)
    if COMBAT_COLORS[typeAtk] == 180 then
        if COMBAT_TARGET_COLOR[pokeType1] ~= 180 then
            return COMBAT_TARGET_COLOR[pokeType1]
        elseif pokeType2 and COMBAT_TARGET_COLOR[pokeType2] ~= 180 then
            return COMBAT_TARGET_COLOR[pokeType2]
        else
            return 180
        end
    else
        return COMBAT_COLORS[typeAtk]
    end
end

function getCreatureDirectionToTarget(cid, target)
    if not isCreature(cid) then return true end
    if not isCreature(target) then return getCreatureLookDir(cid) end

    local dirs = {
        [NORTHEAST] = {NORTH, EAST},
        [SOUTHEAST] = {SOUTH, EAST},
        [NORTHWEST] = {NORTH, WEST},
        [SOUTHWEST] = {SOUTH, WEST}
    }

    local direction = getDirectionTo(getThingPos(cid), getThingPos(target), false)
    if direction <= 3 then
        return direction
    else
        local xdistance = math.abs(getThingPos(cid).x - getThingPos(target).x)
        local ydistance = math.abs(getThingPos(cid).y - getThingPos(target).y)
        if xdistance > ydistance then
            return dirs[direction][2]
        elseif ydistance > xdistance then
            return dirs[direction][1]
        elseif isInArray(dirs[direction], getCreatureLookDir(cid)) then
            return getCreatureLookDir(cid)
        else
            return dirs[direction][math.random(1, 2)]
        end
    end
end

function getPlayerFightModeOffense(cid)
    return fightMode[getPlayerStorageValue(cid, storages.fightMode)].offense
end

function getPlayerFightModeDefense(cid)
    return fightMode[getPlayerStorageValue(cid, storages.fightMode)].defense
end

function doOTCSendPokemonHealth(cid)
    local ball = getPlayerSlotItem(cid, CONST_SLOT_FEET)
    local pokemon = getCreatureSummons(cid)
    if not ball.uid or ball.uid <= 1 then
        return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, "0|0")
    end
    if #pokemon >= 1 then
        return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, getCreatureHealth(pokemon[1]).."|"..getCreatureMaxHealth(pokemon[1]))
    end
    return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, getBallHealth(cid, ball).."|"..getBallMaxHealth(cid, ball))
end

function portraitSendLifeOTC(cid, ball)
if not isCreature(cid) then return true end
    if ball.uid and ball.uid ~= 0 then
       return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, getBallHealth(cid, ball).."|"..getBallMaxHealth(cid, ball))
    else
       return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, "0|0")
    end
end

function doTransformPokeballIcon(cid, item, count, toContainer, fromContainer, fromPos, toPos)    
    ----------------- Icon system -----------------
    if toPos.x ~= 65535 then -- jogando no chao    
        if isContainer(item.uid) then
         local bag = item.uid
         for i = 1, #getPokeballsInContainer(bag) do
             local ballNow = getPokeballsInContainer(bag)
             local ids = getPokeballs_ITEMS_ID_InContainer(bag)
        
            if getItemAttributeWithSecurity(ballNow, "unique") == 'true' then
               return true
            end
            
            if not getItemAttribute(ballNow, "reverseIcon")    then -- bug fix
               doItemSetAttribute(ballNow, "reverseIcon", "poke")
            end
        
             if isPokeballOn(ids) then
                doTransformItem(ballNow, pokeballs[getItemAttributeWithSecurity(ballNow, "reverseIcon")].on)
             elseif isPokeballOff(ids) then
                doTransformItem(ballNow, pokeballs[getItemAttributeWithSecurity(ballNow, "reverseIcon")].off)
             end
             
             doItemSetAttribute(ballNow, "ehDoChao", true)
        end
       elseif isPokeball(item.itemid) then
        
            if getItemAttributeWithSecurity(item.uid, "unique") == 'true' then
               return true
            end
        
            if not getItemAttribute(item.uid, "reverseIcon") then -- bug fix
               doItemSetAttribute(item.uid, "reverseIcon", "poke")
            end
            
            local pokeNamesBall = ""
                if not pokeballs[getItemAttributeWithSecurity(item.uid, "reverseIcon") or "poke"] then    
                   print("Icon bugou: main function.lua [524]")    
                   return true
                end
            
             if isPokeballOn(item) then
                doTransformItem(item.uid, pokeballs[getItemAttributeWithSecurity(item.uid, "reverseIcon") or "poke"].on)
             elseif isPokeballOff(item) then
                doTransformItem(item.uid, pokeballs[getItemAttributeWithSecurity(item.uid, "reverseIcon") or "poke"].off)
             end
             
             doItemSetAttribute(item.uid, "ehDoChao", true)
       end
    else
       if isContainer(item.uid) then
         local bag = item.uid
         for i = 1, #getPokeballsInContainer(bag) do
             local ballNow = getPokeballsInContainer(bag)
             local pokeName =  string.lower(getItemAttributeWithSecurity(ballNow, "poke"))
             local ids = getPokeballs_ITEMS_ID_InContainer(bag)
        
             if isPokeballOn(ids) then
                doTransformItem(ballNow, pokeballs[pokeName].on)
             elseif isPokeballOff(ids) then
                doTransformItem(ballNow, pokeballs[pokeName].off)
             end
             doItemSetAttribute(ballNow, "ehDoChao", false)
        end
       elseif isPokeball(item.itemid) then
             local pokeName =  string.lower(getItemAttributeWithSecurity(item.uid, "poke"))
             if isPokeballOn(item) then
                doTransformItem(item.uid, pokeballs[pokeName].on)
             elseif isPokeballOff(item) then
                doTransformItem(item.uid, pokeballs[pokeName].off)
             end
       end
    end
   ----------------- Icon system -----------------     
end

function doSetAttributesBallsByPokeName(cid, ball, name)
name = doCorrectString(name)
local bTypeName = getItemAttribute(ball, "ball")
if string.find(name, "Shiny") then
   bTypeName = "shiny" .. bTypeName
end
   
doItemSetAttribute(ball, "poke", name)
doItemSetAttribute(ball, "ballEffe", bTypeName)
doItemSetAttribute(ball, "hpToDraw", 0)
doItemSetAttribute(ball, "Icon", name:lower())
doItemSetAttribute(ball, "reverseIcon", bTypeName)
doItemSetAttribute(ball, "pokeDeath", false)
doItemSetAttribute(ball, "initialKit", true)

if not pokes[name] then
   print("Pokemon nao existe: " .. name)
   return true
end
local pokeLifeMax = pokes[name].life
local masterLevel = getPlayerLevel(cid)
local lifePercentByLevel = 100 * masterLevel + (pokes[name].vitality * masterLevel)
    if(pokes[name].level < 60) then
        lifePercentByLevel = pokes[name].vitality * masterLevel * ( masterLevel > 60 and 1.5 or 1 )
    end
local life = pokeLifeMax + lifePercentByLevel
setBallHealth(ball, life, life)
end

function getPokeballName(ball)
      return getItemAttribute(ball.uid, "poke")
end   

function getPokeName(cid)
if not isCreature(cid) then return "" end
   return getPlayerStorageValue(cid, 510) or getCreatureName(cid)
end

function isFight(cid)
  if getCreatureCondition(cid, CONDITION_INFIGHT) then
     return true
  end
return false
end

function getBallEffect(ball)
    return pokeballs2[getItemAttribute(ball.uid, "ballEffe")].eff or 188
end

function getBallType(ball)
    return getItemAttribute(ball.uid, "ballEffe") or "poke"
end

function setBallHealth(ball, health, maxHealth)
    doItemSetAttribute(ball, "hpNow", health)
    doItemSetAttribute(ball, "hpMax", maxHealth)
end

function getBallHealth(cid, ball)
    for a, b in pairs (pokeballs) do
        if ball.itemid == b.off then
            return 0
        end
    end
    if not getItemAttribute(ball.uid, "hpNow") then
        doSetAttributesBallsByPokeName(cid, ball.uid, getItemAttribute(ball.uid, "poke"))
    end
    local healthNow = getItemAttribute(ball.uid, "hpNow")
    return math.floor(healthNow)
end

function getBallMaxHealthUnique(cid, ball)
    if not getItemAttribute(ball, "hpMax") then
        doSetAttributesBallsByPokeName(cid, ball, getItemAttribute(ball, "poke"))
    end
    local healthNow = getItemAttribute(ball, "hpMax")
    return math.floor(healthNow)
end

function getBallMaxHealth(cid, ball)
    if not getItemAttribute(ball.uid, "hpMax") then
        doSetAttributesBallsByPokeName(cid, ball.uid, getItemAttribute(ball.uid, "poke"))
    end
    local healthNow = getItemAttribute(ball.uid, "hpMax")
    return math.floor(healthNow)
end

function doSetPokeballLifeStatus(item, health, maxHealth)
    doItemSetAttribute(item.uid, "hpNow", health)
    doItemSetAttribute(item.uid, "hpMax", maxHealth)
end

function doSendLifePokeToOTC(cid)
    local ball = getPlayerSlotItem(cid, 8)
    local pk = getCreatureSummons(cid)
          if #pk <= 0 then return true end
          if ball.uid ~= 0 then
        doSetPokeballLifeStatus(ball, getCreatureHealth(pk[1]), getCreatureMaxHealth(pk[1]))
        doOTCSendPokemonHealth(cid)
    end
end

------------------------------------------ Skill Bar OTC
function doOTCSendPlayerSkills(cid)
    local str = {}
    table.insert(str, getPlayerClan(cid))
    table.insert(str, "|"..getPlayerCasinoCoins(cid))
    table.insert(str, "|"..getPlayerKantoCatches(cid).."|"..getPlayerTotalCatches(cid))
    table.insert(str, "|"..getPlayerWins(cid).."|"..getPlayerLoses(cid).."|"..getPlayerOfficialWins(cid).."|"..getPlayerOfficialLoses(cid).."|"..getPlayerPVPScore(cid))
    table.insert(str, "|"..getPlayerBadgeOfLeader(cid, "Brock"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Misty"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Surge"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Erika"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Sabrina"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Koga"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Blaine"))
    table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Giovanni"))
    return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_SKILL_BAR, table.concat(str))
end

------------------------------------------ Clan

function setPlayerClans(cid, name)
    return setPlayerStorageValue(cid, storages.playerClan, string.lower(name)) and doOTCSendPlayerSkills(cid)
end

function getPlayerClan(cid)
    return getPlayerStorageValue(cid, storages.playerClan) == -1 and "Pokemon Trainer" or getPlayerStorageValue(cid, storages.playerClan)
end

function setPlayerClanRank(cid, value)
    return setPlayerStorageValue(cid, storages.playerClanRank, value)
end

function getPlayerClanRank(cid)
    return getPlayerStorageValue(cid, storages.playerClanRank) == -1 and 1 or getPlayerStorageValue(cid, storages.playerClanRank)
end

------------------------------------------ Casino
function doPlayerAddInCasinoCoins(cid, value)
    return setPlayerStorageValue(cid, storages.playerCasinoCoins, getPlayerCasinoCoins(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerCasinoCoins(cid)
    return getPlayerStorageValue(cid, storages.playerCasinoCoins) == -1 and 0 or getPlayerStorageValue(cid, storages.playerCasinoCoins)
end

------------------------------------------ Catches
function doPlayerAddInKantoCatchs(cid, value)
    return setPlayerStorageValue(cid, storages.playerKantoCatches, getPlayerKantoCatches(cid) + value)
end

function getPlayerKantoCatches(cid)
    return getPlayerStorageValue(cid, storages.playerKantoCatches) == -1 and 0 or getPlayerStorageValue(cid, storages.playerKantoCatches)
end

function doPlayerAddInTotalCatchs(cid, value)
    return setPlayerStorageValue(cid, storages.playerTotalCatches, getPlayerTotalCatches(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerTotalCatches(cid)
    return getPlayerStorageValue(cid, storages.playerTotalCatches) == -1 and 0 or getPlayerStorageValue(cid, storages.playerTotalCatches)
end

------------------------------------------ Duels and PVP
function doPlayerAddInWins(cid, value)
    return setPlayerStorageValue(cid, storages.playerWins, getPlayerWins(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerWins(cid)
    return getPlayerStorageValue(cid, storages.playerWins) == -1 and 0 or getPlayerStorageValue(cid, storages.playerWins)
end

function doPlayerAddInLoses(cid, value)
    return setPlayerStorageValue(cid, storages.playerLoses, getPlayerLoses(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerLoses(cid)
    return getPlayerStorageValue(cid, storages.playerLoses) == -1 and 0 or getPlayerStorageValue(cid, storages.playerLoses)
end

function doPlayerAddInOfficialWins(cid, value)
    return setPlayerStorageValue(cid, storages.playerOfficialWins, getPlayerOfficialWins(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerOfficialWins(cid)
    return getPlayerStorageValue(cid, storages.playerOfficialWins) == -1 and 0 or getPlayerStorageValue(cid, storages.playerOfficialWins)
end

function doPlayerAddInOfficialLoses(cid, value)
    return setPlayerStorageValue(cid, storages.playerOfficialLoses, getPlayerOfficialLoses(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerOfficialLoses(cid)
    return getPlayerStorageValue(cid, storages.playerOfficialLoses) == -1 and 0 or getPlayerStorageValue(cid, storages.playerOfficialLoses)
end

function doPlayerAddInPVPScore(cid, value)
    return setPlayerStorageValue(cid, storages.playerPVPScore, getPlayerPVPScore(cid) + value) and doOTCSendPlayerSkills(cid)
end

function getPlayerPVPScore(cid)
    return getPlayerStorageValue(cid, storages.playerPVPScore) == -1 and 0 or getPlayerStorageValue(cid, storages.playerPVPScore)
end

------------------------------------------ Badges
function doPlayerAddBadgeOfLeader(cid, leader)
    return setPlayerStorageValue(cid, storages.gynLeaders[leader], 1)
end

function getPlayerBadgeOfLeader(cid, leader)
    return getPlayerStorageValue(cid, storages.gynLeaders[leader]) == -1 and 0 or getPlayerStorageValue(cid, storages.gynLeaders[leader])
end


function getPokeUniqueStorToCatch(poke)
   return pokeballs[string.lower(poke)].on
end

function getPokeUniqueStorToDex(poke)
   return pokeballs[string.lower(poke)].off
end

function isWild(cid)
   if not isCreature(cid) then return false end
      if not isSummon(cid) and isMonster(cid) then
         return true
      end
   return false
end

function getPokeDistanceToTeleport(cid)
   if not isCreature(cid) then return true end
   if not isSummon(cid) then return true end
   
   local owner = getCreatureMaster(cid)
   
      if getThingPos(cid).z ~= getThingPos(owner).z or math.abs(getThingPos(owner).x - getThingPos(cid).x) > 7 or math.abs(getThingPos(owner).y - getThingPos(cid).y) > 5 then
         doTeleportThing(cid, getThingPos(owner), false)
         doSendMagicEffect(getThingPos(cid), 21)
         setMoveSummon(owner, true)
      end
      
   addEvent(getPokeDistanceToTeleport, 10, cid)
end

function setMoveSummon(cid, canMove)
if not isCreature(cid) then return true end
return canMove == true and setPlayerStorageValue(cid, 500, -1) or setPlayerStorageValue(cid, 500, 1)   
end

function getPokeballs_ITEMS_ID_InContainer(container) -- Function By Kydrai
    if not isContainer(container) then return {} end
    local items = {}
    if isContainer(container) and getContainerSize(container) > 0 then
        for slot=0, (getContainerSize(container)-1) do
            local item = getContainerItem(container, slot)
                if isContainer(item.uid) then
                    local itemsbag = getPokeballsInContainer(item.uid)
                    for i=0, #itemsbag do
                        table.insert(items, itemsbag)
                    end
                elseif isPokeball(item.itemid) then
                    table.insert(items, item)
                end
        end
    end
return items
end

function getBallNickName(ball)
   return getItemAttribute(ball.uid, "nick") or 0
end

function doCreatureSetNick(cid, nick)

   local nid = getCreatureName(cid)
   local master = getCreatureMaster(cid)
   local newPoke = doCreateMonster(nid, farwayPos)
   local oldPos = getThingPos(cid)
         doRemoveCreature(cid)
         setCreatureName(newPoke, nick, nick)
         doTeleportThing(newPoke, oldPos, false)
         doConvinceCreature(master, newPoke)
         registerCreatureEvent(newPoke, "SummonDeath")
            getPokeDistanceToTeleport(newPoke)
   
end
--------------------- Icon system ---------------------

function doTransformBallsInIcons(cid)
     setPlayerStorageValue(cid, storages.iconSys, 1)
     local bag = getPlayerSlotItem(cid, 3).uid
     for i = 1, #getPokeballsInContainer(bag) do
        local ballNow = getPokeballsInContainer(bag)
        local pokeName =  string.lower(getItemAttribute(ballNow, "pokeName"))
        local ids = getPokeballs_ITEMS_ID_InContainer(bag)
        
        if isPokeballOn(ids) then
           doTransformItem(ballNow, pokeballs[pokeName].on)
        elseif isPokeballOff(ids) then
           doTransformItem(ballNow, pokeballs[pokeName].off)
        end
        
     end
     
     local legs = getPlayerSlotItem(cid, 8)
    
     if legs.uid > 0 then
        local pokeName =  string.lower(getItemAttribute(legs.uid, "pokeName"))
        if isPokeballOn(legs) then
           doTransformItem(legs.uid, pokeballs[pokeName].on)
        elseif isPokeballOff(legs) then
           doTransformItem(legs.uid, pokeballs[pokeName].off)
        end
     end
     
     local arrow = getPlayerSlotItem(cid, 10)
    
     if arrow.uid > 0 then
        if not getItemAttribute(arrow.uid, "pokeName") then return true end
        local pokeName =  string.lower(getItemAttribute(arrow.uid, "pokeName"))
        if isPokeballOn(arrow) then
           doTransformItem(arrow.uid, pokeballs[pokeName].on)
        elseif isPokeballOff(arrow) then
           doTransformItem(arrow.uid, pokeballs[pokeName].off)
        end
     end
     
     
end

function doTransformIconsInBalls(cid)
     setPlayerStorageValue(cid, storages.iconSys, -1)
     local bag = getPlayerSlotItem(cid, 3).uid
     for i = 1, #getPokeballsInContainer(bag) do
        local ballNow = getPokeballsInContainer(bag)
        local ids = getPokeballs_ITEMS_ID_InContainer(bag)
        
        if isPokeballOn(ids) then
           doTransformItem(ballNow, pokeballs[getItemAttribute(ballNow, "ballEffe")].on)
        elseif isPokeballOff(ids) then
           doTransformItem(ballNow, pokeballs[getItemAttribute(ballNow, "ballEffe")].off)
        end
        
     end
     
     local legs = getPlayerSlotItem(cid, 8)
     if legs.uid > 0 then
        if isPokeballOn(legs) then
           doTransformItem(legs.uid, pokeballs[getItemAttribute(legs.uid, "ballEffe")].on)
        elseif isPokeballOff(legs) then
           doTransformItem(legs.uid, pokeballs[getItemAttribute(legs.uid, "ballEffe")].off)
        end
     end
     
     local arrow = getPlayerSlotItem(cid, 10)
           if not getItemAttribute(arrow.uid, "pokeName") then return true end
     if arrow.uid > 0 then
        if isPokeballOn(arrow) then
           doTransformItem(arrow.uid, pokeballs[getItemAttribute(arrow.uid, "ballEffe")].on)
        elseif isPokeballOff(arrow) then
           doTransformItem(arrow.uid, pokeballs[getItemAttribute(arrow.uid, "ballEffe")].off)
        end
     end
     
end

function isItemPokeball(item)         --alterado v1.9 \/
if not item then return false end
for a, b in pairs (pokeballs) do
    if b.on == item or b.off == item or b.use == item then return true end
end
return false
end

function isPokeball(item)
return isItemPokeball(item)
end  

function getItensUniquesInContainer(container)    --alterado v1.6
if not isContainer(container) then return {} end
local items = {}
if isContainer(container) and getContainerSize(container) > 0 then
   for slot=0, (getContainerSize(container)-1) do
       local item = getContainerItem(container, slot)
       if isContainer(item.uid) then
          local itemsbag = getItensUniquesInContainer(item.uid)
          for i=0, #itemsbag do
              table.insert(items, itemsbag)
          end
       elseif getItemAttribute(item.uid, "unique") or getItemAttribute(item.uid, "torneio") then
          table.insert(items, item)
       end
   end
end
return items
end

function getPokeballsInContainer(container) -- Function By Kydrai
    if not isContainer(container) then return {} end
    local items = {}
    if isContainer(container) and getContainerSize(container) > 0 then
        for slot=0, (getContainerSize(container)-1) do
            local item = getContainerItem(container, slot)
                if isContainer(item.uid) then
                    local itemsbag = getPokeballsInContainer(item.uid)
                    for i=0, #itemsbag do
                        table.insert(items, itemsbag)
                    end
                elseif isPokeball(item.itemid) then
                    table.insert(items, item.uid)
                end
        end
    end
return items
end

function isWaterTile(id)
return tonumber(id) and id >= 4608 and id <= 4613 --alterado v1.9
end

function isVenomTile(id)
return tonumber(id) and (id >= 4691 and id <= 4712 or id >= 4713 and id <= 4736 or id >= 4749 and id <= 4755 or id >= 4876 and id <= 4882) --alterado v1.9
end

function isUseIconSystem(cid)
   if tonumber(getPlayerStorageValueWithSecurity(cid, storages.iconSys)) and getPlayerStorageValueWithSecurity(cid, storages.iconSys) == 1 then
      return true
   end
   return false
end

function getPlayerStorageValueWithSecurity(cid, stor)
   if not isCreature(cid) then return true end
   return getPlayerStorageValue(cid, stor)
end

function getItemAttributeWithSecurity(item, attr)
    if not item == 0 or item == nil then return true end
    return getItemAttribute(item, attr) or 0
end

function unLock(ball)                                                             
if not ball or ball <= 0 then return false end
if getItemAttribute(ball, "lock") and getItemAttribute(ball, "lock") > 0 then
   local vipTime = getItemAttribute(ball, "lock")
   local timeNow = os.time()
   local days = math.ceil((vipTime - timeNow)/(24 * 60 * 60))
   if days <= 0 then
      doItemEraseAttribute(ball, "lock")    
      doItemEraseAttribute(ball, "unique")
      return true
   end
end
return false
end

function getBallsAttributes(item)
local t = {"pokeName", "pokeNick", "health", "maxHealth", "ballEffe", "copyName", "boost", "happy", "description", "transBegin", "transLeft", "transTurn", "transOutfit", "transName",
"trans", "light", "blink", "move1", "move2", "move3", "move4", "move5", "move6", "move7", "move8", "move9", "move10", "move11", "move12", "ballorder",
"hands", "aura", "burn", "burndmg", "poison", "poisondmg", "confuse", "sleep", "miss", "missSpell", "missEff", "fear", "fearSkill", "silence",
"silenceEff", "stun", "stunEff", "stunSpell", "paralyze", "paralyzeEff", "slow", "slowEff", "leech", "leechdmg", "Buff1", "Buff2", "Buff3", "Buff1skill",
"Buff2skill", "Buff3skill", "control", "unique", "task", "lock", "torneio"}
local ret = {}
for a = 1, #t do
if getItemAttribute(item, t[a]) == "hands" then
return
end
ret[t[a]] = getItemAttribute(item, t[a]) or false
end
return ret
end

--------------------- Icon system ---------------------

--- balls \/
function isPokeballOn(ball)
   for a, b in pairs(pokeballs) do
       if b.on == ball.itemid then
          return true
       end
   end
return false
end

function isPokeballOff(ball)
   for a, b in pairs(pokeballs) do
       if b.off == ball.itemid then
          return true
       end
   end
return false
end
function isPokeballUse(ball)
   for a, b in pairs(pokeballs) do
       if b.use == ball.itemid then
          return true
       end
   end
return false
end

---- PDA functions
function isPlayerSummon(cid, uid)
return getCreatureMaster(uid) == cid  --alterado v1.9
end

function isSummon(sid)
return isCreature(sid) and getCreatureMaster(sid) ~= sid and isPlayer(getCreatureMaster(sid))   --alterado v1.9
end

function getPlayerDesc(cid, thing, TV)
if (not isCreature(cid) or not isCreature(thing)) and not TV then return "" end

local pos = getThingPos(thing)
local ocup = youAre[getPlayerGroupId(thing)]
local rank = (getPlayerStorageValue(thing, 86228) <= 0) and "Treinador Pokemon" or lookClans[getPlayerStorageValue(thing, 86228)][getPlayerStorageValue(thing, 862281)]
local name = thing == cid and "você mesmo" or getCreatureName(thing)     
local art = thing == cid and "Você é" or (getPlayerSex(thing) == 0 and "Ela é" or "Ele é")
   
local str = {}
table.insert(str, "Você está vendo "..name..". "..art.." ")
if youAre[getPlayerGroupId(thing)] then
   table.insert(str, (ocup).." e "..rank.." de ".. getTownName(getPlayerTown(thing))..".")       
else
   table.insert(str, (rank).." de ".. getTownName(getPlayerTown(thing))..".")
end
if getPlayerGuildId(thing) > 0 then
   table.insert(str, " "..art.." "..getPlayerGuildRank(thing).." do "..getPlayerGuildName(thing)..".")
end
if TV then
   table.insert(str, " "..art.." watching TV.")
end
table.insert(str, ((isPlayer(cid) and youAre[getPlayerGroupId(cid)]) and "\nPosition: [X: "..pos.x.."][Y: "..pos.y.."][Z: "..pos.z.."]" or ""))

return table.concat(str)
end

function ehNPC(cid)   --alterado v1.9
return isCreature(cid) and not isPlayer(cid) and not isSummon(cid) and not isMonster(cid)
end

function ehMonstro(cid)   --alterado v1.9
return cid and cid >= AUTOID_MONSTERS and cid < AUTOID_NPCS
end

function isPosEqual(pos1, pos2)
      if pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z then
         return true
      end    
return false
end

function isPosInArray(array, pos)
if not next(array) then return false end
for i = 1, #array do
    if isPosEqual(pos, array) then
       return true
    end
end
return false
end

function canWalkOnPos(pos, creature, pz, water, sqm, proj)
if not pos then return false end
if not pos.x then return false end
if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid <= 1 and sqm then return false end
if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 919 then return false end
if isInArray({4820, 4821, 4822, 4823, 4824, 4825}, getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid) and water then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if hasSqm(pos) and getTileInfo(pos).protection and pz  then return false end
    local n = not proj and 3 or 2                                    --alterado v1.6
    for i = 0, 255 do
        pos.stackpos = i                           
        local tile = getTileThingByPos(pos)        
        if tile.itemid ~= 0 and i ~= 253 and not isCreature(tile.uid) then     --edited
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
    end   
return true
end

function isWalkable(pos, creature, proj, pz, water)-- by Nord
    if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
    if isWaterTile(getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid) and water then return false end
    if getTopCreature(pos).uid > 0 and creature 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 ~= 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


conds = {
["Slow"] = 3890,
["Confusion"] = 3891,  
["Burn"] = 3892,
["Poison"] = 3893,
["Fear"] = 3894,
["Stun"] = 3895,
["Paralyze"] = 3896,                              
["Leech"] = 3897,
["Buff1"] = 3898,
["Buff2"] = 3899,
["Buff3"] = 3900,
["Miss"] = 32659,   
["Silence"] = 32698,     
["Sleep"] = 98271,
}
function isSilence(cid)
    if not isCreature(cid) then return false end
    if getPlayerStorageValue(cid, conds["Silence"]) >= 0 then return true end
return false
end

function isParalyze(cid)      
    if not isCreature(cid) then return false end
    if getPlayerStorageValue(cid, conds["Paralyze"]) >= 0 then return true end
return false
end
    
function isSleeping(cid)
    if not isCreature(cid) then return false end
    if getPlayerStorageValue(cid, conds["Sleep"]) >= 0 then return true end
return false
end

function doRegainSpeed(cid)              --alterado v1.9 \/
if not isCreature(cid) then return true end

   local speed = playerSpeed
   if isMonster(cid) then
      speed = getCreatureBaseSpeed(cid)
   elseif isPlayer(cid) and isInArray({4, 5, 6, 15}, getPlayerGroupId(cid)) then
      speed = 200 * getPlayerGroupId(cid)
   end
   
   doChangeSpeed(cid, -getCreatureSpeed(cid))
   if getCreatureCondition(cid, CONDITION_PARALYZE) == true then
      doRemoveCondition(cid, CONDITION_PARALYZE)
      addEvent(doAddCondition, 10, cid, paralizeArea2)             
   end
   
   if isADM(cid) then
      speed = 15000
   end
    
doChangeSpeed(cid, speed)
return speed
end

function doPlayerAddExp_2(cid, exp)
if not isCreature(cid) then return true end
   doPlayerAddExp(cid, exp)
   doSendAnimatedText(getThingPos(cid), exp, 215)
end

function doWalkAgain(cid)
   if not isCreature(cid) then return true end
   if getCreatureTarget(cid) >= 1 then
      setMoveSummon(master, true)
      return true
   end
   local master = getCreatureMaster(cid)
   local pox, poy = getPlayerStorageValue(cid, 505), getPlayerStorageValue(cid, 506)
   
   if pox == -1 and poy == -1 then
       addEvent(doWalkAgain, 200, cid)
       return true
   end
   
       if getThingPos(master).x ~= pox or getThingPos(master).y ~= poy then
         setMoveSummon(master, true)
       end
   addEvent(doWalkAgain, 200, cid)
end

function doMovePokeToPos(cid, pos)
if not isCreature(cid) then return true end
   doMoveCreatureToPos(cid, pos)
end

function getSpeed(cid)
    if not isCreature(cid) then return 0 end
return tonumber(getPlayerStorageValue(cid, 1003))
end

function isGhost(cid)
      
end

function isGhostPokemon(cid)
    if not isCreature(cid) then return false end
    local ghosts = {"Gastly", "Haunter", "Gengar", "Shiny Gengar", "Misdreavus", "Shiny Abra"}
return isInArray(ghosts, getCreatureName(cid))
end

function updateGhostWalk(cid)
    if not isCreature(cid) then return false end
    local pos = getThingPos(cid)
    pos.x = pos.x + 1
    pos.y = pos.y + 1
    local ret = getThingPos(cid)
    doTeleportThing(cid, pos, false)
    doTeleportThing(cid, ret, false)
return true
end

--- funcs
function getTopCorpse(position)
local pos = position
for n = 1, 255 do
    pos.stackpos = n
    local item = getTileThingByPos(pos)
    if (string.find(getItemNameById(item.itemid), "fainted") or string.find(getItemNameById(item.itemid), "defeated ")) then
       return getTileThingByPos(pos)
    end
end
return null
end


function doCorrectPokemonName(poke)
return doCorrectString(poke)
end

function doCorrectString(str)
local name = str:explode(" ")  --alterado v1.9
local final = {}
for _, s in ipairs(name) do
    table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
end
return table.concat(final, (name[2] and " " or ""))
end  

---------------------------------------- Order (Não mexer) ----------------------------------------
function getPokemonName(cid)
   return getCreatureName(cid)
end

function isRiderOrFlyOrSurf(cid)
   if getPlayerStorageValue(cid, orderTalks["surf"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["ride"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["fly"].storage) == 1 then
      return true
   end
   return false
end

function doEreasPlayerOrder(cid)
   setPlayerStorageValue(cid, orderTalks["surf"].storage, -1)
   setPlayerStorageValue(cid, orderTalks["ride"].storage, -1)
   setPlayerStorageValue(cid, orderTalks["fly"].storage, -1)
end

function isRider(cid)
   if getPlayerStorageValue(cid, orderTalks["ride"].storage) == 1 then
      return true
   end
   return false
end

function isFly(cid)
   if getPlayerStorageValue(cid, orderTalks["fly"].storage) == 1 then
      return true
   end
   return false
end

function isSurf(cid)
   if getPlayerStorageValue(cid, orderTalks["surf"].storage) == 1 then
      return true
   end
   return false
end

function isUsingOrder(cid)
   if getPlayerStorageValue(cid, orderTalks["headbutt"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["dig"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["cut"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["rock"].storage) == 1 then
      return true
   end
   return false
end

function doEreaseUsingOrder(cid)
   setPlayerStorageValue(cid, orderTalks["dig"].storage, -1)
   setPlayerStorageValue(cid, orderTalks["cut"].storage, -1)
   setPlayerStorageValue(cid, orderTalks["rock"].storage, -1)
   setPlayerStorageValue(cid, orderTalks["headbutt"].storage, -1)
end

function doSendMsg(cid, msg)
    if not isPlayer(cid) then return true end
    doPlayerSendTextMessage(cid, 27, msg)
end

function doCopyPokemon(cid, copy, eff)
    local item = getPlayerSlotItem(getCreatureMaster(cid), 8)
    local sid = getCreatureMaster(cid)
    local pos, dir = getThingPos(cid), getPlayerLookDir(cid)
            local blockToDitto = {"Shiny Snorlax", "Unown", "Shiny Abra", "Castform", "Smeargle", "Articuno", "Moltres", "Zapdos", "suicune", "Raikou", "Entei", "Minun And Plusle", "Metagross", "Magmortar", "Milotic", "Tangrowth", "Rhyperior", "Dusknoir", "Slaking", "Salamence", "Electivire", "Kecleon", "Rotom", "Froslass"}    
                
                if isInArray(blockToDitto, copy) then
                   doSendMsg(sid, "Can't copy this pokemon.")
                   return true
                end
                
                if isInDuel(sid) then
                   doSendMsg(sid, "You can't turn your ditto into a duel.")
                   return true
                end
    
                local nick = retireShinyName(getItemAttribute(item.uid, "poke"))
                      if getItemAttribute(item.uid, "poke") == "Ditto" and isShinyName(copy) then
                         doSendMsg(sid, "Only a Shiny Ditto can turn into Shiny-type pokemons.")
                         return true
                      end
                
                      if getItemAttribute(item.uid, "nick") then
                         nick = getItemAttribute(item.uid, "nick")
                      end
                      
                      if getItemAttribute(item.uid, "copyName") == copy then
                         doSendMsg(sid, "Your ditto is already a copy of " .. copy)
                         return true
                      end
                      
                      if not pokes[copy] then
                         doSendMsg(cid, "This is not a pokemon.")
                         print(">>>>>DittoBUG: " .. copy)
                         return true
                      end
                      
                doPlayerSay(sid, nick..", copie o "..retireShinyName(copy)..".")
                
                local heath_toDrawPercent = getCreatureMaxHealth(cid) - getCreatureHealth(cid)
                doRemoveCreature(cid)
                local poke = doCreateMonsterNick(sid, copy, nick, pos, true)
                      doTeleportThing(poke, pos)
             
            setPlayerStorageValue(poke, 510, copy)
            doCreatureSetLookDir(poke, dir)
            doItemSetAttribute(item.uid, "copyName", copy)
            doSendPlayerExtendedOpcode(sid, opcodes.OPCODE_BATTLE_POKEMON, tostring(poke))
            doUpdateMoves(sid)
             getPokeDistanceToTeleport(poke)
             adjustStatus(poke, item.uid, true, heath_toDrawPercent, true)
             setPokemonGhost(poke)
             if eff then
               doSendMagicEffect(pos, 184)
             end
             
            -- doOTCSendPokemonHealth(sid)
end

function round(num, idp)
  return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

function doGoPokemonInOrder(cid, item, goMsg)
    if getPlayerSlotItem(cid, 8).uid ~= item.uid then
       return true
    end
    
    item = getPlayerSlotItem(cid, 8)
    if item.uid == 0 then return true end
    
             local name = getItemAttribute(item.uid, "poke")
             local nick = name
                  if isInArray({"Ditto", "shiny ditto"}, name:lower()) then
                     name = getItemAttribute(item.uid, "copyName")
                  end
            
             local effe = pokeballs[getPokeballType(item.itemid)].effect
       
         
            if getItemAttribute(item.uid, "nick") then
                 nick = getItemAttribute(item.uid, "nick")
            end
            
            pokeSourceCode = doCreateMonsterNick(cid, name, retireShinyName(nick), getThingPos(cid), true)
            if not pokeSourceCode then
               doSendMsg(cid, "Erro. Comunique esse codigo ao GM. [31121994]")
               return true
            end
            
             local poke = getCreatureSummons(cid)[1]
             doTeleportThing(poke, farWayPos)
             doTeleportThing(poke, getThingPos(cid))
             
             
             doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_BATTLE_POKEMON, tostring(poke))
             setPlayerStorageValue(poke, 510, name)
             doCreatureSetLookDir(poke, getPlayerLookDir(cid))
             getPokeDistanceToTeleport(poke)
             setMoveSummon(cid, true)
             doUpdateMoves(cid)
             doUpdateCooldowns(cid)

             doItemEraseAttribute(item.uid, "healthChanged")
             adjustStatus(poke, item.uid, true, true, true)
             setPokemonGhost(poke)
             if getCreatureSkullType(cid) == 5 then
                doCreatureSetSkullType(cid, 0)
             end
             --setCreatureMaxHealth(poke, getBallMaxHealth(cid, item))
             --doCreatureAddHealth(poke, -(getCreatureHealth(poke)-1))
             --doCreatureAddHealth(poke, (getBallHealth(cid, item)-1))
             --doItemSetAttribute(item.uid, "healthChanged", getCreatureName(cid))
             --doOTCSendPokemonHealth(cid)
end

function doUp(cid, summon, move)
                     local pokeName = getItemAttribute(getPlayerSlotItem(cid, 8).uid, "poke")
                     local ditto = getItemAttribute(getPlayerSlotItem(cid, 8).uid, "copyName")
                          if ditto and ditto ~= "" then
                             pokeName = ditto
                          end
                     local outfit = getPokemonOutfitToSkill(pokeName)
                     local speed = getPokemonSpeedToSkill(pokeName)
                     addEvent(doRemoveCreature, 10, summon)
                     doSetCreatureOutfit(cid, {lookType = outfit + 351}, -1)
                     
                     doChangeSpeed(cid, -getCreatureSpeed(cid))
                     doChangeSpeed(cid, speed)

                     if #getCreatureSummons(cid) > 1 and getPlayerStorageValue(cid, 212124) <= 0 then     --alterado v1.6
                       if getPlayerStorageValue(cid, 637501) == -2 or getPlayerStorageValue(cid, 637501) >= 1 then  
                          BackTeam(cid)       
                       end
                     end
                    
                    if move == "ride" then
                     setPlayerStorageValue(cid, orderTalks["ride"].storage, 1)
                    elseif move == "fly" then
                     setPlayerStorageValue(cid, orderTalks["fly"].storage, 1)
                    end
                    setPokemonGhost(cid)
                    
                    doPlayerSendCancel(cid, '12//,hide') --alterado v1.7
    
end


function getCylinderTiles(pos, cilinderSize) -- By SmiX
local position = pos
local c = cilinderSize
local pos = {}
for i=-c, c do
        for j=-c, c do
                local posEffect = {x=position.x+i,y=position.y+j,z=position.z}
                  table.insert(pos, posEffect)
        end
end
   return pos
end

function recheck(sid, skill, pos)
    if not isCreature(sid) or not isCreature(getCreatureMaster(sid)) then return end
    if not isUsingOrder(sid) then return true end
    local cid = getCreatureMaster(sid)

    if skill == "cut" then

        local item = getTileItemById(pos, 2767)
        if not item or item.uid <= 0 then return true end
        
        doCreatureSay(sid, "CUT!", TALKTYPE_MONSTER)
        doSendMagicEffect(getThingPos(item.uid), EFFECT_CUT)
        doTransformItem(item.uid, 6216)
        local function growRock()
            doTransformItem(getTileItemById(pos, 6216).uid, 2767)
            end
        addEvent(growRock, tempoPraVoltarAoNormal * 1000)
 
    elseif skill == "rock" then

        local item = getTileItemById(pos, 1285)
        if not item or item.uid <= 0 then return true end
        
        doCreatureSay(sid, "ROCK SMASH!", TALKTYPE_MONSTER)
        doSendMagicEffect(getThingPos(item.uid), EFFECT_DIG)
        doTransformItem(item.uid, 3610)
            local function growRock()
            doTransformItem(getTileItemById(pos, 3610).uid, 1285)
            end
        addEvent(growRock, tempoPraVoltarAoNormal * 1000)
        
 elseif skill == "headbutt" then  --alterado v1.6

    local item = getTileItemById(pos, 2707)    --id do item   arvore normal
        if not item or item.uid <= 0 then return true end
            
    local master = getCreatureMaster(sid)
    local array = {}                           
    local lvl = {25, 40, 60, 80, 150, 1000} --lvls

    for i = 1, #lvl do
        if getPlayerLevel(master) <= lvl then
           array = headbutt[lvl]
           break
        end
    end
    local rand = array[math.random(#array)]
    for j = 1, rand[2] do        
        local poke = doCreateMonster(rand[1] , getClosestFreeTile(sid, pos))
        --doCreatureSay(sid, rand[1], TALKTYPE_MONSTER)
    end
    doCreatureSay(sid, "HEADBUTT!", TALKTYPE_MONSTER)
    doSendMagicEffect(getThingPos(item.uid), EFFECT_DIG)
    doTransformItem(item.uid, 2702)  --id do item   arvore quebrada
    local function growHead()
          doTransformItem(getTileItemById(pos, 2702).uid, 2707) --id do item  arvore quebrada, arvore normal
    end
    addEvent(growHead, choose(5, 8, 10, 15) * 60 * 1000)   --o tempo pra arvore voltar ao normal varia de 5~30min
end
   doEreaseUsingOrder(sid)   
end

function choose(...) -- by mock
    local arg = {...}
    return arg[math.random(1,#arg)]
end


function getFreeTile(pos)
   if canWalkOnPos(pos, true, false, false, false, false) then
      return pos
   end
   local tmp
   for dir = 0, 7 do
      tmp = getPosByDir(pos, dir)
      if canWalkOnPos(tmp, true, false, false, false, false) then
         return tmp
      end
   end
   return farWayPos
end

------------------------ marcar a pos do spawn do poke e retornar ela
function doMarkedSpawnPos(cid)
local pos = getThingPos(cid)
    setPlayerStorageValue(cid, storages.markedPosPoke, "x = "..pos.x..", y = "..pos.y..", z = "..pos.z..";")
end

function doMarkedPos(cid, pos)
    setPlayerStorageValue(cid, storages.markedPosPoke, "x = "..pos.x..", y = "..pos.y..", z = "..pos.z..";")
end

function isInPartyAndSharedExperience(cid)
    if isInParty(cid) and isPartyEnabledExp(cid) then
       return true
    end
    return false
end

function getMarkedSpawnPos(cid)
 local l = {}
 local pos = getPlayerStorageValue(cid, storages.markedPosPoke)
 local strPos = "x = (.-), y = (.-), z = (.-);"
   for a, b, c in pos:gmatch(strPos) do
      l = {x = tonumber(a), y = tonumber(b), z = tonumber(c)}
   end
   return l
end

function doComparePositions(position, positionEx)
return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end
------------------------ marcar a pos do spawn do poke e retornar ela

function doPlayerAddPoke(cid, pokeName, ball, unique)
    local ballid = pokeballs[ball]
    local send = false

    if not ballid then
        return print("doPlayerAddPoke: Não foi encontrada a pokebola: "..ball)
    end

    if isUseIconSystem(cid) then
        id = pokeballs[string.lower(pokeName)].on
    else
        id = ballid.on
    end

    if (getPlayerFreeCap(cid) <= 1 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
        item = doCreateItemEx(id)
        send = true
    else
        item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, id, 1)
    end

    doItemSetAttribute(item, "health", getPokemonHealth(pokeName))
    doItemSetAttribute(item, "maxHealth", getPokemonHealth(pokeName))
    doItemSetAttribute(item, "pokeName", doCorrectString(pokeName))
    doItemSetAttribute(item, "ballEffe", ball)

    if send then
        doPlayerSendMailByName(getCreatureName(cid), item, 1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already holding six pokeballs, your new pokemon has been sent to the Center Pokémon.")
    end
end

function hasSpaceInContainer(container)                --alterado v1.6
if not isContainer(container) then return false end
if getContainerSize(container) < getContainerCap(container) then return true end

for slot = 0, (getContainerSize(container)-1) do
    local item = getContainerItem(container, slot)
    if isContainer(item.uid) then
       if hasSpaceInContainer(item.uid) then
          return true
       end
    end
end
return false
end

function doSendEffect(cid, effe)
if not isCreature(cid) then return true end
   doSendMagicEffect(getThingPos(cid), effe)  
end

function doSendEffectAndText(cid, effe, text, color)
if not isCreature(cid) then return true end
if not color then color = 215 end
   doSendEffect(cid, effe)
   if text and text ~= "" then
      doSendAnimatedText(getThingPos(cid), text, color)
   end
end

function setCreatureVisibility(cid, vis)
    if not isCreature(cid) then return true end
    if vis then
        doAddCondition(cid, invisiblecondition)
    else
        doRemoveCondition(cid, CONDITION_INVISIBLE)
    end
end

function setCreatureHick(cid, secs, i)
if not isCreature(cid) then return true end
    i = i +1
    local pos2 = getThingPos(cid)
          pos2.x = pos2.x + math.random(1, 4)
          pos2.y = pos2.y + math.random(1, 4)
    if(i < secs) then
      local pos = getPosByDir(pos2, math.random(0, 7))
      local master = getCreatureMaster(cid)
        if(isPlayer(master)) then
           setMoveSummon(master, false)
        end
      doAddCondition(cid, bebo)
      doMovePokeToPos(cid, pos)
      pos = getThingPos(cid)
      pos.y = pos.y -1
      doSendMagicEffect(pos, 31)
      addEvent(setCreatureHick, 1000, cid, secs, i)
    else
       doRemoveCondition(cid, CONDITION_DRUNK)
    end
end

function doRemoveConditionWithSecurity(cid, cond)
if not isCreature(cid) then return true end
         doRemoveCondition(cid, cond)
end

function doCanAttackOther(cid, target)

setPlayerStorageValue(cid, storages.teamRed, 1)
setPlayerStorageValue(target, storages.teamBlue, 1)

end

function isInDuel(cid)
if not isCreature(cid) then return false end
   if getPlayerStorageValue(cid, storages.isInDuel) == 1 then
      return true
    end
   return false
end

-------------- pokedex
function getPokemonVitalityD(name)
    if not pokes[name] then return false end
    return pokes[name].vitality
end

function getPokemonAttackD(name)
    if not pokes[name] then return false end
    return pokes[name].offense
end

function getPokemonDefenseD(name)
    if not pokes[name] then return false end
    return pokes[name].defense
end

function getPokemonSpAttackD(name)
    if not pokes[name] then return false end
    return pokes[name].specialattack
end

function getPokemonLevelD(name)
    if not pokes[name] then return false end
    if pokes[name].level <= 1 then
        return 5
    end
    return pokes[name].level
end

function getPokemonPortraitD(name)
    if not pokes[name] then return false end
    return pokes[name].portrait
end

 

function getPokemonType1D(name)
    if not pokes[name] then return "normal" end
    return pokes[name].type
end

function getPokemonType2D(name)
    if not pokes[name] or not pokes[name].type2 then return false end
    return pokes[name].type2
end

function getPokemonHealthD(name)                
    if not pokes[name] then return false end
    return getMonsterInfo(name).healthMax
end

function getPokemonExperienceD(name)
    if not pokes[name] then return false end
    return getMonsterInfo(name).experience
end

function getPokemonCatchedStorage(name)
    if not pokes[name] then return false end
    return getMonsterInfo(name).lookCorpse
end

function getPokemonCorpse(name)
    if not pokes[name] then return false end
    return getMonsterInfo(name).lookCorpse
end

 

meu pokewalk:

 

Spoiler

function onMove(cid, fromPosition, toPosition)
     if isPlayer(cid) then
    
        movePlayerListWatchingMe(cid, toPosition)
        
        if getCreatureSkullType(cid) == SKULL_WHITE then
            local p2 = getPlayerByName(getPlayerAdvers(cid))
            if getDistanceBetween(getThingPos(p2), toPosition) > 3 then
                  doWin(p2)
                  doGiveUP(cid)
                  doSendMsg(cid, "You distanced yourself from your opponent.")
                  doSendMsg(p2, getCreatureName(cid) .. " has distanced himself from you.")
            end
        elseif getCreatureSkullType(cid) == 1 or getCreatureSkullType(cid) == 2 then
            local p2 = getPlayerByName(getPlayerAdvers(cid))
            if getDistanceBetween(getThingPos(p2), toPosition) > 3 then
                doEreaseDuel(cid) doEreaseDuel(p2)
            end
        end

        setMoveSummon(cid, true)
        
        if isInArray({1467, 1468}, getCreatureOutfit(cid).lookType) then--fishing cancel
          setPlayerStorageValue(cid, 154585, -1)
          doRemoveCondition(cid, CONDITION_OUTFIT)
        end
        
        local max = 6 --- poke teletrasporte
        local eff = 21
        local sum = getCreatureSummons(cid)
            if #sum >= 1 then
            local posSummon = getThingPos(sum[1])
               if getDistanceBetween(getThingPos(cid), getThingPos(sum[1])) > max or posSummon.z ~= toPosition.z then
                  doTeleportThing(sum[1], getThingPos(cid), false)
                  doSendMagicEffect(getThingPos(sum[1]), eff)
               end
            end
        return true
     end
     
     if isWild(cid) then
        if getTileInfo(toPosition).itemid == 460 then
           return false
        end
        
        if type(toPosition) == "table" and getTileInfo(toPosition).protection then
           return false
        end
        onWalkSetTargetPassive(cid)
        if getDistanceBetween(toPosition, getMarkedSpawnPos(cid)) > 25 then
          doSendMagicEffect(toPosition, 21)
          doTeleportThing(cid, getMarkedSpawnPos(cid))
          doSendMagicEffect(getThingPos(cid), 21)
          return false
        end
     end
    
     if not isWalkable(toPosition, true, true, false, true) then -- bug dos pokes andarem na agua
        return false
     end
      
      if isSummon(cid) then
           local owner = getCreatureMaster(cid)
      
          -- Summon nao andar em pz caso seu dono esteja em duel
          if getTileInfo(toPosition).protection and (getCreatureSkullType(owner) == SKULL_WHITE or getCreatureSkullType(owner) == 1 or getCreatureSkullType(owner) == 2) then
            return false
          end
            
          if getPlayerStorageValue(owner, 500) == -1 then
             return true
          end
        
         if isRiderOrFlyOrSurf(cid) then
          local cilinderPos = getSpectators(toPosition, 1, 1, false)
             for i, tid in ipairs(cilinderPos) do
                 if (isPlayer(tid) and tid == owner) then  
                 
                    if isRider(cid) then
                     doUp(tid, cid, "ride")
                    elseif isFly(cid) then
                     doUp(tid, cid, "fly")
                    end
                    
                 end
             end
             return true
          elseif isUsingOrder(cid) then
                 local markPos = getMarkedSpawnPos(cid)
                 local dig = getPlayerStorageValue(cid, orderTalks["dig"].storage)
                 local cut = getPlayerStorageValue(cid, orderTalks["cut"].storage)
                 local rock = getPlayerStorageValue(cid, orderTalks["rock"].storage)
                 local head = getPlayerStorageValue(cid, orderTalks["headbutt"].storage)
                 local item, effe = 0, 0
                 local pos = toPosition
                       pos.stackpos = 0
                 local thing = getThingFromPos(pos)       
                 
                 if cut == 1 then
                    local pos = getCylinderTiles(markPos, 1)
                     for i = 1, #pos do
                         if not isUsingOrder(cid) then break end
                              if doComparePositions(pos, toPosition) then
                                 recheck(cid, "cut", markPos)
                                 break
                        end
                     end
                     return true
                 elseif rock == 1 then
                    local pos = getCylinderTiles(markPos, 1)
                     for i = 1, #pos do
                         if not isUsingOrder(cid) then break end
                              if doComparePositions(pos, toPosition) then
                                 recheck(cid, "rock", markPos)
                                 break
                        end
                     end
                     return true  
                 elseif head == 1 then
                    local pos = getCylinderTiles(markPos, 1)
                     for i = 1, #pos do
                         if not isUsingOrder(cid) then break end
                              if doComparePositions(pos, toPosition) then
                                 recheck(cid, "headbutt", markPos)
                                 break
                        end
                     end
                     return true    
                 end  
                 
                 if doComparePositions(pos, markPos) then
                     if dig == 1 then
                        item = thing.itemid+1
                        effe = EFFECT_DIG  
                     end
                     
                     local thing = getThingFromPos(pos)
                     doMovePokeToPos(cid, fromPosition)
                     doTransformItem(thing.uid, item)
                     doDecayItem(thing.uid)
                     doSendMagicEffect(pos, effe)
                     doEreaseUsingOrder(cid)
                 end  
                 
             return true
          end
        
    end
return true
end

 

acredito que possa ser problema no order também, então:

 

Spoiler

function onUse(cid, item, frompos, item2, topos)

if getCreatureCondition(cid, CONDITION_EXHAUST) or isWatchingTv(cid) then return true end
doAddCondition(cid, ordercondition)

local pPos = getThingPos(cid)
      pPos.stackpos = 0
local pos = getThingFromPos(pPos)
      
if isSurf(cid) or isInArray(11756, item2.itemid) or item2.itemid == 11756 or isInArray(11756, pos.itemid) or pos.itemid == 11756 or isInArray({11756, 11675, 11676, 460}, pos.itemid) then
   return doPlayerSendCancel(cid, MSG_NAO_E_POSSIVEL)
end

if item2.uid == cid then -- demound poke
    if isPlayer(item2.uid) and isInDuel(item2.uid) then
       return doPlayerSendCancel(cid, MSG_NAO_E_POSSIVEL)
    end
   if isRiderOrFlyOrSurf(cid) then
      local ball = getPlayerSlotItem(cid, 8)
            doGoPokemonInOrder(cid, ball, false)
            doRemoveCondition(cid, CONDITION_OUTFIT)
            doPlayerSay(cid, getCreatureNick(getCreatureSummons(cid)[1]) .. orderTalks["downability"].talks[math.random(#orderTalks["downability"].talks)])
            
            doRegainSpeed(cid)
            
            setPlayerStorageValue(cid, orderTalks["ride"].storage, -1)
            setPlayerStorageValue(cid, orderTalks["fly"].storage, -1)
            doPlayerSendCancel(cid, '12//,show')
      return true
   end
end
--- ride/fly retirada


if isRiderOrFlyOrSurf(cid) then
   return doPlayerSendCancel(cid, MSG_NAO_E_POSSIVEL)
end
   
if #getCreatureSummons(cid) == 0 then
  return doPlayerSendCancel(cid, "You need a Pokémon to use order.")
end
    
local poke = getCreatureSummons(cid)[1]
local pokeName = getCreatureNick(poke)
local habilidades = getPokemonSkills(getCreatureName(poke))  
 
if item2.uid == cid then

   if isFight(cid) then  -- Edição pra ficar igual pxg.. nao dar fly ou ride com fight
       setMoveSummon(cid, false)
       addEvent(doMovePokeToPos, 5, poke, getThingPos(cid))
       return true
   end
   
   if isMega(poke) then
     return doPlayerSendCancel(cid, "Mega evolutions can't fly or ride.")
   end
   
    if isPlayer(item2.uid) and (isInDuel(item2.uid) or getCreatureSkullType(item2.uid) == SKULL_WHITE or getCreatureSkullType(item2.uid) == 1 or getCreatureSkullType(item2.uid) == 2) then
       return doPlayerSendCancel(cid, MSG_NAO_E_POSSIVEL)
    end
   
   if not (getThingPos(poke) or getThingPos(item2.uid)) then -- correção de um erro.
      return true
   end
   local dist = getDistanceBetween(getThingPos(poke), getThingPos(item2.uid))   
   --- ride
   if string.find(habilidades, "ride") then
      doPlayerSay(cid, pokeName..orderTalks["ride"].talks[math.random(#orderTalks["ride"].talks)])
      
      if dist == 1 then
        doUp(cid, poke, "ride")
      return true
      end
      
      setMoveSummon(cid, false)
      addEvent(doMovePokeToPos, 200, poke, topos)
      setPlayerStorageValue(poke, orderTalks["ride"].storage, 1)
      
   elseif string.find(habilidades, "fly") or string.find(habilidades, "levitate") then
   
       if string.find(habilidades, "levitate") then
          doPlayerSay(cid, pokeName..orderTalks["levitate"].talks[math.random(#orderTalks["levitate"].talks)])
       else
          doPlayerSay(cid, pokeName..orderTalks["fly"].talks[math.random(#orderTalks["fly"].talks)])
       end
       
       if dist == 1 then
        doUp(cid, poke, "fly")
       return true
       end
       
      setMoveSummon(cid, false)
      addEvent(doMovePokeToPos, 200, poke, topos)
      setPlayerStorageValue(poke, orderTalks["fly"].storage, 1)
   end  
----------------- Ditto -----------------
elseif isMonster(item2.uid) and isInArray({"Shiny Ditto", "Ditto"}, getItemAttribute(getPlayerSlotItem(cid, 8).uid, "poke"))  then
       
       if isPlayer(item2.uid) and isInDuel(item2.uid) then
         return doPlayerSendCancel(cid, MSG_NAO_E_POSSIVEL)
       end
       
       local listaproibidos = {"Mew", "Mewtwo", "groudon", "suicune", "raiko", "entei", "moltres", "articuno", "zapdos", "rayquaza"}
       if isInArray(listaproibidos, getCreatureName(item2.uid)) then
            doSendMsg(cid, "Your ditto can't copy these Pokémon.")
         return true
       end
       
       if isPlayerSummon(cid, item2.uid) and isInArray({"Shiny Ditto", "Ditto"}, getItemAttribute(getPlayerSlotItem(cid, 8).uid, "poke")) and not isInArray({"Shiny Ditto", "Ditto"}, getItemAttribute(getPlayerSlotItem(cid, 8).uid, "copyName")) then
       
          doCopyPokemon(poke, getItemAttribute(getPlayerSlotItem(cid, 8).uid, "poke"), true)
          doPlayerSay(cid, getCreatureNick(getCreatureSummons(cid)[1])..", reverta-se.")
          return true
          
       elseif not isPlayerSummon(cid, item2.uid) and getPokeName(item2.uid) ~= getPokeName(poke) then    

        if isSummon(item2.uid) then
           if getPlayerSlotItem(getCreatureMaster(item2.uid), 8).uid ~= 0 and isInArray({"Shiny Ditto", "Ditto"}, getItemAttribute(getPlayerSlotItem(getCreatureMaster(item2.uid), 8).uid, "poke")) then
              doSendMsg(cid, "Your ditto can't copy these Pokémon.")
              return true
           end
        end
           
       local thingName = doCorrectString(getCreatureName(item2.uid))
                if pokes[thingName].level > getPlayerLevel(cid) then
                    doSendMsg(cid, "Your ditto is too weak to copy this Pokémon!")
                    return true
                end
                 doCopyPokemon(poke, thingName, true)
                 return true
                 
       end
                 
      
----------------- Mover -----------------
elseif not isCreature(item2.uid) then
    
    setMoveSummon(cid, false)
    doEreaseUsingOrder(poke)
    local oldTopos = getThingPos(item2.uid)
    local oldTopos_2 = topos
    local x, y = 0, 0
         
    if (topos.x - getThingPos(poke).x)  > 0 then
       topos.x = topos.x +1
    elseif (topos.x - getThingPos(poke).x)  < 0 then
       topos.x = topos.x -1
    end
    if (topos.y - getThingPos(poke).y)  > 0 then
       topos.y = topos.y +1    
    elseif (topos.y - getThingPos(poke).y)  < 0 then
       topos.y = topos.y -1
    end  
    
    
    
    setPlayerStorageValue(poke, 505, getThingPos(cid).x)
    setPlayerStorageValue(poke, 506, getThingPos(cid).y)
    
    addEvent(doMovePokeToPos, 5, poke, topos)
    doWalkAgain(poke)
    
    
    ----- Edições dig/cut/rock smash/headbutt/blink
    local buracos = {468, 481, 483}
    local arvores = {2767, 2768}    
    local pedras = {1285, 3634, 3632, 3667}  
    local headbutt = {2707}   

    if item2.uid == 0 then return true end
    local pos = getThingPos(item2.uid)
    local dist = getDistanceBetween(getThingPos(poke), getThingPos(item2.uid))
    
       
       if not isFight(cid) then  -- Edição pra ficar igual pxg.. nao dar fly ou ride com fight         
          if isInArray(buracos, item2.itemid) then   ----------------------- DIG
          
             if not string.find(habilidades, "dig") then
                return doPlayerSendCancel(cid, "This Pokémon can't dig.")
             end
             
             doMarkedPos(poke, getThingPos(item2.uid))
             doEreaseUsingOrder(cid)
             setPlayerStorageValue(poke, orderTalks["dig"].storage, 1)
             setMoveSummon(cid, false)
             if dist == 1 then
                recheck(poke, "cut", getThingPos(item2.uid))
             else
                addEvent(doMovePokeToPos, 200, poke, topos)
             end
             doPlayerSay(cid, getCreatureNick(poke)..orderTalks["dig"].talks[math.random(#orderTalks["dig"].talks)])
             
             return true
          elseif isInArray(arvores, item2.itemid) then   ----------------------- CUT
          
             if not string.find(habilidades, "cut") then
                return doPlayerSendCancel(cid, "This Pokémon can't cut.")
             end
             
                doMarkedPos(poke, getThingPos(item2.uid))
                doEreaseUsingOrder(cid)
                setPlayerStorageValue(poke, orderTalks["cut"].storage, 1)
                setMoveSummon(cid, false)
                if dist == 1 then
                  addEvent(recheck, (1000 - (2.3*getCreatureSpeed(poke))) * dist, poke, "cut", getThingPos(item2.uid))
                else
                  addEvent(doMovePokeToPos, 200, poke, topos)
                end
                doPlayerSay(cid, getCreatureNick(poke)..orderTalks["cut"].talks[math.random(#orderTalks["cut"].talks)])
                return true
          elseif isInArray(pedras, item2.itemid) then   ----------------------- ROCK
          
             if not string.find(habilidades, "rock smash") then
                return doPlayerSendCancel(cid, "This Pokémon can't break.")
             end
             
             local pos = getThingPos(item2.uid)
                doMarkedPos(poke, getThingPos(item2.uid))
                doEreaseUsingOrder(cid)
                setPlayerStorageValue(poke, orderTalks["rock"].storage, 1)
                setMoveSummon(cid, false)
                if dist == 1 then
                  addEvent(recheck, (1000 - (2.3*getCreatureSpeed(poke))) * dist, poke, "rock", getThingPos(item2.uid))
                else
                  addEvent(doMovePokeToPos, 200, poke, topos)
                end
                doPlayerSay(cid, getCreatureNick(poke)..orderTalks["rock"].talks[math.random(#orderTalks["rock"].talks)])
                return true
                
          elseif isInArray(headbutt, item2.itemid) then   ----------------------- HEAD
          
             if not string.find(habilidades, "headbutt") then
                return doPlayerSendCancel(cid, "This Pokémon cant' headbutt.")
             end
             
            local pos = getThingPos(item2.uid)
                doMarkedPos(poke, getThingPos(item2.uid))
                doEreaseUsingOrder(cid)
                setPlayerStorageValue(poke, orderTalks["headbutt"].storage, 1)
                setMoveSummon(cid, false)
                if dist <= 1 then
                  addEvent(recheck, (1000 - (2.3*getCreatureSpeed(poke))) * dist, poke, "headbutt", getThingPos(item2.uid))
                else
                  addEvent(doMovePokeToPos, 200, poke, topos)
                end
                doPlayerSay(cid, getCreatureNick(poke)..orderTalks["headbutt"].talks[math.random(#orderTalks["headbutt"].talks)])
                
             return true
          end
          end
          if string.find(habilidades, "blink") then
                  if os.time() < getPlayerStorageValue(poke, storages.blink) and not isGod(cid) then
                     doPlayerSay(cid, getCreatureNick(poke)..orderTalks["move"].talks[math.random(#orderTalks["move"].talks)])
                     return true
                  elseif (getCreatureSkullType(cid) == SKULL_WHITE or isInDuel(cid)) and getTileInfo(getThingPos(item2.uid)).protection then
                     doSendMsg(cid, "You can't use blink in a protected zone if you are dueling.")
                     return true
                  end
                       setPlayerStorageValue(poke, storages.blink, os.time()+7)
                       doSendMagicEffect(getThingPos(poke), 134)  
                       doTeleportThing(poke, getThingPos(item2.uid), false)
                       doSendMagicEffect(getThingPos(poke), 134)
                       doPlayerSay(cid, getCreatureNick(poke)..orderTalks["blink"].talks[math.random(#orderTalks["blink"].talks)])
          
              return true
          end
         
         doPlayerSay(cid, getCreatureNick(poke)..orderTalks["move"].talks[math.random(#orderTalks["move"].talks)])
    
end    
    return true
end

function isGhost(cid)
local hab = getPokemonSkills(string.lower(getPokeName(cid)))
   if string.find(hab, "ghost")  then
      return true
   end
  return false
end

 

 

valeu tk!

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.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo