Advertisement
Guest User

Untitled

a guest
May 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.18 KB | None | 0 0
  1. local CriaturaInfo = {
  2.     ['Korzus'] = {mindmg = 30000, str1 = 3686, str2 = 3687}
  3. }
  4. local ativarLootMsg = true -- coloca true para ficar show rs rs rs  // por default é false
  5.  
  6. local function mandarMensagemBoss(oCara, nomeDoBicho, tabelaDeItem, haMsg)
  7.     local msg = ''
  8.     for _, itemLoot in pairs(tabelaDeItem) do
  9.         if table.maxn(tabelaDeItem) >= 1 then
  10.             if msg == '' then
  11.                 if itemLoot.count > 1 then
  12.                     msg = itemLoot.count..' '..ItemType(itemLoot.item):getName()
  13.                 else
  14.                     msg = ItemType(itemLoot.item):getName()
  15.                 end
  16.             else
  17.                 if itemLoot.count > 1 then
  18.                     msg = msg..', '..itemLoot.count..' '..ItemType(itemLoot.item):getName()
  19.                 else
  20.                     msg = msg..', '..ItemType(itemLoot.item):getName()
  21.                 end            
  22.             end
  23.         end
  24.     end
  25.     if haMsg then
  26.         oCara:sendTextMessage(MESSAGE_INFO_DESCR, 'Loot of '.. MonsterType(nomeDoBicho):getNameDescription() ..' (in mailbox): '.. (msg == '' and 'nothing' or msg) ..'')
  27.     end
  28. end
  29.  
  30. local function EnviarPremio(jogador,colocacao,nomecriatura,modoc)
  31.         local dificuldadegeral = 5
  32.        
  33.     -- variavel para armazenar itens e quantidade
  34.         local lootMsg = {}
  35.     -- fim da variavel para armazenar itens e quantidade
  36.    
  37.         if colocacao == 1 then
  38.             chancepremio = 30000
  39.         elseif colocacao == 2 then
  40.             chancepremio = 40000
  41.         elseif colocacao >= 3 and colocacao <= 7 then
  42.             chancepremio = 70000
  43.         else
  44.             chancepremio = 100000
  45.         end
  46.  
  47.         local premio = false
  48.         local crioubolsa = false
  49.         local randomloot = os.time()
  50.         for i, v in ipairs(MonsterType(nomecriatura):getLoot()) do
  51.                 math.randomseed(math.random(randomloot))
  52.                 local randomloot = math.random(1,100000)
  53.                 local randomamount = toint(math.random(1,v.maxCount)/colocacao)
  54.                 if randomamount < 1 then
  55.                     randomamount = 1
  56.                 end
  57.                 if chancepremio <= v.chance and randomloot <= v.chance then
  58.                     if crioubolsa == false then
  59.                         parcel = jogador:getInbox():addItem(2596, 1, false, 1)
  60.                         bag = parcel:addItem(1988, 1, false, 1)
  61.                         crioubolsa = true
  62.                     end
  63.                     bag:addItem(v.itemId, randomamount, false, 1)
  64.                     -- agrupar o loot
  65.                     lootMsg[#lootMsg + 1] = {item = v.itemId, count = randomamount}
  66.                     -- fim agrupar loot
  67.                     premio = true
  68.                 end
  69.         end
  70.         if ativarLootMsg then
  71.             -- gera a mensagem do loot--
  72.             mandarMensagemBoss(jogador, nomecriatura, lootMsg, premio)
  73.             -- fim da mensagem do loot --
  74.         end
  75.        
  76.         if premio then
  77.             doPlayerSendTextMessage(jogador, MESSAGE_EVENT_ADVANCE, "Parabéns! Você ganhou itens ao matar " .. nomecriatura .. ", confira seu mailbox em seu depot. Sua colocação foi " .. colocacao .. "º como " .. modoc .. ".")
  78.         end
  79. end
  80.  
  81. local function IniciarPremiacao(storage,nomecri,modo)
  82.     local colocacao = 1
  83.     local resultId = db.storeQuery("SELECT `player_id`,`value` FROM `player_storage` WHERE `key` = " .. storage .. " AND `value` > 0 ORDER BY `value` DESC")
  84.     if resultId ~= false then
  85.         repeat
  86.             local playerid = result.getDataInt(resultId, "player_id")
  87.             local resultId2 = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. playerid)
  88.             if resultId2 ~= false then
  89.                 name = result.getDataString(resultId2, "name")
  90.             end
  91.             result.free(resultId2)
  92.             local player = Player(getPlayerByName(name))
  93.  
  94.             if player then
  95.                 EnviarPremio(player,colocacao,nomecri,modo)
  96.                 setPlayerStorageValue(player,storage,-1)
  97.                 player:save()
  98.             end
  99.             colocacao = colocacao+1
  100.         until not result.next(resultId)
  101.     end
  102.     result.free(resultId)
  103.     return true
  104. end
  105.  
  106. function onKill(cid, target, lastHit)
  107.     --Evitar execucao de mais de uma vez:
  108.     if getGlobalStorageValue(3688)+5 >= os.time() then
  109.         return true
  110.     else
  111.         setGlobalStorageValue(3688, os.time())
  112.     end
  113.  
  114.     local monster = Monster(target)
  115.     if not monster or isSummon(target) then
  116.             return true
  117.     end
  118.     local nomecri = getCreatureName(monster)
  119.     if CriaturaInfo[nomecri] == nil then
  120.             return true
  121.     end
  122.  
  123.     local attacker = false
  124.     for ida, damagea in pairs(monster:getDamageMap()) do
  125.         local player = Player(ida)
  126.         if player then
  127.             setPlayerStorageValue(player,CriaturaInfo[nomecri].str1,-1)
  128.             setPlayerStorageValue(player,CriaturaInfo[nomecri].str2,-1)
  129.             if damagea.total > CriaturaInfo[nomecri].mindmg then
  130.                 attacker = true
  131.             end
  132.             for idb, damageb in pairs(player:getDamageMap()) do
  133.                 local monsterb = Monster(idb)
  134.                 if monsterb and getCreatureName(monsterb) == nomecri and damageb.total > CriaturaInfo[nomecri].mindmg and damageb.total > damagea.total then
  135.                     setPlayerStorageValue(player,CriaturaInfo[nomecri].str2,damageb.total)
  136.                     attacker = false
  137.                 end
  138.             end
  139.             if attacker then
  140.                 setPlayerStorageValue(player,CriaturaInfo[nomecri].str1,damagea.total)
  141.             end
  142.             player:save()
  143.         end
  144.     end
  145.    
  146.     if ativarLootMsg then
  147.         --não da loot--
  148.         monster:setDropLoot(false)
  149.         local corpoId = MonsterType(monster:getName()):getCorpseId()
  150.         Game.createItem(corpoId, 1, monster:getPosition())
  151.         --fim nao da loot --
  152.     end
  153.    
  154.     IniciarPremiacao(CriaturaInfo[nomecri].str1,nomecri,'attacker')
  155.     IniciarPremiacao(CriaturaInfo[nomecri].str2,nomecri,'blocker')
  156.  
  157.     return true
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement