Guest User

some function.lua

a guest
Jul 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.07 KB | None | 0 0
  1. function getStringOfTaskArray(array)
  2. if type(array) ~= 'table' or not next(array) then return "" end
  3.  
  4. local result = {}
  5. for _, value in ipairs(array) do
  6. local thing, num = (type(value[1]) == 'string' and value[1] or getItemNameById(value[1])), value[2]
  7. table.insert(result, (_ == 1 and "" or ", ")..num.." "..thing..(num == 1 and "" or "s"))
  8. end
  9. result[#result] = " and"..(result[#result]:sub(2,#result[#result]))
  10. return table.concat(result)
  11. end
  12.  
  13. function getVitalityByMaster(cid)
  14. if not isCreature(cid) then return 0 end
  15. local ball = getPlayerSlotItem(cid, 8).uid
  16. if not ball or ball <= 1 or not pokes[getItemAttribute(ball, 'poke')] then return true end
  17. return pokes[getItemAttribute(ball, 'poke')].vitality * (getPlayerLevel(cid) + (getItemAttribute(ball, 'boost') or 0))
  18. end
  19.  
  20. function onPokeHealthChange(cid, zerar)
  21. if not isCreature(cid) then return true end
  22. if zerar then doPlayerSendCancel(cid, '#ph#,0,0') end
  23. local ball = getPlayerSlotItem(cid, 8).uid
  24. if not ball or ball <= 1 or not pokes[getItemAttribute(ball, 'poke')] then return true end
  25.  
  26. if #getCreatureSummons(cid) >= 1 and getPlayerStorageValue(cid, 212124) <= 0 then --alterado v1.6
  27. local pokemon = getCreatureSummons(cid)[1]
  28. local pokelife = (getCreatureHealth(pokemon) / getCreatureMaxHealth(pokemon))
  29. doItemSetAttribute(ball, "hp", pokelife)
  30. end
  31.  
  32. local rd = 1 - (tonumber(getItemAttribute(ball, "hp")))
  33. local maxHp = HPperVITsummon * getVitalityByMaster(cid)
  34. local hp = maxHp -(maxHp * rd)
  35. doPlayerSendCancel(cid, '#ph#,'.. math.floor(hp) ..','.. math.floor(maxHp))
  36. end
  37.  
  38. function addPokeToPlayer(cid, pokemon, boost, gender, ball) --alterado v1.9 \/ peguem ele todo...
  39. local genders = {
  40. ["male"] = 4,
  41. ["female"] = 3,
  42. [1] = 4,
  43. [0] = 3,
  44. [4] = 4,
  45. [3] = 3,
  46. }
  47. if not isCreature(cid) then return false end
  48.  
  49. local pokemon = doCorrectString(pokemon)
  50. if not pokes[pokemon] then return false end
  51.  
  52. local GENDER = (gender and genders[gender]) and genders[gender] or getRandomGenderByName(pokemon)
  53. local btype = (ball and pokeballs[ball]) and ball or isShinyName(pokemon) and "shinynormal" or "normal"
  54. local happy = 250
  55.  
  56. if icons[pokemon] then
  57. id = icons[pokemon].on
  58. else
  59. id = pokeballs[btype].on
  60. end
  61.  
  62. if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  63. item = doCreateItemEx(id)
  64. else
  65. item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, id, 1)
  66. end
  67. if not item then return false end
  68.  
  69. doItemSetAttribute(item, "poke", pokemon)
  70. doItemSetAttribute(item, "hp", 1)
  71. doItemSetAttribute(item, "happy", happy)
  72. --doItemSetAttribute(item, "-1", GENDER)
  73. doSetItemAttribute(item, "hands", 0)
  74. doItemSetAttribute(item, "description", "Contains a "..pokemon..".")
  75. doItemSetAttribute(item, "fakedesc", "Contains a "..pokemon..".")
  76. doItemSetAttribute(item, "defeated", "no")
  77. doItemSetAttribute(item, "ball", btype)
  78. if boost and tonumber(boost) and tonumber(boost) > 0 and tonumber(boost) <= 50 then
  79. doItemSetAttribute(item, "boost", boost)
  80. end
  81. if unique then
  82. doItemSetAttribute(item, "unique", getCreatureName(cid))
  83. end
  84.  
  85. if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  86. doPlayerSendMailByName(getCreatureName(cid), item, 1)
  87. sendMsgToPlayer(cid, 27, "You are already holding six pokemons, so your new pokemon was sent to your depot.")
  88. end
  89. doTransformItem(item, id)
  90. return true
  91. end
  92. ---------------------------
  93.  
  94. function unLock(ball)
  95. if not ball or ball <= 0 then return false end
  96. if getItemAttribute(ball, "lock") and getItemAttribute(ball, "lock") > 0 then
  97. local vipTime = getItemAttribute(ball, "lock")
  98. local timeNow = os.time()
  99. local days = math.ceil((vipTime - timeNow)/(24 * 60 * 60))
  100. if days <= 0 then
  101. doItemEraseAttribute(ball, "lock")
  102. doItemEraseAttribute(ball, "unique")
  103. return true
  104. end
  105. end
  106. return false
  107. end
  108.  
  109. function getGuildMembersOnline(GuildId)
  110. local players = {}
  111. for _, pid in pairs(getPlayersOnline()) do
  112. if getPlayerGuildId(pid) == tonumber(GuildId) then
  113. table.insert(players, pid)
  114. end
  115. end --by Vodkart
  116. return #players > 0 and players or false
  117. end
  118.  
  119. function getGuildMembers(GuildId)
  120. local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
  121. if (query:getID() ~= -1) then
  122. repeat
  123. table.insert(players,query:getDataString("name"))
  124. until not query:next() --by Vodkart
  125. query:free()
  126. end
  127. return #players > 0 and players or false
  128. end
  129.  
  130. function isLegendaryPokemon(name)
  131. if name == nil then return false end
  132. if isInArray({"Mewtwo", "Mew", "Articuno", "Zapdos", "Moltres", "Lugia", "Ho-oh", "Celebi", "Entei", "Raikou", "Suicune", "Darkrai", "Cresselia", "Heatran", "Latios", "Latias", "Manaphy", "Phione", "Uxie", "Mesprit", "Azelf", "Regice", "Registeel", "Regirock", "Regigigas", "Groudon", "Rayquaza", "Kyogre", "Jirachi", "Deoxys", "Shaymin", "Giratina", "Dialga", "Palkia", "Mega Rayquaza", "Arceus"}, name) then
  133. return true
  134. end
  135. return false
  136. end
  137.  
  138. function isFossilPokemon(name)
  139. if name == nil then return false end
  140. if isInArray({"Aerodactyl", "Kabuto", "Kabutops", "Omanyte", "Omastar"}, name) then
  141. return true
  142. end
  143. return false
  144. end
  145.  
  146. function isMegaPokemon(name)
  147. if name == nil then return false end
  148. if isInArray({"Mega Hoopa"}, name) then
  149. return true
  150. end
  151. return false
  152. end
  153. --/////////////////////////////////////////////////////////////////////////////////---
  154. function sendMsgToPlayer(cid, tpw, msg) --alterado v1.7 \/\/\/
  155. if not isCreature(cid) or not tpw or not msg then return true end
  156. return doPlayerSendTextMessage(cid, tpw, msg)
  157. end
  158.  
  159. function getPlayerDesc(cid, thing, TV)
  160. if (not isCreature(cid) or not isCreature(thing)) and not TV then return "" end
  161.  
  162. local pos = getThingPos(thing)
  163. local ocup = youAre[getPlayerGroupId(thing)]
  164. local rank = (getPlayerStorageValue(thing, 86228) <= 0) and "a Pokemon Trainer" or lookClans[getPlayerStorageValue(thing, 86228)][getPlayerStorageValue(thing, 862281)]
  165. local name = thing == cid and "yourself" or getCreatureName(thing)
  166. local art = thing == cid and "You are" or (getPlayerSex(thing) == 0 and "She is" or "He is")
  167.  
  168. local str = {}
  169. table.insert(str, "You see "..name..". "..art.." ")
  170. if youAre[getPlayerGroupId(thing)] then
  171. table.insert(str, (ocup).." and "..rank.." from ".. getTownName(getPlayerTown(thing))..".")
  172. else
  173. table.insert(str, (rank).." from ".. getTownName(getPlayerTown(thing))..".")
  174. end
  175.  
  176. if hasProfession(thing) then -- Profession System
  177. str = str.."\n"..getPlayerSex(thing) == 0 and "She" or "He" .." is a "..getProfessionName(thing).."."
  178. end
  179.  
  180. if getPlayerGuildId(thing) > 0 then
  181. table.insert(str, " "..art.." "..getPlayerGuildRank(thing).." from the "..getPlayerGuildName(thing)..".")
  182. end
  183. if TV then
  184. table.insert(str, " "..art.." watching TV.")
  185. end
  186. table.insert(str, ((isPlayer(cid) and youAre[getPlayerGroupId(cid)]) and "\nPosition: [X: "..pos.x.."][Y: "..pos.y.."][Z: "..pos.z.."]" or ""))
  187.  
  188. return table.concat(str)
  189. end
  190. ------------------------------------------------------------------------------------------------- /\/\
  191. function getLivePokeballs(cid, container, duel)
  192. if not isCreature(cid) then return {} end
  193. if not isContainer(container) then return {} end
  194. local items = {}
  195. ---
  196. local ballSlot = getPlayerSlotItem(cid, 8)
  197. if ballSlot.uid ~= 0 then
  198. for a, b in pairs (pokeballs) do
  199. if ballSlot.itemid == b.on or ballSlot.itemid == b.use then
  200. if duel and getPlayerLevel(cid) >= (pokes[getItemAttribute(ballSlot.uid, "poke")].level + getPokeballBoost(ballSlot)) then
  201. table.insert(items, ballSlot.uid) --alterado v1.8
  202. elseif not duel then
  203. table.insert(items, ballSlot.uid)
  204. end
  205. end
  206. end
  207. end
  208. ---
  209. if isContainer(container) and getContainerSize(container) > 0 then
  210. for slot=0, (getContainerSize(container)-1) do
  211. local item = getContainerItem(container, slot)
  212. if isContainer(item.uid) then
  213. local itemsbag = getPokeballsInContainer(item.uid)
  214. for i=0, #itemsbag do
  215. if not isInArray(items, itemsbag[i]) then
  216. table.insert(items, itemsbag[i])
  217. end
  218. end
  219. elseif isPokeball(item.itemid) then
  220. for a, b in pairs (pokeballs) do
  221. if item.itemid == b.on then
  222. if duel and getPlayerLevel(cid) >= (pokes[getItemAttribute(item.uid, "poke")].level + getPokeballBoost(item)) then
  223. table.insert(items, item.uid) --alterado v1.8
  224. elseif not duel then
  225. table.insert(items, item.uid)
  226. end
  227. end
  228. end
  229. end
  230. end
  231. end
  232. return items
  233. end
  234.  
  235. function addItemInFreeBag(container, item, num)
  236. if not isContainer(container) or not item then return false end
  237. if not num or num <= 0 then num = 1 end --alterado v1.6.1
  238. if getContainerSize(container) < getContainerCap(container) then
  239. return doAddContainerItem(container, item, num)
  240. else
  241. for slot = 0, (getContainerSize(container)-1) do
  242. local container2 = getContainerItem(container, slot)
  243. if isContainer(container2.uid) and getContainerSize(container2.uid) < getContainerCap(container2.uid) then
  244. return doAddContainerItem(container2.uid, item, num)
  245. end
  246. end
  247. end
  248. return false
  249. end
  250. ------------------------------------------------------------------------------------------------------
  251. function pokeHaveReflect(cid)
  252. if not isCreature(cid) then return false end
  253. local table = getTableMove(cid, "Reflect")
  254. if table and table.name then --alterado v1.6
  255. return true
  256. end
  257. return false
  258. end
  259. ------------------------------------------------------------------------------------------------------
  260. function nextHorario(cid)
  261. horarioAtual = os.date("%X")
  262. horario = string.explode(horarioAtual, ":")
  263.  
  264. for i = 1, #horas do
  265. horarioComparacao = horas[i]
  266. horarioComp = string.explode(horarioComparacao, ":")
  267. ---------------
  268. if tonumber(horarioComp[1]) > tonumber(horario[1]) then
  269. return horarioComparacao
  270. elseif tonumber(horarioComp[1]) == tonumber(horario[1]) and tonumber(horario[2]) < tonumber(horarioComp[2]) then
  271. return horarioComparacao
  272. end
  273. end
  274. return horas[1]
  275. end
  276.  
  277. function getTimeDiff(timeDiff)
  278. local dateFormat = {
  279. {'hour', timeDiff / 60 / 60}, --6%
  280. {'min', timeDiff / 60 % 60},
  281. }
  282. local out = {}
  283. for k, t in ipairs(dateFormat) do
  284. local v = math.floor(t[2])
  285. if(v > -1) then
  286. table.insert(out, (k < #dateFormat and '' or ' and ') .. v .. '' .. (v <= 1 and t[1] or t[1].."s"))
  287. end
  288. end
  289. if tonumber(dateFormat[1][2]) == 0 and tonumber(dateFormat[2][2]) == 0 then
  290. return "seconds"
  291. end
  292. return table.concat(out)
  293. end
  294.  
  295. function getTimeDiff2(timeDiff)
  296. local dateFormat = {
  297. {'hour', timeDiff / 60 / 60}, --6%
  298. {'min', timeDiff / 60 % 60},
  299. {'sec', timeDiff % 60},
  300. }
  301. local out = {}
  302. for k, t in ipairs(dateFormat) do
  303. local v = math.floor(t[2])
  304. if(v > 0) then
  305. table.insert(out, (k < #dateFormat and ' ' or ' and ') .. v .. '' .. (v <= 1 and t[1] or t[1].."s"))
  306. end
  307. end
  308. return table.concat(out)
  309. end
  310.  
  311. function showTimeDiff(timeComp)
  312. local b = string.explode(os.date("%X"), ":")
  313. local c = string.explode(timeComp, ":")
  314. ---
  315. local d, m, y = os.date("%d"), os.date("%m"), os.date("%Y")
  316. local hAtual, mAtual = tonumber(b[1]), tonumber(b[2])
  317. local hComp, mComp = tonumber(c[1]), tonumber(c[2])
  318. ---
  319. local t = os.time{year= y, month= m, day= d, hour= hAtual, min= mAtual}
  320. local t1 = os.time{year= y, month= m, day= d, hour= hComp, min= mComp}
  321. ---
  322. comparacao = t1-t
  323. if hComp < hAtual then
  324. v = os.time{year= y, month= m, day= d, hour= 24, min= 0}
  325. v2 = os.time{year= y, month= m, day= d, hour= 0, min= 0}
  326. comparacao = (v-t)+(t1-v2)
  327. end
  328. return getTimeDiff(comparacao)
  329. end
  330. -------------------------------------------------------------------------
  331. function cleanCMcds(item)
  332. if item ~= 0 then
  333. for c = 1, 15 do --alterado v1.5
  334. local str = "cm_move"..c
  335. setCD(item, str, 0)
  336. end
  337. end
  338. end
  339.  
  340. function ehNPC(cid) --alterado v1.9
  341. return isCreature(cid) and not isPlayer(cid) and not isSummon(cid) and not isMonster(cid)
  342. end
  343.  
  344. function ehMonstro(cid)
  345. local eh = false
  346. if not isSummon(cid) and not ehNPC(cid) and not isPlayer(cid) then
  347. eh = true
  348. end
  349. return eh
  350. end --alterado v1.9.1 /\
  351.  
  352. function doAppear(cid) --Faz um poke q tava invisivel voltar a ser visivel...
  353. if not isCreature(cid) then return true end
  354. doRemoveCondition(cid, CONDITION_INVISIBLE)
  355. doRemoveCondition(cid, CONDITION_OUTFIT)
  356. doCreatureSetHideHealth(cid, false)
  357. end
  358.  
  359. function doDisapear(cid) --Faz um pokemon ficar invisivel
  360. if not isCreature(cid) then return true end
  361. doCreatureAddCondition(cid, permanentinvisible)
  362. doCreatureSetHideHealth(cid, true)
  363. doSetCreatureOutfit(cid, {lookType = 2}, -1)
  364. end
  365.  
  366. function hasTile(pos) --Verifica se tem TILE na pos
  367. pos.stackpos = 0
  368. if getTileThingByPos(pos).itemid >= 1 then
  369. return true
  370. end
  371. return false
  372. end
  373.  
  374. function getThingFromPosWithProtect(pos) --Pega uma creatura numa posiçao com proteçoes
  375. if hasTile(pos) then
  376. if isCreature(getRecorderCreature(pos)) then
  377. return getRecorderCreature(pos)
  378. else
  379. pos.stackpos = 253
  380. pid = getThingfromPos(pos).uid
  381. end
  382. else
  383. pid = getThingfromPos({x=1,y=1,z=10,stackpos=253}).uid
  384. end
  385. return pid
  386. end
  387.  
  388. function getTileThingWithProtect(pos) --Pega um TILE com proteçoes
  389. if hasTile(pos) then
  390. pos.stackpos = 0
  391. pid = getTileThingByPos(pos)
  392. else
  393. pid = getTileThingByPos({x=1,y=1,z=10,stackpos=0})
  394. end
  395. return pid
  396. end
  397.  
  398. function canAttackOther(cid, pid) --Function q verifica se um poke/player pode atacar outro poke/player
  399.  
  400. if not isCreature(cid) or not isCreature(pid) then return "Cant" end
  401.  
  402. local master1 = isSummon(cid) and getCreatureMaster(cid) or cid
  403. local master2 = isSummon(pid) and getCreatureMaster(pid) or pid
  404.  
  405. ----
  406. if getPlayerStorageValue(master1, 6598754) >= 5 and getPlayerStorageValue(master2, 6598754) >= 5 then
  407. if getPlayerStorageValue(master1, 6598754) ~= getPlayerStorageValue(master2, 6598754) then
  408. if isDuelingAgainst(master1, master2) then --alterado v1.8
  409. if isSummon(cid) and isPlayer(pid) then
  410. return "Cant"
  411. else
  412. return "Can"
  413. end
  414. end
  415. end
  416. end
  417. ---- pvp system
  418. if getPlayerStorageValue(master1, 6598754) >= 1 and getPlayerStorageValue(master2, 6598755) >= 1 then
  419. return "Can"
  420. end
  421. if getPlayerStorageValue(master1, 6598755) >= 1 and getPlayerStorageValue(master2, 6598754) >= 1 then ---estar em times diferentes
  422. return "Can"
  423. end
  424. ----
  425. if ehMonstro(cid) and ehMonstro(pid) then
  426. return "Can"
  427. end
  428.  
  429. return "Cant"
  430. end
  431.  
  432.  
  433. function stopNow(cid, time)
  434. if not isCreature(cid) or not tonumber(time) or isSleeping(cid) then return true end
  435. --alterado v1.9.1 \/
  436. local function podeMover(cid)
  437. if isPlayer(cid) then
  438. mayNotMove(cid, false)
  439. elseif isCreature(cid) then
  440. doRegainSpeed(cid)
  441. end
  442. end
  443.  
  444. if isPlayer(cid) then mayNotMove(cid, true) else doChangeSpeed(cid, -getCreatureSpeed(cid)) end
  445. addEvent(podeMover, time, cid)
  446. end
  447.  
  448. function doReduceStatus(cid, off, def, agi) --reduz os status
  449. if not isCreature(cid) then return true end
  450. local A = getOffense(cid)
  451. local B = getDefense(cid)
  452. local C = getSpeed(cid)
  453.  
  454. if off > 0 then
  455. setPlayerStorageValue(cid, 1001, A - off)
  456. end
  457. if def > 0 then
  458. setPlayerStorageValue(cid, 1002, B - def)
  459. end
  460. if agi > 0 then
  461. setPlayerStorageValue(cid, 1003, C - agi)
  462. if getCreatureSpeed(cid) ~= 0 then
  463. doRegainSpeed(cid)
  464. end --alterado v1.5 functions arrumadas...
  465. end
  466. end
  467.  
  468. function doRaiseStatus(cid, off, def, agi, time)
  469. if not isCreature(cid) then return true end
  470. local A = getOffense(cid)
  471. local B = getDefense(cid)
  472. local C = getSpeed(cid)
  473.  
  474. if off > 0 then
  475. setPlayerStorageValue(cid, 1001, A * off)
  476. end
  477. if def > 0 then
  478. setPlayerStorageValue(cid, 1002, B * def)
  479. end
  480. if agi > 0 then
  481. setPlayerStorageValue(cid, 1003, C + agi)
  482. if getCreatureSpeed(cid) ~= 0 then
  483. doRegainSpeed(cid)
  484. end
  485. end
  486.  
  487. local D = getOffense(cid)
  488. local E = getDefense(cid)
  489. local F = getSpeed(cid)
  490. ---------------------------
  491. local G = D - A
  492. local H = E - B
  493. local I = F - C
  494.  
  495. addEvent(doReduceStatus, time*1000, cid, G, H, I)
  496. end
  497.  
  498.  
  499. function BackTeam(cid)
  500. if isCreature(cid) then
  501. local summon = getCreatureSummons(cid) --alterado v1.6
  502. for i = 2, #summon do
  503. doSendMagicEffect(getThingPos(summon[i]), 211)
  504. doRemoveCreature(summon[i])
  505. end
  506. setPlayerStorageValue(cid, 637501, -1)
  507. end
  508. end
  509.  
  510. function choose(...) -- by mock
  511. local arg = {...}
  512. return arg[math.random(1,#arg)]
  513. end
  514.  
  515. function AddPremium(cid, days)
  516. local function removerPlayer(cid)
  517. if isCreature(cid) then
  518. doRemoveCreature(cid)
  519. end
  520. end
  521.  
  522. db.executeQuery("UPDATE `accounts` SET `premdays` = '"..days.."' WHERE `accounts`.`id` = ".. getPlayerAccountId(cid) ..";")
  523. doPlayerSendTextMessage(cid,25,"Você será kickado em 5 segundos.")
  524. addEvent(removerPlayer, 5*1000, cid)
  525. return TRUE
  526. end
  527.  
  528. function isShiny(cid)
  529. return isCreature(cid) and string.find(getCreatureName(cid), "Shiny") --alterado v1.9
  530. end
  531.  
  532. function isShinyName(name)
  533. return tostring(name) and string.find(doCorrectString(name), "Shiny") --alterado v1.9
  534. end
  535.  
  536. function isMega(cid)
  537. return isCreature(cid) and string.find(getCreatureName(cid), "Mega") --alterado v1.9
  538. end
  539.  
  540. function isMegaName(name)
  541. return tostring(name) and string.find(doCorrectString(name), "Mega") --alterado v1.9
  542. end
  543.  
  544. function doConvertTypeToStone(type, string)
  545. local t = {
  546. ["fly"] = {heart, "heart"},
  547. ["flying"] = {heart, "heart"},
  548. ["normal"] = {heart, "heart"},
  549. ["fire"] = {fire, "fire"},
  550. ["grass"] = {leaf, "leaf"},
  551. ["leaf"] = {leaf, "leaf"},
  552. ["water"] = {water, "water"},
  553. ["poison"] = {venom, "venom"},
  554. ["venom"] = {venom, "venom"},
  555. ["electric"] = {thunder, "thunder"},
  556. ["thunder"] = {thunder, "thunder"},
  557. ["rock"] = {rock, "rock"},
  558. ["fight"] = {punch, "punch"},
  559. ["fighting"] = {punch, "punch"},
  560. ["bug"] = {coccon, "coccon"},
  561. ["dragon"] = {crystal, "crystal"},
  562. ["dark"] = {dark, "dark"},
  563. ["ghost"] = {dark, "dark"},
  564. ["ground"] = {earth, "earth"},
  565. ["earth"] = {earth, "earth"},
  566. ["psychic"] = {enigma, "enigma"},
  567. ["steel"] = {metal, "metal"},
  568. ["ancient"] = {ancient, "ancient"},
  569. ["metal"] = {metal, "metal"},
  570. ["ice"] = {ice, "ice"},
  571. ["boost"] = {boostStone, "boost"}, --alterado v1.9
  572. }
  573.  
  574. if string then
  575. return t[type][2]
  576. else
  577. return t[type][1]
  578. end
  579. end
  580.  
  581. function doConvertStoneIdToString(stoneID)
  582. local t = {
  583. [11453] = "Heart Stone",
  584. [11441] = "Leaf Stone",
  585. [11442] = "Water Stone",
  586. [11443] = "Venom Stone",
  587. [11444] = "Thunder Stone",
  588. [11445] = "Rock Stone",
  589. [11446] = "Punch Stone",
  590. [11447] = "Fire Stone", --alterado v1.6
  591. [11448] = "Cocoon Stone",
  592. [11449] = "Crystal Stone",
  593. [11450] = "Darkess Stone",
  594. [11451] = "Earth Stone",
  595. [11452] = "Enigma Stone",
  596. [11454] = "Ice Stone",
  597. [12244] = "Ancient Stone",
  598. [12232] = "Metal Stone",
  599. [12401] = "Shiny Fire Stone",
  600. [12402] = "Shiny Water Stone",
  601. [12403] = "Shiny Leaf Stone",
  602. [12404] = "Shiny Heart Stone",
  603. [12405] = "Shiny Enigma Stone",
  604. [12406] = "Shiny Rock Stone",
  605. [12407] = "Shiny Venom Stone",
  606. [12408] = "Shiny Ice Stone",
  607. [12409] = "Shiny Thunder Stone",
  608. [12410] = "Shiny Crystal Stone",
  609. [12411] = "Shiny Cocoon Stone",
  610. [12412] = "Shiny Darkness Stone",
  611. [12413] = "Shiny Punch Stone",
  612. [12414] = "Shiny Earth Stone",
  613. [boostStone] = "Boost Stone", --alterado v1.9
  614. }
  615. if t[stoneID] then
  616. return t[stoneID]
  617. else
  618. return ""
  619. end
  620. end
  621.  
  622. function isStone(id)
  623. if id >= leaf and id <= ice then
  624. return true
  625. end
  626. if id == boostStone then --alterado v1.9
  627. return true
  628. end
  629. if id == 12232 or id == 12244 or id == 12244 or id == 12245 then
  630. return true
  631. end
  632. if (id >= sfire and id <= searth) or id == 12417 or id == 12419 then
  633. return true
  634. end
  635. return false
  636. end
  637.  
  638. function isWater(id)
  639. return tonumber(id) and id >= 4820 and id <= 4825 --alterado v1.9
  640. end
  641.  
  642. function getTopCorpse(position)
  643. local pos = position
  644. for n = 1, 255 do
  645. pos.stackpos = n
  646. local item = getTileThingByPos(pos)
  647. if item.itemid >= 2 and (string.find(getItemNameById(item.itemid), "fainted ") or string.find(getItemNameById(item.itemid), "defeated ")) then
  648. return getTileThingByPos(pos)
  649. end
  650. end
  651. return null
  652. end
  653.  
  654. bpslot = CONST_SLOT_BACKPACK
  655.  
  656. function hasPokemon(cid)
  657. if not isCreature(cid) then return false end
  658. if getCreatureMana(cid) <= 0 then return false end
  659. if #getCreatureSummons(cid) >= 1 then return true end
  660. local item = getPlayerSlotItem(cid, CONST_SLOT_FEET)
  661. local bp = getPlayerSlotItem(cid, bpslot)
  662. for a, b in pairs (pokeballs) do
  663. if item.itemid == b.on or item.itemid == b.use then
  664. return true --alterado v1.4
  665. end
  666. if #getItemsInContainerById(bp.uid, b.on) >= 1 then
  667. return true
  668. end
  669. end
  670. return false
  671. end
  672.  
  673. function isNpcSummon(cid)
  674. return isNpc(getCreatureMaster(cid))
  675. end
  676.  
  677. function getPokemonHappinessDescription(cid)
  678. if not isCreature(cid) then return true end
  679. local str = {}
  680. if getPokemonGender(cid) == SEX_MALE then
  681. table.insert(str, "He")
  682. elseif getPokemonGender(cid) == SEX_FEMALE then
  683. table.insert(str, "She")
  684. else
  685. table.insert(str, "It")
  686. end
  687. local h = getPlayerStorageValue(cid, 1008)
  688. if h >= tonumber(getConfigValue('PokemonStageVeryHappy')) then
  689. table.insert(str, " is very happy with you!")
  690. elseif h >= tonumber(getConfigValue('PokemonStageHappy')) then
  691. table.insert(str, " is happy.")
  692. elseif h >= tonumber(getConfigValue('PokemonStageOK')) then
  693. table.insert(str, " is unhappy.")
  694. elseif h >= tonumber(getConfigValue('PokemonStageSad')) then
  695. table.insert(str, " is sad.")
  696. elseif h >= tonumber(getConfigValue('PokemonStageMad')) then
  697. table.insert(str, " is mad.")
  698. else
  699. table.insert(str, " is very mad at you!")
  700. end
  701. return table.concat(str)
  702. end
  703.  
  704. function doSetItemAttribute(item, key, value)
  705. doItemSetAttribute(item, key, value)
  706. end
  707.  
  708. function deTransform(cid, check)
  709. if not isCreature(cid) then return true end
  710.  
  711. local m = getCreatureMaster(cid)
  712. local p = getPlayerSlotItem(m, 8)
  713.  
  714. if getItemAttribute(p.uid, "transTurn") ~= check then return true end
  715.  
  716. setPlayerStorageValue(cid, 1010, getCreatureName(cid) == "Ditto" and "Ditto" or "Shiny Ditto") --edited
  717. doRemoveCondition(cid, CONDITION_OUTFIT)
  718. doSendMagicEffect(getThingPos(cid), 184)
  719. doCreatureSay(cid, "DITTO!", TALKTYPE_MONSTER)
  720. doItemSetAttribute(p.uid, "transBegin", 0)
  721. doItemSetAttribute(p.uid, "transLeft", 0)
  722. doItemEraseAttribute(p.uid, "transName")
  723. adjustStatus(cid, p.uid, true, true, true)
  724. end
  725.  
  726. function isTransformed(cid)
  727. return isCreature(cid) and not isInArray({-1, "Ditto", "Shiny Ditto"}, getPlayerStorageValue(cid, 1010)) --alterado v1.9
  728. end
  729.  
  730. function doSendFlareEffect(pos)
  731. local random = {28, 29, 79}
  732. doSendMagicEffect(pos, random[math.random(1, 3)])
  733. end
  734.  
  735. function isDay()
  736. local a = getWorldTime()
  737. if a >= 360 and a < 1080 then
  738. return true
  739. end
  740. return false
  741. end
  742.  
  743. function doPlayerSendTextWindow(cid, p1, p2)
  744. if not isCreature(cid) then return true end
  745. local item = 460
  746. local text = ""
  747. if type(p1) == "string" then
  748. doShowTextDialog(cid, item, p1)
  749. else
  750. doShowTextDialog(cid, p1, p2)
  751. end
  752. end
  753.  
  754. function getClockString(tw)
  755. local a = getWorldTime()
  756. local b = a / 60
  757. local hours = math.floor(b)
  758. local minut = a - (60 * hours)
  759.  
  760. if not tw then
  761. if hours < 10 then
  762. hours = "0"..hours..""
  763. end
  764. if minut < 10 then
  765. minut = "0"..minut..""
  766. end
  767. return hours..":"..minut
  768. else
  769. local sm = "a.m"
  770. if hours >= 12 then
  771. hours = hours - 12
  772. sm = "p.m"
  773. end
  774. if hours < 10 then
  775. hours = "0"..hours..""
  776. end
  777. if minut < 10 then
  778. minut = "0"..minut..""
  779. end
  780. return hours..":"..minut.." "..sm
  781. end
  782. end
  783.  
  784. function doCorrectPokemonName(poke)
  785. return doCorrectString(poke)
  786. end
  787.  
  788. function doCorrectString(str)
  789. local name = str:explode(" ") --alterado v1.9
  790. local final = {}
  791. for _, s in ipairs(name) do
  792. table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
  793. end
  794. return table.concat(final, (name[2] and " " or ""))
  795. end
  796.  
  797. function getHappinessRate(cid)
  798. if not isCreature(cid) then return 1 end
  799. local a = getPlayerStorageValue(cid, 1008)
  800. if a == -1 then return 1 end
  801. if a >= getConfigValue('PokemonStageVeryHappy') then
  802. return happinessRate[5].rate
  803. elseif a >= getConfigValue('PokemonStageHappy') then
  804. return happinessRate[4].rate
  805. elseif a >= getConfigValue('PokemonStageOK') then
  806. return happinessRate[3].rate
  807. elseif a >= getConfigValue('PokemonStageSad') then
  808. return happinessRate[2].rate
  809. else
  810. return happinessRate[1].rate
  811. end
  812. return 1
  813. end
  814.  
  815. function doBodyPush(cid, target, go, pos)
  816. if not isCreature(cid) or not isCreature(target) then
  817. doRegainSpeed(cid)
  818. doRegainSpeed(target)
  819. return true
  820. end
  821. if go then
  822. local a = getThingPos(cid)
  823. doChangeSpeed(cid, -getCreatureSpeed(cid))
  824. if not isPlayer(target) then
  825. doChangeSpeed(target, -getCreatureSpeed(target))
  826. end
  827. doChangeSpeed(cid, 800)
  828. doTeleportThing(cid, getThingPos(target))
  829. doChangeSpeed(cid, -800)
  830. addEvent(doBodyPush, 350, cid, target, false, a)
  831. else
  832. doChangeSpeed(cid, 800)
  833. doTeleportThing(cid, pos)
  834. doRegainSpeed(cid)
  835. doRegainSpeed(target)
  836. end
  837. end
  838.  
  839. function doReturnPokemon(cid, pokemon, pokeball, effect, hideeffects, blockevo)
  840.  
  841. --////////////////////////////////////////////////////////////////////////////////////////--
  842. checkDuel(cid) --alterado v1.6 duel system
  843. --////////////////////////////////////////////////////////////////////////////////////////--
  844. if getPlayerStorageValue(cid, 52480) >= 1 and getPlayerStorageValue(cid, 52484) ~= 10 then
  845. return sendMsgToPlayer(cid, 27, "You can't do that while the duel don't begins!") --alterado v1.8
  846. end
  847. --////////////////////////////////////////////////////////////////////////////////////////--
  848.  
  849. if #getCreatureSummons(cid) > 1 and getPlayerStorageValue(cid, 212124) <= 0 then --alterado v1.6
  850. if getPlayerStorageValue(cid, 637501) == -2 or getPlayerStorageValue(cid, 637501) >= 1 then
  851. BackTeam(cid)
  852. end
  853. end
  854. -----------------
  855. local edit = true
  856.  
  857. if not pokeball then
  858. pokeball = getPlayerSlotItem(cid, 8)
  859. end
  860.  
  861. if blockevo then
  862. edit = false
  863. doPlayerSendCancel(cid, "Your pokemon couldn't evolve due to server mistakes, please wait until we fix the problem.")
  864. end
  865.  
  866. local happy = getPlayerStorageValue(pokemon, 1008)
  867. local hunger = getPlayerStorageValue(pokemon, 1009)
  868. local pokelife = (getCreatureHealth(pokemon) / getCreatureMaxHealth(pokemon))
  869.  
  870. if edit then
  871. doItemSetAttribute(pokeball.uid, "happy", happy)
  872. doItemSetAttribute(pokeball.uid, "hunger", hunger)
  873. doItemSetAttribute(pokeball.uid, "hp", pokelife)
  874. end
  875.  
  876. -- if getCreatureName(pokemon) == "Ditto" then
  877. -- if isTransformed(pokemon) then
  878. -- local left = getItemAttribute(pokeball.uid, "transLeft") - (os.clock() - getItemAttribute(pokeball.uid, "transBegin"))
  879. -- doItemSetAttribute(pokeball.uid, "transLeft", left)
  880. -- end
  881. -- end
  882.  
  883. if hideeffects then
  884. doRemoveCreature(pokemon)
  885. return true
  886. end
  887.  
  888. local pokename = getPokeName(pokemon)
  889.  
  890. local mbk = gobackmsgs[math.random(1, #gobackmsgs)].back:gsub("doka", pokename)
  891.  
  892. if getCreatureCondition(cid, CONDITION_INFIGHT) then
  893. if isCreature(getCreatureTarget(cid)) then
  894. doItemSetAttribute(pokeball.uid, "happy", happy - 5)
  895. else
  896. doItemSetAttribute(pokeball.uid, "happy", happy - 2)
  897. end
  898. end
  899.  
  900. doTransformItem(pokeball.uid, pokeball.itemid-1)
  901. doCreatureSay(cid, mbk, TALKTYPE_SAY)
  902.  
  903. doSendMagicEffect(getCreaturePosition(pokemon), effect)
  904.  
  905. doRemoveCreature(pokemon)
  906.  
  907. unLock(pokeball.uid) --alterado v1.8
  908.  
  909. if useOTClient then
  910. doPlayerSendCancel(cid, '12//,hide') --alterado v1.7
  911. end
  912.  
  913. if useKpdoDlls then
  914. doUpdateMoves(cid)
  915. end
  916.  
  917. end
  918.  
  919. local EFFECTS = {
  920. --[OutfitID] = {Effect}
  921. ["Magmar"] = 35, --alterado v1.5
  922. ["Shiny Magmar"] = 35,
  923. ["Magby"] = 35,
  924. ["Jynx"] = 17,
  925. ["Smoochum"] = 17,
  926. ["Shiny Jynx"] = 17,
  927. ["Piloswine"] = 205, --alterado v1.8
  928. ["Swinub"] = 205,
  929. ["Stantler"] = 205,
  930. ["Shiny Stantler"] = 205,
  931. }
  932.  
  933. function doGoPokemon(cid, item)
  934.  
  935. if getPlayerStorageValue(cid, 17000) >= 1 or getPlayerStorageValue(cid, 17001) >= 1 or getPlayerStorageValue(cid, 63215) >= 1 then
  936. return true
  937. end
  938. ---------------------------------------------------------------
  939. local ballName = getItemAttribute(item.uid, "poke")
  940.  
  941. btype = getPokeballType(item.itemid)
  942.  
  943. local effect = pokeballs[btype].effect
  944. if not effect then
  945. effect = 21
  946. end
  947. -----------------------------------------------------------------
  948. if item.uid ~= getPlayerSlotItem(cid, CONST_SLOT_FEET).uid then
  949. doPlayerSendCancel(cid, "You must put your pokeball in the correct place!")
  950. return TRUE
  951. end
  952.  
  953. local thishp = getItemAttribute(item.uid, "hp")
  954.  
  955. if thishp <= 0 then
  956. if isInArray(pokeballs[btype].all, item.itemid) then
  957. doTransformItem(item.uid, pokeballs[btype].off)
  958. doItemSetAttribute(item.uid, "hp", 0)
  959. doPlayerSendCancel(cid, "This pokemon is fainted.")
  960. return true
  961. end
  962. end
  963.  
  964. local pokemon = getItemAttribute(item.uid, "poke")
  965.  
  966. if not pokes[pokemon] then
  967. return true
  968. end
  969.  
  970. ----------------------- Sistema de nao poder carregar mais que 3 pokes lvl baixo e + q 1 poke de lvl medio/alto ---------------------------------
  971. if not isInArray({5, 6}, getPlayerGroupId(cid)) then
  972. local balls = getPokeballsInContainer(getPlayerSlotItem(cid, 3).uid) --alterado v1.9 \/
  973. local low = {}
  974. local lowPokes = {"Rattata", "Caterpie", "Weedle", "Oddish", "Pidgey", "Paras", "Poliwag", "Bellsprout", "Magikarp", "Hoppip", "Sunkern"}
  975. if #balls >= 1 then
  976. for _, uid in ipairs(balls) do
  977. local nome = getItemAttribute(uid, "poke")
  978. if not isInArray(lowPokes, pokemon) and nome == pokemon then
  979. return doPlayerSendTextMessage(cid, 27, "Sorry, but you can't carry two pokemons equals!")
  980. else
  981. if nome == pokemon then
  982. table.insert(low, nome)
  983. end
  984. end
  985. end
  986. end
  987. if #low >= 3 then
  988. return doPlayerSendTextMessage(cid, 27, "Sorry, but you can't carry more than three pokemons equals of low level!")
  989. end
  990. end
  991. ---------------------------------------------------------------------------------------------------------------------------------------------------
  992.  
  993. local x = pokes[pokemon]
  994. local boosts = getItemAttribute(item.uid, "boost") or 0
  995.  
  996. if getPlayerLevel(cid) < (x.level + boosts) then --alterado v1.8 \/
  997. doPlayerSendCancel(cid, "You need level "..(x.level + boosts).." to use this pokemon.")
  998. return true
  999. end
  1000.  
  1001. --------------------------------------------------------------------------------------
  1002. shinysClan = {
  1003. ["Shiny Fearow"] = {4, "Wingeon"},
  1004. ["Shiny Flareon"] = {1, "Volcanic"},
  1005. ["Shiny Vaporeon"] = {2, "Seavel"},
  1006. ["Shiny Jolteon"] = {9, "Raibolt"},
  1007. ["Shiny Hypno"] = {7, "Psycraft"},
  1008. ["Shiny Golem"] = {3, "Orebound"},
  1009. ["Shiny Vileplume"] = {8, "Naturia"},
  1010. ["Shiny Nidoking"] = {5, "Malefic"},
  1011. ["Shiny Hitmontop"] = {6, "Gardestrike"},
  1012. ["Shiny Metagross"] = {9, "Ironhead"},
  1013. }
  1014.  
  1015. if shinysClan[pokemon] and (getPlayerGroupId(cid) < 4 or getPlayerGroupId(cid) > 6) then --alterado v1.9
  1016. if getPlayerStorageValue(cid, 86228) ~= shinysClan[pokemon][1] then
  1017. doPlayerSendCancel(cid, "You need be a member of the clan "..shinysClan[pokemon][2].." to use this pokemon!")
  1018. return true
  1019. elseif getPlayerStorageValue(cid, 862281) ~= 5 then
  1020. doPlayerSendCancel(cid, "You need be atleast rank 5 to use this pokemon!")
  1021. return true
  1022. end
  1023. end
  1024. --------------------------------------------------------------------------------------
  1025.  
  1026. doSummonMonster(cid, pokemon)
  1027.  
  1028. local pk = getCreatureSummons(cid)[1]
  1029. if not isCreature(pk) then return true end
  1030.  
  1031. ------------------------passiva hitmonchan------------------------------
  1032. if isSummon(pk) then --alterado v1.8 \/
  1033. if pokemon == "Shiny Hitmonchan" or pokemon == "Hitmonchan" then
  1034. if not getItemAttribute(item.uid, "hands") then
  1035. doSetItemAttribute(item.uid, "hands", 0)
  1036. end
  1037. local hands = getItemAttribute(item.uid, "hands")
  1038. doSetCreatureOutfit(pk, {lookType = hitmonchans[pokemon][hands].out}, -1)
  1039. end
  1040. end
  1041. -------------------------------------------------------------------------
  1042. ---------movement magmar, jynx-------------
  1043. if EFFECTS[getCreatureName(pk)] then
  1044. markPosEff(pk, getThingPos(pk))
  1045. sendMovementEffect(pk, EFFECTS[getCreatureName(pk)], getThingPos(pk))
  1046. end
  1047. --------------------------------------------------------------------------
  1048.  
  1049. if getCreatureName(pk) == "Ditto" then
  1050.  
  1051. local left = getItemAttribute(item.uid, "transLeft")
  1052. local name = getItemAttribute(item.uid, "transName")
  1053.  
  1054. if left and left > 0 then
  1055. setPlayerStorageValue(pk, 1010, name)
  1056. doSetCreatureOutfit(pk, {lookType = getItemAttribute(item.uid, "transOutfit")}, -1)
  1057. addEvent(deTransform, left * 1000, pk, getItemAttribute(item.uid, "transTurn"))
  1058. doItemSetAttribute(item.uid, "transBegin", os.clock())
  1059. else
  1060. setPlayerStorageValue(pk, 1010, "Ditto")
  1061. end
  1062. end
  1063.  
  1064. if isGhostPokemon(pk) then doTeleportThing(pk, getPosByDir(getThingPos(cid), math.random(0, 7)), false) end
  1065.  
  1066. doCreatureSetLookDir(pk, 2)
  1067.  
  1068. adjustStatus(pk, item.uid, true, true, true)
  1069. doAddPokemonInOwnList(cid, pokemon)
  1070.  
  1071. doTransformItem(item.uid, item.itemid+1)
  1072.  
  1073. local pokename = getPokeName(pk) --alterado v1.7
  1074.  
  1075. local mgo = gobackmsgs[math.random(1, #gobackmsgs)].go:gsub("doka", pokename)
  1076. doCreatureSay(cid, mgo, TALKTYPE_SAY)
  1077.  
  1078. doSendMagicEffect(getCreaturePosition(pk), effect)
  1079.  
  1080. unLock(item.uid) --alterado v1.8
  1081.  
  1082. if useKpdoDlls then
  1083. doUpdateMoves(cid)
  1084. end
  1085. end
  1086.  
  1087. function doRegainSpeed(cid) --alterado v1.9 \/
  1088. if not isCreature(cid) then return true end
  1089.  
  1090. local speed = PlayerSpeed
  1091. if isMonster(cid) then
  1092. speed = getSpeed(cid)
  1093. elseif isPlayer(cid) and isInArray({4, 5, 6}, getPlayerGroupId(cid)) then
  1094. speed = 200*getPlayerGroupId(cid)
  1095. end
  1096.  
  1097. doChangeSpeed(cid, -getCreatureSpeed(cid))
  1098. if getCreatureCondition(cid, CONDITION_PARALYZE) == true then
  1099. doRemoveCondition(cid, CONDITION_PARALYZE)
  1100. addEvent(doAddCondition, 10, cid, paralizeArea2)
  1101. end
  1102.  
  1103. doChangeSpeed(cid, speed)
  1104. return speed
  1105. end
  1106.  
  1107. function isPosEqualPos(pos1, pos2, checkstackpos)
  1108. if pos1.x ~= pos2.x or pos1.y ~= pos2.y and pos1.z ~= pos2.z then
  1109. return false
  1110. end
  1111. if checkstackpos and pos1.stackpos and pos2.stackpos and pos1.stackpos ~= pos2.stackpos then
  1112. return false
  1113. end
  1114. return true
  1115. end
  1116.  
  1117. function getRandomGenderByName(name)
  1118. local rate = newpokedex[name]
  1119. if not rate then return 0 end
  1120. rate = rate.gender
  1121. if rate == 0 then
  1122. gender = 3
  1123. elseif rate == 1000 then
  1124. gender = 4
  1125. elseif rate == -1 then
  1126. gender = 0
  1127. elseif math.random(1, 1000) <= rate then
  1128. gender = 4
  1129. else
  1130. gender = 3
  1131. end
  1132. return gender
  1133. end
  1134.  
  1135. function getRecorderPlayer(pos, cid)
  1136.  
  1137. local ret = 0
  1138.  
  1139. if cid and getThingPos(cid).x == pos.x and getThingPos(cid).y == pos.y then
  1140.  
  1141. return cid
  1142.  
  1143. end
  1144.  
  1145. local s = {}
  1146.  
  1147. s.x = pos.x
  1148.  
  1149. s.y = pos.y
  1150.  
  1151. s.z = pos.z
  1152.  
  1153. for a = 0, 255 do
  1154.  
  1155. s.stackpos = a
  1156.  
  1157. local b = getTileThingByPos(s).uid
  1158.  
  1159. if b > 1 and isPlayer(b) and getCreatureOutfit(b).lookType ~= 814 then
  1160.  
  1161. ret = b
  1162.  
  1163. end
  1164.  
  1165. end
  1166.  
  1167. return ret
  1168.  
  1169. end
  1170.  
  1171. function getRecorderCreature(pos, cid)
  1172. local ret = 0
  1173. if cid and isPosEqual(getThingPos(cid), pos) then --alterado v1.9
  1174. return cid
  1175. end
  1176. local s = {}
  1177. s.x = pos.x
  1178. s.y = pos.y
  1179. s.z = pos.z
  1180. for a = 0, 255 do
  1181. s.stackpos = a
  1182. local b = getTileThingByPos(s).uid
  1183. if b > 1 and isCreature(b) and getCreatureOutfit(b).lookType ~= 814 then
  1184. ret = b
  1185. end
  1186. end
  1187. return ret
  1188. end
  1189.  
  1190. function doCreatureSetOutfit(cid, outfit, time)
  1191. doSetCreatureOutfit(cid, outfit, time)
  1192. end
  1193.  
  1194. function doMagicalFlower(cid, away)
  1195. if not isCreature(cid) then return true end
  1196. for x = -3, 3 do
  1197. for y = -3, 3 do
  1198. local a = getThingPos(cid)
  1199. a.x = a.x + x
  1200. a.y = a.y + y
  1201. if away then
  1202. doSendDistanceShoot(a, getThingPos(cid), 21)
  1203. else
  1204. doSendDistanceShoot(getThingPos(cid), a, 21)
  1205. end
  1206. end
  1207. end
  1208. end
  1209.  
  1210. function isItemPokeball(item) --alterado v1.9 \/
  1211. if not item then return false end
  1212. for a, b in pairs (pokeballs) do
  1213. if isInArray(b.all, item) then return true end
  1214. if item >= 12861 and item <= 13781 then
  1215. return true
  1216. end
  1217. if item >= 13797 and item <= 13823 then
  1218. return true
  1219. end
  1220. if item >= 10975 and item <= 10977 then
  1221. return true
  1222. end
  1223. if item >= 13836 and item <= 13850 then
  1224. return true
  1225. end
  1226. if item >= 13851 and item <= 13856 then
  1227. return true
  1228. end
  1229. if item >= 13859 and item <= 13861 then
  1230. return true
  1231. end
  1232. if item >= 13902 and item <= 13904 then
  1233. return true
  1234. end
  1235. if item >= 13919 and item <= 13930 then
  1236. return true
  1237. end
  1238. end
  1239. return false
  1240. end
  1241.  
  1242. function isPokeball(item)
  1243. if not item then return false end
  1244. for a, b in pairs (pokeballs) do
  1245. if isInArray(b.all, item) then return true end
  1246. if item >= 12861 and item <= 13781 then
  1247. return true
  1248. end
  1249. if item >= 13797 and item <= 13823 then
  1250. return true
  1251. end
  1252. if item >= 10975 and item <= 10977 then
  1253. return true
  1254. end
  1255. if item >= 13836 and item <= 13856 then
  1256. return true
  1257. end
  1258. end
  1259. return false
  1260. end
  1261. function getPokeballType(id)
  1262. for a, b in pairs (pokeballs) do
  1263. if isInArray(b.all, id) then
  1264. return a
  1265. end
  1266. end
  1267. return "none"
  1268. end
  1269.  
  1270. randomdiagonaldir = {
  1271. [NORTHEAST] = {NORTH, EAST},
  1272. [SOUTHEAST] = {SOUTH, EAST},
  1273. [NORTHWEST] = {NORTH, WEST},
  1274. [SOUTHWEST] = {SOUTH, WEST}}
  1275.  
  1276. function doFaceOpposite(cid)
  1277. local a = getCreatureLookDir(cid)
  1278. local d = {
  1279. [NORTH] = SOUTH,
  1280. [SOUTH] = NORTH,
  1281. [EAST] = WEST,
  1282. [WEST] = EAST,
  1283. [NORTHEAST] = SOUTHWEST,
  1284. [NORTHWEST] = SOUTHEAST,
  1285. [SOUTHEAST] = NORTHWEST,
  1286. [SOUTHWEST] = NORTHEAST}
  1287. doCreatureSetLookDir(cid, d[a])
  1288. end
  1289.  
  1290. function doFaceRandom(cid)
  1291. local a = getCreatureLookDir(cid)
  1292. local d = {
  1293. [NORTH] = {SOUTH, WEST, EAST},
  1294. [SOUTH] = {NORTH, WEST, EAST},
  1295. [WEST] = {SOUTH, NORTH, EAST},
  1296. [EAST] = {SOUTH, WEST, NORTH}}
  1297. doChangeSpeed(cid, 1)
  1298. doCreatureSetLookDir(cid, d[a][math.random(1, 3)])
  1299. doChangeSpeed(cid, -1)
  1300. end
  1301.  
  1302. function getFaceOpposite(dir)
  1303. local d = {
  1304. [NORTH] = SOUTH,
  1305. [SOUTH] = NORTH,
  1306. [EAST] = WEST,
  1307. [WEST] = EAST,
  1308. [NORTHEAST] = SOUTHWEST,
  1309. [NORTHWEST] = SOUTHEAST,
  1310. [SOUTHEAST] = NORTHWEST,
  1311. [SOUTHWEST] = NORTHEAST}
  1312. return d[dir]
  1313. end
  1314.  
  1315. function getResistance(cid, combat)
  1316. if isPlayer(cid) then return false end
  1317. local poketype1 = pokes[getCreatureName(cid)].type
  1318. local poketype2 = pokes[getCreatureName(cid)].type2
  1319. local multiplier = 1
  1320. if effectiveness[combat].super and isInArray(effectiveness[combat].super, poketype1) then
  1321. multiplier = multiplier * 2
  1322. end
  1323. if poketype2 and effectiveness[combat].super and isInArray(effectiveness[combat].super, poketype2) then
  1324. multiplier = multiplier * 2
  1325. end
  1326. if effectiveness[combat].weak and isInArray(effectiveness[combat].weak, poketype1) then
  1327. multiplier = multiplier * 0.5
  1328. end
  1329. if poketype2 and effectiveness[combat].weak and isInArray(effectiveness[combat].weak, poketype2) then
  1330. multiplier = multiplier * 0.5
  1331. end
  1332. if effectiveness[combat].non and isInArray(effectiveness[combat].non, poketype1) then
  1333. multiplier = multiplier * 0
  1334. end
  1335. if poketype2 and effectiveness[combat].non and isInArray(effectiveness[combat].non, poketype2) then
  1336. multiplier = multiplier * 0
  1337. end
  1338.  
  1339. if multiplier == 0.25 then
  1340. multiplier = 0.5
  1341. elseif multiplier == 4 then
  1342. multiplier = 2
  1343. end
  1344.  
  1345. return multiplier
  1346. end
  1347.  
  1348. function getCreatureDirectionToTarget(cid, target, ranged)
  1349. if not isCreature(cid) then return true end
  1350. if not isCreature(target) then return getCreatureLookDir(cid) end
  1351. local dirs = {
  1352. [NORTHEAST] = {NORTH, EAST},
  1353. [SOUTHEAST] = {SOUTH, EAST},
  1354. [NORTHWEST] = {NORTH, WEST},
  1355. [SOUTHWEST] = {SOUTH, WEST}}
  1356. local x = getDirectionTo(getThingPos(cid), getThingPos(target), false)
  1357. if x <= 3 then return x
  1358. else
  1359. local xdistance = math.abs(getThingPos(cid).x - getThingPos(target).x)
  1360. local ydistance = math.abs(getThingPos(cid).y - getThingPos(target).y)
  1361. if xdistance > ydistance then
  1362. return dirs[x][2]
  1363. elseif ydistance > xdistance then
  1364. return dirs[x][1]
  1365. elseif isInArray(dirs[x], getCreatureLookDir(cid)) then
  1366. return getCreatureLookDir(cid)
  1367. else
  1368. return dirs[x][math.random(1, 2)]
  1369. end
  1370. end
  1371. end
  1372.  
  1373. function getSomeoneDescription(cid)
  1374. if isPlayer(cid) then return getPlayerNameDescription(cid) end
  1375. return getMonsterInfo(getCreatureName(cid)).description
  1376. end
  1377.  
  1378.  
  1379. function isGhostPokemon(cid)
  1380. if not isCreature(cid) then return false end
  1381. local ghosts = {"Gastly", "Haunter", "Gengar", "Shiny Gengar", "Misdreavus", "Shiny Abra"}
  1382. return isInArray(ghosts, getCreatureName(cid))
  1383. end
  1384.  
  1385. function updateGhostWalk(cid)
  1386. if not isCreature(cid) then return false end
  1387. local pos = getThingPos(cid)
  1388. pos.x = pos.x + 1
  1389. pos.y = pos.y + 1
  1390. local ret = getThingPos(cid)
  1391. doTeleportThing(cid, pos, false)
  1392. doTeleportThing(cid, ret, false)
  1393. return true
  1394. end
  1395.  
  1396. function doRemoveElementFromTable(t, e)
  1397. local ret = {}
  1398. for a = 1, #t do
  1399. if t[a] ~= e then
  1400. table.insert(ret, t[a])
  1401. end
  1402. end
  1403. return ret
  1404. end
  1405.  
  1406. function doFaceCreature(sid, pos)
  1407. if not isCreature(sid) then return true end
  1408. if getThingPos(sid).x == pos.x and getThingPos(sid).y == pos.y then return true end
  1409. local ret = 0
  1410.  
  1411. local ld = getCreatureLookDir(sid)
  1412. local dir = getDirectionTo(getThingPos(sid), pos)
  1413. local al = {
  1414. [NORTHEAST] = {NORTH, EAST},
  1415. [NORTHWEST] = {NORTH, WEST},
  1416. [SOUTHEAST] = {SOUTH, EAST},
  1417. [SOUTHWEST] = {SOUTH, WEST}}
  1418.  
  1419. if dir >= 4 and isInArray(al[dir], ld) then return true end
  1420.  
  1421. doChangeSpeed(sid, 1)
  1422. if dir == 4 then
  1423. ret = math.random(2, 3)
  1424. elseif dir == 5 then
  1425. ret = math.random(1, 2)
  1426. elseif dir == 6 then
  1427. local dirs = {0, 3}
  1428. ret = dirs[math.random(1, 2)]
  1429. elseif dir == 7 then
  1430. ret = math.random(0, 1)
  1431. else
  1432. ret = getDirectionTo(getThingPos(sid), pos)
  1433. end
  1434. doCreatureSetLookDir(sid, ret)
  1435. doChangeSpeed(sid, -1)
  1436. return true
  1437. end
  1438.  
  1439. function doCreatureAddCondition(cid, condition)
  1440. if not isCreature(cid) then return true end
  1441. doAddCondition(cid, condition)
  1442. end
  1443.  
  1444. function doCreatureRemoveCondition(cid, condition)
  1445. if not isCreature(cid) then return true end
  1446. doRemoveCondition(cid, condition)
  1447. end
  1448.  
  1449. function setCD(item, tipo, tempo)
  1450.  
  1451. if not tempo or not tonumber(tempo) then
  1452. doItemEraseAttribute(item, tipo)
  1453. return true
  1454. end
  1455.  
  1456. doItemSetAttribute(item, tipo, "cd:"..(tempo + os.time()).."")
  1457. return tempo + os.time()
  1458. end
  1459.  
  1460. function getCD(item, tipo, limite)
  1461.  
  1462. if not getItemAttribute(item, tipo) then
  1463. return 0
  1464. end
  1465.  
  1466. local string = getItemAttribute(item, tipo):gsub("cd:", "")
  1467. local number = tonumber(string) - os.time()
  1468.  
  1469. if number <= 0 then
  1470. return 0
  1471. end
  1472.  
  1473. if limite and limite < number then
  1474. return 0
  1475. end
  1476.  
  1477. return number
  1478. end
  1479.  
  1480. function doSendMoveEffect(cid, target, effect)
  1481. if not isCreature(cid) or not isCreature(target) then return true end
  1482. doSendDistanceShoot(getThingPos(cid), getThingPos(target), effect)
  1483. return true
  1484. end
  1485.  
  1486. function doSetItemActionId(uid, actionid)
  1487. doItemSetAttribute(uid, "aid", actionid)
  1488. return true
  1489. end
  1490.  
  1491. function threeNumbers(number)
  1492. if number <= 9 then
  1493. return "00"..number..""
  1494. elseif number <= 99 then
  1495. return "0"..number..""
  1496. end
  1497. return ""..number..""
  1498. end
  1499.  
  1500. function isBr(cid)
  1501. if getPlayerStorageValue(cid, 105505) ~= -1 then
  1502. return true
  1503. end
  1504. return false
  1505. end
  1506.  
  1507. function isBeingUsed(ball)
  1508. if not ball then return false end
  1509. for a, b in pairs (pokeballs) do --alterado v1.9
  1510. if b.use == ball then return true end
  1511. end
  1512. return false
  1513. end
  1514.  
  1515. function doRemoveTile(pos)-- Script by mock
  1516. pos.stackpos = 0
  1517. local sqm = getTileThingByPos(pos)
  1518. doRemoveItem(sqm.uid,1)
  1519. end
  1520.  
  1521. function doCreateTile(id,pos) -- By mock
  1522. doAreaCombatHealth(0,0,pos,0,0,0,CONST_ME_NONE)
  1523. doCreateItem(id,1,pos)
  1524. end
  1525.  
  1526. function hasSqm(pos)
  1527. local f = getTileThingByPos(pos)
  1528. if f.itemid ~= 0 and f.itemid ~= 1 then
  1529. return true
  1530. end
  1531. return false
  1532. end
  1533.  
  1534. function getPosDirs(p, dir) -- By MatheusMkalo
  1535. 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}
  1536. end
  1537.  
  1538. function canWalkOnPos(pos, creature, pz, water, sqm, proj)
  1539. if not pos then return false end
  1540. if not pos.x then return false end
  1541. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid <= 1 and sqm then return false end
  1542. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 919 then return false end
  1543. 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
  1544. if getTopCreature(pos).uid > 0 and creature then return false end
  1545. if getTileInfo(pos).protection and pz then return false end
  1546. local n = not proj and 3 or 2 --alterado v1.6
  1547. for i = 0, 255 do
  1548. pos.stackpos = i
  1549. local tile = getTileThingByPos(pos)
  1550. if tile.itemid ~= 0 and i ~= 253 and not isCreature(tile.uid) then --edited
  1551. if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1552. return false
  1553. end
  1554. end
  1555. end
  1556. return true
  1557. end
  1558.  
  1559. function canWalkOnPos2(pos, creature, pz, water, sqm, proj) --alterado v1.6
  1560. if not pos then return false end
  1561. if not pos.x then return false end
  1562. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid <= 1 and sqm then return false end
  1563. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 919 then return false end
  1564. 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
  1565. if getTopCreature(pos).uid > 0 and creature then return false end
  1566. if getTileInfo(pos).protection and pz then return false end
  1567. --[[local n = not proj and 3 or 2
  1568. for i = 0, 255 do
  1569. pos.stackpos = i --edited pra retirar um bug.. ;x
  1570. local tile = getTileThingByPos(pos)
  1571. if tile.itemid ~= 0 and i ~= 253 and not isCreature(tile.uid) then --edited
  1572. if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1573. return false
  1574. end
  1575. end
  1576. end ]]
  1577. return true
  1578. end
  1579.  
  1580. function getFreeTile(pos, cid)
  1581. if canWalkOnPos(pos, true, false, true, true, false) then
  1582. return pos
  1583. end
  1584. local positions = {}
  1585. for a = 0, 7 do
  1586. if canWalkOnPos(getPosByDir(pos, a), true, false, true, true, false) then
  1587. table.insert(positions, pos)
  1588. end
  1589. end
  1590. if #positions >= 1 then
  1591. if isCreature(cid) then
  1592. local range = 1000
  1593. local ret = getThingPos(cid)
  1594. for b = 1, #positions do
  1595. if getDistanceBetween(getThingPos(cid), positions[b]) < range then
  1596. ret = positions[b]
  1597. range = getDistanceBetween(getThingPos(cid), positions[b])
  1598. end
  1599. end
  1600. return ret
  1601. else
  1602. return positions[math.random(#positions)]
  1603. end
  1604. end
  1605. return getThingPos(cid)
  1606. end
  1607.  
  1608. function isWalkable(pos, creature, proj, pz, water)-- by Nord
  1609. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
  1610. if isWater(getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid) and water then return false end
  1611. if getTopCreature(pos).uid > 0 and creature then return false end
  1612. if getTileInfo(pos).protection and pz then return false, true end
  1613. local n = not proj and 3 or 2
  1614. for i = 0, 255 do
  1615. pos.stackpos = i
  1616. local tile = getTileThingByPos(pos)
  1617. if tile.itemid ~= 0 and not isCreature(tile.uid) then
  1618. if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  1619. return false
  1620. end
  1621. end
  1622. end
  1623. return true
  1624. end
  1625.  
  1626.  
  1627. function isPlayerSummon(cid, uid)
  1628. return getCreatureMaster(uid) == cid --alterado v1.9
  1629. end
  1630.  
  1631. function isSummon(sid)
  1632. return isCreature(sid) and getCreatureMaster(sid) ~= sid and isPlayer(getCreatureMaster(sid)) --alterado v1.9
  1633. end
  1634.  
  1635. function getItemsInContainerById(container, itemid) -- Function By Kydrai
  1636. local items = {}
  1637. if isContainer(container) and getContainerSize(container) > 0 then
  1638. for slot=0, (getContainerSize(container)-1) do
  1639. local item = getContainerItem(container, slot)
  1640. if isContainer(item.uid) then
  1641. local itemsbag = getItemsInContainerById(item.uid, itemid)
  1642. for i=0, #itemsbag do
  1643. table.insert(items, itemsbag[i])
  1644. end
  1645. else
  1646. if itemid == item.itemid then
  1647. table.insert(items, item.uid)
  1648. end
  1649. end
  1650. end
  1651. end
  1652. return items
  1653. end
  1654.  
  1655. function getPokeballsInContainer(container) -- Function By Kydrai
  1656. if not isContainer(container) then return {} end
  1657. local items = {}
  1658. if isContainer(container) and getContainerSize(container) > 0 then
  1659. for slot=0, (getContainerSize(container)-1) do
  1660. local item = getContainerItem(container, slot)
  1661. if isContainer(item.uid) then
  1662. local itemsbag = getPokeballsInContainer(item.uid)
  1663. for i=0, #itemsbag do
  1664. table.insert(items, itemsbag[i])
  1665. end
  1666. elseif isPokeball(item.itemid) then
  1667. table.insert(items, item.uid)
  1668. end
  1669. end
  1670. end
  1671. return items
  1672. end
  1673.  
  1674. function getItensUniquesInContainer(container) --alterado v1.6
  1675. if not isContainer(container) then return {} end
  1676. local items = {}
  1677. if isContainer(container) and getContainerSize(container) > 0 then
  1678. for slot=0, (getContainerSize(container)-1) do
  1679. local item = getContainerItem(container, slot)
  1680. if isContainer(item.uid) then
  1681. local itemsbag = getItensUniquesInContainer(item.uid)
  1682. for i=0, #itemsbag do
  1683. table.insert(items, itemsbag[i])
  1684. end
  1685. elseif getItemAttribute(item.uid, "unique") then
  1686. table.insert(items, item)
  1687. end
  1688. end
  1689. end
  1690. return items
  1691. end
  1692.  
  1693. function hasSpaceInContainer(container) --alterado v1.6
  1694. if not isContainer(container) then return false end
  1695. if getContainerSize(container) < getContainerCap(container) then return true end
  1696.  
  1697. for slot = 0, (getContainerSize(container)-1) do
  1698. local item = getContainerItem(container, slot)
  1699. if isContainer(item.uid) then
  1700. if hasSpaceInContainer(item.uid) then
  1701. return true
  1702. end
  1703. end
  1704. end
  1705. return false
  1706. end
  1707.  
  1708. function doPlayerSendCancel2(cid, msg)
  1709. if not isCreature(cid) then return false end
  1710. if isPlayer(cid) then
  1711. return doPlayerSendCancel(cid, msg)
  1712. end
  1713. return false
  1714. end
  1715.  
  1716. function getStonePrice(id)
  1717. if not isStone(id) then return 0 end
  1718. comumStone = {20886,}
  1719. if isInArray(comumStone, id) then
  1720. return 5000
  1721. else
  1722. return 10000
  1723. end
  1724. return 0
  1725. end
  1726.  
  1727. function getPokemonPrice(item)
  1728. if not pokes[getItemAttribute(item, "poke")] then return 0 end
  1729. stoneprice = 0
  1730. price = 0
  1731. name = getItemAttribute(item, "poke")
  1732. boost = getItemAttribute(item, "boost") or 0
  1733. if boost >= 1 then
  1734. stoneid = doConvertTypeToId(pokes[name].type)
  1735. stoneprice = getStonePrice(stoneid) * boost
  1736. end
  1737. price = pokePrice[name] or pokes[name].level * 150
  1738. price = stoneprice + price
  1739. return price
  1740. end
  1741.  
  1742. function getPokeTotalPriceInContainer(container)
  1743. balls = getPokeballsInContainer(container)
  1744. stoneprice = 0
  1745. prices = {}
  1746. if #balls >= 1 then
  1747. for i = 1, #balls do
  1748. if pokes[getItemAttribute(balls[i], "poke")] then
  1749. name = getItemAttribute(balls[i], "poke")
  1750. boost = getItemAttribute(balls[i], "boost") or 0
  1751.  
  1752. if boost >= 1 then
  1753. stoneid = doConvertTypeToId(pokes[name].type)
  1754. stoneprice = getStonePrice(stoneid) * boost
  1755. end
  1756. price = pokePrice[name] or pokes[name].level * 150
  1757. price = stoneprice + price
  1758. else
  1759. price = 0
  1760. end
  1761. table.insert(prices, math.floor(price))
  1762. end
  1763. end
  1764. price1 = 0
  1765. price2 = 0
  1766. price3 = 0
  1767. price4 = 0
  1768. price5 = 0
  1769. price6 = 0
  1770. if #prices == 6 then
  1771. price1 = prices[1]
  1772. price2 = prices[2]
  1773. price3 = prices[3]
  1774. price4 = prices[4]
  1775. price5 = prices[5]
  1776. price6 = prices[6]
  1777. elseif #prices == 5 then
  1778. price1 = prices[1]
  1779. price2 = prices[2]
  1780. price3 = prices[3]
  1781. price4 = prices[4]
  1782. price5 = prices[5]
  1783. elseif #prices == 4 then
  1784. price1 = prices[1]
  1785. price2 = prices[2]
  1786. price3 = prices[3]
  1787. price4 = prices[4]
  1788. elseif #prices == 3 then
  1789. price1 = prices[1]
  1790. price2 = prices[2]
  1791. price3 = prices[3]
  1792. elseif #prices == 2 then
  1793. price1 = prices[1]
  1794. price2 = prices[2]
  1795. elseif #prices == 1 then
  1796. price1 = prices[1]
  1797. end
  1798. pricetotal = price1 + price2 + price3 + price4 + price5 + price6
  1799. return math.floor(pricetotal)
  1800. end
  1801.  
  1802. function doPlayerAddItemStacking(cid, itemid, quant) -- by mkalo
  1803. local item = getItemsInContainerById(getPlayerSlotItem(cid, 3).uid, itemid)
  1804. local piles = 0
  1805. if #item > 0 then
  1806. for i,x in pairs(item) do
  1807. if getThing(x).type < 100 then
  1808. local it = getThing(x)
  1809. doTransformItem(it.uid, itemid, it.type+quant)
  1810. if it.type+quant > 100 then
  1811. doPlayerAddItem(cid, itemid, it.type+quant-100)
  1812. end
  1813. else
  1814. piles = piles+1
  1815. end
  1816. end
  1817. else
  1818. return doPlayerAddItem(cid, itemid, quant)
  1819. end
  1820. if piles == #item then
  1821. doPlayerAddItem(cid, itemid, quant)
  1822. end
  1823. end
  1824.  
  1825. function getPlayerInArea(fromPos, toPos) -- by jhon992
  1826. local online = getPlayersOnline()
  1827. local players = {}
  1828. for i=1, #online do
  1829. if isInArea(getPlayerPosition(online[i]), fromPos, toPos) then
  1830. players[#players+1] = online[i]
  1831. end
  1832. end
  1833. return players
  1834. end
  1835. function isPlayerOnline(uid)
  1836. return isInArray(getPlayersOnline(), uid)
  1837. end
  1838.  
  1839. function doRegenerateWithY(cid, sid)
  1840. if isPlayerOnline(cid) then
  1841. local ball = getPlayerSlotItem(cid, 8) or getPlayerSlotItem(getCreatureMaster(cid), 8)
  1842. local Tiers = {
  1843. [1] = {bonus = Regen1},
  1844. [2] = {bonus = Regen2},
  1845. [3] = {bonus = Regen3},
  1846. [4] = {bonus = Regen4},
  1847. [5] = {bonus = Regen5},
  1848. [6] = {bonus = Regen6},
  1849. [7] = {bonus = Regen7},
  1850. }
  1851. if isPlayer(cid) and #getCreatureSummons(cid) > 0 then
  1852. local Tier = getItemAttribute(ball.uid, "heldy")
  1853. if Tier and Tier > 0 and Tier < 8 then
  1854. if not getCreatureCondition(cid, CONDITION_INFIGHT) then
  1855. if getCreatureHealth(sid) < getCreatureMaxHealth(sid) then
  1856. addEvent(function() doCreatureAddHealth(sid,Tiers[Tier].bonus) doSendAnimatedText(getThingPos(sid), "+ "..Tiers[Tier].bonus, 30) end, 0)
  1857. end
  1858. addEvent(doRegenerateWithY, 1000, cid, sid)
  1859. else
  1860. addEvent(doRegenerateWithY, 1000, cid, sid)
  1861. end
  1862. end
  1863. end
  1864. end
  1865. end
  1866.  
  1867. function doCureWithY(cid, sid)
  1868. if isPlayerOnline(cid) then
  1869. local ball = getPlayerSlotItem(cid, 8) or getPlayerSlotItem(getCreatureMaster(cid), 8)
  1870. local Tiers = {
  1871. [8] = {chance = Cure1},
  1872. [9] = {chance = Cure2},
  1873. [10] = {chance = Cure3},
  1874. [11] = {chance = Cure4},
  1875. [12] = {chance = Cure5},
  1876. [13] = {chance = Cure6},
  1877. [14] = {chance = Cure7},
  1878. }
  1879. local Tier = getItemAttribute(ball.uid, "heldy")
  1880. if isPlayer(cid) and #getCreatureSummons(cid) > 0 and Tier then
  1881. if Tier > 7 and Tier < 15 then
  1882. if math.random(1,100) <= Tiers[Tier].chance then
  1883. doCureStatus(sid, "all")
  1884. doSendMagicEffect(getThingPosWithDebug(sid), 14)
  1885. end
  1886. addEvent(doCureWithY, 1000, cid, sid)
  1887. end
  1888. end
  1889. end
  1890. end
Add Comment
Please, Sign In to add comment