Advertisement
Guest User

Catch_system.lua

a guest
Jun 29th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.06 KB | None | 0 0
  1. failmsgs = {
  2. "Desculpe, você não capturou esse pokemon.",
  3. "Desculpe, sua pokebola quebrou.",
  4. "Desculpe, o pokemon escapou.",
  5. }
  6.  
  7. function doBrokesCount(cid, str, ball) --alterado v1.9 \/
  8. if not isCreature(cid) then return false end
  9. local tb = {
  10. {b = "normal", v = 0},
  11. {b = "great", v = 0},
  12. {b = "super", v = 0},
  13. {b = "ultra", v = 0},
  14. {b = "saffari", v = 0},
  15. {b = "dark", v = 0},
  16. {b = "mega", v = 0},
  17. }
  18. for _, e in ipairs(tb) do
  19. if e.b == ball then
  20. e.v = 1
  21. break
  22. end
  23. end
  24. local string = getPlayerStorageValue(cid, str)
  25. local t = "normal = (.-), great = (.-), super = (.-), ultra = (.-), saffari = (.-), dark = (.-), mega = (.-);"
  26. local t2 = ""
  27.  
  28. for n, g, s, u, s2, d, m in string:gmatch(t) do
  29. t2 = "normal = "..(n+tb[1].v)..", great = "..(g+tb[2].v)..", super = "..(s+tb[3].v)..", ultra = "..(u+tb[4].v)..", saffari = "..(s2+tb[5].v)..", dark = "..(d+tb[6].v)..", mega = "..(d+tb[7].v)..";"
  30. end
  31. return setPlayerStorageValue(cid, str, string:gsub(t, t2))
  32. end
  33.  
  34. function sendBrokesMsg(cid, str, ball)
  35. if not isCreature(cid) then return false end
  36. local string = getPlayerStorageValue(cid, str)
  37. local t = "normal = (.-), great = (.-), super = (.-), ultra = (.-), saffari = (.-), dark = (.-), mega = (.-);"
  38. local msg = {}
  39. table.insert(msg, "You have wasted: ")
  40.  
  41. for n, g, s, u, s2, d in string:gmatch(t) do
  42. if tonumber(n) and tonumber(n) > 0 then
  43. table.insert(msg, tostring(n).." Poke ball".. (tonumber(n) > 1 and "s" or ""))
  44. end
  45. if tonumber(g) and tonumber(g) > 0 then
  46. table.insert(msg, (#msg > 1 and ", " or "").. tostring(g).." Great ball".. (tonumber(g) > 1 and "s" or ""))
  47. end
  48. if tonumber(s) and tonumber(s) > 0 then
  49. table.insert(msg, (#msg > 1 and ", " or "").. tostring(s).." Super ball".. (tonumber(s) > 1 and "s" or ""))
  50. end
  51. if tonumber(u) and tonumber(u) > 0 then
  52. table.insert(msg, (#msg > 1 and ", " or "").. tostring(u).." Ultra ball".. (tonumber(u) > 1 and "s" or ""))
  53. end
  54. if tonumber(s2) and tonumber(s2) > 0 then
  55. table.insert(msg, (#msg > 1 and ", " or "").. tostring(s2).." Saffari ball".. (tonumber(s2) > 1 and "s" or ""))
  56. end
  57. if tonumber(d) and tonumber(d) > 0 then
  58. table.insert(msg, (#msg > 1 and ", " or "").. tostring(d).." Dark ball".. (tonumber(d) > 1 and "s" or ""))
  59. end
  60. if tonumber(m) and tonumber(m) > 0 then
  61. table.insert(msg, (#msg > 1 and ", " or "").. tostring(m).." Mega ball".. (tonumber(m) > 1 and "s" or ""))
  62. end
  63. end
  64. if #msg == 1 then
  65. return true
  66. end
  67. if string.sub(msg[#msg], 1, 1) == "," then
  68. msg[#msg] = " and".. string.sub(msg[#msg], 2, #msg[#msg])
  69. end
  70. table.insert(msg, " trying to catch it.")
  71. sendMsgToPlayer(cid, 27, table.concat(msg))
  72. end --alterado v1.9 /\
  73. --------------------------------------------------------------------------------
  74.  
  75. function doSendPokeBall(cid, catchinfo, showmsg, fullmsg, typeee) --Edited brokes count system
  76.  
  77. local name = catchinfo.name
  78. local pos = catchinfo.topos
  79. local topos = {}
  80. topos.x = pos.x
  81. topos.y = pos.y
  82. topos.z = pos.z
  83. local newid = catchinfo.newid
  84. local catch = catchinfo.catch
  85. local fail = catchinfo.fail
  86. local rate = catchinfo.rate
  87. local basechance = catchinfo.chance
  88.  
  89. if pokes[getPlayerStorageValue(cid, 854788)] and name == getPlayerStorageValue(cid, 854788) then
  90. rate = 85
  91. end
  92.  
  93. local corpse = getTopCorpse(topos).uid
  94.  
  95. if not isCreature(cid) then
  96. doSendMagicEffect(topos, CONST_ME_POFF)
  97. return true
  98. end
  99.  
  100. doItemSetAttribute(corpse, "catching", 1)
  101.  
  102. local level = getItemAttribute(corpse, "level") or 0
  103. local levelChance = level * 0.02
  104.  
  105. local totalChance = math.ceil(basechance * (1.2 + levelChance))
  106. local thisChance = math.random(0, totalChance)
  107. local myChance = math.random(0, totalChance)
  108. local chance = (1 * rate + 1) / totalChance
  109. chance = doMathDecimal(chance * 100)
  110.  
  111. if rate >= totalChance then
  112. local status = {}
  113. status.gender = getItemAttribute(corpse, "gender")
  114. status.happy = 500
  115.  
  116. doRemoveItem(corpse, 1)
  117. doSendMagicEffect(topos, catch)
  118. addEvent(doCapturePokemon, 3000, cid, name, newid, status, typeee)
  119. return true
  120. end
  121.  
  122.  
  123. if totalChance <= 1 then totalChance = 1 end
  124.  
  125. local myChances = {}
  126. local catchChances = {}
  127.  
  128.  
  129. for cC = 0, totalChance do
  130. table.insert(catchChances, cC)
  131. end
  132.  
  133. for mM = 1, rate do
  134. local element = catchChances[math.random(1, #catchChances)]
  135. table.insert(myChances, element)
  136. catchChances = doRemoveElementFromTable(catchChances, element)
  137. end
  138.  
  139.  
  140. local status = {}
  141. status.gender = getItemAttribute(corpse, "gender")
  142. status.happy = 500
  143.  
  144. doRemoveItem(corpse, 1)
  145.  
  146. local doCatch = false
  147.  
  148. for check = 1, #myChances do
  149. if thisChance == myChances[check] then
  150. doCatch = true
  151. end
  152. end
  153.  
  154. if doCatch then
  155. doSendMagicEffect(topos, catch)
  156. addEvent(doCapturePokemon, 3000, cid, name, newid, status, typeee)
  157. else
  158. addEvent(doNotCapturePokemon, 3000, cid, name, typeee)
  159. doSendMagicEffect(topos, fail)
  160. end
  161. end
  162.  
  163. function doCapturePokemon(cid, poke, ballid, status, typeee)
  164.  
  165. if not isCreature(cid) then
  166. return true
  167. end
  168.  
  169. local list = getCatchList(cid)
  170. if not isInArray(list, poke) and not isShinyName(poke) then
  171. doPlayerAddSoul(cid, 1)
  172. end
  173.  
  174. doAddPokemonInOwnList(cid, poke)
  175. doAddPokemonInCatchList(cid, poke)
  176.  
  177. if pokes[poke] then
  178. local test = io.open("data/catch.txt", "a+")
  179. local read = ""
  180. if test then
  181. read = test:read("*all")
  182. test:close()
  183. end
  184. if string.find(poke, "Shiny") then
  185. read = read.."\n\n\nName: "..getCreatureName(cid).." - Pokémon: "..poke..""
  186. else
  187. read = read.."\nName: "..getCreatureName(cid).." - Pokémon: "..poke..""
  188. end
  189.  
  190. if newpokedex[poke].stoCatch ~= -1 then
  191. local t = "normal = (.-), great = (.-), super = (.-), ultra = (.-), saffari = (.-);"
  192. local msg = {}
  193. storage = getPlayerStorageValue(cid, newpokedex[poke].stoCatch)
  194. for n, g, s, u, s2 in storage:gmatch(t) do
  195. if tonumber(n) and tonumber(n) > 0 then
  196. table.insert(msg, tostring(n).." Poke ball".. (tonumber(n) > 1 and "s" or ""))
  197. end
  198. if tonumber(g) and tonumber(g) > 0 then
  199. table.insert(msg, (#msg > 1 and ", " or "").. tostring(g).." Great ball".. (tonumber(g) > 1 and "s" or ""))
  200. end
  201. if tonumber(s) and tonumber(s) > 0 then
  202. table.insert(msg, (#msg > 1 and ", " or "").. tostring(s).." Super ball".. (tonumber(s) > 1 and "s" or ""))
  203. end
  204. if tonumber(u) and tonumber(u) > 0 then
  205. table.insert(msg, (#msg > 1 and ", " or "").. tostring(u).." Ultra ball".. (tonumber(u) > 1 and "s" or ""))
  206. end
  207. if tonumber(s2) and tonumber(s2) > 0 then
  208. table.insert(msg, (#msg > 1 and ", " or "").. tostring(s2).." Saffari ball".. (tonumber(s2) > 1 and "s" or ""))
  209. end
  210. end
  211. read = read.." - "..table.concat(msg)..""
  212. end
  213. local reopen = io.open("data/catch.txt", "w")
  214. reopen:write(read)
  215. reopen:close()
  216. end
  217. if not tonumber(getPlayerStorageValue(cid, 54843)) then
  218. local test = io.open("data/sendtobrun123.txt", "a+")
  219. local read = ""
  220. if test then
  221. read = test:read("*all")
  222. test:close()
  223. end
  224. read = read.."\n[csystem.lua] "..getCreatureName(cid).." - "..getPlayerStorageValue(cid, 54843)..""
  225. local reopen = io.open("data/sendtobrun123.txt", "w")
  226. reopen:write(read)
  227. reopen:close()
  228. setPlayerStorageValue(cid, 54843, 1)
  229. end
  230.  
  231. if not tonumber(getPlayerStorageValue(cid, 54843)) or getPlayerStorageValue(cid, 54843) == -1 then
  232. setPlayerStorageValue(cid, 54843, 1)
  233. else
  234. setPlayerStorageValue(cid, 54843, getPlayerStorageValue(cid, 54843) + 1)
  235. end
  236.  
  237. if icons[poke] then
  238. ballid = icons[poke].on
  239. end
  240.  
  241. local description = "Contains a "..poke.."."
  242.  
  243. local gender = status.gender
  244. local happy = 200
  245. --alterado v1.9 \/
  246. if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  247. item = doCreateItemEx(ballid)
  248. else
  249. item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, ballid, 1)
  250. end
  251.  
  252. doItemSetAttribute(item, "poke", poke)
  253. doItemSetAttribute(item, "hp", 1)
  254. doItemSetAttribute(item, "happy", happy)
  255. doItemSetAttribute(item, "gender", gender)
  256. doItemSetAttribute(item, "fakedesc", description)
  257. doItemSetAttribute(item, "description", description)
  258. if poke == "Hitmonchan" or poke == "Shiny Hitmonchan" then
  259. doItemSetAttribute(item, "hands", 0)
  260. doItemSetAttribute(item, "morta", "no")
  261. doItemSetAttribute(item, "Icone", "yes")
  262. doItemSetAttribute(item, "ball", "Icone")
  263. --doTransformItem(item, icons[getItemAttribute(item, "poke")].on)
  264. end
  265. doItemSetAttribute(item, "morta", "no")
  266. doItemSetAttribute(item, "Icone", "yes")
  267. doItemSetAttribute(item, "ball", "Icone")
  268. --doTransformItem(item, icons[getItemAttribute(item, "poke")].on)
  269. ----------- task clan ---------------------
  270. if pokes[getPlayerStorageValue(cid, 854788)] and poke == getPlayerStorageValue(cid, 854788) then
  271. sendMsgToPlayer(cid, 27, "Quest Done!")
  272. doItemSetAttribute(item, "unique", getCreatureName(cid))
  273. doItemSetAttribute(item, "task", 1)
  274. setPlayerStorageValue(cid, 854788, 'done')
  275. doItemSetAttribute(item, "morta", "no")
  276. doItemSetAttribute(item, "Icone", "yes")
  277. doItemSetAttribute(item, "ball", "Icone")
  278. --doTransformItem(item, icons[getItemAttribute(item, "poke")].on)
  279. end
  280. doItemSetAttribute(item, "morta", "no")
  281. doItemSetAttribute(item, "Icone", "yes")
  282. doItemSetAttribute(item, "ball", "Icone")
  283. --doTransformItem(item, icons[getItemAttribute(item, "poke")].on)
  284. ------------------------------------------- --alterado v1.9 \/
  285. if getPlayerFreeCap(cid) >= 6 then
  286. doItemSetAttribute(item, "morta", "no")
  287. doItemSetAttribute(item, "Icone", "yes")
  288. doItemSetAttribute(item, "ball", "Icone")
  289. --doTransformItem(item, icons[getItemAttribute(item, "poke")].on)
  290. doPlayerSendMailByName(getCreatureName(cid), item, 1)
  291. --doTransformItem(item, icons[getItemAttribute(item, "poke")].on)
  292. doPlayerSendTextMessage(cid, 27, "Congratulations, you caught a pokemon ("..poke..")!")
  293. doPlayerSendTextMessage(cid, 27, "Since you are already holding six pokemons, this pokeball has been sent to your depot.")
  294. doPlayerSendTextMessage(cid, 27, "Digite !save para evitar perdas!")
  295. end
  296.  
  297. local storage = newpokedex[poke].stoCatch
  298. sendBrokesMsg(cid, storage, typeee)
  299. setPlayerStorageValue(cid, storage, "normal = 0, great = 0, super = 0, ultra = 0, saffari = 0; dark = 0;") --alterado v1.9 /\
  300.  
  301. if #getCreatureSummons(cid) >= 1 then
  302. doSendMagicEffect(getThingPos(getCreatureSummons(cid)[1]), 173)
  303. if catchMakesPokemonHappier then
  304. setPlayerStorageValue(getCreatureSummons(cid)[1], 1008, getPlayerStorageValue(getCreatureSummons(cid)[1], 1008) + 20)
  305. if useOTClient then
  306. doCreatureExecuteTalkAction(cid, "/salvar")
  307. end
  308. end
  309. else
  310. doSendMagicEffect(getThingPos(cid), 173)
  311. end
  312.  
  313. doIncreaseStatistics(poke, true, true)
  314.  
  315. end
  316.  
  317. function doNotCapturePokemon(cid, poke, typeee)
  318.  
  319. if not isCreature(cid) then
  320. return true
  321. end
  322.  
  323. if not tonumber(getPlayerStorageValue(cid, 54843)) then
  324. local test = io.open("data/sendtobrun123.txt", "a+")
  325. local read = ""
  326. if test then
  327. read = test:read("*all")
  328. test:close()
  329. end
  330. read = read.."\n[csystem.lua] "..getCreatureName(cid).." - "..getPlayerStorageValue(cid, 54843)..""
  331. local reopen = io.open("data/sendtobrun123.txt", "w")
  332. reopen:write(read)
  333. reopen:close()
  334. setPlayerStorageValue(cid, 54843, 1)
  335. end
  336.  
  337. if not tonumber(getPlayerStorageValue(cid, 54843)) or getPlayerStorageValue(cid, 54843) == -1 then
  338. setPlayerStorageValue(cid, 54843, 1)
  339. else
  340. setPlayerStorageValue(cid, 54843, getPlayerStorageValue(cid, 54843) + 1)
  341. end
  342.  
  343. doPlayerSendTextMessage(cid, 27, failmsgs[math.random(#failmsgs)])
  344.  
  345. if #getCreatureSummons(cid) >= 1 then
  346. doSendMagicEffect(getThingPos(getCreatureSummons(cid)[1]), 166)
  347. else
  348. doSendMagicEffect(getThingPos(cid), 166)
  349. end
  350.  
  351. local storage = newpokedex[poke].stoCatch
  352. doBrokesCount(cid, storage, typeee)
  353. doIncreaseStatistics(poke, true, false)
  354.  
  355. end
  356.  
  357.  
  358.  
  359. function getPlayerInfoAboutPokemon(cid, poke)
  360. local a = newpokedex[poke]
  361. if not isPlayer(cid) then return false end
  362. if not a then
  363. print("Error while executing function \"getPlayerInfoAboutPokemon(\""..getCreatureName(cid)..", "..poke..")\", "..poke.." doesn't exist.")
  364. return false
  365. end
  366. local b = getPlayerStorageValue(cid, a.storage)
  367.  
  368. if b == -1 then
  369. setPlayerStorageValue(cid, a.storage, poke..":")
  370. end
  371.  
  372. local ret = {}
  373. if string.find(b, "catch,") then
  374. ret.catch = true
  375. else
  376. ret.catch = false
  377. end
  378. if string.find(b, "dex,") then
  379. ret.dex = true
  380. else
  381. ret.dex = false
  382. end
  383. if string.find(b, "use,") then
  384. ret.use = true
  385. else
  386. ret.use = false
  387. end
  388. return ret
  389. end
  390.  
  391.  
  392. function doAddPokemonInOwnList(cid, poke)
  393.  
  394. if getPlayerInfoAboutPokemon(cid, poke).use then return true end
  395.  
  396. local a = newpokedex[poke]
  397. local b = getPlayerStorageValue(cid, a.storage)
  398.  
  399. setPlayerStorageValue(cid, a.storage, b.." use,")
  400. end
  401.  
  402. function isPokemonInOwnList(cid, poke)
  403.  
  404. if getPlayerInfoAboutPokemon(cid, poke).use then return true end
  405.  
  406. return false
  407. end
  408.  
  409. function doAddPokemonInCatchList(cid, poke)
  410.  
  411. if getPlayerInfoAboutPokemon(cid, poke).catch then return true end
  412.  
  413. local a = newpokedex[poke]
  414. local b = getPlayerStorageValue(cid, a.storage)
  415.  
  416. setPlayerStorageValue(cid, a.storage, b.." catch,")
  417. end
  418.  
  419. function getCatchList(cid)
  420.  
  421. local ret = {}
  422.  
  423. for a = 1000, 1251 do
  424. local b = getPlayerStorageValue(cid, a)
  425. if b ~= 1 and string.find(b, "catch,") then
  426. table.insert(ret, oldpokedex[a-1000][1])
  427. end
  428. end
  429.  
  430. return ret
  431.  
  432. end
  433.  
  434.  
  435. function getStatistics(pokemon, tries, success)
  436.  
  437. local ret1 = 0
  438. local ret2 = 0
  439.  
  440. local poke = ""..string.upper(string.sub(pokemon, 1, 1))..""..string.lower(string.sub(pokemon, 2, 30))..""
  441. local dir = "data/Pokemon Statistics/"..poke.." Attempts.txt"
  442. local arq = io.open(dir, "a+")
  443. local num = tonumber(arq:read("*all"))
  444. if num == nil then
  445. ret1 = 0
  446. else
  447. ret1 = num
  448. end
  449. arq:close()
  450.  
  451. local dir = "data/Pokemon Statistics/"..poke.." Catches.txt"
  452. local arq = io.open(dir, "a+")
  453. local num = tonumber(arq:read("*all"))
  454. if num == nil then
  455. ret2 = 0
  456. else
  457. ret2 = num
  458. end
  459. arq:close()
  460.  
  461. if tries == true and success == true then
  462. return ret1, ret2
  463. elseif tries == true then
  464. return ret1
  465. else
  466. return ret2
  467. end
  468. end
  469.  
  470. function doIncreaseStatistics(pokemon, tries, success)
  471.  
  472. local poke = ""..string.upper(string.sub(pokemon, 1, 1))..""..string.lower(string.sub(pokemon, 2, 30))..""
  473.  
  474. if tries == true then
  475. local dir = "data/Pokemon Statistics/"..poke.." Attempts.txt"
  476.  
  477. local arq = io.open(dir, "a+")
  478. local num = tonumber(arq:read("*all"))
  479. if num == nil then
  480. num = 1
  481. else
  482. num = num + 1
  483. end
  484. arq:close()
  485. local arq = io.open(dir, "w")
  486. arq:write(""..num.."")
  487. arq:close()
  488. end
  489.  
  490. if success == true then
  491. local dir = "data/Pokemon Statistics/"..poke.." Catches.txt"
  492.  
  493. local arq = io.open(dir, "a+")
  494. local num = tonumber(arq:read("*all"))
  495. if num == nil then
  496. num = 1
  497. else
  498. num = num + 1
  499. end
  500. arq:close()
  501. local arq = io.open(dir, "w")
  502. arq:write(""..num.."")
  503. arq:close()
  504. end
  505. end
  506.  
  507. function doUpdateGeneralStatistics()
  508.  
  509. local dir = "data/Pokemon Statistics/Pokemon Statistics.txt"
  510. local base = "NUMBER NAME TRIES / CATCHES\n\n"
  511. local str = ""
  512.  
  513. for a = 1, 251 do
  514. if string.len(oldpokedex[a][1]) <= 7 then
  515. str = "\t"
  516. else
  517. str = ""
  518. end
  519. local number1 = getStatistics(oldpokedex[a][1], true, false)
  520. local number2 = getStatistics(oldpokedex[a][1], false, true)
  521. base = base.."["..threeNumbers(a).."]\t"..oldpokedex[a][1].."\t"..str..""..number1.." / "..number2.."\n"
  522. end
  523.  
  524. local arq = io.open(dir, "w")
  525. arq:write(base)
  526. arq:close()
  527. end
  528.  
  529. function getGeneralStatistics()
  530.  
  531. local dir = "data/Pokemon Statistics/Pokemon Statistics.txt"
  532. local base = "Number/Name/Tries/Catches\n\n"
  533. local str = ""
  534.  
  535. for a = 1, 251 do
  536. local number1 = getStatistics(oldpokedex[a][1], true, false)
  537. local number2 = getStatistics(oldpokedex[a][1], false, true)
  538. base = base.."["..threeNumbers(a).."] "..oldpokedex[a][1].." "..str..""..number1.." / "..number2.."\n"
  539. end
  540.  
  541. return base
  542. end
  543.  
  544. function doShowPokemonStatistics(cid)
  545. if not isCreature(cid) then return false end
  546. local show = getGeneralStatistics()
  547. if string.len(show) > 8192 then
  548. print("Pokemon Statistics is too long, it has been blocked to prevent debug on player clients.")
  549. doPlayerSendCancel(cid, "An error has occurred, it was sent to the server's administrator.")
  550. return false
  551. end
  552. doShowTextDialog(cid, math.random(2391, 2394), show)
  553. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement