Advertisement
Kevick

Untitled

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