• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.3 Blue Arrow on Drop

darkmubr

Member
Joined
Mar 8, 2019
Messages
47
Solutions
1
Reaction score
13
How do I change in the local code the chance = 1 for a variable of type:

local rare_items = {2152, 2333, 2542}?

Sorry for the doubt, I'm a beginner.

Lua:
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
 
Solution
How do I change in the local code the chance = 1 for a variable of type:

local rare_items = {2152, 2333, 2542}?

Sorry for the doubt, I'm a beginner.

Lua:
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())...
How do I change in the local code the chance = 1 for a variable of type:

local rare_items = {2152, 2333, 2542}?

Sorry for the doubt, I'm a beginner.

Lua:
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
Lua:
local effect = CONST_ME_TUTORIALARROW
local rare_items = {2152, 2333, 2542}

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 onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    if not killer or not corpse then return true end
    addEvent(function(cid)
        if not Item(corpse.uid) then return end
        for i = 0, corpse:getItemHoldingCount() - 1 do
            local item = corpse:getItem(i)
            if item and isInArray(rare_items, item.itemid) then
                corpse:getPosition():sendMagicEffect(effect)
                local temp = Player(cid)
                if temp then
                    temp:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You looted " .. item:getArticle() .. " ".. item:getName():lower() .."!")
                end
            end
        end
    end, 100, killer.uid)
    return true
end
 
Solution
Back
Top