• 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 Imbuements System to 8.60 [0.4]

runsicky

Member
Joined
Apr 19, 2018
Messages
80
Reaction score
12
Like lot other ppl i love this new imbuements from new tibia, but i also like i lot ppl, i love the 8.6
Here on forum i discovery it would be able to get all together (thank you xikini): the imbuements system on a 8.6 server

I have something working, but there are two problems
1) How to convert that time 1565493648 to a something usefull to the users like that has imbuements for 239 minutes left.
Code:
04:20 You see steel boots (Arm:5). It can only be wielded properly by knights. It weighs 29.00 oz.
It can only be wielded properly by knights.
It weighs 29.00 oz.
swiftness,1565493648

Code:
04:22 You see a pair of soft boots (Arm:1) that has energy for 239 minutes left.

2) There is a bug, if i relog with a enchanted boots, with more 500 speed
And remove the boots, the character speed just bug

How to fix it?

Scripts so far:
movemments
Code:
-- credits @Xikini / @StreamSide
local feet_IB_storage = 700
local legs_IB_storage = 701
local armour_IB_storage = 702
local head_IB_storage = 703
local boots_IB_storage = 704
local atkweapon_IB_storage = 705
local defweapon_IB_storage = 706

function onEquip(cid, item, slot)
   print("player equip an item")
   local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid

    local itemString = getItemSpecialDescription(item.uid)
    local one, two = itemString:match("([^,]+),([^,]+)")
    print(one)
    print(two)

   -- bonus speed
   if one == "swiftness" and two + 0 > os.time() then
       if getPlayerStorageValue(cid, feet_IB_storage) < 1 then
           doChangeSpeed(cid, getCreatureSpeed(cid) + 500)
           setPlayerStorageValue(cid, feet_IB_storage, 1)
           print("ENCHANTED ITEM EQUIPED")
       end
   --elseif others
   end
   return true
end

function onDeEquip(cid, item, slot)
   if slot == CONST_SLOT_FEET then
       if getPlayerStorageValue(cid, feet_IB_storage) > 0 then
          doChangeSpeed(cid, getCreatureSpeed(cid) - 500)
          print("ENCHANTED ITEM UNEQUIPED")
       end
   end
   return true
end


npc
Code:
--[[
        CONST_SLOT_FIRST = 1
        CONST_SLOT_HEAD = CONST_SLOT_FIRST
        CONST_SLOT_NECKLACE = 2
        CONST_SLOT_BACKPACK = 3
        CONST_SLOT_ARMOR = 4
        CONST_SLOT_RIGHT = 5
        CONST_SLOT_LEFT = 6
        CONST_SLOT_LEGS = 7
        CONST_SLOT_FEET = 8
        CONST_SLOT_RING = 9
        CONST_SLOT_AMMO = 10
        CONST_SLOT_LAST = CONST_SLOT_AMMO
]]

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic, Description = {}, {}

local thinkMsg = {
        "I can personalise your items, come to me!",
        "Want to upgrade your items temporarily? Come to me!"
}

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                      npcHandler:onThink() end

function greetCallback(cid)
        Topic[cid], Description[cid] = 1, nil
        return true
end

