Advertisement
Nysman

Untitled

Nov 3rd, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.79 KB | None | 0 0
  1. happinessRate = {
  2. [5] = {rate = 1.5, effect = 183, n = getConfigValue(PokemonStageVeryHappy)},
  3. [4] = {rate = 1.2, effect = 170, n = getConfigValue(PokemonStageHappy)},
  4. [3] = {rate = 1.0, effect = 182, n = getConfigValue(PokemonStageOK)},
  5. [2] = {rate = 0.7, effect = 169, n = getConfigValue(PokemonStageSad)},
  6. [1] = {rate = 0.4, effect = 168, n = getConfigValue(PokemonStageMad)}
  7. }
  8.  
  9. function doSetPlayerSpeedLevel(cid)
  10. local speed = 220
  11. local spood = getCreatureSpeed(cid)
  12. local level = getPlayerLevel(cid)
  13. doChangeSpeed(cid, -spood)
  14. doChangeSpeed(cid, speed + (level * 3))
  15. end
  16.  
  17. function levelSystem(cid)
  18.  
  19. local slot = getPlayerSlotItem(cid, 8)
  20. local attr = getItemAttribute(slot.uid, "level")
  21.  
  22. if not attr then
  23. doItemSetAttribute(slot.uid, "level", 1)
  24. doPlayerSendCancel(cid, '12//,levelsystem')
  25. end
  26.  
  27. if attr == 0 then
  28. doItemSetAttribute(slot.uid, "level", 1)
  29. doPlayerSendCancel(cid, '12//,levelsystem')
  30. end
  31. end
  32.  
  33. function addPokeToPlayer(cid, pokemon, boost, gender, ball, unique) --alterado v1.9 \/ peguem ele todo...
  34. local genders = {
  35. ["male"] = 4,
  36. ["female"] = 3,
  37. ["indefinido"] = 1,
  38. ["genderless"] = 1,
  39. [1] = 4,
  40. [0] = 3,
  41. [4] = 4,
  42. [3] = 3,
  43. }
  44. if not isCreature(cid) then return false end
  45.  
  46. local pokemon = doCorrectString(pokemon)
  47. if not pokes[pokemon] then return false end
  48.  
  49. local GENDER = (gender and genders[gender]) and genders[gender] or getRandomGenderByName(pokemon)
  50. local btype = (ball and pokeballs[ball]) and ball or isShinyName(pokemon) and "shinynormal" or "normal"
  51. local happy = 250
  52.  
  53. local ballid = 11826
  54.  
  55. if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  56. item = doCreateItemEx(ballid-1)
  57. else
  58. item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, ballid, 1)
  59. end
  60. if not item then return false end
  61.  
  62. doItemSetAttribute(item, "poke", pokemon)
  63. doItemSetAttribute(item, "hp", 1)
  64. doItemSetAttribute(item, "happy", happy)
  65. doItemSetAttribute(item, "gender", GENDER)
  66. doItemSetAttribute(item, "exp", 0)
  67. doItemSetAttribute(item, "level", 1)
  68. doSetItemAttribute(item, "hands", 0)
  69. doItemSetAttribute(item, "description", "Contains a "..pokemon..".")
  70. doItemSetAttribute(item, "fakedesc", "Contains a "..pokemon..".")
  71. if boost and tonumber(boost) and tonumber(boost) > 0 and tonumber(boost) <= 50 then
  72. doItemSetAttribute(item, "boost", boost)
  73. end
  74. if unique then
  75. doItemSetAttribute(item, "unique", getCreatureName(cid))
  76. end
  77.  
  78. if (getPlayerFreeCap(cid) <= 1 and not isInArray({3, 2}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  79. doPlayerSendMailByName(getCreatureName(cid), item, 1)
  80. sendMsgToPlayer(cid, 27, "You are already holding six pokemons, so your new pokemon was sent to your depot.")
  81. end
  82. if (isShinyName(pokemon) or (boost and tonumber(boost) and tonumber(boost) >= 10)) and pokeballs["shiny"..btype] then
  83. doTransformItem(item, pokeballs["shiny"..btype].on)
  84. else
  85. doTransformItem(item, pokeballs[btype].on)
  86. end
  87. return true
  88. end
  89. ---------------------------
  90.  
  91. function unLock(ball)
  92. if not ball or ball <= 0 then return false end
  93. if getItemAttribute(ball, "lock") and getItemAttribute(ball, "lock") > 0 then
  94. local vipTime = getItemAttribute(ball, "lock")
  95. local timeNow = os.time()
  96. local days = math.ceil((vipTime - timeNow)/(24 * 60 * 60))
  97. if days <= 0 then
  98. doItemEraseAttribute(ball, "lock")
  99. doItemEraseAttribute(ball, "unique")
  100. return true
  101. end
  102. end
  103. return false
  104. end
  105.  
  106. function getGuildMembersOnline(GuildId)
  107. local players = {}
  108. for _, pid in pairs(getPlayersOnline()) do
  109. if getPlayerGuildId(pid) == tonumber(GuildId) then
  110. table.insert(players, pid)
  111. end
  112. end --by Vodkart
  113. return #players > 0 and players or false
  114. end
  115.  
  116. function getGuildMembers(GuildId)
  117. local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
  118. if (query:getID() ~= -1) then
  119. repeat
  120. table.insert(players,query:getDataString("name"))
  121. until not query:next() --by Vodkart
  122. query:free()
  123. end
  124. return #players > 0 and players or false
  125. end
  126. --/////////////////////////////////////////////////////////////////////////////////---
  127. function sendMsgToPlayer(cid, tpw, msg) --alterado v1.7 \/\/\/
  128. if not isCreature(cid) or not tpw or not msg then return true end
  129. return doPlayerSendTextMessage(cid, tpw, msg)
  130. end
  131.  
  132. function getPlayerDesc(cid, thing, TV)
  133. if (not isCreature(cid) or not isCreature(thing)) and not TV then return "" end
  134.  
  135. local pos = getThingPos(thing)
  136. local ocup = youAre[getPlayerGroupId(thing)]
  137. local rank = (getPlayerStorageValue(thing, 86228) <= 0) and "a "..getPlayerVocationName(thing).." " or lookClans[getPlayerStorageValue(thing, 86228)][getPlayerStorageValue(thing, 862281)]
  138. local name = thing == cid and "yourself" or getCreatureName(thing)
  139. local art = thing == cid and "You are" or (getPlayerSex(thing) == 0 and "She is" or "He is")
  140.  
  141. local str = {}
  142. table.insert(str, "You see "..name.." [".. getPlayerLevel(thing) .."]. "..art.." ")
  143. if youAre[getPlayerGroupId(thing)] then
  144. table.insert(str, (ocup).." and "..rank.." from ".. getTownName(getPlayerTown(thing))..".")
  145. else
  146. table.insert(str, (rank).." from ".. getTownName(getPlayerTown(thing))..".")
  147. end
  148. if getPlayerGuildId(thing) > 0 then
  149. table.insert(str, " "..art.." "..getPlayerGuildRank(thing).." from the "..getPlayerGuildName(thing)..".")
  150. end
  151. if TV then
  152. table.insert(str, " "..art.." watching TV.")
  153. end
  154. table.insert(str, ((isPlayer(cid) and youAre[getPlayerGroupId(cid)]) and "\nPosition: [X: "..pos.x.."][Y: "..pos.y.."][Z: "..pos.z.."]" or ""))
  155.  
  156. return table.concat(str)
  157. end
  158. ------------------------------------------------------------------------------------------------- /\/\
  159. function getLivePokeballs(cid, container, duel)
  160. if not isCreature(cid) then return {} end
  161. if not isContainer(container) then return {} end
  162. local items = {}
  163. ---
  164. local ballSlot = getPlayerSlotItem(cid, 8)
  165. if ballSlot.uid ~= 0 then
  166. for a, b in pairs (pokeballs) do
  167. if ballSlot.itemid == b.on or ballSlot.itemid == b.use then
  168. if duel and getPlayerLevel(cid) >= (pokes[getItemAttribute(ballSlot.uid, "poke")].level + getPokeballBoost(ballSlot)) then
  169. table.insert(items, ballSlot.uid) --alterado v1.8
  170. elseif not duel then
  171. table.insert(items, ballSlot.uid)
  172. end
  173. end
  174. end
  175. end
  176. ---
  177. if isContainer(container) and getContainerSize(container) > 0 then
  178. for slot=0, (getContainerSize(container)-1) do
  179. local item = getContainerItem(container, slot)
  180. if isContainer(item.uid) then
  181. local itemsbag = getPokeballsInContainer(item.uid)
  182. for i=0, #itemsbag do
  183. if not isInArray(items, itemsbag[i]) then
  184. table.insert(items, itemsbag[i])
  185. end
  186. end
  187. elseif isPokeball(item.itemid) then
  188. for a, b in pairs (pokeballs) do
  189. if item.itemid == b.on then
  190. if duel and getPlayerLevel(cid) >= (pokes[getItemAttribute(item.uid, "poke")].level + getPokeballBoost(item)) then
  191. table.insert(items, item.uid) --alterado v1.8
  192. elseif not duel then
  193. table.insert(items, item.uid)
  194. end
  195. end
  196. end
  197. end
  198. end
  199. end
  200. return items
  201. end
  202.  
  203. function addItemInFreeBag(container, item, num)
  204. if not isContainer(container) or not item then return false end
  205. if not num or num <= 0 then num = 1 end --alterado v1.6.1
  206. if getContainerSize(container) < getContainerCap(container) then
  207. return doAddContainerItem(container, item, num)
  208. else
  209. for slot = 0, (getContainerSize(container)-1) do
  210. local container2 = getContainerItem(container, slot)
  211. if isContainer(container2.uid) and getContainerSize(container2.uid) < getContainerCap(container2.uid) then
  212. return doAddContainerItem(container2.uid, item, num)
  213. end
  214. end
  215. end
  216. return false
  217. end
  218. ------------------------------------------------------------------------------------------------------
  219. function pokeHaveReflect(cid)
  220. if not isCreature(cid) then return false end
  221. local table = getTableMove(cid, "Reflect")
  222. if table and table.name then --alterado v1.6
  223. return true
  224. end
  225. return false
  226. end
  227. ------------------------------------------------------------------------------------------------------
  228. function nextHorario(cid)
  229. horarioAtual = os.date("%X")
  230. horario = string.explode(horarioAtual, ":")
  231.  
  232. for i = 1, #horas do
  233. horarioComparacao = horas[i]
  234. horarioComp = string.explode(horarioComparacao, ":")
  235. ---------------
  236. if tonumber(horarioComp[1]) > tonumber(horario[1]) then
  237. return horarioComparacao
  238. elseif tonumber(horarioComp[1]) == tonumber(horario[1]) and tonumber(horario[2]) < tonumber(horarioComp[2]) then
  239. return horarioComparacao
  240. end
  241. end
  242. return horas[1]
  243. end
  244.  
  245. function getTimeDiff(timeDiff)
  246. local dateFormat = {
  247. {'hour', timeDiff / 60 / 60}, --6%
  248. {'min', timeDiff / 60 % 60},
  249. }
  250. local out = {}
  251. for k, t in ipairs(dateFormat) do
  252. local v = math.floor(t[2])
  253. if(v > -1) then
  254. table.insert(out, (k < #dateFormat and '' or ' and ') .. v .. '' .. (v <= 1 and t[1] or t[1].."s"))
  255. end
  256. end
  257. if tonumber(dateFormat[1][2]) == 0 and tonumber(dateFormat[2][2]) == 0 then
  258. return "seconds"
  259. end
  260. return table.concat(out)
  261. end
  262.  
  263. function getTimeDiff2(timeDiff)
  264. local dateFormat = {
  265. {'hour', timeDiff / 60 / 60}, --6%
  266. {'min', timeDiff / 60 % 60},
  267. {'sec', timeDiff % 60},
  268. }
  269. local out = {}
  270. for k, t in ipairs(dateFormat) do
  271. local v = math.floor(t[2])
  272. if(v > 0) then
  273. table.insert(out, (k < #dateFormat and ' ' or ' and ') .. v .. '' .. (v <= 1 and t[1] or t[1].."s"))
  274. end
  275. end
  276. return table.concat(out)
  277. end
  278.  
  279. function showTimeDiff(timeComp)
  280. local b = string.explode(os.date("%X"), ":")
  281. local c = string.explode(timeComp, ":")
  282. ---
  283. local d, m, y = os.date("%d"), os.date("%m"), os.date("%Y")
  284. local hAtual, mAtual = tonumber(b[1]), tonumber(b[2])
  285. local hComp, mComp = tonumber(c[1]), tonumber(c[2])
  286. ---
  287. local t = os.time{year= y, month= m, day= d, hour= hAtual, min= mAtual}
  288. local t1 = os.time{year= y, month= m, day= d, hour= hComp, min= mComp}
  289. ---
  290. comparacao = t1-t
  291. if hComp < hAtual then
  292. v = os.time{year= y, month= m, day= d, hour= 24, min= 0}
  293. v2 = os.time{year= y, month= m, day= d, hour= 0, min= 0}
  294. comparacao = (v-t)+(t1-v2)
  295. end
  296. return getTimeDiff(comparacao)
  297. end
  298. -------------------------------------------------------------------------
  299. function cleanCMcds(item)
  300. if item ~= 0 then
  301. for c = 1, 15 do --alterado v1.5
  302. local str = "cm_move"..c
  303. setCD(item, str, 0)
  304. end
  305. end
  306. end
  307.  
  308. function ehNPC(cid) --alterado v1.9
  309. return isCreature(cid) and not isPlayer(cid) and not isSummon(cid) and not isMonster(cid)
  310. end
  311.  
  312. function ehMonstro(cid) --alterado v1.9
  313. return cid and cid >= AUTOID_MONSTERS and cid < AUTOID_NPCS and getCreatureMaster(cid) == cid
  314. end --alterado v1.9.1 /\
  315.  
  316. function doAppear(cid) --Faz um poke q tava invisivel voltar a ser visivel...
  317. if not isCreature(cid) then return true end
  318. doRemoveCondition(cid, CONDITION_INVISIBLE)
  319. doRemoveCondition(cid, CONDITION_OUTFIT)
  320. doCreatureSetHideHealth(cid, false)
  321. if getCreatureName(cid) == "Ditto" and pokes[getPlayerStorageValue(cid, 1010)] and getPlayerStorageValue(cid, 1010) ~= "Ditto" then
  322. if isSummon(cid) then
  323. local item = getPlayerSlotItem(getCreatureMaster(cid), 8)
  324. doSetCreatureOutfit(cid, {lookType = getItemAttribute(item.uid, "transOutfit")}, -1) --alterado v1.6.1
  325. end
  326. end
  327. end
  328.  
  329. function doDisapear(cid) --Faz um pokemon ficar invisivel
  330. if not isCreature(cid) then return true end
  331. doCreatureAddCondition(cid, permanentinvisible)
  332. doCreatureSetHideHealth(cid, true)
  333. doSetCreatureOutfit(cid, {lookType = 2}, -1)
  334. end
  335.  
  336. function hasTile(pos) --Verifica se tem TILE na pos
  337. pos.stackpos = 0
  338. if getTileThingByPos(pos).itemid >= 1 then
  339. return true
  340. end
  341. return false
  342. end
  343.  
  344. function getThingFromPosWithProtect(pos) --Pega uma creatura numa posiçao com proteçoes
  345. if hasTile(pos) then
  346. if isCreature(getRecorderCreature(pos)) then
  347. return getRecorderCreature(pos)
  348. else
  349. pos.stackpos = 253
  350. pid = getThingfromPos(pos).uid
  351. end
  352. else
  353. pid = getThingfromPos({x=1,y=1,z=10,stackpos=253}).uid
  354. end
  355. return pid
  356. end
  357.  
  358. function getTileThingWithProtect(pos) --Pega um TILE com proteçoes
  359. if hasTile(pos) then
  360. pos.stackpos = 0
  361. pid = getTileThingByPos(pos)
  362. else
  363. pid = getTileThingByPos({x=1,y=1,z=10,stackpos=0})
  364. end
  365. return pid
  366. end
  367.  
  368. function canAttackOther(cid, pid) --Function q verifica se um poke/player pode atacar outro poke/player
  369.  
  370. if not isCreature(cid) or not isCreature(pid) then return "Cant" end
  371.  
  372. local master1 = isSummon(cid) and getCreatureMaster(cid) or cid
  373. local master2 = isSummon(pid) and getCreatureMaster(pid) or pid
  374.  
  375. ----
  376. if getPlayerStorageValue(master1, 6598754) >= 5 and getPlayerStorageValue(master2, 6598754) >= 5 then
  377. if getPlayerStorageValue(master1, 6598754) ~= getPlayerStorageValue(master2, 6598754) then
  378. if isDuelingAgainst(master1, master2) then --alterado v1.8
  379. if isSummon(cid) and isPlayer(pid) then
  380.  
  381. return "Cant"
  382. else
  383. return "Can"
  384. end
  385. end
  386. end
  387. end
  388. ---- pvp system
  389. if getPlayerStorageValue(master1, 6598754) >= 1 and getPlayerStorageValue(master2, 6598755) >= 1 then
  390. return "Can"
  391. end
  392. if getPlayerStorageValue(master1, 6598755) >= 1 and getPlayerStorageValue(master2, 6598754) >= 1 then ---estar em times diferentes
  393. return "Can"
  394. end
  395. ----
  396. if getTileInfo(getThingPos(cid)).pvp then
  397. return "Can"
  398. end
  399.  
  400. if ehMonstro(cid) and ehMonstro(pid) then
  401. return "Can"
  402. end
  403.  
  404. return "Cant"
  405. end
  406.  
  407.  
  408. function stopNow(cid, time)
  409. if not isCreature(cid) or not tonumber(time) or isSleeping(cid) then return true end
  410. --alterado v1.9.1 \/
  411. local function podeMover(cid)
  412. if isPlayer(cid) then
  413. mayNotMove(cid, false)
  414. elseif isCreature(cid) then
  415. doRegainSpeed(cid)
  416. end
  417. end
  418.  
  419. if isPlayer(cid) then mayNotMove(cid, true) else doChangeSpeed(cid, -getCreatureSpeed(cid)) end
  420. addEvent(podeMover, time, cid)
  421. end
  422.  
  423. function doReduceStatus(cid, off, def, agi) --reduz os status
  424. if not isCreature(cid) then return true end
  425. local A = getOffense(cid)
  426. local B = getDefense(cid)
  427. local C = getSpeed(cid)
  428.  
  429. if off > 0 then
  430. setPlayerStorageValue(cid, 1001, A - off)
  431. end
  432. if def > 0 then
  433. setPlayerStorageValue(cid, 1002, B - def)
  434. end
  435. if agi > 0 then
  436. setPlayerStorageValue(cid, 1003, C - agi)
  437. if getCreatureSpeed(cid) ~= 0 then
  438. doRegainSpeed(cid)
  439. end --alterado v1.5 functions arrumadas...
  440. end
  441. end
  442.  
  443. function doRaiseStatus(cid, off, def, agi, time)
  444. if not isCreature(cid) then return true end
  445. local A = getOffense(cid)
  446. local B = getDefense(cid)
  447. local C = getSpeed(cid)
  448.  
  449. if off > 0 then
  450. setPlayerStorageValue(cid, 1001, A * off)
  451. end
  452. if def > 0 then
  453. setPlayerStorageValue(cid, 1002, B * def)
  454. end
  455. if agi > 0 then
  456. setPlayerStorageValue(cid, 1003, C + agi)
  457. if getCreatureSpeed(cid) ~= 0 then
  458. doRegainSpeed(cid)
  459. end
  460. end
  461.  
  462. local D = getOffense(cid)
  463. local E = getDefense(cid)
  464. local F = getSpeed(cid)
  465. ---------------------------
  466. local G = D - A
  467. local H = E - B
  468. local I = F - C
  469.  
  470. addEvent(doReduceStatus, time*1000, cid, G, H, I)
  471. end
  472.  
  473.  
  474. function BackTeam(cid)
  475. if isCreature(cid) then
  476. local summon = getCreatureSummons(cid) --alterado v1.6
  477. for i = 2, #summon do
  478. doSendMagicEffect(getThingPos(summon[i]), 211)
  479. doRemoveCreature(summon[i])
  480. end
  481. setPlayerStorageValue(cid, 637501, -1)
  482. end
  483. end
  484.  
  485. function choose(...) -- by mock
  486. local arg = {...}
  487. return arg[math.random(1,#arg)]
  488. end
  489.  
  490. function AddPremium(cid, days)
  491. local function removerPlayer(cid)
  492. if isCreature(cid) then
  493. doRemoveCreature(cid)
  494. end
  495. end
  496.  
  497. db.executeQuery("UPDATE `accounts` SET `premdays` = '"..days.."' WHERE `accounts`.`id` = ".. getPlayerAccountId(cid) ..";")
  498. doPlayerSendTextMessage(cid,25,"Você será kickado em 5 segundos.")
  499. addEvent(removerPlayer, 5*1000, cid)
  500. return TRUE
  501. end
  502.  
  503. function isShiny(cid)
  504. return isCreature(cid) and string.find(getCreatureName(cid), "Shiny") --alterado v1.9
  505. end
  506.  
  507. function isShinyName(name)
  508. return tostring(name) and string.find(doCorrectString(name), "Shiny") --alterado v1.9
  509. end
  510.  
  511. function doConvertTypeToStone(type, string)
  512. local t = {
  513. ["fly"] = {heart, "heart"},
  514. ["flying"] = {heart, "heart"},
  515. ["normal"] = {heart, "heart"},
  516. ["fire"] = {fire, "fire"},
  517. ["grass"] = {leaf, "leaf"},
  518. ["leaf"] = {leaf, "leaf"},
  519. ["water"] = {water, "water"},
  520. ["poison"] = {venom, "venom"},
  521. ["venom"] = {venom, "venom"},
  522. ["electric"] = {thunder, "thunder"},
  523. ["thunder"] = {thunder, "thunder"},
  524. ["rock"] = {rock, "rock"},
  525. ["fight"] = {punch, "punch"},
  526. ["fighting"] = {punch, "punch"},
  527. ["bug"] = {coccon, "coccon"},
  528. ["dragon"] = {crystal, "crystal"},
  529. ["dark"] = {dark, "dark"},
  530. ["ghost"] = {dark, "dark"},
  531. ["ground"] = {earth, "earth"},
  532. ["earth"] = {earth, "earth"},
  533. ["psychic"] = {enigma, "enigma"},
  534. ["steel"] = {metal, "metal"},
  535. ["metal"] = {metal, "metal"},
  536. ["ice"] = {ice, "ice"},
  537. ["boost"] = {boostStone, "boost"}, --alterado v1.9
  538. }
  539.  
  540. if string then
  541. return t[type][2]
  542. else
  543. return t[type][1]
  544. end
  545. end
  546.  
  547. function doConvertStoneIdToString(stoneID)
  548. local t = {
  549. [11453] = "Heart Stone",
  550. [11441] = "Leaf Stone",
  551. [11442] = "Water Stone",
  552. [11443] = "Venom Stone",
  553. [11444] = "Thunder Stone",
  554. [11445] = "Rock Stone",
  555. [11446] = "Punch Stone",
  556. [11447] = "Fire Stone", --alterado v1.6
  557. [11448] = "Cocoon Stone",
  558. [11449] = "Crystal Stone",
  559. [11450] = "Darkess Stone",
  560. [11451] = "Earth Stone",
  561. [11452] = "Enigma Stone",
  562. [11454] = "Ice Stone",
  563. [12244] = "King's Rock",
  564. [12232] = "Metal Stone",
  565. [12242] = "Sun Stone",
  566. [12401] = "Shiny Fire Stone",
  567. [12402] = "Shiny Water Stone",
  568. [12403] = "Shiny Leaf Stone",
  569. [12404] = "Shiny Heart Stone",
  570. [12405] = "Shiny Enigma Stone",
  571. [12406] = "Shiny Rock Stone",
  572. [12407] = "Shiny Venom Stone",
  573. [12408] = "Shiny Ice Stone",
  574. [12409] = "Shiny Thunder Stone",
  575. [12410] = "Shiny Crystal Stone",
  576. [12411] = "Shiny Cocoon Stone",
  577. [12412] = "Shiny Darkness Stone",
  578. [12413] = "Shiny Punch Stone",
  579. [12414] = "Shiny Earth Stone",
  580. [12419] = "dubious disc",
  581. [13381] = "Coursed Souls",
  582. [13229] = "Green Ambar",
  583. [12418] = "Soothe Bell",
  584. [14337] = "Neacle of spirit",
  585. [boostStone] = "Boost Stone", --alterado v1.9
  586. }
  587. if t[stoneID] then
  588. return t[stoneID]
  589. else
  590. return ""
  591. end
  592. end
  593.  
  594. function isWater(id)
  595. return tonumber(id) and id >= 4820 and id <= 4825 --alterado v1.9
  596. end
  597.  
  598. function getTopCorpse(position)
  599. local pos = position
  600. for n = 1, 255 do
  601. pos.stackpos = n
  602. local item = getTileThingByPos(pos)
  603. if item.itemid >= 2 and (string.find(getItemNameById(item.itemid), "fainted ") or string.find(getItemNameById(item.itemid), "defeated ")) then
  604. return getTileThingByPos(pos)
  605. end
  606. end
  607. return null
  608. end
  609.  
  610. bpslot = CONST_SLOT_BACKPACK
  611.  
  612. function hasPokemon(cid)
  613. if not isCreature(cid) then return false end
  614. if getCreatureMana(cid) <= 0 then return false end
  615. if #getCreatureSummons(cid) >= 1 then return true end
  616. local item = getPlayerSlotItem(cid, CONST_SLOT_FEET)
  617. local bp = getPlayerSlotItem(cid, bpslot)
  618. for a, b in pairs (pokeballs) do
  619. if item.itemid == b.on or item.itemid == b.use then
  620. return true --alterado v1.4
  621. end
  622. if #getItemsInContainerById(bp.uid, b.on) >= 1 then
  623. return true
  624. end
  625. end
  626. return false
  627. end
  628.  
  629. function isNpcSummon(cid)
  630. return isNpc(getCreatureMaster(cid))
  631. end
  632.  
  633. function getPokemonHappinessDescription(cid)
  634. if not isCreature(cid) then return true end
  635. local str = {}
  636. if getPokemonGender(cid) == SEX_MALE then
  637. table.insert(str, "He")
  638. elseif getPokemonGender(cid) == SEX_FEMALE then
  639. table.insert(str, "She")
  640. else
  641. table.insert(str, "It")
  642. end
  643. local h = getPlayerStorageValue(cid, 1008)
  644. if h >= tonumber(getConfigValue('PokemonStageVeryHappy')) then
  645. table.insert(str, " is very happy with you!")
  646. elseif h >= tonumber(getConfigValue('PokemonStageHappy')) then
  647. table.insert(str, " is happy.")
  648. elseif h >= tonumber(getConfigValue('PokemonStageOK')) then
  649. table.insert(str, " is unhappy.")
  650. elseif h >= tonumber(getConfigValue('PokemonStageSad')) then
  651. table.insert(str, " is sad.")
  652. elseif h >= tonumber(getConfigValue('PokemonStageMad')) then
  653. table.insert(str, " is mad.")
  654. else
  655. table.insert(str, " is very mad at you!")
  656. end
  657. return table.concat(str)
  658. end
  659.  
  660. function doSetItemAttribute(item, key, value)
  661. doItemSetAttribute(item, key, value)
  662. end
  663.  
  664. function deTransform(cid, check)
  665. if not isCreature(cid) then return true end
  666.  
  667. local m = getCreatureMaster(cid)
  668. local p = getPlayerSlotItem(m, 8)
  669.  
  670. if getItemAttribute(p.uid, "transTurn") ~= check then return true end
  671.  
  672. setPlayerStorageValue(cid, 1010, getCreatureName(cid) == "Ditto" and "Ditto" or "Shiny Ditto") --edited
  673. doRemoveCondition(cid, CONDITION_OUTFIT)
  674. doSendMagicEffect(getThingPos(cid), 184)
  675. doCreatureSay(cid, "DITTO!", TALKTYPE_MONSTER)
  676. doItemSetAttribute(p.uid, "transBegin", 0)
  677. doItemSetAttribute(p.uid, "transLeft", 0)
  678. doItemEraseAttribute(p.uid, "transName")
  679. adjustStatus(cid, p.uid, true, true, true)
  680. end
  681.  
  682. function isTransformed(cid)
  683. return isCreature(cid) and not isInArray({-1, "Ditto", "Shiny Ditto"}, getPlayerStorageValue(cid, 1010)) --alterado v1.9
  684. end
  685.  
  686. function doSendFlareEffect(pos)
  687. local random = {28, 29, 79}
  688. doSendMagicEffect(pos, random[math.random(1, 3)])
  689. end
  690.  
  691. function isDay()
  692. local a = getWorldTime()
  693. if a >= 360 and a < 1080 then
  694. return true
  695. end
  696. return false
  697. end
  698.  
  699. function doPlayerSendTextWindow(cid, p1, p2)
  700. if not isCreature(cid) then return true end
  701. local item = 460
  702. local text = ""
  703. if type(p1) == "string" then
  704. doShowTextDialog(cid, item, p1)
  705. else
  706. doShowTextDialog(cid, p1, p2)
  707. end
  708. end
  709.  
  710. function getClockString(tw)
  711. local a = getWorldTime()
  712. local b = a / 60
  713. local hours = math.floor(b)
  714. local minut = a - (60 * hours)
  715.  
  716. if not tw then
  717. if hours < 10 then
  718. hours = "0"..hours..""
  719. end
  720. if minut < 10 then
  721. minut = "0"..minut..""
  722. end
  723. return hours..":"..minut
  724. else
  725. local sm = "a.m"
  726. if hours >= 12 then
  727. hours = hours - 12
  728. sm = "p.m"
  729. end
  730. if hours < 10 then
  731. hours = "0"..hours..""
  732. end
  733. if minut < 10 then
  734. minut = "0"..minut..""
  735. end
  736. return hours..":"..minut.." "..sm
  737. end
  738. end
  739.  
  740. function doCorrectPokemonName(poke)
  741. return doCorrectString(poke)
  742. end
  743.  
  744. function doCorrectString(str)
  745. local name = str:explode(" ") --alterado v1.9
  746. local final = {}
  747. for _, s in ipairs(name) do
  748. table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
  749. end
  750. return table.concat(final, (name[2] and " " or ""))
  751. end
  752.  
  753. function getHappinessRate(cid)
  754. if not isCreature(cid) then return 1 end
  755. local a = getPlayerStorageValue(cid, 1008)
  756. if a == -1 then return 1 end
  757. if a >= getConfigValue('PokemonStageVeryHappy') then
  758. return happinessRate[5].rate
  759. elseif a >= getConfigValue('PokemonStageHappy') then
  760. return happinessRate[4].rate
  761. elseif a >= getConfigValue('PokemonStageOK') then
  762. return happinessRate[3].rate
  763. elseif a >= getConfigValue('PokemonStageSad') then
  764. return happinessRate[2].rate
  765. else
  766. return happinessRate[1].rate
  767. end
  768. return 1
  769. end
  770.  
  771. function doBodyPush(cid, target, go, pos)
  772. if not isCreature(cid) or not isCreature(target) then
  773. doRegainSpeed(cid)
  774. doRegainSpeed(target)
  775. return true
  776. end
  777. if go then
  778. local a = getThingPos(cid)
  779. doChangeSpeed(cid, -getCreatureSpeed(cid))
  780. if not isPlayer(target) then
  781. doChangeSpeed(target, -getCreatureSpeed(target))
  782. end
  783. doChangeSpeed(cid, 800)
  784. doTeleportThing(cid, getThingPos(target))
  785. doChangeSpeed(cid, -800)
  786. addEvent(doBodyPush, 350, cid, target, false, a)
  787. else
  788. doChangeSpeed(cid, 800)
  789. doTeleportThing(cid, pos)
  790. doRegainSpeed(cid)
  791. doRegainSpeed(target)
  792. end
  793. end
  794.  
  795. function doReturnPokemon(cid, pokemon, pokeball, effect, hideeffects, blockevo)
  796.  
  797. --////////////////////////////////////////////////////////////////////////////////////////--
  798. checkDuel(cid) --alterado v1.6 duel system
  799. --////////////////////////////////////////////////////////////////////////////////////////--
  800. if getPlayerStorageValue(cid, 52480) >= 1 and getPlayerStorageValue(cid, 52484) ~= 10 then
  801. return sendMsgToPlayer(cid, 27, "You can't do that while the duel don't begins!") --alterado v1.8
  802. end
  803. --////////////////////////////////////////////////////////////////////////////////////////--
  804.  
  805. if #getCreatureSummons(cid) > 1 and getPlayerStorageValue(cid, 212124) <= 0 then --alterado v1.6
  806. if getPlayerStorageValue(cid, 637501) == -2 or getPlayerStorageValue(cid, 637501) >= 1 then
  807. BackTeam(cid)
  808. end
  809. end
  810. -----------------
  811. local edit = true
  812.  
  813. if not pokeball then
  814. pokeball = getPlayerSlotItem(cid, 8)
  815. end
  816.  
  817. if blockevo then
  818. edit = false
  819. doPlayerSendCancel(cid, "Your pokemon couldn't evolve due to server mistakes, please wait until we fix the problem.")
  820. end
  821.  
  822. local happy = getPlayerStorageValue(pokemon, 1008)
  823. local hunger = getPlayerStorageValue(pokemon, 1009)
  824. local pokelife = (getCreatureHealth(pokemon) / getCreatureMaxHealth(pokemon))
  825.  
  826. if edit then
  827. doItemSetAttribute(pokeball.uid, "happy", happy)
  828. doItemSetAttribute(pokeball.uid, "hunger", hunger)
  829. doItemSetAttribute(pokeball.uid, "hp", pokelife)
  830. end
  831.  
  832. if getCreatureName(pokemon) == "Ditto" then
  833. if isTransformed(pokemon) then
  834. local left = getItemAttribute(pokeball.uid, "transLeft") - (os.clock() - getItemAttribute(pokeball.uid, "transBegin"))
  835. doItemSetAttribute(pokeball.uid, "transLeft", left)
  836. end
  837. end
  838.  
  839. if hideeffects then
  840. doRemoveCreature(pokemon)
  841. return true
  842. end
  843.  
  844. local pokename = getPokeName(pokemon)
  845.  
  846. local mbk = gobackmsgs[math.random(1, #gobackmsgs)].back:gsub("doka", pokename)
  847. local mbken = gobackmsgsen[math.random(1, #gobackmsgsen)].back:gsub("doka", pokename)
  848. local mbkes = gobackmsgses[math.random(1, #gobackmsgses)].back:gsub("doka", pokename)
  849.  
  850. if getCreatureCondition(cid, CONDITION_INFIGHT) then
  851. if isCreature(getCreatureTarget(cid)) then
  852. doItemSetAttribute(pokeball.uid, "happy", happy - 5)
  853. else
  854. doItemSetAttribute(pokeball.uid, "happy", happy - 2)
  855. end
  856. end
  857.  
  858. doTransformItem(pokeball.uid, pokeball.itemid-1)
  859. if getPlayerLanguage(cid) == 2 then
  860. doCreatureSay(cid, mbken, 19)
  861. doPlayerAddMana(cid, -getCreatureMana(cid))
  862. end
  863. if getPlayerLanguage(cid) == 0 then
  864. doCreatureSay(cid, mbk, 19)
  865. end
  866. if getPlayerLanguage(cid) == 1 then
  867. doCreatureSay(cid, mbkes, 19)
  868. end
  869.  
  870. doSendMagicEffect(getCreaturePosition(pokemon), effect)
  871.  
  872. doRemoveCreature(pokemon)
  873.  
  874. unLock(pokeball.uid) --alterado v1.8
  875.  
  876. if useOTClient then
  877. doPlayerSendCancel(cid, '12//,hide') --alterado v1.7
  878. end
  879.  
  880. if useKpdoDlls then
  881. doUpdateMoves(cid)
  882. end
  883.  
  884. end
  885.  
  886. local EFFECTS = {
  887. --[OutfitID] = {Effect}
  888. ["Magmar"] = 35, --alterado v1.5
  889. ["Jynx"] = 17,
  890. ["Shiny Jynx"] = 17,
  891. ["Piloswine"] = 205, --alterado v1.8
  892. ["Swinub"] = 205,
  893. }
  894.  
  895. function doGoPokemon(cid, item)
  896.  
  897. if getPlayerStorageValue(cid, 17000) >= 1 or getPlayerStorageValue(cid, 17001) >= 1 or getPlayerStorageValue(cid, 63215) >= 1 then
  898. return true
  899. end
  900. ---------------------------------------------------------------
  901. local ballName = getItemAttribute(item.uid, "poke")
  902.  
  903. btype = getPokeballType(item.itemid)
  904.  
  905. local effect = pokeballs[btype].effect
  906. if not effect then
  907. effect = 21
  908. end
  909. -----------------------------------------------------------------
  910. if item.uid ~= getPlayerSlotItem(cid, CONST_SLOT_FEET).uid then
  911. doPlayerSendCancel(cid, "You must put your pokeball in the correct place!")
  912. return TRUE
  913. end
  914.  
  915. local thishp = getItemAttribute(item.uid, "hp")
  916.  
  917. if thishp <= 0 then
  918. if isInArray(pokeballs[btype].all, item.itemid) then
  919. doTransformItem(item.uid, pokeballs[btype].off)
  920. doItemSetAttribute(item.uid, "hp", 0)
  921. doPlayerSendCancel(cid, "This pokemon is fainted.")
  922. return true
  923. end
  924. end
  925.  
  926. local pokemon = getItemAttribute(item.uid, "poke")
  927.  
  928. if not pokes[pokemon] then
  929. return true
  930. end
  931.  
  932. ----------------------- Sistema de nao poder carregar mais que 3 pokes lvl baixo e + q 1 poke de lvl medio/alto ---------------------------------
  933. if not isInArray({5, 6}, getPlayerGroupId(cid)) then
  934. local balls = getPokeballsInContainer(getPlayerSlotItem(cid, 3).uid) --alterado v1.9 \/
  935. local low = {}
  936. local lowPokes = {"Rattata", "Caterpie", "Weedle", "Oddish", "Pidgey", "Paras", "Poliwag", "Bellsprout", "Magikarp", "Hoppip", "Sunkern"}
  937. if #balls >= 1 then
  938. for _, uid in ipairs(balls) do
  939. local nome = getItemAttribute(uid, "poke")
  940. if not isInArray(lowPokes, pokemon) and nome == pokemon then
  941. return doPlayerSendTextMessage(cid, 27, "Sorry, but you can't carry two pokemons equals!")
  942. else
  943. if nome == pokemon then
  944. table.insert(low, nome)
  945. end
  946. end
  947. end
  948. end
  949. if #low >= 3 then
  950. return doPlayerSendTextMessage(cid, 27, "Sorry, but you can't carry more than three pokemons equals of low level!")
  951. end
  952. end
  953. ---------------------------------------------------------------------------------------------------------------------------------------------------
  954.  
  955. local x = pokes[pokemon]
  956. local boosts = getItemAttribute(item.uid, "boost") or 0
  957.  
  958. if getPlayerLevel(cid) < (x.level + boosts) then --alterado v1.8 \/
  959. doPlayerSendCancel(cid, "You need level "..(x.level + boosts).." to use this pokemon.")
  960. return true
  961. end
  962.  
  963. --------------------------------------------------------------------------------------
  964. shinysClan = {
  965. ["Shiny Fearow"] = {4, "Wingeon"},
  966. ["Shiny Flareon"] = {1, "Volcanic"},
  967. ["Shiny Vaporeon"] = {2, "Seavel"},
  968. ["Shiny Jolteon"] = {9, "Raibolt"},
  969. ["Shiny Hypno"] = {7, "Psycraft"},
  970. ["Shiny Golem"] = {3, "Orebound"},
  971. ["Shiny Vileplume"] = {8, "Naturia"},
  972. ["Shiny Nidoking"] = {5, "Malefic"},
  973. ["Shiny Hitmontop"] = {6, "Gardestrike"},
  974. }
  975.  
  976. if shinysClan[pokemon] and (getPlayerGroupId(cid) < 4 or getPlayerGroupId(cid) > 6) then --alterado v1.9
  977. if getPlayerStorageValue(cid, 86228) ~= shinysClan[pokemon][1] then
  978. doPlayerSendCancel(cid, "You need be a member of the clan "..shinysClan[pokemon][2].." to use this pokemon!")
  979. return true
  980. elseif getPlayerStorageValue(cid, 862281) ~= 5 then
  981. doPlayerSendCancel(cid, "You need be atleast rank 5 to use this pokemon!")
  982. return true
  983. end
  984. end
  985. --------------------------------------------------------------------------------------
  986.  
  987. doSummonMonster(cid, pokemon)
  988.  
  989. local pk = getCreatureSummons(cid)[1]
  990. if not isCreature(pk) then return true end
  991.  
  992. ------------------------passiva hitmonchan------------------------------
  993. if isSummon(pk) then --alterado v1.8 \/
  994. if pokemon == "Shiny Hitmonchan" or pokemon == "Hitmonchan" then
  995. if not getItemAttribute(item.uid, "hands") then
  996. doSetItemAttribute(item.uid, "hands", 0)
  997. end
  998. local hands = getItemAttribute(item.uid, "hands")
  999. doSetCreatureOutfit(pk, {lookType = hitmonchans[pokemon][hands].out}, -1)
  1000. end
  1001. end
  1002. -------------------------------------------------------------------------
  1003. ---------movement magmar, jynx-------------
  1004. if EFFECTS[getCreatureName(pk)] then
  1005. markPosEff(pk, getThingPos(pk))
  1006. sendMovementEffect(pk, EFFECTS[getCreatureName(pk)], getThingPos(pk))
  1007. end
  1008. --------------------------------------------------------------------------
  1009.  
  1010. if getCreatureName(pk) == "Ditto" then
  1011.  
  1012. local left = getItemAttribute(item.uid, "transLeft")
  1013. local name = getItemAttribute(item.uid, "transName")
  1014.  
  1015. if left and left > 0 then
  1016. setPlayerStorageValue(pk, 1010, name)
  1017. doSetCreatureOutfit(pk, {lookType = getItemAttribute(item.uid, "transOutfit")}, -1)
  1018. addEvent(deTransform, left * 1000, pk, getItemAttribute(item.uid, "transTurn"))
  1019. doItemSetAttribute(item.uid, "transBegin", os.clock())
  1020. else
  1021. setPlayerStorageValue(pk, 1010, "Ditto")
  1022. end
  1023. end
  1024.  
  1025. if isGhostPokemon(pk) then doTeleportThing(pk, getPosByDir(getThingPos(cid), math.random(0, 7)), false) end
  1026.  
  1027. doCreatureSetLookDir(pk, 2)
  1028.  
  1029. adjustStatus(pk, item.uid, true, true, true)
  1030. doAddPokemonInOwnList(cid, pokemon)
  1031.  
  1032. doTransformItem(item.uid, item.itemid+1)
  1033.  
  1034. local pokename = getPokeName(pk) --alterado v1.7
  1035.  
  1036. local mgo = gobackmsgs[math.random(1, #gobackmsgs)].go:gsub("doka", pokename)
  1037. doCreatureSay(cid, mgo, TALKTYPE_SAY)
  1038.  
  1039. doSendMagicEffect(getCreaturePosition(pk), effect)
  1040.  
  1041. unLock(item.uid) --alterado v1.8
  1042.  
  1043. if useKpdoDlls then
  1044. doUpdateMoves(cid)
  1045. end
  1046. end
  1047.  
  1048. function doRegainSpeed(cid) --alterado v2.9 \/
  1049. if not isCreature(cid) then return true end
  1050.  
  1051. local speed = PlayerSpeed
  1052. if isMonster(cid) then
  1053. speed = getCreatureBaseSpeed(cid)
  1054. elseif isPlayer(cid) and isInArray({4, 5, 6}, getPlayerGroupId(cid)) then
  1055. speed = 200*getPlayerGroupId(cid)
  1056. end
  1057. if speed > 1500 then speed = 1500 end
  1058.  
  1059. doChangeSpeed(cid, -getCreatureSpeed(cid))
  1060. if getCreatureCondition(cid, CONDITION_PARALYZE) == true then
  1061. doRemoveCondition(cid, CONDITION_PARALYZE)
  1062. addEvent(doAddCondition, 10, cid, paralizeArea2)
  1063. end
  1064.  
  1065. doChangeSpeed(cid, speed)
  1066. return speed
  1067. end
  1068.  
  1069. function doRegainSpeedLevel(cid)
  1070.  
  1071. local speed = 220
  1072. local spood = getCreatureSpeed(cid)
  1073. local level = getPlayerLevel(cid)
  1074.  
  1075. if isPlayer(cid) then
  1076. doChangeSpeed(cid, -spood)
  1077. doChangeSpeed(cid, speed + (level * 3))
  1078. setPlayerStorageValue(cid, 1242343, (speed + (level * 3)))
  1079. end
  1080. return true
  1081. end
  1082.  
  1083. function isPosEqualPos(pos1, pos2, checkstackpos)
  1084. if pos1.x ~= pos2.x or pos1.y ~= pos2.y and pos1.z ~= pos2.z then
  1085. return false
  1086. end
  1087. if checkstackpos and pos1.stackpos and pos2.stackpos and pos1.stackpos ~= pos2.stackpos then
  1088. return false
  1089. end
  1090. return true
  1091. end
  1092.  
  1093. function getRandomGenderByName(name)
  1094. local rate = newpokedex[name]
  1095. if not rate then return 0 end
  1096. rate = rate.gender
  1097. if rate == 0 then
  1098. gender = 3
  1099. elseif rate == 1000 then
  1100. gender = 4
  1101. elseif rate == -1 then
  1102. gender = 1
  1103. elseif math.random(1, 1000) <= rate then
  1104. gender = 4
  1105. else
  1106. gender = 3
  1107. end
  1108. return gender
  1109. end
  1110.  
  1111. function getRecorderPlayer(pos, cid)
  1112. local ret = 0
  1113. if cid and isPosEqual(getThingPos(cid), pos) then --alterado v1.9
  1114. return cid
  1115. end
  1116. local s = {}
  1117. s.x = pos.x
  1118. s.y = pos.y
  1119. s.z = pos.z
  1120. for a = 0, 255 do
  1121. s.stackpos = a
  1122. local b = getTileThingByPos(s).uid
  1123. if b > 1 and isPlayer(b) and getCreatureOutfit(b).lookType ~= 814 then
  1124. ret = b
  1125. end
  1126. end
  1127. return ret
  1128. end
  1129.  
  1130. function getRecorderCreature(pos, cid)
  1131. local ret = 0
  1132. if cid and isPosEqual(getThingPos(cid), pos) then --alterado v1.9
  1133. return cid
  1134. end
  1135. local s = {}
  1136. s.x = pos.x
  1137. s.y = pos.y
  1138. s.z = pos.z
  1139. for a = 0, 255 do
  1140. s.stackpos = a
  1141. local b = getTileThingByPos(s).uid
  1142. if b > 1 and isCreature(b) and getCreatureOutfit(b).lookType ~= 814 then
  1143. ret = b
  1144. end
  1145. end
  1146. return ret
  1147. end
  1148.  
  1149. function doCreatureSetOutfit(cid, outfit, time)
  1150. doSetCreatureOutfit(cid, outfit, time)
  1151. end
  1152.  
  1153. function doMagicalFlower(cid, away)
  1154. if not isCreature(cid) then return true end
  1155. for x = -3, 3 do
  1156. for y = -3, 3 do
  1157. local a = getThingPos(cid)
  1158. a.x = a.x + x
  1159. a.y = a.y + y
  1160. if away then
  1161. doSendDistanceShoot(a, getThingPos(cid), 21)
  1162. else
  1163. doSendDistanceShoot(getThingPos(cid), a, 21)
  1164. end
  1165. end
  1166. end
  1167. end
  1168.  
  1169. function isItemPokeball(item) --alterado v1.9 \/
  1170. if not item then return false end
  1171. for a, b in pairs (pokeballs) do
  1172. if isInArray(b.all, item) then return true end
  1173. end
  1174. return false
  1175. end
  1176.  
  1177. function isPokeball(item)
  1178. return isItemPokeball(item)
  1179. end --/\
  1180.  
  1181. function getPokeballType(id)
  1182. for a, b in pairs (pokeballs) do
  1183. if isInArray(b.all, id) then
  1184. return a
  1185. end
  1186. end
  1187. return "none"
  1188. end
  1189.  
  1190. randomdiagonaldir = {
  1191. [NORTHEAST] = {NORTH, EAST},
  1192. [SOUTHEAST] = {SOUTH, EAST},
  1193. [NORTHWEST] = {NORTH, WEST},
  1194. [SOUTHWEST] = {SOUTH, WEST}}
  1195.  
  1196. function doFaceOpposite(cid)
  1197. local a = getCreatureLookDir(cid)
  1198. local d = {
  1199. [NORTH] = SOUTH,
  1200. [SOUTH] = NORTH,
  1201. [EAST] = WEST,
  1202. [WEST] = EAST,
  1203. [NORTHEAST] = SOUTHWEST,
  1204. [NORTHWEST] = SOUTHEAST,
  1205. [SOUTHEAST] = NORTHWEST,
  1206. [SOUTHWEST] = NORTHEAST}
  1207. doCreatureSetLookDir(cid, d[a])
  1208. end
  1209.  
  1210. function doFaceRandom(cid)
  1211. local a = getCreatureLookDir(cid)
  1212. local d = {
  1213. [NORTH] = {SOUTH, WEST, EAST},
  1214. [SOUTH] = {NORTH, WEST, EAST},
  1215. [WEST] = {SOUTH, NORTH, EAST},
  1216. [EAST] = {SOUTH, WEST, NORTH}}
  1217. doChangeSpeed(cid, 1)
  1218. doCreatureSetLookDir(cid, d[a][math.random(1, 3)])
  1219. doChangeSpeed(cid, -1)
  1220. end
  1221.  
  1222. function getFaceOpposite(dir)
  1223. local d = {
  1224. [NORTH] = SOUTH,
  1225. [SOUTH] = NORTH,
  1226. [EAST] = WEST,
  1227. [WEST] = EAST,
  1228. [NORTHEAST] = SOUTHWEST,
  1229. [NORTHWEST] = SOUTHEAST,
  1230. [SOUTHEAST] = NORTHWEST,
  1231. [SOUTHWEST] = NORTHEAST}
  1232. return d[dir]
  1233. end
  1234.  
  1235. function getResistance(cid, combat)
  1236. if isPlayer(cid) then return false end
  1237. local poketype1 = pokes[getCreatureName(cid)].type
  1238. local poketype2 = pokes[getCreatureName(cid)].type2
  1239. local multiplier = 1
  1240. if effectiveness[combat].super and isInArray(effectiveness[combat].super, poketype1) then
  1241. multiplier = multiplier * 2
  1242. end
  1243. if poketype2 and effectiveness[combat].super and isInArray(effectiveness[combat].super, poketype2) then
  1244. multiplier = multiplier * 2
  1245. end
  1246. if effectiveness[combat].weak and isInArray(effectiveness[combat].weak, poketype1) then
  1247. multiplier = multiplier * 0.5
  1248. end
  1249. if poketype2 and effectiveness[combat].weak and isInArray(effectiveness[combat].weak, poketype2) then
  1250. multiplier = multiplier * 0.5
  1251. end
  1252. if effectiveness[combat].non and isInArray(effectiveness[combat].non, poketype1) then
  1253. multiplier = multiplier * 0
  1254. end
  1255. if poketype2 and effectiveness[combat].non and isInArray(effectiveness[combat].non, poketype2) then
  1256. multiplier = multiplier * 0
  1257. end
  1258.  
  1259. if multiplier == 0.25 then
  1260. multiplier = 0.5
  1261. elseif multiplier == 4 then
  1262. multiplier = 2
  1263. end
  1264.  
  1265. return multiplier
  1266. end
  1267.  
  1268. function getCreatureDirectionToTarget(cid, target, ranged)
  1269. if not isCreature(cid) then return true end
  1270. if not isCreature(target) then return getCreatureLookDir(cid) end
  1271. local dirs = {
  1272. [NORTHEAST] = {NORTH, EAST},
  1273. [SOUTHEAST] = {SOUTH, EAST},
  1274. [NORTHWEST] = {NORTH, WEST},
  1275. [SOUTHWEST] = {SOUTH, WEST}}
  1276. local x = getDirectionTo(getThingPos(cid), getThingPos(target), false)
  1277. if x <= 3 then return x
  1278. else
  1279. local xdistance = math.abs(getThingPos(cid).x - getThingPos(target).x)
  1280. local ydistance = math.abs(getThingPos(cid).y - getThingPos(target).y)
  1281. if xdistance > ydistance then
  1282. return dirs[x][2]
  1283. elseif ydistance > xdistance then
  1284. return dirs[x][1]
  1285. elseif isInArray(dirs[x], getCreatureLookDir(cid)) then
  1286. return getCreatureLookDir(cid)
  1287. else
  1288. return dirs[x][math.random(1, 2)]
  1289. end
  1290. end
  1291. end
  1292.  
  1293. function getSomeoneDescription(cid)
  1294. if isPlayer(cid) then return getPlayerNameDescription(cid) end
  1295. return getMonsterInfo(getCreatureName(cid)).description
  1296. end
  1297.  
  1298.  
  1299. function isGhostPokemon(cid)
  1300. if not isCreature(cid) then return false end
  1301. local ghosts = {"Gastly", "Haunter", "Gengar", "Shiny Gengar", "Misdreavus", "Shiny Abra"}
  1302. return isInArray(ghosts, getCreatureName(cid))
  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 v1.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 v1.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 v1.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 v1.9
  1549. end
  1550.  
  1551. function isSummon(sid)
  1552. return isCreature(sid) and getCreatureMaster(sid) ~= sid and isPlayer(getCreatureMaster(sid)) --alterado v1.9
  1553. end
  1554.  
  1555. function getItemsInContainerById(container, itemid) -- Function By Kydrai
  1556. local items = {}
  1557. if isContainer(container) and getContainerSize(container) > 0 then
  1558. for slot=0, (getContainerSize(container)-1) do
  1559. local item = getContainerItem(container, slot)
  1560. if isContainer(item.uid) then
  1561. local itemsbag = getItemsInContainerById(item.uid, itemid)
  1562. for i=0, #itemsbag do
  1563. table.insert(items, itemsbag[i])
  1564. end
  1565. else
  1566. if itemid == item.itemid then
  1567. table.insert(items, item.uid)
  1568. end
  1569. end
  1570. end
  1571. end
  1572. return items
  1573. end
  1574.  
  1575. function getPokeballsInContainer(container) -- Function By Kydrai
  1576. if not isContainer(container) then return {} end
  1577. local items = {}
  1578. if isContainer(container) and getContainerSize(container) > 0 then
  1579. for slot=0, (getContainerSize(container)-1) do
  1580. local item = getContainerItem(container, slot)
  1581. if isContainer(item.uid) then
  1582. local itemsbag = getPokeballsInContainer(item.uid)
  1583. for i=0, #itemsbag do
  1584. table.insert(items, itemsbag[i])
  1585. end
  1586. elseif isPokeball(item.itemid) then
  1587. table.insert(items, item.uid)
  1588. end
  1589. end
  1590. end
  1591. return items
  1592. end
  1593.  
  1594. function getItensUniquesInContainer(container) --alterado v1.6
  1595. if not isContainer(container) then return {} end
  1596. local items = {}
  1597. if isContainer(container) and getContainerSize(container) > 0 then
  1598. for slot=0, (getContainerSize(container)-1) do
  1599. local item = getContainerItem(container, slot)
  1600. if isContainer(item.uid) then
  1601. local itemsbag = getItensUniquesInContainer(item.uid)
  1602. for i=0, #itemsbag do
  1603. table.insert(items, itemsbag[i])
  1604. end
  1605. elseif getItemAttribute(item.uid, "unique") then
  1606. table.insert(items, item)
  1607. end
  1608. end
  1609. end
  1610. return items
  1611. end
  1612. function isInHouse(cid)
  1613. if getTileHouseInfo(getThingPos(cid)) then
  1614. return true
  1615. else
  1616. return false
  1617. end
  1618. end
  1619.  
  1620. function isHouseTile(item)
  1621. local houseTilesId = {11674,414,405,424,1284,406,11667,458,14418,14420,14422,14424,14426,14428,14430,14432,14434,14436,14438,14440,14442,14444,14446}
  1622. if isInArray(houseTilesId, item) then
  1623. return true
  1624. else
  1625. return false
  1626. end
  1627. return true
  1628. end
  1629.  
  1630. function hasSpaceInContainer(container) --alterado v1.6
  1631. if not isContainer(container) then return false end
  1632. if getContainerSize(container) < getContainerCap(container) then return true end
  1633.  
  1634. for slot = 0, (getContainerSize(container)-1) do
  1635. local item = getContainerItem(container, slot)
  1636. if isContainer(item.uid) then
  1637. if hasSpaceInContainer(item.uid) then
  1638. return true
  1639. end
  1640. end
  1641. end
  1642. return false
  1643. end
  1644.  
  1645. function doPlayerAddItemStacking(cid, itemid, quant) -- by mkalo
  1646. local item = getItemsInContainerById(getPlayerSlotItem(cid, 3).uid, itemid)
  1647. local piles = 0
  1648. if #item > 0 then
  1649. for i,x in pairs(item) do
  1650. if getThing(x).type < 100 then
  1651. local it = getThing(x)
  1652. doTransformItem(it.uid, itemid, it.type+quant)
  1653. if it.type+quant > 100 then
  1654. doPlayerAddItem(cid, itemid, it.type+quant-100)
  1655. end
  1656. else
  1657. piles = piles+1
  1658. end
  1659. end
  1660. else
  1661. return doPlayerAddItem(cid, itemid, quant)
  1662. end
  1663. if piles == #item then
  1664. doPlayerAddItem(cid, itemid, quant)
  1665. end
  1666. end
  1667.  
  1668. function sendAllPokemonsBarPoke(cid)
  1669. local container = getPlayerSlotItem(cid, 3).uid
  1670. local pokes = "Pokebar"
  1671. local t = getPlayerSlotItem(cid, 8)
  1672. if t.uid ~= 0 then
  1673. pokeslot = getItemAttribute(t.uid, "poke")
  1674. pokes = pokes.."/"..pokeslot..""
  1675. end
  1676. local pokeballs = getPokeballsInContainer(container)
  1677. for i =1, #pokeballs do
  1678. pokemons = getItemAttribute(pokeballs[i], "poke")
  1679. pokes = pokes.."/"..pokemons..""
  1680. end
  1681. doPlayerSendCancel(cid, pokes)
  1682. end
  1683.  
  1684.  
  1685. function getPlayerLanguage(cid) -- By Acubens
  1686. local Lang = db.getResult("SELECT `language` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
  1687. if Lang:getID() ~= LUA_ERROR then
  1688. local langid = Lang:getDataInt("language")
  1689. Lang:free()
  1690. return langid
  1691. end
  1692. return LUA_ERROR
  1693. end
  1694.  
  1695. function doPlayerSetLanguage(cid, new) -- By Drazyn1291
  1696. local acc = getPlayerAccountId(cid)
  1697. if new == 2 then
  1698. db.executeQuery("UPDATE `accounts` SET language = 2 WHERE `id` = " .. acc)
  1699. elseif new == 1 then
  1700. db.executeQuery("UPDATE `accounts` SET language = 1 WHERE `id` = " .. acc)
  1701. else
  1702. db.executeQuery("UPDATE `accounts` SET language = 0 WHERE `id` = " .. acc)
  1703. end
  1704. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement