• 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 Request item that unequips after X seconds and goes back to bp

katumblo

Member
Joined
Oct 20, 2010
Messages
60
Reaction score
7
Hello, I would like to know if anyone could help me with an item I need to make (actually there are 3 items, but if you can help me with any amount I will be immensely grateful)

I've already added the item on the server and everything else, I put its ID and put it as ring, however, I would like when equipping it, it stays for X seconds, gives Y status and then goes back to BP, and the cooldown to be able to equip it again it would be Z hours...

For example:

Diamond ring
<Equipping gains +200 ML and +30 sword for 3 seconds>
<The cooldown is 24 hours>

Silver ring:
<Equipping it earns double xp for 1 hour>
<The cooldown is 24 hours>

Bronze Ring:
<Equipping gains a 200% loot chance for 1 hour>
<The cooldown is 12 hours>

If someone can help me, I'd really appreciate it <3

*I am using an 8.60 server
 
Solution
exp ring
tfs 1.4+
Lua:
G_exp_ring_config = { -- global
    equipCdTime = 20 * 60 * 60, -- in sec
    equipCdStorageValue = 15000,
    expBoostMultipler = 2,
    expBoostTime = 60 * 60, -- in sec
    expBoostTimeStorageValue = 15001,
    deequipTime= 3 * 1000, -- in milisec
    ringId = 2179
}

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)

    if not ring or ring:getId() ~= G_exp_ring_config.ringId then
        return false
    end
   
    if backpack then
        local container = Container(backpack.uid)
        if not container then...
tfs version, what if ring will be deequiped(no fully expired), add cooldown on equip is easy but deequip is problematic
you can equip ring, exp for 5min, deequip and wait 1 day for cooldown
Following this logic, would it be possible to do so?

The ring lasts for 3 seconds After these 3 seconds, it does not disappear, but it will return to the backpack and can only be equipped after 24 hours
 
exp ring
tfs 1.4+
Lua:
G_exp_ring_config = { -- global
    equipCdTime = 20 * 60 * 60, -- in sec
    equipCdStorageValue = 15000,
    expBoostMultipler = 2,
    expBoostTime = 60 * 60, -- in sec
    expBoostTimeStorageValue = 15001,
    deequipTime= 3 * 1000, -- in milisec
    ringId = 2179
}

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)

    if not ring or ring:getId() ~= G_exp_ring_config.ringId then
        return false
    end
   
    if backpack then
        local container = Container(backpack.uid)
        if not container then
            return false
        end
        ring:moveTo(container)
    else
        ring:moveTo(player:getPosition())
    end
end

local function setStorages(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    player:setStorageValue(G_exp_ring_config.equipCdStorageValue, os.time() + G_exp_ring_config.equipCdTime)
    player:setStorageValue(G_exp_ring_config.expBoostTimeStorageValue, os.time() + G_exp_ring_config.expBoostTime)
end

local ringEq = MoveEvent()
function ringEq.onEquip(player, item, slot)
    local eq_cooldown = player:getStorageValue(G_exp_ring_config.equipCdStorageValue)
    if eq_cooldown > os.time() then
        return false
    end
    -- on my engine onEquip is triggered 2 times, addEvent delay setStorages and equip is done without issue
    addEvent(setStorages, 1, player:getId())
    addEvent(moveRingToBp, G_exp_ring_config.deequipTime, player:getId())
    return true
end

ringEq:type("equip")
ringEq:slot("ring")
ringEq:id(G_exp_ring_config.ringId) -- gold ring
ringEq:register()
events\scripts\player.lua
function
Code:
Player:onGainExperience(source, exp, rawExp)
add
Code:
    local expRingStorageValue = self:getStorageValue(G_exp_ring_config.expBoostTimeStorageValue)
    if expRingStorageValue > os.time() then
        exp = exp * G_exp_ring_config.expBoostMultipler
    end
Post automatically merged:

Mlvl and skill ring

Code:
local config = { -- global
    equipCdTime = 20 * 60 * 60, -- in sec
    equipCdStorageValue = 15002,
    deequipTime= 3 * 1000, -- in milisec
    conditionTime = 5 * 1000, -- in milisec
    ringId = 2179
}

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_TICKS, config.conditionTime)
condition:setParameter(CONDITION_PARAM_SKILL_MELEE, 30)
condition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 200)
condition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 30)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
    if not ring or ring:getId() ~= config.ringId then
        return false
    end
    
    if backpack then
        local container = Container(backpack.uid)
        if not container then
            return false
        end
        ring:moveTo(container)
    else
        ring:moveTo(player:getPosition())
    end
