• 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!

Lua TFS 1.2 Looking for Amulet of Loss with charges

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
993
Solutions
5
Reaction score
55
Does anyone have amulet of loss with charges? Lets say Amulet id is 3333 and it has 5 charges so what it means is only 5th death will remove the amulet and lets say amulet 3334 have 10 charges so only 10th death will remove this amulet so basically it same like amulet of loss only with charges
 
Solution
ah oops.

Try
Lua:
local amuletOfLosses = {2173, 13805}

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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and isInArray(amuletOfLosses, amulet.itemid) and not hasSkull then
        local isPlayer = false
        if killer then
            if killer:isPlayer() then
                isPlayer = true...
Just change the value to 10 if you want it to have more than 1 charge
XML:
<item id="2173" article="an" name="amulet of loss">
        <attribute key="weight" value="420" />
        <attribute key="slotType" value="necklace" />
        <attribute key="charges" value="10" />
 
Just change the value to 10 if you want it to have more than 1 charge
XML:
<item id="2173" article="an" name="amulet of loss">
        <attribute key="weight" value="420" />
        <attribute key="slotType" value="necklace" />
        <attribute key="charges" value="10" />
Still losing items (its a custom item) and charges doesnt work made 5 charges and died like 7 times and it didnt removed the amulet
 
Can you post your script
Lua:
    <item id="13805" article="a" name="God Amulet">
        <attribute key="description" value="+1000 HP/MP, all skills +2, With this item you wont lose your equipement when you die." />
        <attribute key="weight" value="500" />
        <attribute key="slotType" value="necklace" />
        <attribute key="skillsword" value="2"/>
        <attribute key="skillaxe" value="2"/>
        <attribute key="skillclub" value="2"/>
        <attribute key="skilldist" value="2"/>
        <attribute key="skillfish" value="2"/>
        <attribute key="skillshield" value="2"/>
        <attribute key="skillfist" value="2"/>
        <attribute key="charges" value="5" />
        <attribute key="maxhitpoints" value="1000"/>
        <attribute key="maxmanapoints" value="1000"/>    
    </item>
 
Lua:
    <item id="13805" article="a" name="God Amulet">
        <attribute key="description" value="+1000 HP/MP, all skills +2, With this item you wont lose your equipement when you die." />
        <attribute key="weight" value="500" />
        <attribute key="slotType" value="necklace" />
        <attribute key="skillsword" value="2"/>
        <attribute key="skillaxe" value="2"/>
        <attribute key="skillclub" value="2"/>
        <attribute key="skilldist" value="2"/>
        <attribute key="skillfish" value="2"/>
        <attribute key="skillshield" value="2"/>
        <attribute key="skillfist" value="2"/>
        <attribute key="charges" value="5" />
        <attribute key="maxhitpoints" value="1000"/>
        <attribute key="maxmanapoints" value="1000"/>  
    </item>
You should generally allow the player to see how many charges an item has left, as it's useful information for them to know.
XML:
<attribute key="showcharges" value="1" />

In either case, this isn't the script he was asking for.
We are looking for the onDeath / onKill / onPrepareDeath script that is responsible for removing these items.

In most cases this file is named droploot.lua
 
You should generally allow the player to see how many charges an item has left, as it's useful information for them to know.
XML:
<attribute key="showcharges" value="1" />

In either case, this isn't the script he was asking for.
We are looking for the onDeath / onKill / onPrepareDeath script that is responsible for removing these items.

In most cases this file is named droploot.lua
Sorry
Lua:
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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not hasSkull 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
        local lossPercent = player:getLossPercent()
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                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
 
Sorry
Lua:
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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not hasSkull 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
        local lossPercent = player:getLossPercent()
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                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
Sorry that this took so long.
I had to install / compile tfs on my system, so I could test lol
Lua:
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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not hasSkull 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
            amulet:transform(amulet:getId(), amulet:getCharges() - 1)
        end
    else
        local lossPercent = player:getLossPercent()
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                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
 
Lua:
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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not hasSkull 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
            amulet:transform(amulet:getId(), amulet:getCharges() - 1)
        end
    else
        local lossPercent = player:getLossPercent()
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                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
Sadly its same still losing everything, doesnt remove amulet either
XML:
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="1" />/code]
died like 7 times
 
Sadly its same still losing everything, doesnt remove amulet either
XML:
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="1" />/code]
died like 7 times

You must be doing something wrong.


bandicam 2021-01-26 13-05-02-476.gif

-- Edit

Oh, I see your issue.
You aren't using an amulet of loss, you're using some other necklace item.

Okay, use this.
Lua:
local amuletOfLosses = {2173, 13805}