function creatureSayCallback(cid, type, msg)
        if not npcHandler:isFocused(cid) then
                return false
        elseif (Topic[cid] == 1) and (msgcontains(msg, 'yes') or msgcontains(msg, 'imbuement') or msgcontains(msg, 'imbuements')) then
                npcHandler:say('Choose the imbuements type: {swiftness}', cid)
                Topic[cid] = 2
       


        elseif Topic[cid] == 2 and msgcontains(msg, 'swiftness') then
                npcHandler:say('What kinda of weapon you want to upgrade? {boots}', cid)
                Topic[cid] = 17

        -- swiftness
        elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
                local ib_UID = getPlayerSlotItem(cid, CONST_SLOT_FEET).uid
                -- HOW TO CHECK IF PLAYER IS USING A BOOTS?
                local recipient_itemid = 11219 -- compasses
                local recipient_neededammount = 25
                if(getPlayerItemCount(cid, recipient_itemid) >= recipient_neededammount) then
                        doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
                        npcHandler:say('Here you are. May I help you with something else? ', cid)
                        local hours = 60 * 60
                        local time = 20 * hours
                        doSetItemSpecialDescription(ib_UID, "swiftness," .. (os.time() + time) .. "")
                        Topic[cid] = 1
                else
                        npcHandler:say('You do not have the recipients enoght to make the Imbuement! May I help you with something else?', cid)
                        Topic[cid] = 1
                end
        end
        return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'I hope you made the right choice, have a wonderful day.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Okay well, I guess you don\'t care if someone steals your stuff... You will have no idea if it\'s yours...')
npcHandler:setMessage(MESSAGE_GREET, 'Hello, |PLAYERNAME|! I am a brander. I can personalize any of your items for a price, would you like to continue to the next step?')

npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Code:
attempt to compare number with string
Lua:
if one == "swiftness" and two > 1 then
two > 1, two is a string, 1 is a number
use tonumber(two) > 1
for the boots thing you can create a login and logout event on creaturescripts to remove/add stuff currectly once the guy relog, dunno about the storage becoming something usefull tho, I'm interested in that answer too
 
You can get the number of minutes by subtracting the endtime from os.time() and dividing by 60 to get minutes, since os.time() is the clock's time in seconds.
 
@Stigmawould can you show me a lign like
Code:
setPlayerStorageValue (cid, config.storage, config.timeForUse * 60 * 60 + os.time())
but being a get and returning in minutes?
I just tried
Lua:
doPlayerSendTextMessage (cid, 19, "tempo da cave 1: ".. ((getPlayerStorageValue(cid, 789456)+os.time())/60) .. "")
and got
Code:
tempo da cave 1: 52225714.516667
what is this endtime I need to subtract?

Edit:
nvm, just managed to get it to work, the code is
Lua:
local thing = getPlayerStorageValue(cid, 789456) --* 4 * 60 * 60
        doPlayerSendTextMessage (cid, 19, "tempo da cave 1: ".. ((thing - os.time())/60) .. "")
It will return the minutes and a lot of miliseconds, I don't know how to ignore those not integer numers in lua. if anyone knows it would help a lot !
 
Last edited:
You can use this function:
Lua:
os.date(format: string[, time])
per example that:
Lua:
os.date('%H:%M:%S', os.time() - 20)
This way it will show you the time in a human format, 20 seconds ago.

<< os.time() - 20 >> You can replace this with the seconds stored in the article to show the expiration date.
 
yeah thank you for the answers but I also managed to make it work! any idea how I can ignore those broken numbers like
Code:
17:24 tempo da cave 1: 232.66666666667
I want to print only 'til the 232, I'm using this code
Lua:
local thing = getPlayerStorageValue(cid, 789456) --* 4 * 60 * 60
doPlayerSendTextMessage (cid, 19, "tempo da cave 1: ".. ((thing - os.time())/60) .. "")
I knew how to print only the integer part of a number in C and Java but it's been a long time since I had the need to do such a thing and I don't know much of lua

Edit: just managed to do it using math.floor, this is the code:
Lua:
math.floor(((thing - os.time())/60))
thank you all guys
 
Last edited:
Truncate:
Lua:
math.floor((thing - os.time())/60) -- 232
Rounding:
Lua:
math.floor(((thing - os.time())/60) + 0.5) -- 233
Decimal (2 places)
Lua:
string.format("%.2f", (thing - os.time())/60) -- 232.66
 
But the description is only changed on player talk to the NPC
Code:
                if(getPlayerItemCount(cid, recipient_itemid) >= recipient_neededammount) then
                        doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
                        npcHandler:say('Here you are. May I help you with something else? ', cid)
                        local hours = 60 * 60
                        local time = 20 * hours
                        doSetItemSpecialDescription(ib_UID, "swiftness," .. (os.time() + time) .. "")
                        Topic[cid] = 1

I could do something like:
Code:
                if(getPlayerItemCount(cid, recipient_itemid) >= recipient_neededammount) then
                        doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
                        npcHandler:say('Here you are. May I help you with something else? ', cid)
                        local hours = 60 * 60
                        local time = 20 * hours
                        local humantime = os.date('%H:%M:%S', (os.time() + time))
                        doSetItemSpecialDescription(ib_UID, "swiftness," .. (humantime) .. "")
                        Topic[cid] = 1
(is it right?)

But it would be static...
How to somehow each sometime check the players equips to adjust the time until remove the description?

On this slots:
Code:
        CONST_SLOT_NECKLACE = 2
        CONST_SLOT_BACKPACK = 3
        CONST_SLOT_ARMOR = 4
        CONST_SLOT_RIGHT = 5
        CONST_SLOT_LEFT = 6
        CONST_SLOT_LEGS = 7
        CONST_SLOT_FEET = 8

I think if it is possible to check with sometime movements script would be unnecessary...
Right?
 
You can use this function:
Lua:
os.date(format: string[, time])
per example that:
Lua:
os.date('%H:%M:%S', os.time() - 20)
This way it will show you the time in a human format, 20 seconds ago.

<< os.time() - 20 >> You can replace this with the seconds stored in the article to show the expiration date.

@Sarah Wesker
it shouldnt be 20:00:00?

Code:
        -- swiftness
        elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
                local ib_UID = getPlayerSlotItem(cid, CONST_SLOT_FEET).uid
                -- HOW TO CHECK IF PLAYER IS USING A BOOTS?
                local recipient_itemid = 11219 -- compasses
                local recipient_neededammount = 25
                if(getPlayerItemCount(cid, recipient_itemid) >= recipient_neededammount) then
                        doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
                        npcHandler:say('Here you are. May I help you with something else? ', cid)
                        local hours = 60 * 60
                        local time = 20 * hours
                        local humantime = os.date('%H:%M:%S', (os.time() + time))
                        doSetItemSpecialDescription(ib_UID, "swiftness," .. (humantime) .. "")
                        Topic[cid] = 1
                else
                        npcHandler:say('You do not have the recipients enoght to make the Imbuement! May I help you with something else?', cid)
                        Topic[cid] = 1
                end
        end

Code:
16:26 You see steel boots (Arm:5). It can only be wielded properly by knights. It weighs 29.00 oz. swiftness,12:25:50 ItemID: [2645].
 
Yes, you converted this to daytime.. 12:25:50.
To solve this, you need to use a custom attribute on the item to calculate the timeleft and update the description with that time.

PS: the fault in your code is here:
Lua:
local hours = 60 * 60
local time = 20 * hours
local humantime = os.date('%H:%M:%S', (os.time() + time))
doSetItemSpecialDescription(ib_UID, "swiftness," .. (humantime) .. "")

Sincerely,
Slavi
 
Yes, you converted this to daytime.. 12:25:50.
To solve this, you need to use a custom attribute on the item to calculate the timeleft and update the description with that time.

PS: the fault in your code is here:
Lua:
local hours = 60 * 60
local time = 20 * hours
local humantime = os.date('%H:%M:%S', (os.time() + time))
doSetItemSpecialDescription(ib_UID, "swiftness," .. (humantime) .. "")

Sincerely,
Slavi

But my ask is just about it....

Why
Code:
os.time() + time)

Returning 12:25:50 instead of 20:00:00
os.time isnt the time now?
time now + 60 * 60 * 20 should works right?
 
Getting your ideas and my limited knowlged, i tried to do in this way
npc add minutes to enchanted items and a globalevent run each min to control all stuff

But i was not able to make it work, so i need some help...


There are two things that is not working how should work


1- the minutes are returning 56 instead of 1200 (60min * 20hours)
Code:
19:56 You see leather boots (Arm:3).
It weighs 9.00 oz.
swiftness,56

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic, Description = {}, {}
 
local thinkMsg = {
        "I can personalise your items, come to me!",
        "Want to upgrade your items temporarily? Come to me!"
}

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                      npcHandler:onThink() end

function greetCallback(cid)
        Topic[cid], Description[cid] = 1, nil
        return true
end
 
function creatureSayCallback(cid, type, msg)
        if not npcHandler:isFocused(cid) then
                return false
        elseif (Topic[cid] == 1) and (msgcontains(msg, 'yes') or msgcontains(msg, 'imbuement') or msgcontains(msg, 'imbuements')) then
                npcHandler:say('Choose the imbuements type: {swiftness}', cid)
                Topic[cid] = 2
        


        elseif Topic[cid] == 2 and msgcontains(msg, 'swiftness') then
                npcHandler:say('What kinda of weapon you want to upgrade? {boots}', cid)
                Topic[cid] = 17

        -- swiftness
        elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
                local ib_UID = getPlayerSlotItem(cid, CONST_SLOT_FEET).uid
                -- HOW TO CHECK IF PLAYER IS USING A BOOTS?
                local recipient_itemid = 11219 -- compasses
                local recipient_neededammount = 25
                if(getPlayerItemCount(cid, recipient_itemid) >= recipient_neededammount) then
                        doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
                        npcHandler:say('Here you are. May I help you with something else? ', cid)
                        local hours = 60 * 60
                        local time = 20 * hours
                        local humantime = os.date('%M', (os.time() + time))
                        doSetItemSpecialDescription(ib_UID, "swiftness," .. (humantime) .. "")
                        Topic[cid] = 1
                else
                        npcHandler:say('You do not have the recipients enoght to make the Imbuement! May I help you with something else?', cid)
                        Topic[cid] = 1
                end
        end
        return true
end
 
npcHandler:setMessage(MESSAGE_FAREWELL, 'I hope you made the right choice, have a wonderful day.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Okay well, I guess you don\'t care if someone steals your stuff... You will have no idea if it\'s yours...')
npcHandler:setMessage(MESSAGE_GREET, 'Hello, |PLAYERNAME|! I am a brander. I can personalize any of your items for a price, would you like to continue to the next step?')
 
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



2- Tried a globalevent to adjust items enchanteds

An error was print on console:
Code:
[19:56:17.548] [Error - GlobalEvent Interface] 
[19:56:17.548] data/globalevents/scripts/imbu_globalevents.lua:onThink
[19:56:17.548] Description: 
[19:56:17.548] data/globalevents/scripts/imbu_globalevents.lua:21: attempt to compare number with string
[19:56:17.548] stack traceback:
[19:56:17.548]     data/globalevents/scripts/imbu_globalevents.lua:21: in function <data/globalevents/scripts/imbu_globalevents.lua:10>
[19:56:17.548] [Error - GlobalEvents::think] Couldn't execute event: imbu_globalevents


Code:
<globalevent name="imbu_globalevents" interval="60000" script="imbu_globalevents.lua" />

imbu_globalevents.lua
Code:
-- credits @Xikini / @StreamSide
local feet_IB_storage = 700
local legs_IB_storage = 701
local armour_IB_storage = 702
local head_IB_storage = 703
local boots_IB_storage = 704
local atkweapon_IB_storage = 705
local defweapon_IB_storage = 706

function onThink(interval, lastExecution)
    for _, cid in ipairs(getPlayersOnline()) do



       -- ======================= BOOTS =======================
       local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
       local ib_UID = getPlayerSlotItem(cid, CONST_SLOT_FEET).uid
       local itemString = getItemSpecialDescription(ib_UID)
       local one, two = itemString:match("([^,]+),([^,]+)")
       -- swiftness on
       if one == "swiftness" and two > 1 then
              print(two)
           two = two - 1
           doSetItemSpecialDescription(ib_UID, "swiftness," .. (two) .. "")

           if getPlayerStorageValue(cid, feet_IB_storage) < 1 then
               doChangeSpeed(cid, getCreatureSpeed(cid) + 500)
               setPlayerStorageValue(cid, feet_IB_storage, 1)
               print("swiftness on")
           end
       elseif one == "swiftness" or two <= 0 then
           -- time over
           if one == "swiftness" and two <= 0 then
               doRemoveItemSpecialDescription(ib_UID)
           end
           -- swiftness bonus off
           if getPlayerStorageValue(cid, feet_IB_storage) == 1 then
           doChangeSpeed(cid, getCreatureSpeed(cid) - 500)
           setPlayerStorageValue(cid, feet_IB_storage, 0)
           print("swiftness off")
           end
       end
       




       return true
    end
    return true
end
 
Code:
attempt to compare number with string
Lua:
if one == "swiftness" and two > 1 then
two > 1, two is a string, 1 is a number
use tonumber(two) > 1
 
Solution
Code:
attempt to compare number with string
Lua:
if one == "swiftness" and two > 1 then
two > 1, two is a string, 1 is a number
use tonumber(two) > 1

oh man, thank you so much!

i think there is only that minutes problem

1- the minutes are returning 56 instead of 1200 (60min * 20hours)

did u know why?

1- the minutes are returning 56 instead of 1200 (60min * 20hours)
Code:
19:56 You see leather boots (Arm:3).
It weighs 9.00 oz.
swiftness,56

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic, Description = {}, {}

local thinkMsg = {
        "I can personalise your items, come to me!",
        "Want to upgrade your items temporarily? Come to me!"
}

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                      npcHandler:onThink() end

function greetCallback(cid)
        Topic[cid], Description[cid] = 1, nil
        return true
end

function creatureSayCallback(cid, type, msg)
        if not npcHandler:isFocused(cid) then
                return false
        elseif (Topic[cid] == 1) and (msgcontains(msg, 'yes') or msgcontains(msg, 'imbuement') or msgcontains(msg, 'imbuements')) then
                npcHandler:say('Choose the imbuements type: {swiftness}', cid)
                Topic[cid] = 2
       


        elseif Topic[cid] == 2 and msgcontains(msg, 'swiftness') then
                npcHandler:say('What kinda of weapon you want to upgrade? {boots}', cid)
                Topic[cid] = 17

        -- swiftness
        elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
                local ib_UID = getPlayerSlotItem(cid, CONST_SLOT_FEET).uid
                -- HOW TO CHECK IF PLAYER IS USING A BOOTS?
                local recipient_itemid = 11219 -- compasses
                local recipient_neededammount = 25
                if(getPlayerItemCount(cid, recipient_itemid) >= recipient_neededammount) then
                        doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
                        npcHandler:say('Here you are. May I help you with something else? ', cid)
                        local hours = 60 * 60
                        local time = 20 * hours
                        local humantime = os.date('%M', (os.time() + time))
                        doSetItemSpecialDescription(ib_UID, "swiftness," .. (humantime) .. "")
                        Topic[cid] = 1
                else
                        npcHandler:say('You do not have the recipients enoght to make the Imbuement! May I help you with something else?', cid)
                        Topic[cid] = 1
                end
        end
        return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'I hope you made the right choice, have a wonderful day.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Okay well, I guess you don\'t care if someone steals your stuff... You will have no idea if it\'s yours...')
npcHandler:setMessage(MESSAGE_GREET, 'Hello, |PLAYERNAME|! I am a brander. I can personalize any of your items for a price, would you like to continue to the next step?')

npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top