Ir para conteúdo

Featured Replies

Postado

Como faço para que o local chance = 1 seja alterado para uma array do tipo local rare_items = {2152, 2555, 3252}?


Desde já agradeço pela ajuda. (Sou iniciante).

 

Código:

 

local effect = CONST_ME_TUTORIALARROW -- magic effect
local chance = 1 -- magic effect for item that drops less than 5% of the time

function onLogin(player)
    player:registerEvent('rarelootkill')
    return true
end

function onKill(player, target)
    if target:isMonster() then target:registerEvent('rarelootdeath') end
    return true
end

function getContainerItemIds(container)
    t = {}
    if not container then return t end
    if not container:getSize() then return t end
    for i = container:getSize()-1, 1, -1 do
        table.insert(t,container:getItem(i):getId())
    end
    return t
end

function hasItemById(container,itemid)
    if not itemid or not container then return false end
    if isInArray(getContainerItemIds(container),itemid) then return true end
    return false
end

function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if not creature then return true end
    local loot = creature:getType():getLoot()
    if not loot then return true end
    local totalchance = 0
    for i, k in pairs(loot) do
        totalchance = totalchance + k.chance
    end
    addEvent(function()
        for i, k in pairs(loot) do
            if not corpse or not killer then
                return
            end
            if hasItemById(corpse,k.itemId) and k.chance/totalchance < chance/100  then
                corpse:getPosition():sendMagicEffect(effect)
                killer:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You looted a "..ItemType(k.itemId):getName().."!")
            end
        end
    end,1)
    return true
end

 

Editado por darkmu (veja o histórico de edições)

Postado

Não testado.

Spoiler

local effect = CONST_ME_TUTORIALARROW -- magic effect
local rareItems = {2154, 2160}

function onLogin(player)
    player:registerEvent('rarelootkill')
    return true
end

function onKill(player, target)
    if target:isMonster() then target:registerEvent('rarelootdeath') end
    return true
end

function getContainerItemIds(container)
    t = {}
    if not container then return t end
    if not container:getSize() then return t end
    for i = container:getSize()-1, 1, -1 do
        table.insert(t,container:getItem(i):getId())
    end
    return t
end

function hasItemById(container,itemid)
    if not itemid or not container then return false end
    if isInArray(getContainerItemIds(container),itemid) then return true end
    return false
end

function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if not creature then return true end
    local loot = creature:getType():getLoot()
    if not loot then return true end
    addEvent(function()
        for i, k in pairs(loot) do
            if not corpse or not killer then
                return
            end
            if hasItemById(corpse,k.itemId) and isInArray(rareItems, k.itemid) then
                corpse:getPosition():sendMagicEffect(effect)
                killer:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You looted a "..ItemType(k.itemId):getName().."!")
            end
        end
    end,1)
    return true
end

 

 

 

 

 

Nós somos aquilo que fazemos repetidamente. Excelência, não é um modo de agir, mas um hábito.

                                                                                                                                                                                                                                        Aristóteles 

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo