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

Need Custom Amulet of Loss (No experience loss)

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
625
Reaction score
71
How to make amulet that when you die you wont lose any experience and that amulet would be active for 5deaths and after 5deaths it would remove that amulet.

TFS 1.2
 
This should work:
LUA:
local config = {
    amuletID = 15687,
    storageKey = 100371
}

function onPrepareDeath(creature, killer)
    local player = Player(creature)
    if not player then
        return true
    end
    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    local storage = player:getStorageValue(config.storageKey)
    if amulet and amulet:getId() == config.amuletID then
        if storage <= 5 then
            player:setDropLoot(false)
            for i = 1, 5 do
                player:addBlessing(i)
            end
            player:setStorageValue(config.storageKey, storage == -1 and 1 or storage + 1)
        else
            amulet:remove()
        end
    end
    return true
end
 
This should work:
LUA:
local config = {
    amuletID = 15687,
    storageKey = 100371
}

function onPrepareDeath(creature, killer)
    local player = Player(creature)
    if not player then
        return true
    end
    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    local storage = player:getStorageValue(config.storageKey)
    if amulet and amulet:getId() == config.amuletID then
        if storage <= 5 then
            player:setDropLoot(false)
            for i = 1, 5 do
                player:addBlessing(i)
            end
            player:setStorageValue(config.storageKey, storage == -1 and 1 or storage + 1)
        else
            amulet:remove()
        end
    end
    return true
end
It does work but you still lose experience. And after 5death it removes the amulet and you lose a lot even when you have a amulet on you, it should have removed the amulet and didnt removed the loot which is weird why it lost loot when there still was a amulet
 
It does work but you still lose experience
I guess blessings only work up to a reduction of 40% (70% if promoted), if you want 100% xp reduction loss it requires a source edit.
If you're willing to do a source edit and recompile, let me know.
Either way what I just realized what I gave you is bugged, the amulet will have to use charges:
LUA:
local config = {
    amuletID = 15687
}

function onPrepareDeath(creature, killer)
    local player = Player(creature)
    if not player then
        return true
    end
    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    local charges = item:getAttribute(ITEM_ATTRIBUTE_CHARGES) or 5
    if amulet and amulet:getId() == config.amuletID then
        if charges > 0 then
            player:setDropLoot(false)
            for i = 1, 5 do
                player:addBlessing(i)
            end
            item:setAttribute(ITEM_ATTRIBUTES_CHARGES, charges - 1)
        else
            amulet:remove()
        end
    end
    return true
end

Add charges="5" in items.xml as well and showcharges="1".
 
I guess blessings only work up to a reduction of 40% (70% if promoted), if you want 100% xp reduction loss it requires a source edit.
If you're willing to do a source edit and recompile, let me know.
Either way what I just realized what I gave you is bugged, the amulet will have to use charges:
LUA:
local config = {
    amuletID = 15687
}

function onPrepareDeath(creature, killer)
    local player = Player(creature)
    if not player then
        return true
    end
    local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
    local charges = item:getAttribute(ITEM_ATTRIBUTE_CHARGES) or 5
    if amulet and amulet:getId() == config.amuletID then
        if charges > 0 then
            player:setDropLoot(false)
            for i = 1, 5 do
                player:addBlessing(i)
            end
            item:setAttribute(ITEM_ATTRIBUTES_CHARGES, charges - 1)
        else
            amulet:remove()
        end
    end
    return true
end

Add charges="5" in items.xml as well and showcharges="1".
So what happens by adding
XML:
       <attribute key="charges" value="5"/>
        <attribute key="showcharges" value="1"/>
is
Untitled.png

Actually i am down to do source editing its not a problem but it would be dope to have a function in local like
LUA:
local config = {
    amuletID = 15687,
    LossExpPrecent= 85
}
so it could be used in different codes either or could be helpful for a lot of people if its even possible to achieve something like this
 
So what happens by adding
XML:
       <attribute key="charges" value="5"/>
        <attribute key="showcharges" value="1"/>
is
View attachment 38736

Actually i am down to do source editing its not a problem but it would be dope to have a function in local like
LUA:
local config = {
    amuletID = 15687,
    LossExpPrecent= 85
}
so it could be used in different codes either or could be helpful for a lot of people if its even possible to achieve something like this
Any ideas?
 
EXPERIENCE_LOSS = 0 via SQL? on equip? and onDeequip or onlogin?
what you mean by onquip and ondeequip or onlogin, as far as i understand it would require extra codes then either or why quipt and dequip is needed when it can be done in creaturescript like now
 
Why don't you use the exp loss formula as formula of exp the player gets +/- on death?

ondeath script -> give 5k exp
player dies loses 5k exp...

ofc 5k is a example, i would recommend to test it throughly as it may be mess up...
script gives exp -> higher total exp -> higher exp loss?

or just calculate the exp and save it as storage to give exp on login?( i do not think storage can save values as big as exp loss on high lvls....)

Animera
 
Why don't you use the exp loss formula as formula of exp the player gets +/- on death?

ondeath script -> give 5k exp
player dies loses 5k exp...

ofc 5k is a example, i would recommend to test it throughly as it may be mess up...
script gives exp -> higher total exp -> higher exp loss?

or just calculate the exp and save it as storage to give exp on login?( i do not think storage can save values as big as exp loss on high lvls....)

Animera
No this sounds really messy giving the same exp as he lose isnt it like over load for entire server, how it will react if a lot of people will die at the same time. Then you lose different exp with each level so its impossible so it sounds really not smart to do that.
 
No this sounds really messy giving the same exp as he lose isnt it like over load for entire server, how it will react if a lot of people will die at the same time. Then you lose different exp with each level so its impossible so it sounds really not smart to do that.

Why not? if you use the same/similar formula as it is hardcoded you won't get that huge difference at all.
And a small formula with a few lines of code on a player ondeath script won't have performance issues lol.

I have like a few k of code in lua for monsters, and at my server people can kill like 100 mobs at a time. No issues. And i am not even using high end equipment. For the amount of map/systems i have the hosting is even too low for what i actually should have or atleast have(And still im hosting it with very low % usages, it's important to know how you code it.).

Not to mention it's easier to tweak/test it in lua then actually changing source files, recompile, run, test.

EDIT:
Just checked the death formula

Code:
local neck = player:getSlotItem(CONST_SLOT_NECKLACE)
local AOL = ITEMID

if neck then
    if neck:getId() == AOL then
    player:getExperience() * deathLossPercent
    end    
end

Shouldn't be a big problem, i do not know what client your working with. But there should be made some declaration for deathlosspercent, and ofcourse unfairfight reduction (if you have those systems on your server), Which is still possible with iterating through damage.map(or similar custom function) and a small calculation of level/vocation. EZ PZ. Yes those things may be more expensive in resource usage. But it should't be a big issue at all.

I'm not saying it is the best solution, just trying to tell you to be 'creative' so you can create some stuff you couldn't do before by using 'hacky' methods..

Animera
 
Last edited:
Back
Top