Advertisement
Guest User

some function.lua

a guest
May 21st, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 43.78 KB | None | 0 0
  1. function pokeHaveReflect(cid)
  2. if not isCreature(cid) then return false end
  3. local table = getTableMove(cid, "Reflect")
  4. if table and table.name then     --alterado v1.6
  5.    return true
  6. end
  7. return false
  8. end
  9. ------------------------------------------------------------------------------------------------------
  10. function endInviting(cid)
  11. if isCreature(cid) and getPlayerStorageValue(cid, 52483) == 0 then
  12.    setPlayerStorageValue(cid, 52480, -1)    --sto de duelo
  13.    setPlayerStorageValue(cid, 52481, -1)    --sto de pokes no duel
  14.    setPlayerStorageValue(cid, 52482, -1)    --sto do player q vai duela contigo       --alterado v2.6 duel system
  15.    setPlayerStorageValue(cid, 52483, -1)    --sto de aceitaçao de duel
  16.    setPlayerStorageValue(cid, 6598754, -1)   --sto do canAttackOther
  17.    doCreatureSetSkullType(cid, 0)
  18.    doPlayerSendTextMessage(cid, 20, "The other player don't accepted the duel...")
  19. end
  20. end
  21.  
  22. function checkDuel(cid)
  23. if getPlayerStorageValue(cid, 52481) >= 1 then
  24.    setPlayerStorageValue(cid, 52481, getPlayerStorageValue(cid, 52481)-1)
  25.    doSendAnimatedText(getThingPos(cid), "POKE DOWN", 65)
  26. end
  27. if getPlayerStorageValue(cid, 52481) == 0 and isInParty(cid) then
  28.    addEvent(doRemoveCreature, 400, cid)
  29. elseif getPlayerStorageValue(cid, 52481) == 0 and not isInParty(cid) then           --alterado v2.6 duel system
  30.    for _, sid in ipairs(getPlayersOnline()) do
  31.       if getPlayerStorageValue(sid, 52482) == getCreatureName(cid) then
  32.          addEvent(doSendAnimatedText, 1000, getThingPosWithDebug(sid), "WIN", COLOR_ELECTRIC)
  33.          setPlayerStorageValue(sid, 52480, -1)
  34.          setPlayerStorageValue(sid, 52481, -1)
  35.          setPlayerStorageValue(sid, 52482, -1)
  36.          setPlayerStorageValue(sid, 52483, -1)
  37.          setPlayerStorageValue(sid, 6598754, -1)
  38.          doCreatureSetSkullType(sid, 0)
  39.          doRemoveCondition(sid, CONDITION_INFIGHT)
  40.       end
  41.    end
  42.    addEvent(doSendAnimatedText, 1000, getThingPosWithDebug(cid), "LOSE", COLOR_BURN)
  43.    setPlayerStorageValue(cid, 52480, -1)
  44.    setPlayerStorageValue(cid, 52481, -1)
  45.    setPlayerStorageValue(cid, 52482, -1)
  46.    setPlayerStorageValue(cid, 52483, -1)
  47.    setPlayerStorageValue(cid, 6598754, -1)
  48.    doCreatureSetSkullType(cid, 0)
  49.    doRemoveCondition(cid, CONDITION_INFIGHT)
  50. end        
  51. end
  52. --/////////////////////////////////////////////////////////////////////////////////////////////--
  53. function nextHorario(cid)
  54.     horarioAtual = os.date("%X")
  55.     horario = string.explode(horarioAtual, ":")
  56.    
  57.     for i = 1, #horas do
  58.         horarioComparacao = horas[i]
  59.         horarioComp = string.explode(horarioComparacao, ":")
  60.         ---------------
  61.         if tonumber(horarioComp[1]) > tonumber(horario[1]) then
  62.            return horarioComparacao                                 --alterado v2.3
  63.         elseif tonumber(horarioComp[1]) == tonumber(horario[1]) and tonumber(horario[2]) < tonumber(horarioComp[2]) then
  64.            return horarioComparacao
  65.         end
  66.     end
  67.     return horas[1]                                  --alterado v2.3
  68. end                                                              
  69.  
  70. function getTimeDiff(timeDiff)
  71. local dateFormat = {
  72. {'hour', timeDiff / 60 / 60}, --6%
  73. {'min', timeDiff / 60 % 60},
  74. }
  75. local out = {}                                   --alterado v2.3
  76. for k, t in ipairs(dateFormat) do
  77.     local v = math.floor(t[2])
  78.     if(v > -1) then
  79.          table.insert(out, (k < #dateFormat and '' or ' and ') .. v .. '' .. (v <= 1 and t[1] or t[1].."s"))
  80.     end
  81. end
  82. if tonumber(dateFormat[1][2]) == 0 and tonumber(dateFormat[2][2]) == 0 then
  83.    return "seconds"
  84. end
  85. return table.concat(out)
  86. end
  87.  
  88. function showTimeDiff(timeComp)
  89. local b = string.explode(os.date("%X"), ":")
  90. local c = string.explode(timeComp, ":")
  91.     ---
  92.     local d, m, y = os.date("%d"), os.date("%m"), os.date("%Y")
  93.     local hAtual, mAtual = tonumber(b[1]), tonumber(b[2])
  94.     local hComp, mComp = tonumber(c[1]), tonumber(c[2])
  95.     ---
  96.     local t = os.time{year= y, month= m, day= d, hour= hAtual, min= mAtual}
  97.     local t1 = os.time{year= y, month= m, day= d, hour= hComp, min= mComp}
  98.     ---                                                                         --alterado v2.3
  99.     comparacao = t1-t
  100.     if hComp < hAtual then
  101.        v = os.time{year= y, month= m, day= d, hour= 24, min= 0}
  102.        v2 = os.time{year= y, month= m, day= d, hour= 0, min= 0}
  103.        comparacao = (v-t)+(t1-v2)
  104.     end
  105. return getTimeDiff(comparacao)
  106. end
  107. -------------------------------------------------------------------------
  108. function cleanCMcds(item)
  109. if item ~= 0 then
  110.    for c = 1, 15 do              --alterado v2.5
  111.       local str = "cm_move"..c
  112.       setCD(item, str, 0)
  113.    end
  114. end
  115. end
  116.  
  117. function ehNPC(cid)
  118. if isCreature(cid) and not isPlayer(cid) and not isSummon(cid) and not isMonster(cid) then
  119. return true
  120. end                                 --alterado v2.5                  
  121. return false
  122. end
  123.  
  124.  
  125. function ehMonstro(cid)
  126. if not isPlayer(cid) and not isSummon(cid) and not isNpc(cid) then
  127. return true
  128. end                                                   --function pro exp.lua...
  129. return false
  130. end
  131.  
  132. function doAppear(cid)    --Faz um poke q tava invisivel voltar a ser visivel...
  133. if not isCreature(cid) then return true end
  134.     doRemoveCondition(cid, CONDITION_INVISIBLE)
  135.     doRemoveCondition(cid, CONDITION_OUTFIT)
  136.     doCreatureSetHideHealth(cid, false)
  137. end
  138.  
  139. function doDisapear(cid)   --Faz um pokemon ficar invisivel
  140. if not isCreature(cid) then return true end
  141. doCreatureAddCondition(cid, permanentinvisible)
  142. doCreatureSetHideHealth(cid, true)
  143. doSetCreatureOutfit(cid, {lookType = 2}, -1)
  144. end
  145.  
  146. function hasTile(pos)    --Verifica se tem TILE na pos
  147. pos.stackpos = 0
  148. if getTileThingByPos(pos).itemid >= 1 then
  149.    return true
  150. end
  151. return false
  152. end
  153.  
  154. function getThingFromPosWithProtect(pos)  --Pega uma creatura numa posiçao com proteçoes
  155. if hasTile(pos) then
  156. pos.stackpos = 253
  157.    pid = getThingfromPos(pos).uid
  158. else
  159.    pid = getThingfromPos({x=1,y=1,z=10,stackpos=253}).uid
  160. end
  161. return pid
  162. end
  163.  
  164. function getTileThingWithProtect(pos)    --Pega um TILE com proteçoes
  165. if hasTile(pos) then
  166. pos.stackpos = 0
  167.    pid = getTileThingByPos(pos)
  168. else
  169.    pid = getTileThingByPos({x=1,y=1,z=10,stackpos=0})
  170. end
  171. return pid
  172. end
  173.  
  174. function canAttackOther(cid, pid)         --Function q verifica se um poke/player pode atacar outro poke/player
  175.  
  176. if not isCreature(cid) or not isCreature(pid) then return "Cant" end
  177.  
  178. local master1 = isSummon(cid) and getCreatureMaster(cid) or cid
  179. local master2 = isSummon(pid) and getCreatureMaster(pid) or pid
  180.  
  181.    if isInParty(master1) and isInParty(master2) then
  182.       if getPlayerParty(master1) == getPlayerParty(master2) then
  183.          if isSummon(cid) and isPlayer(pid) then
  184.             return "Cant"
  185.          else
  186.             return "Can"
  187.          end
  188.       end
  189.    end
  190.    ----              --alterado v2.6 duel system
  191.    if getPlayerStorageValue(master1, 6598754) >= 5 and getPlayerStorageValue(master2, 6598754) >= 5 then
  192.       if getPlayerStorageValue(master1, 6598754) ~= getPlayerStorageValue(master2, 6598754) then
  193.          if getPlayerStorageValue(master1, 52482) == getCreatureName(master2) and getPlayerStorageValue(master2, 52482) == getCreatureName(master1) then
  194.             if isSummon(cid) and isPlayer(pid) then
  195.                return "Cant"
  196.             else
  197.                return "Can"
  198.             end
  199.          end
  200.       end
  201.    end
  202.    ----
  203.    if getPlayerStorageValue(master1, 6598754) >= 1 and getPlayerStorageValue(master2, 6598755) >= 1 then
  204.       return "Can"
  205.    end
  206.    if getPlayerStorageValue(master1, 6598755) >= 1 and getPlayerStorageValue(master2, 6598754) >= 1 then  ---estar em times diferentes
  207.       return "Can"
  208.    end
  209.    ----
  210.    if ehMonstro(cid) or ehMonstro(pid) then
  211.       return "Can"
  212.    end
  213.  
  214. return "Cant"
  215. end
  216.    
  217.      
  218. function stopNow(cid, time)    --function q faz o poke/player ficar imovel por um tempo
  219. if not isCreature(cid) then return true end
  220. if isSleeping(cid) then return true end
  221.  
  222. local speed = getCreatureSpeed(cid)
  223.  
  224. if isPlayer(cid) then
  225.    mayNotMove(cid, true)                      --alterado v2.4
  226.    addEvent(mayNotMove, time, cid, false)
  227. else
  228.    doChangeSpeed(cid, -speed)
  229.    addEvent(doRegainSpeed, time, cid)
  230. end
  231. end
  232.  
  233.  
  234. function doReduceStatus(cid, off, def, agi)   --reduz os status
  235. if not isCreature(cid) then return true end
  236. local A = getOffense(cid)
  237. local B = getDefense(cid)
  238. local C = getSpeed(cid)
  239.  
  240. if off > 0 then
  241.    setPlayerStorageValue(cid, 1001, A - off)
  242. end
  243. if def > 0 then
  244.    setPlayerStorageValue(cid, 1002, B - def)
  245. end
  246. if agi > 0 then
  247.    setPlayerStorageValue(cid, 1003, C - agi)
  248.    if getCreatureSpeed(cid) ~= 0 then
  249.       doRegainSpeed(cid)
  250.    end                                              --alterado v2.5  functions arrumadas...
  251. end
  252. end
  253.  
  254. function doRaiseStatus(cid, off, def, agi, time)  
  255. if not isCreature(cid) then return true end
  256. local A = getOffense(cid)
  257. local B = getDefense(cid)
  258. local C = getSpeed(cid)
  259.  
  260. if off > 0 then
  261.    setPlayerStorageValue(cid, 1001, A * off)
  262. end
  263. if def > 0 then
  264.    setPlayerStorageValue(cid, 1002, B * def)
  265. end
  266. if agi > 0 then
  267.    setPlayerStorageValue(cid, 1003, C + agi)
  268.    if getCreatureSpeed(cid) ~= 0 then
  269.       doRegainSpeed(cid)
  270.    end
  271. end
  272.  
  273. local D = getOffense(cid)
  274. local E = getDefense(cid)
  275. local F = getSpeed(cid)
  276. ---------------------------
  277. local G = D - A
  278. local H = E - B
  279. local I = F - C
  280.  
  281. addEvent(doReduceStatus, time*1000, cid, G, H, I)
  282. end
  283.  
  284.  
  285. function BackTeam(cid)          
  286.   if isCreature(cid) then
  287.      local summon = getCreatureSummons(cid)   --alterado v2.6
  288.      for i = 2, #summon do
  289.          doSendMagicEffect(getThingPos(summon[i]), 211)
  290.          doRemoveCreature(summon[i])
  291.      end
  292.      setPlayerStorageValue(cid, 637501, -1)
  293.   end  
  294. end
  295.    
  296. function choose(...) -- by mock
  297.     local arg = {...}
  298.     return arg[math.random(1,#arg)]
  299. end
  300.  
  301. function AddPremium(cid, days)
  302. local function removerPlayer(cid)
  303. if isCreature(cid) then
  304.    doRemoveCreature(cid)
  305. end
  306. end
  307.  
  308. db.executeQuery("UPDATE `accounts` SET `premdays` = '"..days.."' WHERE `accounts`.`id` = ".. getPlayerAccountId(cid) ..";")
  309. doPlayerSendTextMessage(cid,25,"Você será kickado em 5 segundos.")    
  310. addEvent(removerPlayer, 5*1000, cid)    
  311. return TRUE
  312. end
  313.  
  314. function isShiny(cid)
  315. if not isCreature(cid) then
  316. return false
  317. end
  318.  
  319. if string.find(tostring(getCreatureName(cid)), "Shiny") then
  320. return true
  321. end
  322. return false
  323. end
  324.  
  325. function isShinyName(name)       --verifica se um nome tem a palavra "Shiny" nele...
  326.   if string.find(tostring(name), "Shiny") then
  327.   return true
  328.   end
  329. return false
  330. end
  331.  
  332. function doConvertTypeToStone(type, string)
  333. local t = {
  334. ["fly"] = {heart, "heart"},
  335. ["flying"] = {heart, "heart"},
  336. ["normal"] = {heart, "heart"},
  337. ["fire"] = {fire, "fire"},
  338. ["grass"] = {leaf, "leaf"},
  339. ["leaf"] = {leaf, "leaf"},
  340. ["water"] = {water, "water"},
  341. ["poison"] = {venom, "venom"},
  342. ["venom"] = {venom, "venom"},
  343. ["electric"] = {thunder, "thunder"},
  344. ["thunder"] = {thunder, "thunder"},
  345. ["rock"] = {rock, "rock"},
  346. ["fight"] = {punch, "punch"},
  347. ["fighting"] = {punch, "punch"},
  348. ["bug"] = {coccon, "coccon"},
  349. ["dragon"] = {crystal, "crystal"},
  350. ["dark"] = {dark, "dark"},
  351. ["ghost"] = {dark, "dark"},
  352. ["ground"] = {earth, "earth"},
  353. ["earth"] = {earth, "earth"},
  354. ["psychic"] = {enigma, "enigma"},
  355. ["steel"] = {metal, "metal"},
  356. ["metal"] = {metal, "metal"},
  357. ["ice"] = {ice, "ice"},
  358. }
  359.  
  360. if string then
  361. return t[type][2]
  362. else
  363. return t[type][1]
  364. end
  365. end
  366.  
  367. function doConvertStoneIdToString(stoneID)
  368. local t = {
  369. [11453] = "Heart Stone",
  370. [11441] = "Leaf Stone",
  371. [11442] = "Water Stone",
  372. [11443] = "Venom Stone",
  373. [11444] = "Thunder Stone",
  374. [11445] = "Rock Stone",
  375. [11446] = "Punch Stone",
  376. [11447] = "Fire Stone",               --alterado v2.6
  377. [11448] = "Cocoon Stone",
  378. [11449] = "Crystal Stone",
  379. [11450] = "Darkess Stone",
  380. [11451] = "Earth Stone",
  381. [11452] = "Enigma Stone",
  382. [11454] = "Ice Stone",
  383. [12244] = "King's Rock",
  384. [12232] = "Metal Stone",
  385. [12242] = "Sun Stone",
  386. [12401] = "Shiny Fire Stone",
  387. [12402] = "Shiny Water Stone",
  388. [12403] = "Shiny Leaf Stone",
  389. [12404] = "Shiny Heart Stone",
  390. [12405] = "Shiny Enigma Stone",
  391. [12406] = "Shiny Rock Stone",
  392. [12407] = "Shiny Venom Stone",
  393. [12408] = "Shiny Ice Stone",
  394. [12409] = "Shiny Thunder Stone",
  395. [12410] = "Shiny Crystal Stone",
  396. [12411] = "Shiny Cocoon Stone",
  397. [12412] = "Shiny Darkness Stone",
  398. [12413] = "Shiny Punch Stone",
  399. [12414] = "Shiny Earth Stone",
  400. }
  401. if t[stoneID] then
  402. return t[stoneID]
  403. else
  404. return ""
  405. end
  406. end
  407.  
  408. function isStone(id)
  409.     if id >= leaf and id <= ice then
  410.     return true
  411.     end
  412. return false
  413. end
  414.  
  415. function isWater(id)
  416. if id >= 4820 and id <= 4825 then
  417. return true
  418. end
  419. return false
  420. end
  421.  
  422. function getTopCorpse(position)
  423.     local pos = position
  424.  
  425.         for n = 1, 255 do
  426.  
  427.             pos.stackpos = n
  428.             local item = getTileThingByPos(pos)
  429.  
  430.             if item.itemid >= 2 and (string.find(getItemNameById(item.itemid), "fainted ") or string.find(getItemNameById(item.itemid), "defeated ")) then
  431.                 return getTileThingByPos(pos)
  432.             end
  433.         end
  434. return null
  435. end
  436.  
  437. bpslot = CONST_SLOT_BACKPACK
  438.  
  439. function hasPokemon(cid)
  440.     if not isCreature(cid) then return false end
  441.     if getCreatureMana(cid) <= 0 then return false end
  442.     if #getCreatureSummons(cid) >= 1 then return true end
  443.     local item = getPlayerSlotItem(cid, CONST_SLOT_FEET)
  444.     local bp = getPlayerSlotItem(cid, bpslot)
  445.     for a, b in pairs (pokeballs) do
  446.         if item.itemid == b.on or item.itemid == b.use then
  447.         return true                              --alterado v2.4
  448.         end
  449.         if #getItemsInContainerById(bp.uid, b.on) >= 1 then
  450.         return true
  451.         end
  452.     end
  453. return false
  454. end
  455.  
  456. function isNpcSummon(cid)
  457. return isNpc(getCreatureMaster(cid))
  458. end
  459.  
  460. function getPokemonHappinessDescription(cid)
  461.     if not isCreature(cid) then return true end
  462.     local str = ""
  463.     if getPokemonGender(cid) == SEX_MALE then
  464.         str = "He"
  465.     elseif getPokemonGender(cid) == SEX_FEMALE then
  466.         str = "She"
  467.     else
  468.         str = "It"
  469.     end
  470.     local h = getPlayerStorageValue(cid, 1008)
  471.     if h >= tonumber(getConfigValue('PokemonStageVeryHappy')) then
  472.         str = str.." is very happy with you!"
  473.     elseif h >= tonumber(getConfigValue('PokemonStageHappy')) then
  474.         str = str.." is happy."
  475.     elseif h >= tonumber(getConfigValue('PokemonStageOK')) then
  476.         str = str.." is unhappy."
  477.     elseif h >= tonumber(getConfigValue('PokemonStageSad')) then
  478.         str = str.." is sad."
  479.     elseif h >= tonumber(getConfigValue('PokemonStageMad')) then
  480.         str = str.." is mad."
  481.     else
  482.         str = str.." is very mad at you!"
  483.     end
  484. return str
  485. end
  486.  
  487. function doSetItemAttribute(item, key, value)
  488. doItemSetAttribute(item, key, value)
  489. end
  490.  
  491. function deTransform(cid, check)
  492.     if not isCreature(cid) then return true end
  493.  
  494.     local m = getCreatureMaster(cid)
  495.     local p = getPlayerSlotItem(m, 8)
  496.  
  497.     if getItemAttribute(p.uid, "transTurn") ~= check then return true end
  498.  
  499.     setPlayerStorageValue(cid, 1010, "Ditto")
  500.     doRemoveCondition(cid, CONDITION_OUTFIT)
  501.     doSendMagicEffect(getThingPos(cid), 184)
  502.     doCreatureSay(cid, "DITTO!", TALKTYPE_MONSTER)
  503.     doItemSetAttribute(p.uid, "transBegin", 0)
  504.     doItemSetAttribute(p.uid, "transLeft", 0)
  505.     doItemEraseAttribute(p.uid, "transName")
  506.     doItemEraseAttribute(p.uid, "boffense")
  507.     doItemEraseAttribute(p.uid, "bdefense")
  508.     doItemEraseAttribute(p.uid, "bsattack")
  509.     doItemEraseAttribute(p.uid, "bagility")
  510. end
  511.  
  512. function isTransformed(cid)
  513.     if getPlayerStorageValue(cid, 1010) == "Ditto" then
  514.     return false
  515.     else
  516.     return true
  517.     end
  518. end
  519.  
  520. function doSendFlareEffect(pos)
  521.     local random = {28, 29, 79}
  522.     doSendMagicEffect(pos, random[math.random(1, 3)])
  523. end
  524.  
  525. function isDay()
  526.     local a = getWorldTime()
  527.     if a >= 360 and a < 1080 then
  528.     return true
  529.     end
  530. return false
  531. end
  532.  
  533. function doPlayerSendTextWindow(cid, p1, p2)
  534.     if not isCreature(cid) then return true end
  535.     local item = 460
  536.     local text = ""
  537.     if type(p1) == "string" then
  538.         doShowTextDialog(cid, item, p1)
  539.     else
  540.         doShowTextDialog(cid, p1, p2)
  541.     end
  542. end
  543.  
  544. function getClockString(tw)
  545.     local a = getWorldTime()
  546.     local b = a / 60
  547.     local hours = math.floor(b)
  548.     local minut = a - (60 * hours)
  549.  
  550.     if not tw then
  551.         if hours < 10 then
  552.             hours = "0"..hours..""
  553.         end
  554.         if minut < 10 then
  555.             minut = "0"..minut..""
  556.         end
  557.     return hours..":"..minut
  558.     else
  559.         local sm = "a.m"
  560.         if hours >= 12 then
  561.             hours = hours - 12
  562.             sm = "p.m"
  563.         end
  564.         if hours < 10 then
  565.             hours = "0"..hours..""
  566.         end
  567.         if minut < 10 then
  568.             minut = "0"..minut..""
  569.         end
  570.     return hours..":"..minut.." "..sm
  571.     end
  572. end
  573.  
  574. function doCorrectPokemonName(poke)
  575. return doCorrectString(poke)
  576. end
  577.  
  578. function doCorrectString(poke)
  579. local name = ""
  580.     local n = string.explode(poke, " ")
  581.     local str = string.sub(n[1], 1, 1)
  582.     local sta = string.sub(n[1], 2, string.len(n[1]))
  583.     name = ""..string.upper(str)..""..string.lower(sta)..""
  584.     if n[2] then
  585.     str = string.sub(n[2], 1, 1)
  586.     sta = string.sub(n[2], 2, string.len(n[2]))
  587.     name = name.." "..string.upper(str)..""..string.lower(sta)..""
  588.     end
  589. return name
  590. end
  591.  
  592. function getHappinessRate(cid)
  593.     if not isCreature(cid) then return 1 end
  594.     local a = getPlayerStorageValue(cid, 1008)
  595.         if a == -1 then return 1 end
  596.     if a >= getConfigValue('PokemonStageVeryHappy') then
  597.         return happinessRate[5].rate
  598.     elseif a >= getConfigValue('PokemonStageHappy') then
  599.         return happinessRate[4].rate
  600.     elseif a >= getConfigValue('PokemonStageOK') then
  601.         return happinessRate[3].rate
  602.     elseif a >= getConfigValue('PokemonStageSad') then
  603.         return happinessRate[2].rate
  604.     else
  605.         return happinessRate[1].rate
  606.     end
  607. return 1
  608. end
  609.  
  610. function doBodyPush(cid, target, go, pos)
  611.     if not isCreature(cid) or not isCreature(target) then
  612.         doRegainSpeed(cid)
  613.         doRegainSpeed(target)
  614.     return true
  615.     end
  616.         if go then
  617.             local a = getThingPos(cid)
  618.             doChangeSpeed(cid, -getCreatureSpeed(cid))
  619.                 if not isPlayer(target) then
  620.                     doChangeSpeed(target, -getCreatureSpeed(target))
  621.                 end
  622.             doChangeSpeed(cid, 800)
  623.             doTeleportThing(cid, getThingPos(target))
  624.             doChangeSpeed(cid, -800)
  625.             addEvent(doBodyPush, 350, cid, target, false, a)
  626.         else
  627.             doChangeSpeed(cid, 800)
  628.             doTeleportThing(cid, pos)
  629.             doRegainSpeed(cid)
  630.             doRegainSpeed(target)
  631.         end
  632. end
  633.  
  634. function doReturnPokemon(cid, pokemon, pokeball, effect, hideeffects, blockevo)
  635.  
  636.     --////////////////////////////////////////////////////////////////////////////////////////--
  637.     checkDuel(cid)                                                                      --alterado v2.6 duel system
  638.     --////////////////////////////////////////////////////////////////////////////////////////--
  639.     if #getCreatureSummons(cid) > 1 and getPlayerStorageValue(cid, 212124) <= 0 then     --alterado v2.6
  640.        if getPlayerStorageValue(cid, 637501) == -2 or getPlayerStorageValue(cid, 637501) >= 1 then  
  641.           BackTeam(cid)      
  642.        end
  643.     end
  644.     ----------------------
  645.     local edit = true
  646.  
  647.     if not pokeball then
  648.         pokeball = getPlayerSlotItem(cid, 8)
  649.     end
  650.  
  651.     if blockevo then
  652.         edit = false
  653.         doPlayerSendCancel(cid, "Your pokemon couldn't evolve due to server mistakes, please wait until we fix the problem.")
  654.     end
  655.  
  656.     local happy = getPlayerStorageValue(pokemon, 1008)
  657.     local hunger = getPlayerStorageValue(pokemon, 1009)
  658.     local pokelife = (getCreatureHealth(pokemon) / getCreatureMaxHealth(pokemon))
  659.  
  660.     if edit then
  661.         doItemSetAttribute(pokeball.uid, "happy", happy)
  662.         doItemSetAttribute(pokeball.uid, "hunger", hunger)
  663.         doItemSetAttribute(pokeball.uid, "hp", pokelife)
  664.     end
  665.  
  666.     if getCreatureName(pokemon) == "Ditto" then
  667.         if isTransformed(pokemon) then
  668.             local left = getItemAttribute(pokeball.uid, "transLeft") - (os.clock() - getItemAttribute(pokeball.uid, "transBegin"))
  669.             doItemSetAttribute(pokeball.uid, "transLeft", left)
  670.         end
  671.     end
  672.  
  673.     if hideeffects then
  674.         doRemoveCreature(pokemon)
  675.     return true
  676.     end
  677.  
  678.     local pokename = getPokeName(pokemon)
  679.  
  680.     local mbk = gobackmsgs[math.random(1, #gobackmsgs)].back:gsub("doka", pokename)
  681.  
  682.     if getCreatureCondition(cid, CONDITION_INFIGHT) then
  683.         if isCreature(getCreatureTarget(cid)) then
  684.             doItemSetAttribute(pokeball.uid, "happy", happy - 5)
  685.         else
  686.             doItemSetAttribute(pokeball.uid, "happy", happy - 2)
  687.         end
  688.     end
  689.  
  690.     doTransformItem(pokeball.uid, pokeball.itemid-1)
  691.     doCreatureSay(cid, mbk, TALKTYPE_SAY)
  692.  
  693.     doSendMagicEffect(getCreaturePosition(pokemon), effect)
  694.  
  695.     doRemoveCreature(pokemon)
  696.  
  697.     if useKpdoDlls then
  698.         doUpdateMoves(cid)
  699.     end
  700.  
  701. end
  702.  
  703. local EFFECTS = {
  704.     --[OutfitID] = {Effect}
  705.     ["Magmar"] = 35,    --magmar            --alterado v2.5
  706.     ["Jynx"] = 17,    --jynx
  707.     ["Shiny Jynx"] = 17,    --shiny jynx
  708. }
  709.  
  710. function doGoPokemon(cid, item)
  711.  
  712.     if getPlayerStorageValue(cid, 17000) >= 1 or getPlayerStorageValue(cid, 17001) >= 1 or getPlayerStorageValue(cid, 63215) >= 1 then
  713.     return true
  714.     end
  715. ---------------------------------------------------------------
  716. local ballName = getItemAttribute(item.uid, "poke")
  717.  
  718.    btype = getPokeballType(item.itemid)                  
  719.  
  720.     local effect = pokeballs[btype].effect
  721.         if not effect then
  722.             effect = 21
  723.         end
  724. -----------------------------------------------------------------
  725.     if item.uid ~= getPlayerSlotItem(cid, CONST_SLOT_FEET).uid then
  726.         doPlayerSendCancel(cid, "You must put your pokeball in the correct place!")
  727.     return TRUE
  728.     end
  729.  
  730.     local thishp = getItemAttribute(item.uid, "hp")
  731.  
  732.     if thishp <= 0 then
  733.         if isInArray(pokeballs[btype].all, item.itemid) then
  734.             doTransformItem(item.uid, pokeballs[btype].off)
  735.             doItemSetAttribute(item.uid, "hp", 0)
  736.             doPlayerSendCancel(cid, "This pokemon is fainted.")
  737.             return true
  738.         end
  739.     end
  740.    
  741.     local pokemon = getItemAttribute(item.uid, "poke")
  742.  
  743.     if not pokes[pokemon] then
  744.     return true
  745.     end
  746.    
  747. ----------------------- Sistema de nao poder carregar mais que 3 pokes lvl baixo e + q 1 poke de lvl medio/alto ---------------------------------
  748. if not isInArray({5, 6}, getPlayerGroupId(cid)) then
  749. local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
  750. local lowPokes = {"Rattata", "Caterpie", "Weedle", "Oddish", "Pidgey", "Paras", "Poliwag", "Bellsprout", "Magikarp", "Hoppip", "Sunkern"}
  751. local low = {}
  752. local lw = 1
  753. for e, f in pairs(pokeballs) do
  754.     for times = 1, 3 do
  755.         local items = getItemsInContainerById(bp.uid, pokeballs[e].all[times])
  756.         if #items >= 1 then                                                                 --alterado v2.6
  757.            for _, uid in pairs(items) do
  758.                local nome1 = getItemAttribute(uid, "poke")
  759.                if not isInArray(lowPokes, pokemon) and nome1 == pokemon then
  760.                   return doPlayerSendTextMessage(cid, 27, "Sorry, but you can't carry two pokemons equals!")
  761.                elseif isInArray(lowPokes, pokemon) then
  762.                   if nome1 == pokemon then
  763.                      table.insert(low, lw, nome1)
  764.                      lw = lw +1
  765.                   end
  766.                end
  767.            end
  768.         end
  769.     end
  770. end
  771. if #low >= 3 then
  772.    return doPlayerSendTextMessage(cid, 27, "Sorry, but you can't carry more than three pokemons equals of low level!")
  773. end
  774. end
  775. ---------------------------------------------------------------------------------------------------------------------------------------------------
  776.  
  777.     local x = pokes[pokemon]
  778.     local boosts = getItemAttribute(item.uid, "boost") or 0
  779.  
  780.     if getPlayerLevel(cid) + pokemonMaxLevelAbovePlayer < getItemAttribute(item.uid, "level") then
  781.     doPlayerSendCancel(cid, "Your pokemon's level is much higher than yours, you can't use him.")
  782.     return true
  783.     end
  784.    
  785.     --------------------------------------------------------------------------------------
  786.     shinysClan = {
  787.     ["Shiny Fearow"] = {4, "Wingeon"},
  788.     ["Shiny Flareon"] = {1, "Volcanic"},
  789.     ["Shiny Vaporeon"] = {2, "Seavel"},
  790.     ["Shiny Jolteon"] = {9, "Raibolt"},
  791.     ["Shiny Hypno"] = {7, "Psycraft"},          
  792.     ["Shiny Golem"] = {3, "Orebound"},
  793.     ["Shiny Vileplume"] = {8, "Naturia"},
  794.     ["Shiny Nidoking"] = {5, "Malefic"},
  795.     ["Shiny Hitmontop"] = {6, "Gardestrike"},   --alterado v2.4
  796.     }
  797.    
  798.     if shinysClan[pokemon] and (getPlayerGroupId(cid) < 3 or getPlayerGroupId(cid) > 6) then
  799.        if getPlayerStorageValue(cid, 86228) ~= shinysClan[pokemon][1] then
  800.           doPlayerSendCancel(cid, "You need be a member of the clan "..shinysClan[pokemon][2].." to use this pokemon!")
  801.           return true  
  802.        elseif getPlayerStorageValue(cid, 862281) ~= 5 then
  803.           doPlayerSendCancel(cid, "You need be atleast rank 5 to use this pokemon!")
  804.           return true
  805.        end
  806.     end
  807.     --------------------------------------------------------------------------------------
  808.  
  809.     doSummonMonster(cid, pokemon)
  810.  
  811.     local pk = getCreatureSummons(cid)[1]
  812.     if not isCreature(pk) then return true end
  813.    
  814.     ------------------------passiva hitmonchan------------------------------
  815.     if isSummon(pk) then
  816.        --local e = getCreatureMaster(cid)
  817.        local nameHIT = getItemAttribute(getPlayerSlotItem(cid, 8).uid, "poke")
  818.        local hands = getItemAttribute(getPlayerSlotItem(cid, 8).uid, "hands")
  819.        if nameHIT == "Shiny Hitmonchan" or nameHIT == "Hitmonchan" then
  820.           if getItemAttribute(getPlayerSlotItem(cid, 8).uid, "hands") then
  821.              doSetCreatureOutfit(pk, {lookType = hitmonchans[nameHIT][hands].out}, -1)
  822.           else
  823.               doPlayerSendTextMessage(cid, 27, "Contact a GameMaster! Error in passive system! Attribute \"hands\" missing")  
  824.           end
  825.        end
  826.     end
  827.     -------------------------------------------------------------------------
  828.     ---------movement magmar, jynx-------------
  829.     if EFFECTS[getCreatureName(pk)] then   --alterado v2.5  
  830.        markPosEff(pk, getThingPos(pk))
  831.        sendMovementEffect(pk, EFFECTS[getCreatureName(pk)], getThingPos(pk))  --alterado v2.5
  832.     end
  833.     --------------------------------------------------------------------------  
  834.  
  835.     if getCreatureName(pk) == "Ditto" then
  836.  
  837.         local left = getItemAttribute(item.uid, "transLeft")
  838.         local name = getItemAttribute(item.uid, "transName")
  839.  
  840.         if left and left > 0 then
  841.             setPlayerStorageValue(pk, 1010, name)
  842.             doSetCreatureOutfit(pk, {lookType = getItemAttribute(item.uid, "transOutfit")}, -1)
  843.             addEvent(deTransform, left * 1000, pk, getItemAttribute(item.uid, "transTurn"))
  844.             doItemSetAttribute(item.uid, "transBegin", os.clock())
  845.         else
  846.             setPlayerStorageValue(pk, 1010, "Ditto")
  847.         end
  848.     end
  849.  
  850.     if isGhostPokemon(pk) then doTeleportThing(pk, getPosByDir(getThingPos(cid), math.random(0, 7)), false) end
  851.  
  852.     doCreatureSetLookDir(pk, 2)
  853.  
  854.     adjustStatus(pk, item.uid, true, false, true)
  855.     doAddPokemonInOwnList(cid, pokemon)
  856.  
  857.     doTransformItem(item.uid, item.itemid+1)
  858.  
  859.     local pokename = getItemAttribute(item.uid, "nick") or getCreatureName(pk)
  860.  
  861.     local mgo = gobackmsgs[math.random(1, #gobackmsgs)].go:gsub("doka", pokename)
  862.     doCreatureSay(cid, mgo, TALKTYPE_SAY)
  863.  
  864.     doSendMagicEffect(getCreaturePosition(pk), effect)
  865.  
  866.     if useKpdoDlls then
  867.         doUpdateMoves(cid)
  868.     end
  869. end
  870.  
  871. function doRegainSpeed(cid)
  872. if not isCreature(cid) then return 0 end
  873.     if isPlayer(cid) or isNpc(cid) or ehNPC(cid) then  --alterado v2.5
  874.         local speed = PlayerSpeed
  875.         if isPlayer(cid) and getPlayerGroupId(cid) >= 4 and getPlayerGroupId(cid) <= 7 then
  876.            speed = 140*getPlayerGroupId(cid)
  877.         end
  878.         if getCreatureCondition(cid, CONDITION_PARALYZE) == true then
  879.            doRemoveCondition(cid, CONDITION_PARALYZE)
  880.            addEvent(doAddCondition, 10, cid, paralizeArea2)              --alterado v2.5
  881.         end                                    
  882.         doChangeSpeed(cid, speed)
  883.     return speed
  884.     end
  885.    
  886. local speed = getCreatureBaseSpeed(cid) + getSpeed(cid) * speedRate   --alterado v2.3
  887.     if speed > 1500 then
  888.         speed = 1500
  889.     end
  890.    
  891. doChangeSpeed(cid, -getCreatureSpeed(cid))
  892. if getCreatureCondition(cid, CONDITION_PARALYZE) == true then
  893.    doRemoveCondition(cid, CONDITION_PARALYZE)
  894.    addEvent(doAddCondition, 10, cid, paralizeArea2)     --alterado v2.5        
  895. end
  896. doChangeSpeed(cid, speed)
  897. return speed
  898. end
  899.  
  900. function isPosEqualPos(pos1, pos2, checkstackpos)
  901.     if pos1.x ~= pos2.x or pos1.y ~= pos2.y and pos1.z ~= pos2.z then
  902.     return false
  903.     end
  904.     if checkstackpos and pos1.stackpos and pos2.stackpos and pos1.stackpos ~= pos2.stackpos then
  905.     return false
  906.     end
  907. return true
  908. end
  909.  
  910. function getRandomGenderByName(name)
  911. local rate = newpokedex[name]
  912.     if not rate then return 0 end
  913.     rate = rate.gender
  914.     if rate == 0 then
  915.         gender = 3
  916.     elseif rate == 1000 then
  917.         gender = 4
  918.     elseif rate == -1 then
  919.         gender = 0
  920.     elseif math.random(1, 1000) <= rate then
  921.         gender = 4
  922.     else
  923.         gender = 3
  924.     end
  925. return gender
  926. end
  927.  
  928. function getRecorderPlayer(pos, cid)
  929.     local ret = 0
  930.     if cid and getThingPos(cid).x == pos.x and getThingPos(cid).y == pos.y then
  931.     return cid
  932.     end
  933.     local s = {}
  934.     s.x = pos.x
  935.     s.y = pos.y
  936.     s.z = pos.z
  937.         for a = 0, 255 do
  938.             s.stackpos = a
  939.             local b = getTileThingByPos(s).uid
  940.             if b > 1 and isPlayer(b) and getCreatureOutfit(b).lookType ~= 814 then
  941.                 ret = b
  942.             end
  943.         end
  944. return ret
  945. end
  946.  
  947. function getRecorderCreature(pos, cid)
  948.     local ret = 0
  949.     if cid and getThingPos(cid).x == pos.x and getThingPos(cid).y == pos.y then
  950.     return cid
  951.     end
  952.     local s = {}
  953.     s.x = pos.x
  954.     s.y = pos.y
  955.     s.z = pos.z                                       --alterado v2.6
  956.         for a = 0, 255 do
  957.             s.stackpos = a
  958.             local b = getTileThingByPos(s).uid
  959.             if b > 1 and isCreature(b) and getCreatureOutfit(b).lookType ~= 814 then
  960.                 ret = b
  961.             end
  962.         end
  963. return ret
  964. end
  965.  
  966. function doCreatureSetOutfit(cid, outfit, time)
  967.     doSetCreatureOutfit(cid, outfit, time)
  968. end
  969.  
  970. function doMagicalFlower(cid, away)
  971.     if not isCreature(cid) then return true end
  972.     for x = -3, 3 do
  973.         for y = -3, 3 do
  974.         local a = getThingPos(cid)
  975.         a.x = a.x + x
  976.         a.y = a.y + y
  977.             if away then
  978.                 doSendDistanceShoot(a, getThingPos(cid), 21)
  979.             else
  980.                 doSendDistanceShoot(getThingPos(cid), a, 21)
  981.             end
  982.         end
  983.     end
  984. end    
  985.  
  986. function isItemPokeball(item)
  987. if not item then return false end
  988. for a, b in pairs (pokeballs) do
  989.     if isInArray(b.all, item) then return true end
  990. end
  991. return false
  992. end
  993.  
  994. function isPokeball(item)
  995. if not item then return false end
  996.     if item >= 11826 and item <= 11837 then
  997.     return true
  998.     end
  999.     if item >= 11737 and item <= 11748 then
  1000.     return true
  1001.     end
  1002. return false
  1003. end
  1004.  
  1005. function getPokeballType(id)
  1006.     for a, b in pairs (pokeballs) do
  1007.         if isInArray(b.all, id) then
  1008.             return a
  1009.         end
  1010.     end
  1011. return "none"
  1012. end
  1013.  
  1014. randomdiagonaldir = {
  1015. [NORTHEAST] = {NORTH, EAST},
  1016. [SOUTHEAST] = {SOUTH, EAST},
  1017. [NORTHWEST] = {NORTH, WEST},
  1018. [SOUTHWEST] = {SOUTH, WEST}}
  1019.  
  1020. function doFaceOpposite(cid)
  1021. local a = getCreatureLookDir(cid)
  1022. local d = {
  1023. [NORTH] = SOUTH,
  1024. [SOUTH] = NORTH,
  1025. [EAST] = WEST,
  1026. [WEST] = EAST,
  1027. [NORTHEAST] = SOUTHWEST,
  1028. [NORTHWEST] = SOUTHEAST,
  1029. [SOUTHEAST] = NORTHWEST,
  1030. [SOUTHWEST] = NORTHEAST}
  1031. doCreatureSetLookDir(cid, d[a])
  1032. end
  1033.  
  1034. function doFaceRandom(cid)
  1035. local a = getCreatureLookDir(cid)
  1036. local d = {
  1037. [NORTH] = {SOUTH, WEST, EAST},
  1038. [SOUTH] = {NORTH, WEST, EAST},
  1039. [WEST] = {SOUTH, NORTH, EAST},
  1040. [EAST] = {SOUTH, WEST, NORTH}}
  1041. doChangeSpeed(cid, 1)
  1042. doCreatureSetLookDir(cid, d[a][math.random(1, 3)])
  1043. doChangeSpeed(cid, -1)
  1044. end
  1045.  
  1046. function getFaceOpposite(dir)
  1047. local d = {
  1048. [NORTH] = SOUTH,
  1049. [SOUTH] = NORTH,
  1050. [EAST] = WEST,
  1051. [WEST] = EAST,
  1052. [NORTHEAST] = SOUTHWEST,
  1053. [NORTHWEST] = SOUTHEAST,
  1054. [SOUTHEAST] = NORTHWEST,
  1055. [SOUTHWEST] = NORTHEAST}
  1056. return d[dir]
  1057. end
  1058.  
  1059. function getResistance(cid, combat)
  1060.     if isPlayer(cid) then return false end
  1061. local poketype1 = pokes[getCreatureName(cid)].type
  1062. local poketype2 = pokes[getCreatureName(cid)].type2
  1063. local multiplier = 1
  1064.     if effectiveness[combat].super and isInArray(effectiveness[combat].super, poketype1) then
  1065.         multiplier = multiplier * 2
  1066.     end
  1067.     if poketype2 and effectiveness[combat].super and isInArray(effectiveness[combat].super, poketype2) then
  1068.         multiplier = multiplier * 2
  1069.     end
  1070.     if effectiveness[combat].weak and isInArray(effectiveness[combat].weak, poketype1) then
  1071.         multiplier = multiplier * 0.5
  1072.     end
  1073.     if poketype2 and effectiveness[combat].weak and isInArray(effectiveness[combat].weak, poketype2) then
  1074.         multiplier = multiplier * 0.5
  1075.     end
  1076.     if effectiveness[combat].non and isInArray(effectiveness[combat].non, poketype1) then
  1077.         multiplier = multiplier * 0
  1078.     end
  1079.     if poketype2 and effectiveness[combat].non and isInArray(effectiveness[combat].non, poketype2) then
  1080.         multiplier = multiplier * 0
  1081.     end
  1082.  
  1083.     if multiplier == 0.25 then
  1084.         multiplier = 0.5
  1085.     elseif multiplier == 4 then
  1086.         multiplier = 2
  1087.     end
  1088.  
  1089. return multiplier
  1090. end
  1091.  
  1092. function getCreatureDirectionToTarget(cid, target, ranged)
  1093.     if not isCreature(cid) then return true end
  1094.     if not isCreature(target) then return getCreatureLookDir(cid) end
  1095.     local dirs = {
  1096.     [NORTHEAST] = {NORTH, EAST},
  1097.     [SOUTHEAST] = {SOUTH, EAST},
  1098.     [NORTHWEST] = {NORTH, WEST},
  1099.     [SOUTHWEST] = {SOUTH, WEST}}
  1100.     local x = getDirectionTo(getThingPos(cid), getThingPos(target), false)
  1101.         if x <= 3 then return x
  1102.         else
  1103.             local xdistance = math.abs(getThingPos(cid).x - getThingPos(target).x)
  1104.             local ydistance = math.abs(getThingPos(cid).y - getThingPos(target).y)
  1105.                 if xdistance > ydistance then
  1106.                     return dirs[x][2]
  1107.                 elseif ydistance > xdistance then
  1108.                     return dirs[x][1]
  1109.                 elseif isInArray(dirs[x], getCreatureLookDir(cid)) then
  1110.                     return getCreatureLookDir(cid)
  1111.                 else
  1112.                     return dirs[x][math.random(1, 2)]
  1113.                 end
  1114.         end
  1115. end
  1116.  
  1117. function getSomeoneDescription(cid)
  1118.     if isPlayer(cid) then return getPlayerNameDescription(cid) end
  1119. return getMonsterInfo(getCreatureName(cid)).description
  1120. end
  1121.    
  1122.  
  1123. function isGhostPokemon(cid)
  1124.     if not isCreature(cid) then return false end
  1125.     if isInArray({"Gengar", "Haunter", "Gastly", "Misdreavus", "Shiny Gengar"}, getCreatureName(cid)) then
  1126.     return true
  1127.     end
  1128. return false
  1129. end
  1130.  
  1131. function updateGhostWalk(cid)
  1132.     if not isCreature(cid) then return false end
  1133.     local pos = getThingPos(cid)
  1134.     pos.x = pos.x + 1
  1135.     pos.y = pos.y + 1
  1136.     local ret = getThingPos(cid)
  1137.     doTeleportThing(cid, pos, false)
  1138.     doTeleportThing(cid, ret, false)
  1139. return true
  1140. end
  1141.  
  1142. function doRemoveElementFromTable(t, e)
  1143.     local ret = {}
  1144.     for a = 1, #t do
  1145.         if t[a] ~= e then
  1146.         table.insert(ret, t[a])
  1147.         end
  1148.     end
  1149. return ret
  1150. end
  1151.  
  1152. function doFaceCreature(sid, pos)
  1153. if not isCreature(sid) then return true end
  1154.     if getThingPos(sid).x == pos.x and getThingPos(sid).y == pos.y then return true end
  1155.     local ret = 0
  1156.  
  1157.     local ld = getCreatureLookDir(sid)
  1158.     local dir = getDirectionTo(getThingPos(sid), pos)
  1159.     local al = {
  1160.     [NORTHEAST] = {NORTH, EAST},
  1161.     [NORTHWEST] = {NORTH, WEST},
  1162.     [SOUTHEAST] = {SOUTH, EAST},
  1163.     [SOUTHWEST] = {SOUTH, WEST}}
  1164.  
  1165.     if dir >= 4 and isInArray(al[dir], ld) then return true end
  1166.  
  1167.     doChangeSpeed(sid, 1)
  1168.         if dir == 4 then
  1169.             ret = math.random(2, 3)
  1170.         elseif dir == 5 then
  1171.             ret = math.random(1, 2)
  1172.         elseif dir == 6 then
  1173.             local dirs = {0, 3}
  1174.             ret = dirs[math.random(1, 2)]
  1175.         elseif dir == 7 then
  1176.             ret = math.random(0, 1)
  1177.         else
  1178.             ret = getDirectionTo(getThingPos(sid), pos)
  1179.         end
  1180. doCreatureSetLookDir(sid, ret)
  1181. doChangeSpeed(sid, -1)
  1182. return true
  1183. end
  1184.  
  1185. function doCreatureAddCondition(cid, condition)
  1186. if not isCreature(cid) then return true end
  1187. doAddCondition(cid, condition)
  1188. end
  1189.  
  1190. function doCreatureRemoveCondition(cid, condition)
  1191. if not isCreature(cid) then return true end
  1192. doRemoveCondition(cid, condition)
  1193. end
  1194.  
  1195. function setCD(item, tipo, tempo)
  1196.  
  1197.     if not tempo or not tonumber(tempo) then
  1198.         doItemEraseAttribute(item, tipo)
  1199.     return true
  1200.     end
  1201.  
  1202.     doItemSetAttribute(item, tipo, "cd:"..(tempo + os.time()).."")
  1203. return tempo + os.time()
  1204. end
  1205.  
  1206. function getCD(item, tipo, limite)
  1207.  
  1208.     if not getItemAttribute(item, tipo) then
  1209.     return 0
  1210.     end
  1211.  
  1212.     local string = getItemAttribute(item, tipo):gsub("cd:", "")
  1213.     local number = tonumber(string) - os.time()
  1214.  
  1215.     if number <= 0 then
  1216.     return 0
  1217.     end
  1218.  
  1219.     if limite and limite < number then
  1220.         return 0
  1221.     end
  1222.  
  1223. return number
  1224. end
  1225.  
  1226. function doSendMoveEffect(cid, target, effect)
  1227. if not isCreature(cid) or not isCreature(target) then return true end
  1228. doSendDistanceShoot(getThingPos(cid), getThingPos(target), effect)
  1229. return true
  1230. end
  1231.  
  1232. function doSetItemActionId(uid, actionid)
  1233. doItemSetAttribute(uid, "aid", actionid)
  1234. return true
  1235. end
  1236.  
  1237. function threeNumbers(number)
  1238.     if number <= 9 then
  1239.     return "00"..number..""
  1240.     elseif number <= 99 then
  1241.     return "0"..number..""
  1242.     end
  1243. return ""..number..""
  1244. end
  1245.  
  1246. function isBr(cid)
  1247. if getPlayerStorageValue(cid, 105505) ~= -1 then
  1248. return true
  1249. end
  1250. return false
  1251. end
  1252.  
  1253. function isBeingUsed(ball)
  1254. if isInArray({11827, 11830, 11833, 11836, 11738, 11741, 11744, 11747}, ball) then
  1255. return true
  1256. end
  1257. return false
  1258. end
  1259.  
  1260. function doRemoveTile(pos)-- Script by mock
  1261. pos.stackpos = 0
  1262. local sqm = getTileThingByPos(pos)
  1263. doRemoveItem(sqm.uid,1)
  1264. end
  1265.  
  1266. function doCreateTile(id,pos) -- By mock
  1267. doAreaCombatHealth(0,0,pos,0,0,0,CONST_ME_NONE)
  1268. doCreateItem(id,1,pos)
  1269. end
  1270.  
  1271. function hasSqm(pos)
  1272. local f = getTileThingByPos(pos)
  1273. if f.itemid ~= 0 and f.itemid ~= 1 then
  1274. return true
  1275. end
  1276. return false
  1277. end
  1278.  
  1279. function getPosDirs(p, dir) -- By MatheusMkalo
  1280. return dir == 1 and {x=p.x-1, y=p.y, z=p.z} or dir == 2 and {x=p.x-1, y=p.y+1, z=p.z} or dir == 3 and {x=p.x, y=p.y+1, z=p.z} or dir == 4 and {x=p.x+1, y=p.y+1, z=p.z} or dir == 5 and {x=p.x+1, y=p.y, z=p.z} or dir == 6 and {x=p.x+1, y=p.y-1, z=p.z} or dir == 7 and {x=p.x, y=p.y-1, z=p.z} or dir == 8 and {x=p.x-1, y=p.y-1, z=p.z}
  1281. end
  1282.  
  1283. function canWalkOnPos(pos, creature, pz, water, sqm, proj)
  1284. if not pos then return false end
  1285. if not pos.x then return false end
  1286. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid <= 1 and sqm then return false end
  1287. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 919 then return false end
  1288. 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
  1289. if getTopCreature(pos).uid > 0 and creature then return false end
  1290. if getTileInfo(pos).protection and pz then return false end
  1291.     local n = not proj and 3 or 2                                    --alterado v2.6
  1292.     for i = 0, 255 do
  1293.         pos.stackpos = i                          
  1294.         local tile = getTileThingByPos(pos)        
  1295.         if tile.itemid ~= 0 and i ~= 253 and not isCreature(tile.uid) then     --edited
  1296.             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1297.                 return false
  1298.             end
  1299.         end
  1300.     end  
  1301. return true
  1302. end
  1303.  
  1304. function canWalkOnPos2(pos, creature, pz, water, sqm, proj)     --alterado v2.6
  1305. if not pos then return false end
  1306. if not pos.x then return false end
  1307. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid <= 1 and sqm then return false end
  1308. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 919 then return false end
  1309. 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
  1310. if getTopCreature(pos).uid > 0 and creature then return false end
  1311. if getTileInfo(pos).protection and pz then return false end
  1312.     --[[local n = not proj and 3 or 2
  1313.     for i = 0, 255 do
  1314.         pos.stackpos = i                           --edited pra retirar um bug.. ;x
  1315.         local tile = getTileThingByPos(pos)        
  1316.         if tile.itemid ~= 0 and i ~= 253 and not isCreature(tile.uid) then     --edited
  1317.             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1318.                 return false
  1319.             end
  1320.         end
  1321.     end ]]  
  1322. return true
  1323. end
  1324.  
  1325. function getFreeTile(pos, cid)
  1326.     if canWalkOnPos(pos, true, false, true, true, false) then
  1327.         return pos
  1328.     end
  1329.     local positions = {}
  1330.     for a = 0, 7 do
  1331.         if canWalkOnPos(getPosByDir(pos, a), true, false, true, true, false) then
  1332.         table.insert(positions, pos)
  1333.         end
  1334.     end
  1335.     if #positions >= 1 then
  1336.         if isCreature(cid) then
  1337.             local range = 1000
  1338.             local ret = getThingPos(cid)
  1339.             for b = 1, #positions do
  1340.                 if getDistanceBetween(getThingPos(cid), positions[b]) < range then
  1341.                     ret = positions[b]
  1342.                     range = getDistanceBetween(getThingPos(cid), positions[b])
  1343.                 end
  1344.             end
  1345.             return ret
  1346.         else
  1347.             return positions[math.random(#positions)]
  1348.         end
  1349.     end
  1350. return getThingPos(cid)
  1351. end
  1352.  
  1353. function isWalkable(pos, creature, proj, pz, water)-- by Nord
  1354.     if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
  1355.     if isWater(getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid) and water then return false end
  1356.     if getTopCreature(pos).uid > 0 and creature then return false end
  1357.     if getTileInfo(pos).protection and pz then return false, true end
  1358.     local n = not proj and 3 or 2
  1359.     for i = 0, 255 do
  1360.         pos.stackpos = i
  1361.         local tile = getTileThingByPos(pos)
  1362.         if tile.itemid ~= 0 and not isCreature(tile.uid) then
  1363.             if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1364.                 return false
  1365.             end
  1366.         end
  1367.     end
  1368.     return true
  1369. end
  1370.  
  1371.  
  1372. function isPlayerSummon(cid, uid)
  1373. if getCreatureMaster(uid) == cid then
  1374. return TRUE
  1375. end
  1376. return FALSE
  1377. end
  1378.  
  1379. function isSummon(sid)
  1380. if not isCreature(sid) then return false end  --alterado v2.5
  1381. --
  1382. if isPlayer(sid) then
  1383. return false
  1384. end
  1385. if isPlayer(getCreatureMaster(sid)) then
  1386. return true
  1387. end
  1388. return false
  1389. end
  1390.  
  1391. function hasSpaceInContainer(container)                --alterado v2.6
  1392. if not isContainer(container) then return false end
  1393. if getContainerSize(container) < getContainerCap(container) then return true end
  1394.  
  1395. for slot = 0, (getContainerSize(container)-1) do
  1396.     local item = getContainerItem(container, slot)
  1397.     if isContainer(item.uid) then
  1398.        if hasSpaceInContainer(item.uid) then
  1399.           return true
  1400.        end
  1401.     end
  1402. end
  1403. return false
  1404. end
  1405.  
  1406. function getItemsInContainerById(container, itemid) -- Function By Kydrai
  1407. local items = {}
  1408. if isContainer(container) and getContainerSize(container) > 0 then
  1409. for slot=0, (getContainerSize(container)-1) do
  1410. local item = getContainerItem(container, slot)
  1411. if isContainer(item.uid) then
  1412. local itemsbag = getItemsInContainerById(item.uid, itemid)
  1413. for i=0, #itemsbag do
  1414. table.insert(items, itemsbag[i])
  1415. end
  1416. else
  1417. if itemid == item.itemid then
  1418. table.insert(items, item.uid)
  1419. end
  1420. end
  1421. end
  1422. end
  1423. return items
  1424. end
  1425.  
  1426. function getPokeballsInContainer(container) -- Function By Kydrai
  1427.     if not isContainer(container) then return {} end
  1428.     local items = {}
  1429.     if isContainer(container) and getContainerSize(container) > 0 then
  1430.         for slot=0, (getContainerSize(container)-1) do
  1431.             local item = getContainerItem(container, slot)
  1432.                 if isContainer(item.uid) then
  1433.                     local itemsbag = getPokeballsInContainer(item.uid)
  1434.                     for i=0, #itemsbag do
  1435.                         table.insert(items, itemsbag[i])
  1436.                     end
  1437.                 elseif isPokeball(item.itemid) then
  1438.                     table.insert(items, item.uid)
  1439.                 end
  1440.         end
  1441.     end
  1442. return items
  1443. end
  1444.  
  1445. function getItensUniquesInContainer(container)    --alterado v2.6
  1446. if not isContainer(container) then return {} end
  1447. local items = {}
  1448. if isContainer(container) and getContainerSize(container) > 0 then
  1449.    for slot=0, (getContainerSize(container)-1) do
  1450.        local item = getContainerItem(container, slot)
  1451.        if isContainer(item.uid) then
  1452.           local itemsbag = getItensUniquesInContainer(item.uid)
  1453.           for i=0, #itemsbag do
  1454.               table.insert(items, itemsbag[i])
  1455.           end
  1456.        elseif getItemAttribute(item.uid, "unique") then
  1457.           table.insert(items, item)
  1458.        end
  1459.    end
  1460. end
  1461. return items
  1462. end
  1463.  
  1464. function addItemInFreeBag(container, item, num)
  1465. if not isContainer(container) or not item then return false end                                            
  1466. if not num or num <= 0 then num = 1 end
  1467. if getContainerSize(container) < getContainerCap(container) then
  1468.    return doAddContainerItem(container, item, num)
  1469. else
  1470.    for slot = 0, (getContainerSize(container)-1) do
  1471.        local container2 = getContainerItem(container, slot)
  1472.        if isContainer(container2.uid) and getContainerSize(container2.uid) < getContainerCap(container2.uid) then
  1473.           return doAddContainerItem(container2.uid, item, num)
  1474.        end
  1475.    end
  1476. end
  1477. return false
  1478. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement