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

help force tfs 1.4.2

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,338
Solutions
71
Reaction score
699
Location
ლ(ಠ益ಠლ)
Could someone please give me a tip regarding item descriptions that change over time? For example, I want to display an item description indicating the remaining time, such as '60m' and then after a minute '59m', and so on. Which part of the code should I modify? Should I look into Global Events or OnThink? If yes, which specific part? Any guidance would be greatly appreciated. Thank you.
 
Could someone please give me a tip regarding item descriptions that change over time? For example, I want to display an item description indicating the remaining time, such as '60m' and then after a minute '59m', and so on. Which part of the code should I modify? Should I look into Global Events or OnThink? If yes, which specific part? Any guidance would be greatly appreciated. Thank you.
Can’t you use onlook? Whenever a player looks at the item you update the remaining time?
 
Depending on how u add the timer, you could add the initial description using
Lua:
item:setAttribute(key, value)
and in Onlook script you could use
Code:
if item:hasAttribute(key) then
..-get timer value
- update timer value

Or something..?
 
you can use custom attributes for that, set for a item "cooldown" + os.time() then read it on "OnLook" event
 
Look what I did, is it correct or wrong? Actually, I'm using the Zbizu system, I liked it a lot. Now I need to add it to the onLook... help me xD

Lua:
function Player:onLook(thing, position, distance)
    local description = ""
    local onLook = EventCallback.onLook
    
    if onLook then
        description = onLook(self, thing, position, distance, description)
    end
    
    if thing:getId() == SwordItemId then
        local cooldownTime = os.time() + CooldownDurationInSeconds
        thing:setAttribute("Sword", cooldownTime)
        description = description .. "\n+10 sword skill - Cooldown Remaining: " .. os.date("%H:%M:%S", cooldownTime)
    end

    if description ~= "" then
        self:sendTextMessage(MESSAGE_INFO_DESCR, description)
    end
end
 
do not use setAttribute in onLook, you have to read not write here, otherwise u will overwrite your already cooldown set by other script
 
do not use setAttribute in onLook, you have to read not write here, otherwise u will overwrite your already cooldown set by other script
Look what I did, is it correct? I'm using the 'addStat' function to equip and unequip attributes that appear and disappear. I wanted to add the item's appearance that shows you have 30 minutes remaining, something like that...
Lua:
local SwordItemIds = {2400, 2401}

local skillsLook = EventCallback
local swordSkillDuration = 30 * 60 
local swordSkillTimers = {}

function skillsLook.onLook(player, thing, position, distance, description)
    local itemId = thing:getId()
    
    if contains(SwordItemIds, itemId) then
        if not swordSkillTimers[player:getId()] or os.time() - swordSkillTimers[player:getId()] >= swordSkillDuration then
            thing:addStat("Sword")
            description = description .. "\n+10 sword skill"
            swordSkillTimers[player:getId()] = os.time()
        else
            local timeRemaining = swordSkillDuration - (os.time() - swordSkillTimers[player:getId()])
            local minutesRemaining = math.floor(timeRemaining / 60)
            local secondsRemaining = timeRemaining % 60
            description = description .. "\nTime left: " .. minutesRemaining .. " minutes It is " .. secondsRemaining .. " seconds"
        end
    end
    return description
end

function contains(table, element)
    for _, value in pairs(table) do
        if value == element then
            return true
        end
    end
    return false
end

skillsLook:register(2)
 
this part
Lua:
thing:addStat("Sword")
shouldbe in executing code (like action)

otherwise you are executing addingStats every time when player click on item to see description "onLook"

correct example:
action:
player:setLevel(300)

onLook
player:getLevel() -- will return 300

so u should set addStat to onEquipedItem function, then read in onLook if item that player click has this stat so u can display the timer
but if its something like that you are using "gem" on item that shouldbe charged for lets say 30 minutes then u should set this "addStat" in that gem function
 
Last edited:
Back
Top