• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.2 - Player has a chance to drop certain items upon death

Joined
Dec 13, 2015
Messages
45
Reaction score
13
Distro Name: TFS 1.2
Script type: Lua script

Description of the script: Upon death the script would check if player has certain itens in his backpack. For each of those itens the script would have a 5% chance to remove them from the player and add them to the player's dead body. (this drop chance would still be taken in consideration even with amulet of loss and full blessings)

File: data/creaturescripts/scripts/others/droploot.lua

example of IDs of itens the script would consider: {2195, 2187, 8878} (boh, wand of inferno, crystaline armor}

unedited droploot.lua
Code:
function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return true
    end

    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        local isPlayer = false
        if killer then
            if killer:isPlayer() then
                isPlayer = true
            else
                local master = killer:getMaster()
                if master and master:isPlayer() then
                    isPlayer = true
                end
            end
        end

        if not isPlayer or not player:hasBlessing(6) then
            player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
        end
    else
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) or math.random(item:isContainer() and 100 or 1000) <= player:getLossPercent() then
                    item:moveTo(corpse)
                end
            end
        end
    end

    if not player:getSlotItem(CONST_SLOT_BACKPACK) then
        player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
    end
    return true
end

Thanks for your help.
 
Un-tested, but this should work if I've read how getItemByID() works correctly.

Code:
function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return true
    end

    -- Code starts HERE
    local itemstodrop {
        2195, -- BOH
        2187, -- WOI
        8878 -- C ARM
    }
   
    if player:getSlotItem(CONST_SLOT_BACKPACK) then
        local bag = player:getSlotItem(CONST_SLOT_BACKPACK)
        for i = 1,#itemstodrop do
            local item = bag:getItemByID(itemstodrop[i], true)
            if item then
                item:moveTo(corpse)
            end
        end
    end
    -- Code ends HERE

    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        local isPlayer = false
        if killer then
            if killer:isPlayer() then
                isPlayer = true
            else
                local master = killer:getMaster()
                if master and master:isPlayer() then
                    isPlayer = true
                end
            end
        end

        if not isPlayer or not player:hasBlessing(6) then
            player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
        end
    else
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) or math.random(item:isContainer() and 100 or 1000) <= player:getLossPercent() then
                    item:moveTo(corpse)
                end
            end
        end
    end

    if not player:getSlotItem(CONST_SLOT_BACKPACK) then
        player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
    end
    return true
end
 
Last edited:
but what about the 5%chance part? xD
Also, if, for example, the player has 3 boots of haste in the backpack, I'd want each one to have a 5% chance to drop (separately).
And I would want the script to not consider equipped itens.

Anyway, thanks very much! I don't want to abuse you. :P
Ill see if I can make these changes that I've mentioned myself.
 
but what about the 5%chance part? xD
Also, if, for example, the player has 3 boots of haste in the backpack, I'd want each one to have a 5% chance to drop (separately).
And I would want the script to not consider equipped items.

Anyway, thanks very much! I don't want to abuse you. :p
Ill see if I can make these changes that I've mentioned myself.

I've since edited the code to only check the backpack slot.
The percent chance is calculated using math.random(1000) <= player:getLossPercent() by default.
The default drop chance is 10% it seems.

So this gives you 5%:
Code:
if math.random(500) <= player:getLossPercent() then
Using this would allow you to ensure the 5% is reduced based on player blessings.
If you want 5% regardless of blessings, simply use:
Code:
if math.random(1,100) <= 5 then
 
Last edited:
Back
Top