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

TFS 0.X How to add temporally a item atribute

runsicky

Member
Joined
Apr 19, 2018
Messages
80
Reaction score
12
I wanna do a system like Imbuements but on 8.60 server (0.4)

But i'm stuck in a thing...
How to add a temporally atribute to a item?

For example:
local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid

How to add +10 speed for the item ibID for 20 hours?

bump
 
Last edited by a moderator:
via exhaustion.set (cid , storage, time)

and check it when a player log in, set the speed.

We can think of how to do it by source, what would be more optimal.

via items.xml attributes and duration.
 
You can try to set attribute with os.time()
Lua:
doItemSetAttribute(item.uid, "BonusSpeed", os.time() + 60 * 60 * 20)

And onLogin() or onMove()
Lua:
if getItemAttribute(item.uid, "BonusSpeed") and type(getItemAttribute(item.uid, "BonusSpeed") ) == "number" and getItemAttribute(item.uid, "BonusSpeed")  > os.time() then
-- add speed
end
 
You can try to set attribute with os.time()
Lua:
doItemSetAttribute(item.uid, "BonusSpeed", os.time() + 60 * 60 * 20)

And onLogin() or onMove()
Lua:
if getItemAttribute(item.uid, "BonusSpeed") and type(getItemAttribute(item.uid, "BonusSpeed") ) == "number" and getItemAttribute(item.uid, "BonusSpeed")  > os.time() then
-- add speed
end

Using your way...
How to add a item description temporally?
doItemSetAttribute(ibID, 'description', '[Imbuement: Speed]' .. (desc == '' and '' or '\n' .. desc))

And after 20 hours it clean?
 
Using your way...
How to add a item description temporally?
doItemSetAttribute(ibID, 'description', '[Imbuement: Speed]' .. (desc == '' and '' or '\n' .. desc))

And after 20 hours it clean?

I think it's best if you use onLook()

Lua:
function onLook(cid, thing, position, lookDistance)
local itemInfo = getItemInfo(thing.itemid)
if thing.itemid == BOOTS_ITEMID and getItemAttribute(thing.uid, "BonusSpeed") and type(getItemAttribute(thing.uid, "BonusSpeed")) == "number" and getItemAttribute(thing.uid, "BonusSpeed") > os.time() then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, itemInfo.description .. "\nTemporally faster.") -- You can add the speed bonus or time left here
return false
end
return true
end
 
Thank you all who was helping here:

Sorry to this too long, I' was trying do by my way...
But i got some problems and I need some help:

1- NPC error on ibu
Code:
        -- swiftness
        elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
                local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
                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('Your item was imbuemented successfully', cid)
                        doItemSetAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)
                end
                else
                        npcHandler:say('You do not have items enoght to make a Imbuement', cid)
                end

Printing this error:
Code:
[13:53:16.693] [Error - NpcScript Interface]
[13:53:16.693] data/npc/scripts/npc_imbuements.lua:onCreatureSay
[13:53:16.693] Description:
[13:53:16.693] (luaDoItemSetAttribute) Item not found

2- On Equip add the atribute is not working:
Movemments.xml
Code:
    <!-- imbuements -->
   <movevent type="Equip" event="function" value="movemment_imbuements.lua"/>
   <movevent type="DeEquip" event="function" value="movemment_imbuements.lua"/>

Movemment.lua
Code:
local speed_IB_storage = 700


function onEquip(cid, item, slot)
   local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
   -- bonus speed
   if getItemAttribute(ibID, "BonusSpeed") and getItemAttribute(ibID, "BonusSpeed")  > os.time() then
       if getPlayerStorageValue(cid, speed_IB_storage) < 1 then
           doChangeSpeed(cid, getCreatureSpeed(cid) + 10)
           setPlayerStorageValue(cid, speed_IB_storage, 1)
       end
   -- bonus axe
   elseif getItemAttribute(ibID, "BonusAxe") and getItemAttribute(ibID, "BonusAxe")  > os.time() then
   
   end
   return true
end

function onDeEquip(cid, item, slot)
   if slot == CONST_SLOT_FEET then
       if getPlayerStorageValue(cid, speed_IB_storage) > 0 then
          doChangeSpeed(cid, getCreatureSpeed(cid) - 10)
       end
   end
   return true
end

Error:
Code:
[13:50:07.179] [Warning - MoveEvent::loadFunction] Function "movemment_imbuements.lua" does not exist.
[13:50:07.179] [Warning - MoveEvent::loadFunction] Function "movemment_imbuements.lua" does not exist.
 
At the first, use
Lua:
doSetItemAttribute

At the second, you called wrong the files. In movements.xml there is movement_imbuements.lua but you have movemment.lua .....
 
At the first, use
Lua:
doSetItemAttribute

At the second, you called wrong the files. In movements.xml there is movement_imbuements.lua but you have movemment.lua .....

First.. I'm sorry if sounds dumb, but what are u mean?

Second.. No that is the right file:

<!-- imbuements -->
<movevent type="Equip" event="function" value="movemment_imbuements.lua"/>
<movevent type="DeEquip" event="function" value="movemment_imbuements.lua"/>

file: movemment_imbuements.lua
 