end

local function setStorages(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    player:setStorageValue(config.equipCdStorageValue, os.time() + config.equipCdTime)
end

local ringEq = MoveEvent()
function ringEq.onEquip(player, item, slot)
    local eq_cooldown = player:getStorageValue(config.equipCdStorageValue)
    if eq_cooldown > os.time() then
        return false
    end
    -- on my engine onEquip is triggered 2 times, addEvent delay setStorages and equip is done without issue
    addEvent(setStorages, 1, player:getId())
    addEvent(moveRingToBp, config.deequipTime, player:getId())
    player:addCondition(condition)
    return true
end

ringEq:type("equip")
ringEq:slot("ring")
ringEq:id(config.ringId) -- gold ring
ringEq:register()
Post automatically merged:

loot ring
Lua:
G_loot_ring_config = { -- global
    equipCdTime = 10, --20 * 60 * 60, -- in sec
    equipCdStorageValue = 15003,
    additionalLootRolls = 1,
    lootBoostTime = 5, --60 * 60, -- in sec
    lootBoostTimeStorageValue = 15003,
    deequipTime= 3 * 1000, -- in milisec
    ringId = 2179
}

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)

    if not ring or ring:getId() ~= G_loot_ring_config.ringId then
        return false
    end
  
    if backpack then
        local container = Container(backpack.uid)
        if not container then
            return false
        end
        ring:moveTo(container)
    else
        ring:moveTo(player:getPosition())
    end
end

local function setStorages(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    player:setStorageValue(G_loot_ring_config.equipCdStorageValue, os.time() + G_loot_ring_config.equipCdTime)
    player:setStorageValue(G_loot_ring_config.lootBoostTimeStorageValue, os.time() + G_loot_ring_config.lootBoostTime)
end

local ringEq = MoveEvent()
function ringEq.onEquip(player, item, slot)
    local eq_cooldown = player:getStorageValue(G_loot_ring_config.equipCdStorageValue)
    if eq_cooldown > os.time() then
        return false
    end
    -- on my engine onEquip is triggered 2 times, addEvent delay setStorages and equip is done without issue
    addEvent(setStorages, 1, player:getId())
    addEvent(moveRingToBp, G_loot_ring_config.deequipTime, player:getId())
    return true
end

ringEq:type("equip")
ringEq:slot("ring")
ringEq:id(G_loot_ring_config.ringId) -- gold ring
ringEq:register()
in scripts\eventcallbacks\monster\default_onDropLoot.lua

Code:
ec.onDropLoot = function(self, corpse)
add
Code:
    local lootRingStorageValue = player:getStorageValue(G_loot_ring_config.lootBoostTimeStorageValue)
    if lootRingStorageValue > os.time() then
        local monsterLoot = mType:getLoot()
        for i = 1, G_loot_ring_config.additionalLootRolls, 1 do
            for i = 1, #monsterLoot do
                local item = corpse:createLootItem(monsterLoot[i])
                if not item then
                    print("[Warning] DropLoot: Could not add loot item to corpse.")
                end
            end
        end
    end
 
Last edited:
Solution
exp ring
tfs 1.4+
Lua:
G_exp_ring_config = { -- global
    equipCdTime = 20 * 60 * 60, -- in sec
    equipCdStorageValue = 15000,
    expBoostMultipler = 2,
    expBoostTime = 60 * 60, -- in sec
    expBoostTimeStorageValue = 15001,
    deequipTime= 3 * 1000, -- in milisec
    ringId = 2179
}

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)

    if not ring or ring:getId() ~= G_exp_ring_config.ringId then
        return false
    end
  
    if backpack then
        local container = Container(backpack.uid)
        if not container then
            return false
        end
        ring:moveTo(container)
    else
        ring:moveTo(player:getPosition())
    end
end

