Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.31 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.         doPlayerSendCancel(cid, "#catch,"..fotos[i]..","..i..","..getPlayerStorageValue(cid, storage))
  65. end                                                             --alterado v1.9 /\
  66. --------------------------------------------------------------------------------
  67.  
  68. function doSendPokeBall(cid, catchinfo, showmsg, fullmsg, typeee) --Edited brokes count system
  69.  
  70.     local name = catchinfo.name
  71.     local pos = catchinfo.topos
  72.     local topos = {}
  73.         topos.x = pos.x
  74.         topos.y = pos.y
  75.         topos.z = pos.z
  76.     local newid = catchinfo.newid
  77.     local catch = catchinfo.catch
  78.     local fail = catchinfo.fail
  79.     local rate = catchinfo.rate
  80.     local basechance = catchinfo.chance
  81.    
  82.     if pokes[getPlayerStorageValue(cid, 854788)] and name == getPlayerStorageValue(cid, 854788) then
  83.        rate = 15
  84.     end
  85.  
  86.     local corpse = getTopCorpse(topos).uid
  87.  
  88.     if not isCreature(cid) then
  89.         doSendMagicEffect(topos, CONST_ME_POFF)
  90.     return true
  91.     end
  92.  
  93.     doItemSetAttribute(corpse, "catching", 1)
  94.  
  95.     local levelChance = getItemAttribute(corpse, "level") * 0.02
  96.  
  97.     local totalChance = math.ceil(basechance * (1.2 + levelChance))
  98.     local thisChance = math.random(0, totalChance)
  99.     local myChance = math.random(0, totalChance)
  100.     local chance = (1 * rate + 1) / totalChance
  101.         chance = doMathDecimal(chance * 100)
  102.  
  103.     if rate >= totalChance then
  104.         local status = {}
  105.               status.gender = getItemAttribute(corpse, "gender")
  106.               status.happy = 160
  107.  
  108.         doRemoveItem(corpse, 1)
  109.         doSendMagicEffect(topos, catch)
  110.         addEvent(doCapturePokemon, 3000, cid, name, newid, status, typeee)  
  111.     return true
  112.     end
  113.  
  114.  
  115.     if totalChance <= 1 then totalChance = 1 end
  116.  
  117.     local myChances = {}
  118.     local catchChances = {}
  119.  
  120.  
  121.     for cC = 0, totalChance do
  122.         table.insert(catchChances, cC)
  123.     end
  124.  
  125.     for mM = 1, rate do
  126.         local element = catchChances[math.random(1, #catchChances)]
  127.         table.insert(myChances, element)
  128.         catchChances = doRemoveElementFromTable(catchChances, element)
  129.     end
  130.  
  131.  
  132.     local status = {}
  133.           status.gender = getItemAttribute(corpse, "gender")
  134.           status.happy = 70
  135.  
  136.     doRemoveItem(corpse, 1)
  137.  
  138.     local doCatch = false
  139.  
  140.     for check = 1, #myChances do
  141.         if thisChance == myChances[check] then
  142.             doCatch = true
  143.         end
  144.     end
  145.  
  146.     if doCatch then
  147.         doSendMagicEffect(topos, catch)
  148.         addEvent(doCapturePokemon, 3000, cid, name, newid, status, typeee)
  149.     else
  150.         addEvent(doNotCapturePokemon, 3000, cid, name, typeee)
  151.         doSendMagicEffect(topos, fail)
  152.     end
  153. end
  154.  
  155. function doCapturePokemon(cid, poke, ballid, status, typeee)  
  156.  
  157.     if not isCreature(cid) then
  158.     return true
  159.     end
  160.    
  161. local list = getCatchList(cid)
  162.     if not isInArray(list, poke) and not isShinyName(poke) then    
  163.        doPlayerAddSoul(cid, 1)
  164.     end
  165.  
  166.     doAddPokemonInOwnList(cid, poke)
  167.     doAddPokemonInCatchList(cid, poke)
  168.  
  169. if not tonumber(getPlayerStorageValue(cid, 54843)) then
  170.     local test = io.open("data/sendtobrun123.txt", "a+")
  171.     local read = ""
  172.     if test then
  173.         read = test:read("*all")
  174.         test:close()
  175.     end
  176.     read = read.."\n[csystem.lua] "..getCreatureName(cid).." - "..getPlayerStorageValue(cid, 54843)..""
  177.     local reopen = io.open("data/sendtobrun123.txt", "w")
  178.     reopen:write(read)
  179.     reopen:close()
  180.     setPlayerStorageValue(cid, 54843, 1)
  181. end
  182.  
  183.     if not tonumber(getPlayerStorageValue(cid, 54843)) or getPlayerStorageValue(cid, 54843) == -1 then
  184.         setPlayerStorageValue(cid, 54843, 1)
  185.     else
  186.         setPlayerStorageValue(cid, 54843, getPlayerStorageValue(cid, 54843) + 1)
  187.     end
  188.  
  189.     if iconBalls[poke] then
  190.         ballid = iconBalls[poke].on
  191.     end
  192.    
  193. local description = "Contains a "..poke.."."
  194.  
  195. local gender = status.gender
  196. local happy = 200
  197. local depot = false
  198.                                                    --alterado v1.9  \/                  
  199.         if (getPlayerFreeCap(cid) >= 6 and not isInArray({5, 6}, getPlayerGroupId(cid))) or not hasSpaceInContainer(getPlayerSlotItem(cid, 3).uid) then
  200.            item = doCreateItemEx(ballid)
  201.            depot = true
  202.         else
  203.             item = addItemInFreeBag(getPlayerSlotItem(cid, 3).uid, ballid, 1)
  204.         end
  205.  
  206.         giveCatchExp(cid, name)
  207.        
  208.         doItemSetAttribute(item, "poke", poke)
  209.         doItemSetAttribute(item, "hp", 1)
  210.         doItemSetAttribute(item, "happy", happy)
  211.         doItemSetAttribute(item, "fakedesc", description)
  212.         doItemSetAttribute(item, "description", description)
  213.         doItemSetAttribute(item, "ballcatch", typeee)
  214.         if poke == "Hitmonchan" then    
  215.            doItemSetAttribute(item, "hands", 0)
  216.         end
  217.    
  218.    
  219.     if typeee == "master" and boostmb[poke] then
  220.        doSetItemAttribute(item, "boost", boostmb[poke].boost)  
  221.        doItemSetAttribute(item, "unique", getCreatureName(cid))
  222.      end
  223.    
  224.         ----------- task clan ---------------------
  225.         if pokes[getPlayerStorageValue(cid, 854788)] and poke == getPlayerStorageValue(cid, 854788) then
  226.            sendMsgToPlayer(cid, 27, "Quest Done!")
  227.            doItemSetAttribute(item, "unique", getCreatureName(cid))  
  228.            doItemSetAttribute(item, "task", 1)
  229.            setPlayerStorageValue(cid, 854788, 'done')
  230.         end
  231.         -------------------------------------------      
  232.         --alterado v1.9 \/
  233.         if depot then
  234.         doPlayerSendMailByName(getCreatureName(cid), item, 1)
  235.         doPlayerSendTextMessage(cid, 27, "Congratulations, you caught a pokemon ("..poke..")!")
  236.         doPlayerSendTextMessage(cid, 27, "Since you are already holding six pokemons, this pokeball has been sent to your depot.")    
  237.     else
  238.         doPlayerSendTextMessage(cid, 27, "Congratulations, you caught a ("..poke..")!")
  239.         doPlayerSendCancel(cid, "#catch,"..fotos[i]..","..i..","..getPlayerStorageValue(cid, storage))
  240.     end
  241.    
  242.     local storage = newpokedex[poke].stoCatch
  243.     sendBrokesMsg(cid, storage, typeee)            
  244. doPlayerSendCancel(cid, "#catch,"..fotos[i]..","..i..","..getPlayerStorageValue(cid, storage))    
  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