First.. I'm sorry if sounds dumb, but what are u mean?

Second.. No that is the right file:

<!-- imbuements -->
<movevent type="Equip" event="function" value="movemment_imbuements.lua"/>
<movevent type="DeEquip" event="function" value="movemment_imbuements.lua"/>

file: movemment_imbuements.lua
You have incorrect function in line 11 in NPC file
Lua:
11.   doItemSetAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)

Should be doSetItemAttribute
 
Code:
[2:36:22.654] [Error - NpcScript Interface]
[2:36:22.654] data/npc/scripts/npc_imbuements.lua:onCreatureSay
[2:36:22.654] Description:
[2:36:22.654] data/npc/scripts/npc_imbuements.lua:120: attempt to call global 'doSetItemAttribute' (a nil value)
[2:36:22.654] stack traceback:
[2:36:22.655]    data/npc/scripts/npc_imbuements.lua:120: in function 'callback'
[2:36:22.655]    data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
[2:36:22.655]    data/npc/scripts/npc_imbuements.lua:14: in function <data/npc/scripts/npc_imbuements.lua:14>
 
You have incorrect function in line 11 in NPC file
Lua:
11.   doItemSetAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)

Should be doSetItemAttribute
no it's not, doItemSetAttribute is correct, the error he got was a uid being invalid resulting in it saying it couldn't find the item, it didn't say "attempt to call global nil value"

Thank you all who was helping here:

Sorry to this too long, I' was trying do by my way...
But i got some problems and I need some help:

1- NPC error on ibu
Code:
        -- swiftness
        elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
                local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
                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('Your item was imbuemented successfully', cid)
                        doItemSetAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)
                end
                else
                        npcHandler:say('You do not have items enoght to make a Imbuement', cid)
                end

Printing this error:
Code:
[13:53:16.693] [Error - NpcScript Interface]
[13:53:16.693] data/npc/scripts/npc_imbuements.lua:onCreatureSay
[13:53:16.693] Description:
[13:53:16.693] (luaDoItemSetAttribute) Item not found

2- On Equip add the atribute is not working:
Movemments.xml
Code:
    <!-- imbuements -->
   <movevent type="Equip" event="function" value="movemment_imbuements.lua"/>
   <movevent type="DeEquip" event="function" value="movemment_imbuements.lua"/>

Movemment.lua
Code:
local speed_IB_storage = 700


function onEquip(cid, item, slot)
   local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
   -- bonus speed
   if getItemAttribute(ibID, "BonusSpeed") and getItemAttribute(ibID, "BonusSpeed")  > os.time() then
       if getPlayerStorageValue(cid, speed_IB_storage) < 1 then
           doChangeSpeed(cid, getCreatureSpeed(cid) + 10)
           setPlayerStorageValue(cid, speed_IB_storage, 1)
       end
   -- bonus axe
   elseif getItemAttribute(ibID, "BonusAxe") and getItemAttribute(ibID, "BonusAxe")  > os.time() then
  
   end
   return true
end

function onDeEquip(cid, item, slot)
   if slot == CONST_SLOT_FEET then
       if getPlayerStorageValue(cid, speed_IB_storage) > 0 then
          doChangeSpeed(cid, getCreatureSpeed(cid) - 10)
       end
   end
   return true
end

Error:
Code:
[13:50:07.179] [Warning - MoveEvent::loadFunction] Function "movemment_imbuements.lua" does not exist.
[13:50:07.179] [Warning - MoveEvent::loadFunction] Function "movemment_imbuements.lua" does not exist.
ibID is an item id, not a unique id (which it needs to be a unique id for getItemAttribute to find the correct item)
you need to define ibID as:
Lua:
local boots = getPlayerSlotItem(cid, CONST_SLOT_FEET)
if boots then
    local ibID = boots.uid
    -- the rest of your code here
end
you must check if the item exists first in the feet slot and then get the unique id, afterwards you can continue on normally with the rest of your script
 
no it's not, doItemSetAttribute is correct, the error he got was a uid being invalid resulting in it saying it couldn't find the item, it didn't say "attempt to call global nil value"


ibID is an item id, not a unique id (which it needs to be a unique id for getItemAttribute to find the correct item)
you need to define ibID as:
Lua:
local boots = getPlayerSlotItem(cid, CONST_SLOT_FEET)
if boots then
    local ibID = boots.uid
    -- the rest of your code here
end
you must check if the item exists first in the feet slot and then get the unique id, afterwards you can continue on normally with the rest of your script

@Vulcan_ sorry this long, i thought no one would know how to do imbuements to 8.6 and i gave up moths ago...
I was playing a my local server with friends and we thought to add it again, so i saw your message...
Thank you to give me this try, but it not work at all...

I've tried this 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 slot = getPlayerSlotItem(cid, CONST_SLOT_FEET)
                print(slot)
                if slot then
                        npcHandler:say('You do not have the equipament in the slot you select.')   
                        return true
                end
                local ibID = slot.uid
                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('Your item was imbuemented successfully', cid)                       
                        doSetItemAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)
                end
                else
                        npcHandler:say('You do not have items enoght to make a Imbuement', cid)
                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())

And it's printing nothing...
And not working...

Do i doing something wrong?
 
Back
Top