Guest User

Untitled

a guest
Apr 13th, 2017
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 62.76 KB | None | 0 0
  1. --// Edicioes DarkXPoke \\-
  2. farwayPos = {x = 2, y = 1, z = 15}
  3.  
  4. function doSendUpdatesOnlineToADM()
  5.     local player = getPlayerByNameWildcard("[ADM] One")
  6.     if player == nil then return true end
  7.     doGetPlayersOnToADM(player)
  8. end
  9.  
  10. function doGetPlayersOnToADM(cid)
  11.    local players = getPlayersOnline()
  12.    local str = "online/"
  13.    if #players > 0 then
  14.        for _, pid in ipairs(players) do
  15.           str = str .. getCreatureName(pid) .. "," .. getPlayerLevel(pid) .. "/"
  16.        end
  17.    end
  18.    doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_PLAYER_SHOW_ONLINE, str)
  19.    return str
  20. end
  21.  
  22. function getExpByMoreDano(cid)
  23. if not isCreature(cid) then return "" end
  24. local listPlayers = ""
  25. local life = getCreatureMaxHealth(cid)
  26. local str = getPlayerStorageValue(cid, storages.damageKillExp)
  27. if str == -1 then return true end -- self destruct
  28. local players = string.explode(str, "|")
  29.  
  30.     local strEnd, mairDano = "", 0
  31.     if players ~= nil then
  32.         for i = 1, #players do
  33.         local name = string.explode(players[i], "/")[1]
  34.         local dano = string.explode(players[i], "/")[2]
  35.               listPlayers = listPlayers .. name .. "/" .. (dano * 100 / life) .. "|"
  36.         end
  37.     end
  38.     return listPlayers
  39. end
  40.  
  41. function addPlayerDano(cid, attacker, newDano)
  42. if not isCreature(cid) then return true end
  43. if not isCreature(attacker) then return true end
  44. local playerName = getCreatureName(attacker)
  45. local str = getPlayerStorageValue(cid, storages.damageKillExp)
  46. if str == -1 then
  47.    setPlayerStorageValue(cid, storages.damageKillExp, playerName .. "/" .. newDano .. "|") 
  48.    return true
  49. end
  50.     local players = string.explode(str, "|")
  51.     local strEnd, imAre = "", false
  52.     if players ~= nil then
  53.         for i = 1, #players do
  54.            local name = string.explode(players[i], "/")[1]
  55.            local dano = string.explode(players[i], "/")[2]
  56.            
  57.            if name == playerName then
  58.               strEnd = strEnd .. name .. "/" .. dano + newDano .. "|"
  59.               imAre = true
  60.            else
  61.               strEnd = strEnd .. name .. "/" .. dano .. "|"
  62.            end
  63.            
  64.         end
  65.         if not imAre then
  66.            strEnd = strEnd .. playerName .. "/" .. newDano .. "|"
  67.         end
  68.         setPlayerStorageValue(cid, storages.damageKillExp, strEnd)
  69.     end    
  70.  
  71. end
  72.  
  73. function removeSpellInXML(name, spell)
  74. local path = "data/monster/pokes/geracao 1/"..name..".xml"
  75. local tpw = io.type(io.open(path))
  76. if not tpw then
  77.     path = "data/monster/pokes/geracao 2/"..name..".xml"
  78.     tpw = io.type(io.open(path))
  79. end
  80. if not tpw then return false end
  81. local line = readLineSpellXMLSOURCE(path, '"'.. spell ..'"')
  82. if line == 0 then return false end -- nao achou a spell
  83. removeSpellFromXMLSOURCE(path, line, "-->")
  84. local admNAME = "[ADM] One"
  85. doReloadInfo(RELOAD_MONSTERS, getPlayerByName(admNAME))
  86. return true
  87. end
  88.  
  89. function removeSpellFromXMLSOURCE(filename, linha, texto)
  90.  
  91.     local hFile = io.open(filename, "r") --Reading.
  92.     local lines = {}
  93.     local restOfFile
  94.     local lineCt = 1
  95.     for line in hFile:lines() do
  96.     if(lineCt == linha) then --Is this the line to modify?
  97.         lines[#lines + 1] = "<!-- Magina nao pertence a esse pokemon " .. line .. " " .. texto --Modify line by appending a string to the end.
  98.         restOfFile = hFile:read("*a")
  99.         break
  100.     else
  101.         lineCt = lineCt + 1
  102.         lines[#lines + 1] = line
  103.     end
  104.     end
  105.     hFile:close()
  106.  
  107.     hFile = io.open(filename, "w") --Write the file.
  108.     for i, line in ipairs(lines) do
  109.         hFile:write(line, "\n")
  110.     end
  111.     hFile:write(restOfFile)
  112.     hFile:close()
  113.  
  114. end
  115. function readLineSpellXMLSOURCE(filename, texto)
  116.  
  117.     local hFile = io.open(filename, "r") --Reading.
  118.     local lines = {}
  119.     local restOfFile
  120.     local lineCt = 1
  121.     local ret = 1
  122.     local achou = false
  123.     for line in hFile:lines() do
  124.     if(line:find(texto) and not line:find("pokemon")) then --Is this the line to modify?
  125.         ret = ret
  126.         achou = true
  127.         break
  128.     else
  129.         ret = ret + 1
  130.     end
  131.     end
  132.     hFile:close()
  133.     if not achou then
  134.         return 0
  135.     end
  136.     return ret
  137.  
  138. end
  139.  
  140. function isTwoGerenetion(name)
  141. local path = "data/monster/pokes/geracao 2/"..name..".xml"
  142. local tpw = io.type(io.open(path))
  143. if not tpw then
  144. return false
  145. else
  146. return true
  147. end
  148. end
  149.  
  150. function setPokemonGhost(cid)
  151. if not isCreature(cid) then return true end
  152.     if isInArray(pokesGhosts, doCorrectString(getCreatureName(cid))) then
  153.        doCreatureSetSkullType(cid, 5)
  154.     end
  155.     if isSummon(cid) then
  156.     local item = getPlayerSlotItem(getCreatureMaster(cid), 8)
  157.         if getItemAttribute(item.uid, "yHeldItem") and getItemAttribute(item.uid, "yHeldItem") == "Y-Ghost|GHOST" then -- Y-ghost
  158.            doCreatureSetSkullType(cid, 5)
  159.         end
  160.     end
  161.     if isPlayer(cid) then
  162.        local item = getPlayerSlotItem(cid, 8)
  163.        local name = getItemAttribute(item.uid, "poke")
  164.        
  165.        if isInArray({"ditto", "shiny ditto"}, name) then
  166.           if getItemAttribute(item.uid, "copyName") then
  167.              name = getItemAttribute(item.uid, "copyName")
  168.           end
  169.        end
  170.        
  171.        if isInArray(pokesGhosts, name) or (getItemAttribute(item.uid, "yHeldItem") and getItemAttribute(item.uid, "yHeldItem") == "Y-Ghost|GHOST") then -- Y-ghost
  172.            doCreatureSetSkullType(cid, 5)
  173.         end
  174.     end
  175.     setPlayerStorageValue(cid, storages.isPokemonGhost, 1)
  176. end
  177.  
  178. function isPokeGhost(cid)
  179. if not isCreature(cid) then return true end
  180.     if isInArray(pokesGhosts, doCorrectString(getCreatureName(cid))) then
  181.         return true
  182.     end
  183.     return false
  184. end
  185.  
  186. ------ Funcoes de efetividades
  187. function doSendParticleAura(cid, color)
  188. if not isCreature(cid) then return true end
  189.     if getCreatureOutfit(cid).lookAddons == 2 then
  190.       -- doSetCreatureOutfit(cid, {lookType = getCreatureOutfit(cid).lookType, lookAddons = 1, lookHead = color}, -1)
  191.     else
  192.       -- doSetCreatureOutfit(cid, {lookType = getCreatureOutfit(cid).lookType, lookAddons = 2, lookHead = color}, -1)
  193.     end
  194.     --addEvent(doSendParticleAura, 365, cid, color)
  195. end
  196.  
  197. function playerAddExp(cid, exp)
  198.     doPlayerAddExp(cid, exp)
  199.     doSendAnimatedText(getThingPos(cid), exp, 215)
  200. end
  201.  
  202. function getTableMove(name, moveName)
  203.     local x = movestable[doCorrectString(name)]
  204.     if not x then return "" end
  205.    
  206.     local z = "\n"
  207.     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}
  208.     for i = 1, #tables do
  209.         if tables[i].name == moveName then
  210.            return tables[i]
  211.         end
  212.     end
  213. end
  214.  
  215. function getMoveForce(name, moveName)
  216.     local x = movestable[doCorrectString(name)]
  217.     if not x then return "" end
  218.    
  219.     local z = "\n"
  220.     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}
  221.     for i = 1, #tables do
  222.         if tables[i].name == moveName then
  223.            return tables[i].f
  224.         end
  225.     end
  226. end
  227.  
  228. function retireShinyName(str)
  229.    if string.find(str, "Shiny") then
  230.       return str:match("Shiny (.*)")  
  231.    end
  232.    return str
  233. end  
  234.  
  235. function doPassives(cid)
  236.    
  237. end
  238.  
  239. function isReflect(cid)
  240.     return getPlayerStorageValue(cid, storages.reflect) >= 1
  241. end
  242.  
  243. function removeReflect(cid)
  244.           if not isCreature(cid) then return true end
  245.             if getPlayerStorageValue(cid, storages.reflect) >= 1 then -- reflect system
  246.                setPlayerStorageValue(cid, storages.reflect, getPlayerStorageValue(cid, storages.reflect) -1)
  247.             end
  248. end
  249. function getEffectvineCombat(cid, attacker, value)
  250. if isPlayer(cid) or isPlayer(attacker) then return false end -- seguranca do player nao atacar
  251.     local pokeRaceAttacker, pokeRaceDefender = getPokemonType(attacker).type1, getPokemonType(cid).type1
  252.     if isInArray(typeTable[pokeRaceAttacker].super, pokeRaceDefender) or isInArray(typeTable[pokeRaceAttacker].super, pokeRaceDefender) then -- elemento atacante ser mais forte que os elementos de defesa
  253.         value = value * 1.3
  254.     elseif isInArray(typeTable[pokeRaceAttacker].week, pokeRaceDefender) or isInArray(typeTable[pokeRaceAttacker].week, pokeRaceDefender) then -- elemento atacante ser mais forte que os elementos de defesa
  255.         value = value
  256.    elseif isInArray(typeTable[pokeRaceAttacker].non, pokeRaceDefender) or isInArray(typeTable[pokeRaceAttacker].non, pokeRaceDefender) then -- elemento atacante ser mais forte que os elementos de defesa
  257.         value = 0
  258.     end
  259.     if getCreatureName(cid) == "Venusaur" and value ~= 0 and isMega(cid) and isInArray({"ice", "fire"}, pokeRaceAttacker)then -- Passiva thick fat
  260.        value = value / 2
  261.     end
  262.     return value
  263. end
  264.  
  265. if pokeRaceDefender == "ghost" then         --Melee ser anulado vs ghost type.
  266.     value = 0
  267. end
  268.  
  269. function getEffectvineSpell(attacker, spellNameFromAttacker, value, cid) -- printar os elementos
  270.     if(spellNameFromAttacker ~= -1) then -- checagem de efetividades
  271.         local name = getCreatureName(attacker) -- reflect system
  272.         if isMega(attacker) then
  273.          name = getPlayerStorageValue(attacker, storages.isMega)
  274.         end
  275.        
  276.         local spellRace, pokeElement1, pokeElement2 = getMoveType(name, spellNameFromAttacker), getPokemonType(cid).type1, getPokemonType(cid).type2
  277.        
  278.         if not typeTable[spellRace] then
  279.             local remover = removeSpellInXML(doCorrectString(name), spellNameFromAttacker)
  280.             if remover then print("Magia: " .. spellNameFromAttacker .. " removida do XML: " .. doCorrectString(name) .. ".xml") end
  281.             return 0
  282.         end
  283.        
  284.         local multiplier = 1
  285.         if isInArray(typeTable[spellRace].super, pokeElement1) then
  286.             multiplier = multiplier + 0.5
  287.         end
  288.         if pokeElement2 and isInArray(typeTable[spellRace].super, pokeElement2) then
  289.             multiplier = multiplier + 0.5
  290.         end
  291.         if isInArray(typeTable[spellRace].weak, pokeElement1) then
  292.             multiplier = multiplier - 0.25
  293.         end
  294.         if pokeElement2 and isInArray(typeTable[spellRace].weak, pokeElement2) then
  295.             multiplier = multiplier - 0.25
  296.         end
  297. --Miracle eye
  298. if spellRace == "psychic" and (pokeElement1 == "dark" or pokeElement2 and pokeElement2 == "dark") and getPlayerStorageValue(attacker, 999457) > -1 then
  299.     multiplier = 0.75
  300.     setPlayerStorageValue(attacker, 999457, -1)
  301. else
  302.     if isInArray(typeTable[spellRace].non, pokeElement1) then
  303.          multiplier = multiplier * 0
  304.     end
  305.  
  306.     if pokeElement2 and isInArray(typeTable[spellRace].non, pokeElement2) then
  307.         multiplier = multiplier * 0
  308.     end
  309. end
  310.         if multiplier == 1.5 and poketype2 == "no type" then
  311.             multiplier = 2                                        
  312.         elseif multiplier == 0.75 and poketype2 == "no type" then    
  313.             multiplier = 0.5    
  314.         elseif multiplier == 1.25 then    
  315.             multiplier = 1  
  316.         end
  317.        
  318.         value = value * multiplier
  319.    
  320.         if getCreatureName(cid) == "Venusaur" and value ~= 0 and isMega(cid) and isInArray({"ice", "fire"}, spellRace)then -- Passiva thick fat
  321.            value = value / 2
  322.         end
  323.     end
  324.     return value
  325. end
  326.  
  327. function getMoveType(name, moveName)
  328.     local x = movestable[doCorrectString(name)]
  329.     if not x then return "" end
  330.    
  331.     local z = "\n"
  332.     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}
  333.     for i = 1, #tables do
  334.         if tables[i].name == moveName then
  335.            return tables[i].t
  336.         end
  337.     end
  338.         return true
  339. end
  340.  
  341. function isGod(cid)
  342. if isPlayer(cid) then
  343.   if getPlayerGroupId(cid) >= 6 then
  344.      return true
  345.   end
  346.   return false
  347. end
  348. end
  349.  
  350. function isADM(cid)
  351. if isPlayer(cid) then
  352.   if getPlayerGroupId(cid) >= 15 then
  353.      return true
  354.   end
  355.   return false
  356. end
  357. end
  358.  
  359.  
  360. function doKillPlayer(cid, attacker, hit)
  361.     if not isCreature(cid) then return true end
  362.     demountPokemon(cid)
  363.     local myName, attackerName =  getCreatureName(cid), getCreatureName(attacker)
  364.     if canWalkOnPos(getThingPos(cid), false, true, true, true, true) then
  365.         if getPlayerSex(cid) == 1 then
  366.          local corpse = doCreateItem(3058, 1, getThingPos(cid))
  367.          doDecayItem(corpse)
  368.          doItemSetAttribute(corpse, "iname", "\nYou recognize ".. myName ..". He was killed by a ".. attackerName .."")
  369.          elseif getPlayerSex(cid) == 0 then  
  370.          local corpse = doCreateItem(3065, 1, getThingPos(cid))
  371.          doDecayItem(corpse)
  372.          doItemSetAttribute(corpse, "iname", "\nYou recognize ".. myName ..". She was killed by a ".. attackerName .."")
  373.         end
  374.     end
  375.    
  376.     --setPlayerStorageValue(cid, storage.securityDead, 1)
  377.     --setPlayerGr
  378.     local townName = getTownName(getPlayerTown(cid))
  379.         if townName then
  380.           doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  381.         end
  382.     doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
  383.     doRemoveCondition(cid, CONDITION_INFIGHT)
  384.     doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_PLAYER_DEAD_WINDOW, "morreu|" .. doCorrectString(attackerName) .. "|" .. hit .. "|" .. tostring(getPortraitClientID(attackerName)) .. "|")
  385.    
  386.     addEvent(doRemoveCreatureWithS, 1, cid)
  387.     return false
  388. end
  389.  
  390. function doRemoveCreatureWithS(cid)
  391. if not isCreature(cid) then return true end
  392.    doRemoveCreature(cid)
  393. end
  394.  
  395. function doKillPlayerPokemon(cid)
  396.     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!"}
  397.     local master = getCreatureMaster(cid)
  398.     local thisball = getPlayerSlotItem(master, 8)
  399.     local ballName = getItemAttribute(thisball.uid, "poke")
  400.    
  401.    
  402.     if not isCreature(cid) or not isCreature(master) then return true end
  403.    
  404.    
  405.     if #getCreatureSummons(master) > 1 then
  406.         BackTeam(master, getCreatureSummons(master))      
  407.     end
  408.  
  409.     doSendMagicEffect(getThingPos(cid), pokeballs[getPokeballType(thisball.itemid)].effect) -- rever isso aqui
  410.     doTransformItem(thisball.uid, pokeballs[getPokeballType(thisball.itemid)].off)
  411.    
  412.     local say = deathtexts[math.random(#deathtexts)]
  413.           say = string.gsub(say, "POKENAME", getCreatureName(cid))
  414.           doCreatureSay(master, say, TALKTYPE_ORANGE_1)
  415.          
  416.           doItemSetAttribute(thisball.uid, "hpToDraw", 0)
  417.    
  418. end
  419.  
  420. function getPokemonType(cid)
  421. if isPlayer(cid) then return false end -- seguranca do player nao atacar
  422.     local name = doCorrectString(getCreatureName(cid))
  423.     if not pokes[name] then return print("getPokemonType(cid): O pokemon " .. name .. " nao tem um tipo efetivo.") end
  424.     local types = {}
  425.           types.type1 = pokes[name].type
  426.           types.type2 = pokes[name].type2  
  427.     return types
  428. end
  429.  
  430. function getElementByCombat(combat)
  431.     local element = "normal"
  432.     for a, b in pairs(typeTable) do
  433.         if(b.damageID == combat)then
  434.           element = a
  435.           break
  436.         end
  437.     end
  438.     return element
  439. end
  440.  
  441. ------ Funcoes de efetividades ----------
  442.  
  443. function  getPokemonOutfitToSkill(pokeName)
  444.     if flys[pokeName] then
  445.        return flys[pokeName][1]
  446.     elseif rides[pokeName] then
  447.        return rides[pokeName][1]
  448.     else
  449.        return surfs[pokeName].lookType
  450.     end
  451. end
  452.  
  453. function  getPokemonSpeedToSkill(pokeName)
  454.     if flys[pokeName] then
  455.        return flys[pokeName][2]
  456.     elseif rides[pokeName] then
  457.        return rides[pokeName][2] * 4.5
  458.     else
  459.        return surfs[pokeName].speed
  460.     end
  461. end
  462.  
  463. function getPokemonSkills(pokeName)  
  464.     local str = ""
  465.     for a, b in pairs(specialabilities) do
  466.         for i = 1, #b do
  467.             if(b[i] == pokeName) then
  468.                str = str .. (str == "" and "" or ", ") .. a
  469.             end
  470.         end
  471.     end
  472.     return str
  473. end
  474.  
  475. function demountPokemon(cid, kill)
  476. if not isCreature(cid) then return false end
  477. if not isRiderOrFlyOrSurf(cid) then return false end
  478.     doEreasPlayerOrder(cid)
  479.     if not kill then
  480.         local ball = getPlayerSlotItem(cid, 8)
  481.         doTransformItem(ball.uid, pokeballs[getPokeballType(ball.itemid)].off)
  482.     end
  483. end
  484.  
  485. --// Edicioes DarkXPoke \\--
  486.  
  487. function isUsingPotion(pokemon)
  488.     if getPlayerStorageValue(pokemon, storages.potion) and getPlayerStorageValue(pokemon, storages.potion) >= 1 then
  489.         return true
  490.     else
  491.         return false
  492.     end
  493. end
  494.  
  495. function isNumberPair(number)
  496.     return number % 2 == 0 and true or false
  497. end
  498.  
  499. function getCombatColor(typeAtk, pokemon)
  500.     local pokeName = getCreatureName(pokemon)
  501.     local pokeType1 = getPokemonType1(pokeName)
  502.     local pokeType2 = getPokemonType2(pokeName)
  503.     if COMBAT_COLORS[typeAtk] == 180 then
  504.         if COMBAT_TARGET_COLOR[pokeType1] ~= 180 then
  505.             return COMBAT_TARGET_COLOR[pokeType1]
  506.         elseif pokeType2 and COMBAT_TARGET_COLOR[pokeType2] ~= 180 then
  507.             return COMBAT_TARGET_COLOR[pokeType2]
  508.         else
  509.             return 180
  510.         end
  511.     else
  512.         return COMBAT_COLORS[typeAtk]
  513.     end
  514. end
  515.  
  516. function getCreatureDirectionToTarget(cid, target)
  517.     if not isCreature(cid) then return true end
  518.     if not isCreature(target) then return getCreatureLookDir(cid) end
  519.  
  520.     local dirs = {
  521.         [NORTHEAST] = {NORTH, EAST},
  522.         [SOUTHEAST] = {SOUTH, EAST},
  523.         [NORTHWEST] = {NORTH, WEST},
  524.         [SOUTHWEST] = {SOUTH, WEST}
  525.     }
  526.  
  527.     local direction = getDirectionTo(getThingPos(cid), getThingPos(target), false)
  528.     if direction <= 3 then
  529.         return direction
  530.     else
  531.         local xdistance = math.abs(getThingPos(cid).x - getThingPos(target).x)
  532.         local ydistance = math.abs(getThingPos(cid).y - getThingPos(target).y)
  533.         if xdistance > ydistance then
  534.             return dirs[direction][2]
  535.         elseif ydistance > xdistance then
  536.             return dirs[direction][1]
  537.         elseif isInArray(dirs[direction], getCreatureLookDir(cid)) then
  538.             return getCreatureLookDir(cid)
  539.         else
  540.             return dirs[direction][math.random(1, 2)]
  541.         end
  542.     end
  543. end
  544.  
  545. function getPlayerFightModeOffense(cid)
  546.     return fightMode[getPlayerStorageValue(cid, storages.fightMode)].offense
  547. end
  548.  
  549. function getPlayerFightModeDefense(cid)
  550.     return fightMode[getPlayerStorageValue(cid, storages.fightMode)].defense
  551. end
  552.  
  553. function doOTCSendPokemonHealth(cid)
  554.     local ball = getPlayerSlotItem(cid, CONST_SLOT_FEET)
  555.     local pokemon = getCreatureSummons(cid)
  556.     if not ball.uid or ball.uid <= 1 then
  557.         return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, "0|0")
  558.     end
  559.     if #pokemon >= 1 then
  560.         return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, getCreatureHealth(pokemon[1]).."|"..getCreatureMaxHealth(pokemon[1]))
  561.     end
  562.     return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, getBallHealth(cid, ball).."|"..getBallMaxHealth(cid, ball))
  563. end
  564.  
  565. function portraitSendLifeOTC(cid, ball)
  566. if not isCreature(cid) then return true end
  567.     if ball.uid and ball.uid ~= 0 then
  568.        return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, getBallHealth(cid, ball).."|"..getBallMaxHealth(cid, ball))
  569.     else
  570.        return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_POKEMON_HEALTH, "0|0")
  571.     end
  572. end
  573.  
  574. function doTransformPokeballIcon(cid, item, count, toContainer, fromContainer, fromPos, toPos) 
  575.     ----------------- Icon system -----------------
  576.     if toPos.x ~= 65535 then -- jogando no chao
  577.         if isContainer(item.uid) then
  578.          local bag = item.uid
  579.          for i = 1, #getPokeballsInContainer(bag) do
  580.              local ballNow = getPokeballsInContainer(bag)[i]
  581.              local ids = getPokeballs_ITEMS_ID_InContainer(bag)[i]
  582.        
  583.             if getItemAttributeWithSecurity(ballNow, "unique") == 'true' then
  584.                return true
  585.             end
  586.            
  587.             if not getItemAttribute(ballNow, "reverseIcon") then -- bug fix
  588.                doItemSetAttribute(ballNow, "reverseIcon", "poke")
  589.             end
  590.        
  591.              if isPokeballOn(ids) then
  592.                 doTransformItem(ballNow, pokeballs[getItemAttributeWithSecurity(ballNow, "reverseIcon")].on)
  593.              elseif isPokeballOff(ids) then
  594.                 doTransformItem(ballNow, pokeballs[getItemAttributeWithSecurity(ballNow, "reverseIcon")].off)
  595.              end
  596.              
  597.              doItemSetAttribute(ballNow, "ehDoChao", true)
  598.         end
  599.        elseif isPokeball(item.itemid) then
  600.        
  601.             if getItemAttributeWithSecurity(item.uid, "unique") == 'true' then
  602.                return true
  603.             end
  604.        
  605.             if not getItemAttribute(item.uid, "reverseIcon") then -- bug fix
  606.                doItemSetAttribute(item.uid, "reverseIcon", "poke")
  607.             end
  608.            
  609.             local pokeNamesBall = ""
  610.                 if not pokeballs[getItemAttributeWithSecurity(item.uid, "reverseIcon") or "poke"] then 
  611.                    print("Icon bugou: main function.lua [524]")
  612.                    return true
  613.                 end
  614.            
  615.              if isPokeballOn(item) then
  616.                 doTransformItem(item.uid, pokeballs[getItemAttributeWithSecurity(item.uid, "reverseIcon") or "poke"].on)
  617.              elseif isPokeballOff(item) then
  618.                 doTransformItem(item.uid, pokeballs[getItemAttributeWithSecurity(item.uid, "reverseIcon") or "poke"].off)
  619.              end
  620.              
  621.              doItemSetAttribute(item.uid, "ehDoChao", true)
  622.        end
  623.     else
  624.        if isContainer(item.uid) then
  625.          local bag = item.uid
  626.          for i = 1, #getPokeballsInContainer(bag) do
  627.              local ballNow = getPokeballsInContainer(bag)[i]
  628.              local pokeName =  string.lower(getItemAttributeWithSecurity(ballNow, "poke"))
  629.              local ids = getPokeballs_ITEMS_ID_InContainer(bag)[i]
  630.        
  631.              if isPokeballOn(ids) then
  632.                 doTransformItem(ballNow, pokeballs[pokeName].on)
  633.              elseif isPokeballOff(ids) then
  634.                 doTransformItem(ballNow, pokeballs[pokeName].off)
  635.              end
  636.              doItemSetAttribute(ballNow, "ehDoChao", false)
  637.         end
  638.        elseif isPokeball(item.itemid) then
  639.              local pokeName =  string.lower(getItemAttributeWithSecurity(item.uid, "poke"))
  640.              if isPokeballOn(item) then
  641.                 doTransformItem(item.uid, pokeballs[pokeName].on)
  642.              elseif isPokeballOff(item) then
  643.                 doTransformItem(item.uid, pokeballs[pokeName].off)
  644.              end
  645.        end
  646.     end
  647.    ----------------- Icon system -----------------    
  648. end
  649.  
  650. function doSetAttributesBallsByPokeName(cid, ball, name)
  651. name = doCorrectString(name)
  652. local bTypeName = getItemAttribute(ball, "ball")
  653. if string.find(name, "Shiny") then
  654.    bTypeName = "shiny" .. bTypeName
  655. end
  656.    
  657. doItemSetAttribute(ball, "poke", name)
  658. doItemSetAttribute(ball, "ballEffe", bTypeName)
  659. doItemSetAttribute(ball, "hpToDraw", 0)
  660. doItemSetAttribute(ball, "Icon", name:lower())
  661. doItemSetAttribute(ball, "reverseIcon", bTypeName)
  662. doItemSetAttribute(ball, "pokeDeath", false)
  663. doItemSetAttribute(ball, "initialKit", true)
  664.  
  665. if not pokes[name] then
  666.    print("Pokemon nao existe: " .. name)
  667.    return true
  668. end
  669. local pokeLifeMax = pokes[name].life
  670. local masterLevel = getPlayerLevel(cid)
  671. local lifePercentByLevel = 100 * masterLevel + (pokes[name].vitality * masterLevel)
  672.     if(pokes[name].level < 60) then
  673.         lifePercentByLevel = pokes[name].vitality * masterLevel * ( masterLevel > 60 and 1.5 or 1 )
  674.     end
  675. local life = pokeLifeMax + lifePercentByLevel
  676. setBallHealth(ball, life, life)
  677. end
  678.  
  679. function getPokeballName(ball)
  680.       return getItemAttribute(ball.uid, "poke")
  681. end  
  682.  
  683. function getPokeName(cid)
  684. if not isCreature(cid) then return "" end
  685.    return getPlayerStorageValue(cid, 510) or getCreatureName(cid)
  686. end
  687.  
  688. function isFight(cid)
  689.   if getCreatureCondition(cid, CONDITION_INFIGHT) then
  690.      return true
  691.   end
  692. return false
  693. end
  694.  
  695. function getBallEffect(ball)
  696.     return pokeballs2[getItemAttribute(ball.uid, "ballEffe")].eff or 188
  697. end
  698.  
  699. function getBallType(ball)
  700.     return getItemAttribute(ball.uid, "ballEffe") or "poke"
  701. end
  702.  
  703. function setBallHealth(ball, health, maxHealth)
  704.     doItemSetAttribute(ball, "hpNow", health)
  705.     doItemSetAttribute(ball, "hpMax", maxHealth)
  706. end
  707.  
  708. function getBallHealth(cid, ball)
  709.     for a, b in pairs (pokeballs) do
  710.         if ball.itemid == b.off then
  711.             return 0
  712.         end
  713.     end
  714.     if not getItemAttribute(ball.uid, "hpNow") then
  715.         doSetAttributesBallsByPokeName(cid, ball.uid, getItemAttribute(ball.uid, "poke"))
  716.     end
  717.     local healthNow = getItemAttribute(ball.uid, "hpNow")
  718.     return math.floor(healthNow)
  719. end
  720.  
  721. function getBallMaxHealthUnique(cid, ball)
  722.     if not getItemAttribute(ball, "hpMax") then
  723.         doSetAttributesBallsByPokeName(cid, ball, getItemAttribute(ball, "poke"))
  724.     end
  725.     local healthNow = getItemAttribute(ball, "hpMax")
  726.     return math.floor(healthNow)
  727. end
  728.  
  729. function getBallMaxHealth(cid, ball)
  730.     if not getItemAttribute(ball.uid, "hpMax") then
  731.         doSetAttributesBallsByPokeName(cid, ball.uid, getItemAttribute(ball.uid, "poke"))
  732.     end
  733.     local healthNow = getItemAttribute(ball.uid, "hpMax")
  734.     return math.floor(healthNow)
  735. end
  736.  
  737. function doSetPokeballLifeStatus(item, health, maxHealth)
  738.     doItemSetAttribute(item.uid, "hpNow", health)
  739.     doItemSetAttribute(item.uid, "hpMax", maxHealth)
  740. end
  741.  
  742. function doSendLifePokeToOTC(cid)
  743.     local ball = getPlayerSlotItem(cid, 8)
  744.     local pk = getCreatureSummons(cid)
  745.           if #pk <= 0 then return true end
  746.           if ball.uid ~= 0 then
  747.         doSetPokeballLifeStatus(ball, getCreatureHealth(pk[1]), getCreatureMaxHealth(pk[1]))
  748.         doOTCSendPokemonHealth(cid)
  749.     end
  750. end
  751.  
  752. ------------------------------------------ Skill Bar OTC
  753. function doOTCSendPlayerSkills(cid)
  754.     local str = {}
  755.     table.insert(str, getPlayerClan(cid))
  756.     table.insert(str, "|"..getPlayerCasinoCoins(cid))
  757.     table.insert(str, "|"..getPlayerKantoCatches(cid).."|"..getPlayerTotalCatches(cid))
  758.     table.insert(str, "|"..getPlayerWins(cid).."|"..getPlayerLoses(cid).."|"..getPlayerOfficialWins(cid).."|"..getPlayerOfficialLoses(cid).."|"..getPlayerPVPScore(cid))
  759.     table.insert(str, "|"..getPlayerBadgeOfLeader(cid, "Brock"))
  760.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Misty"))
  761.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Surge"))
  762.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Erika"))
  763.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Sabrina"))
  764.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Koga"))
  765.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Blaine"))
  766.     table.insert(str, ";"..getPlayerBadgeOfLeader(cid, "Giovanni"))
  767.     return doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_SKILL_BAR, table.concat(str))
  768. end
  769.  
  770. ------------------------------------------ Clan
  771.  
  772. function setPlayerClans(cid, name)
  773.     return setPlayerStorageValue(cid, storages.playerClan, string.lower(name)) and doOTCSendPlayerSkills(cid)
  774. end
  775.  
  776. function getPlayerClan(cid)
  777.     return getPlayerStorageValue(cid, storages.playerClan) == -1 and "Pokemon Trainer" or getPlayerStorageValue(cid, storages.playerClan)
  778. end
  779.  
  780. function setPlayerClanRank(cid, value)
  781.     return setPlayerStorageValue(cid, storages.playerClanRank, value)
  782. end
  783.  
  784. function getPlayerClanRank(cid)
  785.     return getPlayerStorageValue(cid, storages.playerClanRank) == -1 and 1 or getPlayerStorageValue(cid, storages.playerClanRank)
  786. end
  787.  
  788. ------------------------------------------ Casino
  789. function doPlayerAddInCasinoCoins(cid, value)
  790.     return setPlayerStorageValue(cid, storages.playerCasinoCoins, getPlayerCasinoCoins(cid) + value) and doOTCSendPlayerSkills(cid)
  791. end
  792.  
  793. function getPlayerCasinoCoins(cid)
  794.     return getPlayerStorageValue(cid, storages.playerCasinoCoins) == -1 and 0 or getPlayerStorageValue(cid, storages.playerCasinoCoins)
  795. end
  796.  
  797. ------------------------------------------ Catches
  798. function doPlayerAddInKantoCatchs(cid, value)
  799.     return setPlayerStorageValue(cid, storages.playerKantoCatches, getPlayerKantoCatches(cid) + value)
  800. end
  801.  
  802. function getPlayerKantoCatches(cid)
  803.     return getPlayerStorageValue(cid, storages.playerKantoCatches) == -1 and 0 or getPlayerStorageValue(cid, storages.playerKantoCatches)
  804. end
  805.  
  806. function doPlayerAddInTotalCatchs(cid, value)
  807.     return setPlayerStorageValue(cid, storages.playerTotalCatches, getPlayerTotalCatches(cid) + value) and doOTCSendPlayerSkills(cid)
  808. end
  809.  
  810. function getPlayerTotalCatches(cid)
  811.     return getPlayerStorageValue(cid, storages.playerTotalCatches) == -1 and 0 or getPlayerStorageValue(cid, storages.playerTotalCatches)
  812. end
  813.  
  814. ------------------------------------------ Duels and PVP
  815. function doPlayerAddInWins(cid, value)
  816.     return setPlayerStorageValue(cid, storages.playerWins, getPlayerWins(cid) + value) and doOTCSendPlayerSkills(cid)
  817. end
  818.  
  819. function getPlayerWins(cid)
  820.     return getPlayerStorageValue(cid, storages.playerWins) == -1 and 0 or getPlayerStorageValue(cid, storages.playerWins)
  821. end
  822.  
  823. function doPlayerAddInLoses(cid, value)
  824.     return setPlayerStorageValue(cid, storages.playerLoses, getPlayerLoses(cid) + value) and doOTCSendPlayerSkills(cid)
  825. end
  826.  
  827. function getPlayerLoses(cid)
  828.     return getPlayerStorageValue(cid, storages.playerLoses) == -1 and 0 or getPlayerStorageValue(cid, storages.playerLoses)
  829. end
  830.  
  831. function doPlayerAddInOfficialWins(cid, value)
  832.     return setPlayerStorageValue(cid, storages.playerOfficialWins, getPlayerOfficialWins(cid) + value) and doOTCSendPlayerSkills(cid)
  833. end
  834.  
  835. function getPlayerOfficialWins(cid)
  836.     return getPlayerStorageValue(cid, storages.playerOfficialWins) == -1 and 0 or getPlayerStorageValue(cid, storages.playerOfficialWins)
  837. end
  838.  
  839. function doPlayerAddInOfficialLoses(cid, value)
  840.     return setPlayerStorageValue(cid, storages.playerOfficialLoses, getPlayerOfficialLoses(cid) + value) and doOTCSendPlayerSkills(cid)
  841. end
  842.  
  843. function getPlayerOfficialLoses(cid)
  844.     return getPlayerStorageValue(cid, storages.playerOfficialLoses) == -1 and 0 or getPlayerStorageValue(cid, storages.playerOfficialLoses)
  845. end
  846.  
  847. function doPlayerAddInPVPScore(cid, value)
  848.     return setPlayerStorageValue(cid, storages.playerPVPScore, getPlayerPVPScore(cid) + value) and doOTCSendPlayerSkills(cid)
  849. end
  850.  
  851. function getPlayerPVPScore(cid)
  852.     return getPlayerStorageValue(cid, storages.playerPVPScore) == -1 and 0 or getPlayerStorageValue(cid, storages.playerPVPScore)
  853. end
  854.  
  855. ------------------------------------------ Badges
  856. function doPlayerAddBadgeOfLeader(cid, leader)
  857.     return setPlayerStorageValue(cid, storages.gynLeaders[leader], 1)
  858. end
  859.  
  860. function getPlayerBadgeOfLeader(cid, leader)
  861.     return getPlayerStorageValue(cid, storages.gynLeaders[leader]) == -1 and 0 or getPlayerStorageValue(cid, storages.gynLeaders[leader])
  862. end
  863.  
  864.  
  865. function getPokeUniqueStorToCatch(poke)
  866.    return pokeballs[string.lower(poke)].on
  867. end
  868.  
  869. function getPokeUniqueStorToDex(poke)
  870.    return pokeballs[string.lower(poke)].off
  871. end
  872.  
  873. function isWild(cid)
  874.    if not isCreature(cid) then return false end
  875.       if not isSummon(cid) and isMonster(cid) then
  876.          return true
  877.       end
  878.    return false
  879. end
  880.  
  881. function getPokeDistanceToTeleport(cid)
  882.    if not isCreature(cid) then return true end
  883.    if not isSummon(cid) then return true end
  884.    
  885.    local owner = getCreatureMaster(cid)
  886.    
  887.       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
  888.          doTeleportThing(cid, getThingPos(owner), false)
  889.          doSendMagicEffect(getThingPos(cid), 21)
  890.          setMoveSummon(owner, true)
  891.       end
  892.      
  893.    addEvent(getPokeDistanceToTeleport, 10, cid)
  894. end
  895.  
  896. function setMoveSummon(cid, canMove)
  897. if not isCreature(cid) then return true end
  898. return canMove == true and setPlayerStorageValue(cid, 500, -1) or setPlayerStorageValue(cid, 500, 1)  
  899. end
  900.  
  901. function getPokeballs_ITEMS_ID_InContainer(container) -- Function By Kydrai
  902.     if not isContainer(container) then return {} end
  903.     local items = {}
  904.     if isContainer(container) and getContainerSize(container) > 0 then
  905.         for slot=0, (getContainerSize(container)-1) do
  906.             local item = getContainerItem(container, slot)
  907.                 if isContainer(item.uid) then
  908.                     local itemsbag = getPokeballsInContainer(item.uid)
  909.                     for i=0, #itemsbag do
  910.                         table.insert(items, itemsbag[i])
  911.                     end
  912.                 elseif isPokeball(item.itemid) then
  913.                     table.insert(items, item)
  914.                 end
  915.         end
  916.     end
  917. return items
  918. end
  919.  
  920. function getBallNickName(ball)
  921.    return getItemAttribute(ball.uid, "nick") or 0
  922. end
  923.  
  924. function doCreatureSetNick(cid, nick)
  925.  
  926.    local nid = getCreatureName(cid)
  927.    local master = getCreatureMaster(cid)
  928.    local newPoke = doCreateMonster(nid, farwayPos)
  929.    local oldPos = getThingPos(cid)
  930.          doRemoveCreature(cid)
  931.          setCreatureName(newPoke, nick, nick)
  932.          doTeleportThing(newPoke, oldPos, false)
  933.          doConvinceCreature(master, newPoke)
  934.          registerCreatureEvent(newPoke, "SummonDeath")
  935.             getPokeDistanceToTeleport(newPoke)
  936.    
  937. end
  938. --------------------- Icon system ---------------------
  939.  
  940. function doTransformBallsInIcons(cid)
  941.      setPlayerStorageValue(cid, storages.iconSys, 1)
  942.      local bag = getPlayerSlotItem(cid, 3).uid
  943.      for i = 1, #getPokeballsInContainer(bag) do
  944.         local ballNow = getPokeballsInContainer(bag)[i]
  945.         local pokeName =  string.lower(getItemAttribute(ballNow, "pokeName"))
  946.         local ids = getPokeballs_ITEMS_ID_InContainer(bag)[i]
  947.        
  948.         if isPokeballOn(ids) then
  949.            doTransformItem(ballNow, pokeballs[pokeName].on)
  950.         elseif isPokeballOff(ids) then
  951.            doTransformItem(ballNow, pokeballs[pokeName].off)
  952.         end
  953.        
  954.      end
  955.      
  956.      local legs = getPlayerSlotItem(cid, 8)
  957.    
  958.      if legs.uid > 0 then
  959.         local pokeName =  string.lower(getItemAttribute(legs.uid, "pokeName"))
  960.         if isPokeballOn(legs) then
  961.            doTransformItem(legs.uid, pokeballs[pokeName].on)
  962.         elseif isPokeballOff(legs) then
  963.            doTransformItem(legs.uid, pokeballs[pokeName].off)
  964.         end
  965.      end
  966.      
  967.      local arrow = getPlayerSlotItem(cid, 10)
  968.    
  969.      if arrow.uid > 0 then
  970.         if not getItemAttribute(arrow.uid, "pokeName") then return true end
  971.         local pokeName =  string.lower(getItemAttribute(arrow.uid, "pokeName"))
  972.         if isPokeballOn(arrow) then
  973.            doTransformItem(arrow.uid, pokeballs[pokeName].on)
  974.         elseif isPokeballOff(arrow) then
  975.            doTransformItem(arrow.uid, pokeballs[pokeName].off)
  976.         end
  977.      end
  978.      
  979.      
  980. end
  981.  
  982. function doTransformIconsInBalls(cid)
  983.      setPlayerStorageValue(cid, storages.iconSys, -1)
  984.      local bag = getPlayerSlotItem(cid, 3).uid
  985.      for i = 1, #getPokeballsInContainer(bag) do
  986.         local ballNow = getPokeballsInContainer(bag)[i]
  987.         local ids = getPokeballs_ITEMS_ID_InContainer(bag)[i]
  988.        
  989.         if isPokeballOn(ids) then
  990.            doTransformItem(ballNow, pokeballs[getItemAttribute(ballNow, "ballEffe")].on)
  991.         elseif isPokeballOff(ids) then
  992.            doTransformItem(ballNow, pokeballs[getItemAttribute(ballNow, "ballEffe")].off)
  993.         end
  994.        
  995.      end
  996.      
  997.      local legs = getPlayerSlotItem(cid, 8)
  998.      if legs.uid > 0 then
  999.         if isPokeballOn(legs) then
  1000.            doTransformItem(legs.uid, pokeballs[getItemAttribute(legs.uid, "ballEffe")].on)
  1001.         elseif isPokeballOff(legs) then
  1002.            doTransformItem(legs.uid, pokeballs[getItemAttribute(legs.uid, "ballEffe")].off)
  1003.         end
  1004.      end
  1005.      
  1006.      local arrow = getPlayerSlotItem(cid, 10)
  1007.            if not getItemAttribute(arrow.uid, "pokeName") then return true end
  1008.      if arrow.uid > 0 then
  1009.         if isPokeballOn(arrow) then
  1010.            doTransformItem(arrow.uid, pokeballs[getItemAttribute(arrow.uid, "ballEffe")].on)
  1011.         elseif isPokeballOff(arrow) then
  1012.            doTransformItem(arrow.uid, pokeballs[getItemAttribute(arrow.uid, "ballEffe")].off)
  1013.         end
  1014.      end
  1015.      
  1016. end
  1017.  
  1018. function isItemPokeball(item)         --alterado v1.9 \/
  1019. if not item then return false end
  1020. for a, b in pairs (pokeballs) do
  1021.     if b.on == item or b.off == item or b.use == item then return true end
  1022. end
  1023. return false
  1024. end
  1025.  
  1026. function isPokeball(item)
  1027. return isItemPokeball(item)
  1028. end  
  1029.  
  1030. function getItensUniquesInContainer(container)    --alterado v1.6
  1031. if not isContainer(container) then return {} end
  1032. local items = {}
  1033. if isContainer(container) and getContainerSize(container) > 0 then
  1034.    for slot=0, (getContainerSize(container)-1) do
  1035.        local item = getContainerItem(container, slot)
  1036.        if isContainer(item.uid) then
  1037.           local itemsbag = getItensUniquesInContainer(item.uid)
  1038.           for i=0, #itemsbag do
  1039.               table.insert(items, itemsbag[i])
  1040.           end
  1041.        elseif getItemAttribute(item.uid, "unique") or getItemAttribute(item.uid, "torneio") then
  1042.           table.insert(items, item)
  1043.        end
  1044.    end
  1045. end
  1046. return items
  1047. end
  1048.  
  1049. function getPokeballsInContainer(container) -- Function By Kydrai
  1050.     if not isContainer(container) then return {} end
  1051.     local items = {}
  1052.     if isContainer(container) and getContainerSize(container) > 0 then
  1053.         for slot=0, (getContainerSize(container)-1) do
  1054.             local item = getContainerItem(container, slot)
  1055.                 if isContainer(item.uid) then
  1056.                     local itemsbag = getPokeballsInContainer(item.uid)
  1057.                     for i=0, #itemsbag do
  1058.                         table.insert(items, itemsbag[i])
  1059.                     end
  1060.                 elseif isPokeball(item.itemid) then
  1061.                     table.insert(items, item.uid)
  1062.                 end
  1063.         end
  1064.     end
  1065. return items
  1066. end
  1067.  
  1068. function isWaterTile(id)
  1069. return tonumber(id) and id >= 4608 and id <= 4613 --alterado v1.9
  1070. end
  1071.  
  1072. function isVenomTile(id)
  1073. 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
  1074. end
  1075.  
  1076. function isUseIconSystem(cid)
  1077.    if tonumber(getPlayerStorageValueWithSecurity(cid, storages.iconSys)) and getPlayerStorageValueWithSecurity(cid, storages.iconSys) == 1 then
  1078.       return true
  1079.    end
  1080.    return false
  1081. end
  1082.  
  1083. function getPlayerStorageValueWithSecurity(cid, stor)
  1084.    if not isCreature(cid) then return true end
  1085.    return getPlayerStorageValue(cid, stor)
  1086. end
  1087.  
  1088. function getItemAttributeWithSecurity(item, attr)
  1089.     if not item == 0 or item == nil then return true end
  1090.     return getItemAttribute(item, attr) or 0
  1091. end
  1092.  
  1093. function unLock(ball)                                                            
  1094. if not ball or ball <= 0 then return false end
  1095. if getItemAttribute(ball, "lock") and getItemAttribute(ball, "lock") > 0 then
  1096.    local vipTime = getItemAttribute(ball, "lock")
  1097.    local timeNow = os.time()
  1098.    local days = math.ceil((vipTime - timeNow)/(24 * 60 * 60))
  1099.    if days <= 0 then
  1100.       doItemEraseAttribute(ball, "lock")    
  1101.       doItemEraseAttribute(ball, "unique")
  1102.       return true
  1103.    end
  1104. end
  1105. return false
  1106. end
  1107.  
  1108. function getBallsAttributes(item)
  1109. local t = {"pokeName", "pokeNick", "health", "maxHealth", "ballEffe", "copyName", "boost", "happy", "description", "transBegin", "transLeft", "transTurn", "transOutfit", "transName",
  1110. "trans", "light", "blink", "move1", "move2", "move3", "move4", "move5", "move6", "move7", "move8", "move9", "move10", "move11", "move12", "ballorder",
  1111. "hands", "aura", "burn", "burndmg", "poison", "poisondmg", "confuse", "sleep", "miss", "missSpell", "missEff", "fear", "fearSkill", "silence",
  1112. "silenceEff", "stun", "stunEff", "stunSpell", "paralyze", "paralyzeEff", "slow", "slowEff", "leech", "leechdmg", "Buff1", "Buff2", "Buff3", "Buff1skill",
  1113. "Buff2skill", "Buff3skill", "control", "unique", "task", "lock", "torneio"}
  1114. local ret = {}
  1115. for a = 1, #t do
  1116. if getItemAttribute(item, t[a]) == "hands" then
  1117. return
  1118. end
  1119. ret[t[a]] = getItemAttribute(item, t[a]) or false
  1120. end
  1121. return ret
  1122. end
  1123.  
  1124. --------------------- Icon system ---------------------
  1125.  
  1126. --- balls \/
  1127. function isPokeballOn(ball)
  1128.    for a, b in pairs(pokeballs) do
  1129.        if b.on == ball.itemid then
  1130.           return true
  1131.        end
  1132.    end
  1133. return false
  1134. end
  1135.  
  1136. function isPokeballOff(ball)
  1137.    for a, b in pairs(pokeballs) do
  1138.        if b.off == ball.itemid then
  1139.           return true
  1140.        end
  1141.    end
  1142. return false
  1143. end
  1144. function isPokeballUse(ball)
  1145.    for a, b in pairs(pokeballs) do
  1146.        if b.use == ball.itemid then
  1147.           return true
  1148.        end
  1149.    end
  1150. return false
  1151. end
  1152.  
  1153. ---- PDA functions
  1154. function isPlayerSummon(cid, uid)
  1155. return getCreatureMaster(uid) == cid  --alterado v1.9
  1156. end
  1157.  
  1158. function isSummon(sid)
  1159. return isCreature(sid) and getCreatureMaster(sid) ~= sid and isPlayer(getCreatureMaster(sid))   --alterado v1.9
  1160. end
  1161.  
  1162. function getPlayerDesc(cid, thing, TV)
  1163. if (not isCreature(cid) or not isCreature(thing)) and not TV then return "" end
  1164.  
  1165. local pos = getThingPos(thing)
  1166. local ocup = youAre[getPlayerGroupId(thing)]
  1167. local rank = (getPlayerStorageValue(thing, 86228) <= 0) and "Treinador Pokemon" or lookClans[getPlayerStorageValue(thing, 86228)][getPlayerStorageValue(thing, 862281)]
  1168. local name = thing == cid and "você mesmo" or getCreatureName(thing)    
  1169. local art = thing == cid and "Você é" or (getPlayerSex(thing) == 0 and "Ela é" or "Ele é")
  1170.    
  1171. local str = {}
  1172. table.insert(str, "Você está vendo "..name..". "..art.." ")
  1173. if youAre[getPlayerGroupId(thing)] then
  1174.    table.insert(str, (ocup).." e "..rank.." de ".. getTownName(getPlayerTown(thing))..".")      
  1175. else
  1176.    table.insert(str, (rank).." de ".. getTownName(getPlayerTown(thing))..".")
  1177. end
  1178. if getPlayerGuildId(thing) > 0 then
  1179.    table.insert(str, " "..art.." "..getPlayerGuildRank(thing).." do "..getPlayerGuildName(thing)..".")
  1180. end
  1181. if TV then
  1182.    table.insert(str, " "..art.." watching TV.")
  1183. end
  1184. table.insert(str, ((isPlayer(cid) and youAre[getPlayerGroupId(cid)]) and "\nPosition: [X: "..pos.x.."][Y: "..pos.y.."][Z: "..pos.z.."]" or ""))
  1185.  
  1186. return table.concat(str)
  1187. end
  1188.  
  1189. function ehNPC(cid)   --alterado v1.9
  1190. return isCreature(cid) and not isPlayer(cid) and not isSummon(cid) and not isMonster(cid)
  1191. end
  1192.  
  1193. function ehMonstro(cid)   --alterado v1.9
  1194. return cid and cid >= AUTOID_MONSTERS and cid < AUTOID_NPCS
  1195. end
  1196.  
  1197. function isPosEqual(pos1, pos2)
  1198.       if pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z then
  1199.          return true
  1200.       end  
  1201. return false
  1202. end
  1203.  
  1204. function isPosInArray(array, pos)
  1205. if not next(array) then return false end
  1206. for i = 1, #array do
  1207.     if isPosEqual(pos, array[i]) then
  1208.        return true
  1209.     end
  1210. end
  1211. return false
  1212. end
  1213.  
  1214. function canWalkOnPos(pos, creature, pz, water, sqm, proj)
  1215. if not pos then return false end
  1216. if not pos.x then return false end
  1217. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid <= 1 and sqm then return false end
  1218. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 919 then return false end
  1219. 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
  1220. if getTopCreature(pos).uid > 0 and creature then return false end
  1221. if hasSqm(pos) and getTileInfo(pos).protection and pz  then return false end
  1222.     local n = not proj and 3 or 2                                    --alterado v1.6
  1223.     for i = 0, 255 do
  1224.         pos.stackpos = i                          
  1225.         local tile = getTileThingByPos(pos)        
  1226.         if tile.itemid ~= 0 and i ~= 253 and not isCreature(tile.uid) then     --edited
  1227.             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1228.                 return false
  1229.             end
  1230.         end
  1231.     end  
  1232. return true
  1233. end
  1234.  
  1235. function isWalkable(pos, creature, proj, pz, water)-- by Nord
  1236.     if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
  1237.     if isWaterTile(getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid) and water then return false end
  1238.     if getTopCreature(pos).uid > 0 and creature then return false end
  1239.     if getTileInfo(pos).protection and pz then return false, true end
  1240.     local n = not proj and 3 or 2
  1241.     for i = 0, 255 do
  1242.         pos.stackpos = i
  1243.         local tile = getTileThingByPos(pos)
  1244.         if tile.itemid ~= 0 and not isCreature(tile.uid) then
  1245.             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1246.                 return false
  1247.             end
  1248.         end
  1249.     end
  1250.     return true
  1251. end
  1252.  
  1253.  
  1254. conds = {
  1255. ["Slow"] = 3890,
  1256. ["Confusion"] = 3891,  
  1257. ["Burn"] = 3892,
  1258. ["Poison"] = 3893,
  1259. ["Fear"] = 3894,
  1260. ["Stun"] = 3895,
  1261. ["Paralyze"] = 3896,                              
  1262. ["Leech"] = 3897,
  1263. ["Buff1"] = 3898,
  1264. ["Buff2"] = 3899,
  1265. ["Buff3"] = 3900,
  1266. ["Miss"] = 32659,  
  1267. ["Silence"] = 32698,    
  1268. ["Sleep"] = 98271,
  1269. }
  1270. function isSilence(cid)
  1271.     if not isCreature(cid) then return false end
  1272.     if getPlayerStorageValue(cid, conds["Silence"]) >= 0 then return true end
  1273. return false
  1274. end
  1275.  
  1276. function isParalyze(cid)      
  1277.     if not isCreature(cid) then return false end
  1278.     if getPlayerStorageValue(cid, conds["Paralyze"]) >= 0 then return true end
  1279. return false
  1280. end
  1281.    
  1282. function isSleeping(cid)
  1283.     if not isCreature(cid) then return false end
  1284.     if getPlayerStorageValue(cid, conds["Sleep"]) >= 0 then return true end
  1285. return false
  1286. end
  1287.  
  1288. function doRegainSpeed(cid)              --alterado v1.9 \/
  1289. if not isCreature(cid) then return true end
  1290.  
  1291.    local speed = playerSpeed
  1292.    if isMonster(cid) then
  1293.       speed = getCreatureBaseSpeed(cid)
  1294.    elseif isPlayer(cid) and isInArray({4, 5, 6, 15}, getPlayerGroupId(cid)) then
  1295.       speed = 200 * getPlayerGroupId(cid)
  1296.    end
  1297.    
  1298.    doChangeSpeed(cid, -getCreatureSpeed(cid))
  1299.    if getCreatureCondition(cid, CONDITION_PARALYZE) == true then
  1300.       doRemoveCondition(cid, CONDITION_PARALYZE)
  1301.       addEvent(doAddCondition, 10, cid, paralizeArea2)            
  1302.    end
  1303.    
  1304.    if isADM(cid) then
  1305.       speed = 15000
  1306.    end
  1307.    
  1308. doChangeSpeed(cid, speed)
  1309. return speed
  1310. end
  1311.  
  1312. function doPlayerAddExp_2(cid, exp)
  1313. if not isCreature(cid) then return true end
  1314.    doPlayerAddExp(cid, exp)
  1315.    doSendAnimatedText(getThingPos(cid), exp, 215)
  1316. end
  1317.  
  1318. function doWalkAgain(cid)
  1319.    if not isCreature(cid) then return true end
  1320.    if getCreatureTarget(cid) >= 1 then
  1321.       setMoveSummon(master, true)
  1322.       return true
  1323.    end
  1324.    local master = getCreatureMaster(cid)
  1325.    local pox, poy = getPlayerStorageValue(cid, 505), getPlayerStorageValue(cid, 506)
  1326.    
  1327.    if pox == -1 and poy == -1 then
  1328.        addEvent(doWalkAgain, 200, cid)
  1329.        return true
  1330.    end
  1331.    
  1332.        if getThingPos(master).x ~= pox or getThingPos(master).y ~= poy then
  1333.          setMoveSummon(master, true)
  1334.        end
  1335.    addEvent(doWalkAgain, 200, cid)
  1336. end
  1337.  
  1338. function doMovePokeToPos(cid, pos)
  1339. if not isCreature(cid) then return true end
  1340.    doMoveCreatureToPos(cid, pos)
  1341. end
  1342.  
  1343. function getSpeed(cid)
  1344.     if not isCreature(cid) then return 0 end
  1345. return tonumber(getPlayerStorageValue(cid, 1003))
  1346. end
  1347.  
  1348. function isGhost(cid)
  1349.      
  1350. end
  1351.  
  1352. function isGhostPokemon(cid)
  1353.     if not isCreature(cid) then return false end
  1354.     local ghosts = {"Gastly", "Haunter", "Gengar", "Shiny Gengar", "Misdreavus", "Shiny Abra"}
  1355. return isInArray(ghosts, getCreatureName(cid))
  1356. end
  1357.  
  1358. function updateGhostWalk(cid)
  1359.     if not isCreature(cid) then return false end
  1360.     local pos = getThingPos(cid)
  1361.     pos.x = pos.x + 1
  1362.     pos.y = pos.y + 1
  1363.     local ret = getThingPos(cid)
  1364.     doTeleportThing(cid, pos, false)
  1365.     doTeleportThing(cid, ret, false)
  1366. return true
  1367. end
  1368.  
  1369. --- funcs
  1370. function getTopCorpse(position)
  1371. local pos = position
  1372. for n = 1, 255 do
  1373.     pos.stackpos = n
  1374.     local item = getTileThingByPos(pos)
  1375.     if (string.find(getItemNameById(item.itemid), "fainted") or string.find(getItemNameById(item.itemid), "defeated ")) then
  1376.        return getTileThingByPos(pos)
  1377.     end
  1378. end
  1379. return null
  1380. end
  1381.  
  1382.  
  1383. function doCorrectPokemonName(poke)
  1384. return doCorrectString(poke)
  1385. end
  1386.  
  1387. function doCorrectString(str)
  1388. local name = str:explode(" ")  --alterado v1.9
  1389. local final = {}
  1390. for _, s in ipairs(name) do
  1391.     table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
  1392. end
  1393. return table.concat(final, (name[2] and " " or ""))
  1394. end  
  1395.  
  1396. ---------------------------------------- Order (Não mexer) ----------------------------------------
  1397. function getPokemonName(cid)
  1398.    return getCreatureName(cid)
  1399. end
  1400.  
  1401. function isRiderOrFlyOrSurf(cid)
  1402.    if getPlayerStorageValue(cid, orderTalks["surf"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["ride"].storage) == 1 or getPlayerStorageValue(cid, orderTalks["fly"].storage) == 1 then
  1403.       return true
  1404.    end
  1405.    return false
  1406. end
  1407.  
  1408. function doEreasPlayerOrder(cid)
  1409.    setPlayerStorageValue(cid, orderTalks["surf"].storage, -1)
  1410.    setPlayerStorageValue(cid, orderTalks["ride"].storage, -1)
  1411.    setPlayerStorageValue(cid, orderTalks["fly"].storage, -1)
  1412. end
  1413.  
  1414. function isRider(cid)
  1415.    if getPlayerStorageValue(cid, orderTalks["ride"].storage) == 1 then
  1416.       return true
  1417.    end
  1418.    return false
  1419. end
  1420.  
  1421. function isFly(cid)
  1422.    if getPlayerStorageValue(cid, orderTalks["fly"].storage) == 1 then
  1423.       return true
  1424.    end
  1425.    return false
  1426. end
  1427.  
  1428. function isSurf(cid)
  1429.    if getPlayerStorageValue(cid, orderTalks["surf"].storage) == 1 then
  1430.       return true
  1431.    end
  1432.    return false
  1433. end
  1434.  
  1435. function isUsingOrder(cid)
  1436.    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
  1437.       return true
  1438.    end
  1439.    return false
  1440. end
  1441.  
  1442. function doEreaseUsingOrder(cid)
  1443.    setPlayerStorageValue(cid, orderTalks["dig"].storage, -1)
  1444.    setPlayerStorageValue(cid, orderTalks["cut"].storage, -1)
  1445.    setPlayerStorageValue(cid, orderTalks["rock"].storage, -1)
  1446.    setPlayerStorageValue(cid, orderTalks["headbutt"].storage, -1)
  1447. end
  1448.  
  1449. function doSendMsg(cid, msg)
  1450.     if not isPlayer(cid) then return true end
  1451.     doPlayerSendTextMessage(cid, 27, msg)
  1452. end
  1453.  
  1454. function doCopyPokemon(cid, copy, eff)
  1455.     local item = getPlayerSlotItem(getCreatureMaster(cid), 8)
  1456.     local sid = getCreatureMaster(cid)
  1457.     local pos, dir = getThingPos(cid), getPlayerLookDir(cid)
  1458.             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"}  
  1459.                
  1460.                 if isInArray(blockToDitto, copy) then
  1461.                    doSendMsg(sid, "Impossivel copiar este pokemon.")
  1462.                    return true
  1463.                 end
  1464.                
  1465.                 if isInDuel(sid) then
  1466.                    doSendMsg(sid, "Você não pode transformar seu ditto estando duelo.")
  1467.                    return true
  1468.                 end
  1469.    
  1470.                 local nick = retireShinyName(getItemAttribute(item.uid, "poke"))
  1471.                       if getItemAttribute(item.uid, "poke") == "Ditto" and isShinyName(copy) then
  1472.                          doSendMsg(sid, "So um Shiny Ditto pode se transformar em pokemons do tipo Shiny.")
  1473.                          return true
  1474.                       end
  1475.                
  1476.                       if getItemAttribute(item.uid, "nick") then
  1477.                          nick = getItemAttribute(item.uid, "nick")
  1478.                       end
  1479.                      
  1480.                       if getItemAttribute(item.uid, "copyName") == copy then
  1481.                          doSendMsg(sid, "Seu ditto já é uma copia do " .. copy)
  1482.                          return true
  1483.                       end
  1484.                      
  1485.                       if not pokes[copy] then
  1486.                          doSendMsg(cid, "Isso não é um pokemon.")
  1487.                          print(">>>>>DittoBUG: " .. copy)
  1488.                          return true
  1489.                       end
  1490.                      
  1491.                 doPlayerSay(sid, nick..", copie o "..retireShinyName(copy)..".")
  1492.                
  1493.                 local heath_toDrawPercent = getCreatureMaxHealth(cid) - getCreatureHealth(cid)
  1494.                 doRemoveCreature(cid)
  1495.                 local poke = doCreateMonsterNick(sid, copy, nick, pos, true)
  1496.                       doTeleportThing(poke, pos)
  1497.              
  1498.             setPlayerStorageValue(poke, 510, copy)
  1499.             doCreatureSetLookDir(poke, dir)
  1500.             doItemSetAttribute(item.uid, "copyName", copy)
  1501.             doSendPlayerExtendedOpcode(sid, opcodes.OPCODE_BATTLE_POKEMON, tostring(poke))
  1502.             doUpdateMoves(sid)
  1503.              getPokeDistanceToTeleport(poke)
  1504.              adjustStatus(poke, item.uid, true, heath_toDrawPercent, true)
  1505.              setPokemonGhost(poke)
  1506.              if eff then
  1507.                doSendMagicEffect(pos, 184)
  1508.              end
  1509.              
  1510.             -- doOTCSendPokemonHealth(sid)
  1511. end
  1512.  
  1513. function round(num, idp)
  1514.   return tonumber(string.format("%." .. (idp or 0) .. "f", num))
  1515. end
  1516.  
  1517. function doGoPokemonInOrder(cid, item, goMsg)
  1518.     if getPlayerSlotItem(cid, 8).uid ~= item.uid then
  1519.        return true
  1520.     end
  1521.    
  1522.     item = getPlayerSlotItem(cid, 8)
  1523.     if item.uid == 0 then return true end
  1524.    
  1525.              local name = getItemAttribute(item.uid, "poke")
  1526.              local nick = name
  1527.                   if isInArray({"Ditto", "shiny ditto"}, name:lower()) then
  1528.                      name = getItemAttribute(item.uid, "copyName")
  1529.                   end
  1530.            
  1531.              local effe = pokeballs[getPokeballType(item.itemid)].effect
  1532.        
  1533.          
  1534.             if getItemAttribute(item.uid, "nick") then
  1535.                  nick = getItemAttribute(item.uid, "nick")
  1536.             end
  1537.            
  1538.             pokeSourceCode = doCreateMonsterNick(cid, name, retireShinyName(nick), getThingPos(cid), true)
  1539.             if not pokeSourceCode then
  1540.                doSendMsg(cid, "Erro. Comunique esse codigo ao GM. [31121994]")
  1541.                return true
  1542.             end
  1543.            
  1544.              local poke = getCreatureSummons(cid)[1]
  1545.              doTeleportThing(poke, farWayPos)
  1546.              doTeleportThing(poke, getThingPos(cid))
  1547.              
  1548.              
  1549.              doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_BATTLE_POKEMON, tostring(poke))
  1550.              setPlayerStorageValue(poke, 510, name)
  1551.              doCreatureSetLookDir(poke, getPlayerLookDir(cid))
  1552.              getPokeDistanceToTeleport(poke)
  1553.              setMoveSummon(cid, true)
  1554.              doUpdateMoves(cid)
  1555.              doUpdateCooldowns(cid)
  1556.  
  1557.              doItemEraseAttribute(item.uid, "healthChanged")
  1558.              adjustStatus(poke, item.uid, true, true, true)
  1559.              setPokemonGhost(poke)
  1560.              if getCreatureSkullType(cid) == 5 then
  1561.                 doCreatureSetSkullType(cid, 0)
  1562.              end
  1563.              --setCreatureMaxHealth(poke, getBallMaxHealth(cid, item))
  1564.              --doCreatureAddHealth(poke, -(getCreatureHealth(poke)-1))
  1565.              --doCreatureAddHealth(poke, (getBallHealth(cid, item)-1))
  1566.              --doItemSetAttribute(item.uid, "healthChanged", getCreatureName(cid))
  1567.              --doOTCSendPokemonHealth(cid)
  1568. end
  1569.  
  1570. function doUp(cid, summon, move)
  1571.                      local pokeName = getItemAttribute(getPlayerSlotItem(cid, 8).uid, "poke")
  1572.                      local ditto = getItemAttribute(getPlayerSlotItem(cid, 8).uid, "copyName")
  1573.                           if ditto and ditto ~= "" then
  1574.                              pokeName = ditto
  1575.                           end
  1576.                      local outfit = getPokemonOutfitToSkill(pokeName)
  1577.                      local speed = getPokemonSpeedToSkill(pokeName)
  1578.                      addEvent(doRemoveCreature, 10, summon)
  1579.                      doSetCreatureOutfit(cid, {lookType = outfit + 351}, -1)
  1580.                      
  1581.                      doChangeSpeed(cid, -getCreatureSpeed(cid))
  1582.                      doChangeSpeed(cid, speed)
  1583.  
  1584.                      if #getCreatureSummons(cid) > 1 and getPlayerStorageValue(cid, 212124) <= 0 then     --alterado v1.6
  1585.                        if getPlayerStorageValue(cid, 637501) == -2 or getPlayerStorageValue(cid, 637501) >= 1 then  
  1586.                           BackTeam(cid)      
  1587.                        end
  1588.                      end
  1589.                    
  1590.                     if move == "ride" then
  1591.                      setPlayerStorageValue(cid, orderTalks["ride"].storage, 1)
  1592.                     elseif move == "fly" then
  1593.                      setPlayerStorageValue(cid, orderTalks["fly"].storage, 1)
  1594.                     end
  1595.                     setPokemonGhost(cid)
  1596.                    
  1597.                     doPlayerSendCancel(cid, '12//,hide') --alterado v1.7
  1598.    
  1599. end
  1600.  
  1601.  
  1602. function getCylinderTiles(pos, cilinderSize) -- By SmiX
  1603. local position = pos
  1604. local c = cilinderSize
  1605. local pos = {}
  1606. for i=-c, c do
  1607.         for j=-c, c do
  1608.                 local posEffect = {x=position.x+i,y=position.y+j,z=position.z}
  1609.                   table.insert(pos, posEffect)
  1610.         end
  1611. end
  1612.    return pos
  1613. end
  1614.  
  1615. function recheck(sid, skill, pos)
  1616.     if not isCreature(sid) or not isCreature(getCreatureMaster(sid)) then return end
  1617.     if not isUsingOrder(sid) then return true end
  1618.     local cid = getCreatureMaster(sid)
  1619.  
  1620.     if skill == "cut" then
  1621.  
  1622.         local item = getTileItemById(pos, 2767)
  1623.         if not item or item.uid <= 0 then return true end
  1624.        
  1625.         doCreatureSay(sid, "CUT!", TALKTYPE_MONSTER)
  1626.         doSendMagicEffect(getThingPos(item.uid), EFFECT_CUT)
  1627.         doTransformItem(item.uid, 6216)
  1628.         local function growRock()
  1629.             doTransformItem(getTileItemById(pos, 6216).uid, 2767)
  1630.             end
  1631.         addEvent(growRock, tempoPraVoltarAoNormal * 1000)
  1632.  
  1633.     elseif skill == "rock" then
  1634.  
  1635.         local item = getTileItemById(pos, 1285)
  1636.         if not item or item.uid <= 0 then return true end
  1637.        
  1638.         doCreatureSay(sid, "ROCK SMASH!", TALKTYPE_MONSTER)
  1639.         doSendMagicEffect(getThingPos(item.uid), EFFECT_DIG)
  1640.         doTransformItem(item.uid, 3610)
  1641.             local function growRock()
  1642.             doTransformItem(getTileItemById(pos, 3610).uid, 1285)
  1643.             end
  1644.         addEvent(growRock, tempoPraVoltarAoNormal * 1000)
  1645.        
  1646.  elseif skill == "headbutt" then  --alterado v1.6
  1647.  
  1648.     local item = getTileItemById(pos, 2707)    --id do item   arvore normal
  1649.         if not item or item.uid <= 0 then return true end
  1650.            
  1651.     local master = getCreatureMaster(sid)
  1652.     local array = {}                          
  1653.     local lvl = {25, 40, 60, 80, 150, 1000} --lvls
  1654.  
  1655.     for i = 1, #lvl do
  1656.         if getPlayerLevel(master) <= lvl[i] then
  1657.            array = headbutt[lvl[i]]
  1658.            break
  1659.         end
  1660.     end
  1661.     local rand = array[math.random(#array)]
  1662.     for j = 1, rand[2] do      
  1663.         local poke = doCreateMonster(rand[1] , getClosestFreeTile(sid, pos))
  1664.         --doCreatureSay(sid, rand[1], TALKTYPE_MONSTER)
  1665.     end
  1666.     doCreatureSay(sid, "HEADBUTT!", TALKTYPE_MONSTER)
  1667.     doSendMagicEffect(getThingPos(item.uid), EFFECT_DIG)
  1668.     doTransformItem(item.uid, 2702)  --id do item   arvore quebrada
  1669.     local function growHead()
  1670.           doTransformItem(getTileItemById(pos, 2702).uid, 2707) --id do item  arvore quebrada, arvore normal
  1671.     end
  1672.     addEvent(growHead, choose(5, 8, 10, 15) * 60 * 1000)   --o tempo pra arvore voltar ao normal varia de 5~30min
  1673. end
  1674.    doEreaseUsingOrder(sid)  
  1675. end
  1676.  
  1677. function choose(...) -- by mock
  1678.     local arg = {...}
  1679.     return arg[math.random(1,#arg)]
  1680. end
  1681.  
  1682.  
  1683. function getFreeTile(pos)
  1684.    if canWalkOnPos(pos, true, false, false, false, false) then
  1685.       return pos
  1686.    end
  1687.    local tmp
  1688.    for dir = 0, 7 do
  1689.       tmp = getPosByDir(pos, dir)
  1690.       if canWalkOnPos(tmp, true, false, false, false, false) then
  1691.          return tmp
  1692.       end
  1693.    end
  1694.    return farWayPos
  1695. end
  1696.  
  1697. ------------------------ marcar a pos do spawn do poke e retornar ela
  1698. function doMarkedSpawnPos(cid)
  1699. local pos = getThingPos(cid)
  1700.     setPlayerStorageValue(cid, storages.markedPosPoke, "x = "..pos.x..", y = "..pos.y..", z = "..pos.z..";")
  1701. end
  1702.  
  1703. function doMarkedPos(cid, pos)
  1704.     setPlayerStorageValue(cid, storages.markedPosPoke, "x = "..pos.x..", y = "..pos.y..", z = "..pos.z..";")
  1705. end
  1706.  
  1707. function isInPartyAndSharedExperience(cid)
  1708.     if isInParty(cid) and isPartyEnabledExp(cid) then
  1709.        return true
  1710.     end
  1711.     return false
  1712. end
  1713.  
  1714. function getMarkedSpawnPos(cid)
  1715.  local l = {}
  1716.  local pos = getPlayerStorageValue(cid, storages.markedPosPoke)
  1717.  local strPos = "x = (.-), y = (.-), z = (.-);"
  1718.    for a, b, c in pos:gmatch(strPos) do
  1719.       l = {x = tonumber(a), y = tonumber(b), z = tonumber(c)}
  1720.    end
  1721.    return l
  1722. end
  1723.  
  1724. function doComparePositions(position, positionEx)
  1725. return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
  1726. end
  1727. ------------------------ marcar a pos do spawn do poke e retornar ela
  1728.  
  1729. function doPlayerAddPoke(cid, pokeName, ball, unique)
  1730.     local ballid = pokeballs[ball]
  1731.     local send = false
  1732.  
  1733.     if not ballid then
  1734.         return print("doPlayerAddPoke: Não foi encontrada a pokebola: "..ball)
  1735.     end
  1736.  
  1737.     if isUseIconSystem(cid) then
  1738.         id = pokeballs[string.lower(pokeName)].on
  1739.     else
  1740.         id = ballid.on
  1741.     end
  1742.  
  1743.     if (getPlayerFreeCap(cid) <= 1 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  1744.         item = doCreateItemEx(id)
  1745.         send = true
  1746.     else
  1747.         item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, id, 1)
  1748.     end
  1749.  
  1750.     doItemSetAttribute(item, "health", getPokemonHealth(pokeName))
  1751.     doItemSetAttribute(item, "maxHealth", getPokemonHealth(pokeName))
  1752.     doItemSetAttribute(item, "pokeName", doCorrectString(pokeName))
  1753.     doItemSetAttribute(item, "ballEffe", ball)
  1754.  
  1755.     if send then
  1756.         doPlayerSendMailByName(getCreatureName(cid), item, 1)
  1757.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você já está segurando seis pokebolas, o seu novo pokemon foi enviado para o CP.")
  1758.     end
  1759. end
  1760.  
  1761. function hasSpaceInContainer(container)                --alterado v1.6
  1762. if not isContainer(container) then return false end
  1763. if getContainerSize(container) < getContainerCap(container) then return true end
  1764.  
  1765. for slot = 0, (getContainerSize(container)-1) do
  1766.     local item = getContainerItem(container, slot)
  1767.     if isContainer(item.uid) then
  1768.        if hasSpaceInContainer(item.uid) then
  1769.           return true
  1770.        end
  1771.     end
  1772. end
  1773. return false
  1774. end
  1775.  
  1776. function doSendEffect(cid, effe)
  1777. if not isCreature(cid) then return true end
  1778.    doSendMagicEffect(getThingPos(cid), effe)  
  1779. end
  1780.  
  1781. function doSendEffectAndText(cid, effe, text, color)
  1782. if not isCreature(cid) then return true end
  1783. if not color then color = 215 end
  1784.    doSendEffect(cid, effe)
  1785.    if text and text ~= "" then
  1786.       doSendAnimatedText(getThingPos(cid), text, color)
  1787.    end
  1788. end
  1789.  
  1790. function setCreatureVisibility(cid, vis)
  1791.     if not isCreature(cid) then return true end
  1792.     if vis then
  1793.         doAddCondition(cid, invisiblecondition)
  1794.     else
  1795.         doRemoveCondition(cid, CONDITION_INVISIBLE)
  1796.     end
  1797. end
  1798.  
  1799. function setCreatureHick(cid, secs, i)
  1800. if not isCreature(cid) then return true end
  1801.     i = i +1
  1802.     local pos2 = getThingPos(cid)
  1803.           pos2.x = pos2.x + math.random(1, 4)
  1804.           pos2.y = pos2.y + math.random(1, 4)
  1805.     if(i < secs) then
  1806.       local pos = getPosByDir(pos2, math.random(0, 7))
  1807.       local master = getCreatureMaster(cid)
  1808.         if(isPlayer(master)) then
  1809.            setMoveSummon(master, false)
  1810.         end
  1811.       doAddCondition(cid, bebo)
  1812.       doMovePokeToPos(cid, pos)
  1813.       pos = getThingPos(cid)
  1814.       pos.y = pos.y -1
  1815.       doSendMagicEffect(pos, 31)
  1816.       addEvent(setCreatureHick, 1000, cid, secs, i)
  1817.     else
  1818.        doRemoveCondition(cid, CONDITION_DRUNK)
  1819.     end
  1820. end
  1821.  
  1822. function doRemoveConditionWithSecurity(cid, cond)
  1823. if not isCreature(cid) then return true end
  1824.          doRemoveCondition(cid, cond)
  1825. end
  1826.  
  1827. function doCanAttackOther(cid, target)
  1828.  
  1829. setPlayerStorageValue(cid, storages.teamRed, 1)
  1830. setPlayerStorageValue(target, storages.teamBlue, 1)
  1831.  
  1832. end
  1833.  
  1834. function isInDuel(cid)
  1835. if not isCreature(cid) then return false end
  1836.    if getPlayerStorageValue(cid, storages.isInDuel) == 1 then
  1837.       return true
  1838.     end
  1839.    return false
  1840. end
  1841.  
  1842. -------------- pokedex
  1843. function getPokemonVitalityD(name)
  1844.     if not pokes[name] then return false end
  1845.     return pokes[name].vitality
  1846. end
  1847.  
  1848. function getPokemonAttackD(name)
  1849.     if not pokes[name] then return false end
  1850.     return pokes[name].offense
  1851. end
  1852.  
  1853. function getPokemonDefenseD(name)
  1854.     if not pokes[name] then return false end
  1855.     return pokes[name].defense
  1856. end
  1857.  
  1858. function getPokemonSpAttackD(name)
  1859.     if not pokes[name] then return false end
  1860.     return pokes[name].specialattack
  1861. end
  1862.  
  1863. function getPokemonLevelD(name)
  1864.     if not pokes[name] then return false end
  1865.     if pokes[name].level <= 1 then
  1866.         return 5
  1867.     end
  1868.     return pokes[name].level
  1869. end
  1870.  
  1871. function getPokemonPortraitD(name)
  1872.     if not pokes[name] then return false end
  1873.     return pokes[name].portrait
  1874. end
  1875.  
  1876.  
  1877.  
  1878. function getPokemonType1D(name)
  1879.     if not pokes[name] then return "normal" end
  1880.     return pokes[name].type
  1881. end
  1882.  
  1883. function getPokemonType2D(name)
  1884.     if not pokes[name] or not pokes[name].type2 then return false end
  1885.     return pokes[name].type2
  1886. end
  1887.  
  1888. function getPokemonHealthD(name)                
  1889.     if not pokes[name] then return false end
  1890.     return getMonsterInfo(name).healthMax
  1891. end
  1892.  
  1893. function getPokemonExperienceD(name)
  1894.     if not pokes[name] then return false end
  1895.     return getMonsterInfo(name).experience
  1896. end
  1897.  
  1898. function getPokemonCatchedStorage(name)
  1899.     if not pokes[name] then return false end
  1900.     return getMonsterInfo(name).lookCorpse
  1901. end
  1902.  
  1903. function getPokemonCorpse(name)
  1904.     if not pokes[name] then return false end
  1905.     return getMonsterInfo(name).lookCorpse
  1906. end
Advertisement
Add Comment
Please, Sign In to add comment