Advertisement
Guest User

Untitled

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