TFS 0.X How to add temporally a item atribute

Discussion in 'Support' started by runsicky, Apr 19, 2018.

  1. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
    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: Apr 20, 2018
    Nikesio and supergt like this.
  2. jestem pro

    jestem pro That is the question

    Joined:
    Apr 20, 2013
    Messages:
    535
    Likes Received:
    58
    Best Answers:
    9
    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.
     
    runsicky likes this.
  3. bepokemon

    bepokemon New Member

    Joined:
    May 16, 2011
    Messages:
    28
    Likes Received:
    6
    Best Answers:
    0
    You can try to set attribute with os.time()
    Code (Lua):
    1. doItemSetAttribute(item.uid, "BonusSpeed", os.time() + 60 * 60 * 20)
    And onLogin() or onMove()
    Code (Lua):
    1. if getItemAttribute(item.uid, "BonusSpeed") and type(getItemAttribute(item.uid, "BonusSpeed") ) == "number" and getItemAttribute(item.uid, "BonusSpeed")  > os.time() then
    2. -- add speed
    3. end
     
    supergt, runsicky and warriorfrog like this.
  4. warriorfrog

    warriorfrog Member

    Joined:
    Jul 29, 2015
    Messages:
    243
    Likes Received:
    16
    Best Answers:
    0
    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?
     
    supergt and runsicky like this.
  5. bepokemon

    bepokemon New Member

    Joined:
    May 16, 2011
    Messages:
    28
    Likes Received:
    6
    Best Answers:
    0
    I think it's best if you use onLook()

    Code (Lua):
    1. function onLook(cid, thing, position, lookDistance)
    2. local itemInfo = getItemInfo(thing.itemid)
    3. 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
    4. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, itemInfo.description .. "\nTemporally faster.") -- You can add the speed bonus or time left here
    5. return false
    6. end
    7. return true
    8. end
     
    supergt and runsicky like this.
  6. bepokemon

    bepokemon New Member

    Joined:
    May 16, 2011
    Messages:
    28
    Likes Received:
    6
    Best Answers:
    0
    I don't know if onLook and getItemInfo are avaiable in all distros, tho.
     
    runsicky likes this.
  7. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
    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 (Text):
    1.  
    2.         -- swiftness
    3.         elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
    4.                 local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
    5.                 local recipient_itemid = 11219 -- compasses
    6.                 local recipient_neededammount = 25
    7.                 if(getPlayerItemCount(cid,recipient_itemid,recipient_neededammount)) then
    8.                         doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
    9.                         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
    10.                         npcHandler:say('Your item was imbuemented successfully', cid)
    11.                         doItemSetAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)
    12.                 end
    13.                 else
    14.                         npcHandler:say('You do not have items enoght to make a Imbuement', cid)
    15.                 end
    16.  
    Printing this error:
    Code (Text):
    1.  
    2. [13:53:16.693] [Error - NpcScript Interface]
    3. [13:53:16.693] data/npc/scripts/npc_imbuements.lua:onCreatureSay
    4. [13:53:16.693] Description:
    5. [13:53:16.693] (luaDoItemSetAttribute) Item not found
    6.  
    2- On Equip add the atribute is not working:
    Movemments.xml
    Code (Text):
    1.  
    2.     <!-- imbuements -->
    3.    <movevent type="Equip" event="function" value="movemment_imbuements.lua"/>
    4.    <movevent type="DeEquip" event="function" value="movemment_imbuements.lua"/>
    5.  
    Movemment.lua
    Code (Text):
    1.  
    2. local speed_IB_storage = 700
    3.  
    4.  
    5. function onEquip(cid, item, slot)
    6.    local ibID = getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid
    7.    -- bonus speed
    8.    if getItemAttribute(ibID, "BonusSpeed") and getItemAttribute(ibID, "BonusSpeed")  > os.time() then
    9.        if getPlayerStorageValue(cid, speed_IB_storage) < 1 then
    10.            doChangeSpeed(cid, getCreatureSpeed(cid) + 10)
    11.            setPlayerStorageValue(cid, speed_IB_storage, 1)
    12.        end
    13.    -- bonus axe
    14.    elseif getItemAttribute(ibID, "BonusAxe") and getItemAttribute(ibID, "BonusAxe")  > os.time() then
    15.    
    16.    end
    17.    return true
    18. end
    19.  
    20. function onDeEquip(cid, item, slot)
    21.    if slot == CONST_SLOT_FEET then
    22.        if getPlayerStorageValue(cid, speed_IB_storage) > 0 then
    23.           doChangeSpeed(cid, getCreatureSpeed(cid) - 10)
    24.        end
    25.    end
    26.    return true
    27. end
    28.  
    Error:
    Code (Text):
    1.  
    2. [13:50:07.179] [Warning - MoveEvent::loadFunction] Function "movemment_imbuements.lua" does not exist.
    3. [13:50:07.179] [Warning - MoveEvent::loadFunction] Function "movemment_imbuements.lua" does not exist.
    4.  
     
    supergt likes this.
  8. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
  9. jestem pro

    jestem pro That is the question

    Joined:
    Apr 20, 2013
    Messages:
    535
    Likes Received:
    58
    Best Answers:
    9
    At the first, use
    Code (Lua):
    1. doSetItemAttribute
    At the second, you called wrong the files. In movements.xml there is movement_imbuements.lua but you have movemment.lua .....
     
    supergt likes this.
  10. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
    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
     
  11. jestem pro

    jestem pro That is the question

    Joined:
    Apr 20, 2013
    Messages:
    535
    Likes Received:
    58
    Best Answers:
    9
    You have incorrect function in line 11 in NPC file
    Code (Lua):
    1. 11.   doItemSetAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)
    Should be doSetItemAttribute
     
    supergt likes this.
  12. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
    Code (Text):
    1.  
    2. [2:36:22.654] [Error - NpcScript Interface]
    3. [2:36:22.654] data/npc/scripts/npc_imbuements.lua:onCreatureSay
    4. [2:36:22.654] Description:
    5. [2:36:22.654] data/npc/scripts/npc_imbuements.lua:120: attempt to call global 'doSetItemAttribute' (a nil value)
    6. [2:36:22.654] stack traceback:
    7. [2:36:22.655]    data/npc/scripts/npc_imbuements.lua:120: in function 'callback'
    8. [2:36:22.655]    data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
    9. [2:36:22.655]    data/npc/scripts/npc_imbuements.lua:14: in function <data/npc/scripts/npc_imbuements.lua:14>
    10.  
     
  13. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
  14. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
  15. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
  16. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
  17. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
  18. Sarah Wesker

    Sarah Wesker ค∂vαηcε รүηтαx ❤

    Joined:
    Mar 16, 2017
    Messages:
    313
    Likes Received:
    142
    Best Answers:
    22
    ERROR in
    Code (Text):
    1.  event="function"
    is
    Code (Text):
    1. event="script"
     
    supergt and runsicky like this.
  19. Stigma

    Stigma Support Team Support Team

    Joined:
    Feb 14, 2015
    Messages:
    4,225
    Likes Received:
    1,972
    Best Answers:
    341
    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:
    Code (Lua):
    1. local boots = getPlayerSlotItem(cid, CONST_SLOT_FEET)
    2. if boots then
    3.     local ibID = boots.uid
    4.     -- the rest of your code here
    5. 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
     
    supergt and runsicky like this.
  20. runsicky

    runsicky New Member

    Joined:
    Apr 19, 2018
    Messages:
    22
    Likes Received:
    9
    Best Answers:
    0
    @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 (Text):
    1.  
    2. --[[
    3.         CONST_SLOT_FIRST = 1
    4.         CONST_SLOT_HEAD = CONST_SLOT_FIRST
    5.         CONST_SLOT_NECKLACE = 2
    6.         CONST_SLOT_BACKPACK = 3
    7.         CONST_SLOT_ARMOR = 4
    8.         CONST_SLOT_RIGHT = 5
    9.         CONST_SLOT_LEFT = 6
    10.         CONST_SLOT_LEGS = 7
    11.         CONST_SLOT_FEET = 8
    12.         CONST_SLOT_RING = 9
    13.         CONST_SLOT_AMMO = 10
    14.         CONST_SLOT_LAST = CONST_SLOT_AMMO
    15. ]]
    16.  
    17. local keywordHandler = KeywordHandler:new()
    18. local npcHandler = NpcHandler:new(keywordHandler)
    19. NpcSystem.parseParameters(npcHandler)
    20. local Topic, Description = {}, {}
    21. local thinkMsg = {
    22.         "I can personalise your items, come to me!",
    23.         "Want to upgrade your items temporarily? Come to me!"
    24. }
    25.  
    26. function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid) end
    27. function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
    28. function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg) end
    29. function onThink()                      npcHandler:onThink() end
    30.  
    31. function greetCallback(cid)
    32.         Topic[cid], Description[cid] = 1, nil
    33.         return true
    34. end
    35. function creatureSayCallback(cid, type, msg)
    36.         if not npcHandler:isFocused(cid) then
    37.                 return false
    38.         elseif (Topic[cid] == 1) and (msgcontains(msg, 'yes') or msgcontains(msg, 'imbuement') or msgcontains(msg, 'imbuements')) then
    39.                 npcHandler:say('Choose the imbuements type: {swiftness}', cid)
    40.                 Topic[cid] = 2
    41.        
    42.  
    43.  
    44.         elseif Topic[cid] == 2 and msgcontains(msg, 'swiftness') then
    45.                 npcHandler:say('What kinda of weapon you want to upgrade? {boots}', cid)
    46.                 Topic[cid] = 17
    47.  
    48.  
    49.         -- swiftness
    50.         elseif Topic[cid] == 17 and msgcontains(msg, 'boots') then
    51.                 local slot = getPlayerSlotItem(cid, CONST_SLOT_FEET)
    52.                 print(slot)
    53.                 if slot then
    54.                         npcHandler:say('You do not have the equipament in the slot you select.')  
    55.                         return true
    56.                 end
    57.                 local ibID = slot.uid
    58.                 local recipient_itemid = 11219 -- compasses
    59.                 local recipient_neededammount = 25
    60.  
    61.  
    62.                 if(getPlayerItemCount(cid,recipient_itemid,recipient_neededammount)) then
    63.                         doPlayerRemoveItem(cid,recipient_itemid,recipient_neededammount)
    64.                         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
    65.                         npcHandler:say('Your item was imbuemented successfully', cid)                      
    66.                         doSetItemAttribute(ibID, "BonusSpeed", os.time() + 60 * 60 * 20)
    67.                 end
    68.                 else
    69.                         npcHandler:say('You do not have items enoght to make a Imbuement', cid)
    70.                 end
    71.  
    72.  
    73.  
    74.         return true
    75. end
    76. npcHandler:setMessage(MESSAGE_FAREWELL, 'I hope you made the right choice, have a wonderful day.')
    77. 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...')
    78. 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?')
    79. npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
    80. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
    81. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    82. npcHandler:addModule(FocusModule:new())
    83.  
    And it's printing nothing...
    And not working...

    Do i doing something wrong?
     
    supergt likes this.

Share This Page

Loading...