function onDeath(player, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if player:hasFlag(PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return true
    end

    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    local isRedOrBlack = table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and table.contains(amuletOfLosses, amulet.itemid) and not isRedOrBlack 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
            amulet:transform(amulet:getId(), amulet:getCharges() - 1)
        end
    else
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            local lossPercent = player:getLossPercent()
            if item then
                if isRedOrBlack or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if (isRedOrBlack or lossPercent ~= 0) and not item:moveTo(corpse) then
                        item:remove()
                    end
                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:
You must be doing something wrong.


View attachment 54214

-- Edit

Oh, I see your issue.
You aren't using an amulet of loss, you're using some other necklace item.

Okay, use this.
Lua:
local amuletOfLosses = {2173, 13805}

function onDeath(player, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if player:hasFlag(PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return true
    end

    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    local isRedOrBlack = table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and table.contains(amuletOfLosses, amulet.itemid) and not isRedOrBlack 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
            amulet:transform(amulet:getId(), amulet:getCharges() - 1)
        end
    else
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            local lossPercent = player:getLossPercent()
            if item then
                if isRedOrBlack or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if (isRedOrBlack or lossPercent ~= 0) and not item:moveTo(corpse) then
                        item:remove()
                    end
                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
 
ah oops.

Try
Lua:
local amuletOfLosses = {2173, 13805}

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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and isInArray(amuletOfLosses, amulet.itemid) and not hasSkull 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
            amulet:transform(amulet:getId(), amulet:getCharges() - 1)
        end
    else
        local lossPercent = player:getLossPercent()
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                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
 
Solution
ah oops.

Try
Lua:
local amuletOfLosses = {2173, 13805}

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)
    local hasSkull = isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull())
    if amulet and isInArray(amuletOfLosses, amulet.itemid) and not hasSkull 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
            amulet:transform(amulet:getId(), amulet:getCharges() - 1)
        end
    else
        local lossPercent = player:getLossPercent()
        for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
            local item = player:getSlotItem(i)
            if item then
                if hasSkull or math.random(item:isContainer() and 100 or 1000) <= lossPercent then
                    if not item:moveTo(corpse) then
                        item:remove()
                    end
                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
Okay it works now but cant get more then 1 charge even when in xml made 5
tried
Lua:
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="5" />
and this
Lua:
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="1" />

not sure whats wrong
 
Okay it works now but cant get more then 1 charge even when in xml made 5
tried
Lua:
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="5" />
and this
Lua:
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="1" />

not sure whats wrong
How are you creating the item?
 
How are you creating the item?
XML:
    <item id="13805" article="a" name="God Amulet">
        <attribute key="description" value="+1000 HP/MP, all skills +2, With this item you wont lose your equipement when you die." />
        <attribute key="weight" value="500" />
        <attribute key="slotType" value="necklace" />
        <attribute key="skillsword" value="2"/>
        <attribute key="skillaxe" value="2"/>
        <attribute key="skillclub" value="2"/>
        <attribute key="skilldist" value="2"/>
        <attribute key="skillfish" value="2"/>
        <attribute key="skillshield" value="2"/>
        <attribute key="skillfist" value="2"/>
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="5" />
        <attribute key="maxhitpoints" value="1000"/>
        <attribute key="maxmanapoints" value="1000"/>    
    </item>

XML:
    <movevent event="Equip" itemid="13805" slot="necklace" level="100" function="onEquipItem" />
    <movevent event="DeEquip" itemid="13805" slot="necklace" function="onDeEquipItem" />
 
XML:
    <item id="13805" article="a" name="God Amulet">
        <attribute key="description" value="+1000 HP/MP, all skills +2, With this item you wont lose your equipement when you die." />
        <attribute key="weight" value="500" />
        <attribute key="slotType" value="necklace" />
        <attribute key="skillsword" value="2"/>
        <attribute key="skillaxe" value="2"/>
        <attribute key="skillclub" value="2"/>
        <attribute key="skilldist" value="2"/>
        <attribute key="skillfish" value="2"/>
        <attribute key="skillshield" value="2"/>
        <attribute key="skillfist" value="2"/>
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="5" />
        <attribute key="maxhitpoints" value="1000"/>
        <attribute key="maxmanapoints" value="1000"/>   
    </item>

XML:
    <movevent event="Equip" itemid="13805" slot="necklace" level="100" function="onEquipItem" />
    <movevent event="DeEquip" itemid="13805" slot="necklace" function="onDeEquipItem" />
Right, this is your items.xml and movements.xml

But how are you creating the item in-game?
Script? God?
 
Works but when you do look on item it doesnt say you have 5 charges left, says nothing about charges at all
change
<attribute key="showcharges" value="5" />
to
<attribute key="showcharges" value="1" />
 
Back
Top