Guest User

Untitled

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