local function setStorages(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    player:setStorageValue(G_exp_ring_config.equipCdStorageValue, os.time() + G_exp_ring_config.equipCdTime)
    player:setStorageValue(G_exp_ring_config.expBoostTimeStorageValue, os.time() + G_exp_ring_config.expBoostTime)
end

local ringEq = MoveEvent()
function ringEq.onEquip(player, item, slot)
    local eq_cooldown = player:getStorageValue(G_exp_ring_config.equipCdStorageValue)
    if eq_cooldown > os.time() then
        return false
    end
    -- on my engine onEquip is triggered 2 times, addEvent delay setStorages and equip is done without issue
    addEvent(setStorages, 1, player:getId())
    addEvent(moveRingToBp, G_exp_ring_config.deequipTime, player:getId())
    return true
end

ringEq:type("equip")
ringEq:slot("ring")
ringEq:id(G_exp_ring_config.ringId) -- gold ring
ringEq:register()
events\scripts\player.lua
function
Code:
Player:onGainExperience(source, exp, rawExp)
add
Code:
    local expRingStorageValue = self:getStorageValue(G_exp_ring_config.expBoostTimeStorageValue)
    if expRingStorageValue > os.time() then
        exp = exp * G_exp_ring_config.expBoostMultipler
    end
Post automatically merged:

Mlvl and skill ring

Code:
local config = { -- global
    equipCdTime = 20 * 60 * 60, -- in sec
    equipCdStorageValue = 15002,
    deequipTime= 3 * 1000, -- in milisec
    conditionTime = 5 * 1000, -- in milisec
    ringId = 2179
}

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_TICKS, config.conditionTime)
condition:setParameter(CONDITION_PARAM_SKILL_MELEE, 30)
condition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 200)
condition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 30)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
    if not ring or ring:getId() ~= config.ringId then
        return false
    end
   
    if backpack then
        local container = Container(backpack.uid)
        if not container then
            return false
        end
        ring:moveTo(container)
    else
        ring:moveTo(player:getPosition())
    end
end

local function setStorages(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    player:setStorageValue(config.equipCdStorageValue, os.time() + config.equipCdTime)
end

local ringEq = MoveEvent()
function ringEq.onEquip(player, item, slot)
    local eq_cooldown = player:getStorageValue(config.equipCdStorageValue)
    if eq_cooldown > os.time() then
        return false
    end
    -- on my engine onEquip is triggered 2 times, addEvent delay setStorages and equip is done without issue
    addEvent(setStorages, 1, player:getId())
    addEvent(moveRingToBp, config.deequipTime, player:getId())
    player:addCondition(condition)
    return true
end

ringEq:type("equip")
ringEq:slot("ring")
ringEq:id(config.ringId) -- gold ring
ringEq:register()
Post automatically merged:

loot ring
Lua:
G_loot_ring_config = { -- global
    equipCdTime = 10, --20 * 60 * 60, -- in sec
    equipCdStorageValue = 15003,
    additionalLootRolls = 1,
    lootBoostTime = 5, --60 * 60, -- in sec
    lootBoostTimeStorageValue = 15003,
    deequipTime= 3 * 1000, -- in milisec
    ringId = 2179
}

local function moveRingToBp(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    local ring = player:getSlotItem(CONST_SLOT_RING)
    local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)

    if not ring or ring:getId() ~= G_loot_ring_config.ringId then
        return false
    end
 
    if backpack then
        local container = Container(backpack.uid)
        if not container then
            return false
        end
        ring:moveTo(container)
    else
        ring:moveTo(player:getPosition())
    end
end

local function setStorages(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end
    player:setStorageValue(G_loot_ring_config.equipCdStorageValue, os.time() + G_loot_ring_config.equipCdTime)
    player:setStorageValue(G_loot_ring_config.lootBoostTimeStorageValue, os.time() + G_loot_ring_config.lootBoostTime)
end

local ringEq = MoveEvent()
function ringEq.onEquip(player, item, slot)
    local eq_cooldown = player:getStorageValue(G_loot_ring_config.equipCdStorageValue)
    if eq_cooldown > os.time() then
        return false
    end
    -- on my engine onEquip is triggered 2 times, addEvent delay setStorages and equip is done without issue
    addEvent(setStorages, 1, player:getId())
    addEvent(moveRingToBp, G_loot_ring_config.deequipTime, player:getId())
    return true
end

ringEq:type("equip")
ringEq:slot("ring")
ringEq:id(G_loot_ring_config.ringId) -- gold ring
ringEq:register()
in scripts\eventcallbacks\monster\default_onDropLoot.lua

Code:
ec.onDropLoot = function(self, corpse)
add
Code:
    local lootRingStorageValue = player:getStorageValue(G_loot_ring_config.lootBoostTimeStorageValue)
    if lootRingStorageValue > os.time() then
        local monsterLoot = mType:getLoot()
        for i = 1, G_loot_ring_config.additionalLootRolls, 1 do
            for i = 1, #monsterLoot do
                local item = corpse:createLootItem(monsterLoot[i])
                if not item then
                    print("[Warning] DropLoot: Could not add loot item to corpse.")
                end
            end
        end
    end
OMG !!

Thank u very much
 
Back
Top