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

Solved Decay item after 1 hour, given from npc

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,793
Solutions
581
Reaction score
5,357
Code:
The Forgotten Server, version 0.3.7_SVN (Crying Damson)
Inside my npc, I have the below script.
I originally had the item decay from items.xml, but when given from an npc or quest it did not decay.
So I've tried transforming the item given into a uniqueid, with a decay time, however the npc does not give the item at all!
Currently does nothing when you say 'blah' except give the player the message.
No error's in console when loading/reloading npc's.
No error when player says 'blah'.

Any idea's?

Thanks for any help, and as always,
I love you guys and gals. :p
Code:
if msgcontains(msg, "blah") then
       selfSay("Here is an item. It will expire in 1 hour.", cid)
         local time = 60
         function decay()
         local thing = doPlayerAddItem(cid, 6537, 1)
         doTransformItem(thing.uid, 1000)
         addEvent(decay,time*1000)
       end
end
 
Last edited:
Bump~
In case it's unclear, I want the item to decay to nothing, No matter if the item is on the floor, equipped, or in backpack.
It's alright if it stays when they are logged off, so I don't need to change the onlogin.
A similar item in tibia would be the icicle that 'melts' after 10 minutes.
http://tibia.wikia.com/wiki/Icicle_(Item)
Any help is appreciated! :)
 
In data/items/items.xml find your item and add this:
Code:
<attribute key="decayTo" value="0"/>
<attribute key="duration" value="3600"/>
This XML code will works only for items dropped from monsters or spawned on map. To enable XML decaying via LUA you have to add this little part:
Code:
local thing = doPlayerAddItem(cid, 6537, 1)
doDecayItem(thing.uid)
You don't need any addEvents.
 
Thank you! I was getting so confused. Been trying for close to six days getting this to work! :p
 
In data/items/items.xml find your item and add this:
Code:
<attribute key="decayTo" value="0"/>
<attribute key="duration" value="3600"/>
This XML code will works only for items dropped from monsters or spawned on map. To enable XML decaying via LUA you have to add this little part:
Code:
local thing = doPlayerAddItem(cid, 6537, 1)
doDecayItem(thing.uid)
You don't need any addEvents.
I was kind of premature in saying it was solved!
It seems doing it this way is having problem with lib, npchandler.
I've tried a few things on my own, however I'm really having no luck at the moment.
I've stripped everything down to 'barebones' to make everything easier to solve.
Once again, thank you for all the help!
-- small edit -- When the server is restarted, the item's duration will start counting down. However any new item's given from the npc will not countdown, until once again the server is restarted? Maybe I'm using the function wrong :/
-- second small edit -- If a player re-log's it also starts the timer. :p

errors in console
in-game text and item
Items.xml
currentNPC.lua
npchandler.lua -- via pastebin
Code:
[7:33:40.459] [Error - NpcScript Interface]
[7:33:40.460] data/npc/scripts/CarlsQuests/currentNPC.lua:onCreatureSay
[7:33:40.460] Description:
[7:33:40.461] data/npc/scripts/CarlsQuests/currentNPC.lua:22: attempt to index local
'thing' (a number value)
[7:33:40.461] stack traceback:
[7:33:40.461]   data/npc/scripts/CarlsQuests/currentNPC.lua:22: in function 'callback
'
[7:33:40.461]   data/npc/lib/npcsystem/npchandler.lua:455: in function 'onCreatu
reSay'
[7:33:40.462]   data/npc/scripts/CarlsQuests/currentNPC.lua:8: in function <data/npc/
scripts/CarlsQuests/currentNPC.lua:8>
Code:
07:33 Xikini [17]: keyword
07:33 Red Petal Lips: I will give you the item.

07:39 You see a handcuffs that will expire in 1 minute.
It weighs 2.00 oz.
ItemID: [6537].
DecayTo: [0].
Position: [X: 1623] [Y: 1253] [Z: 7].
Code:
    <item id="6537" article="a" name="handcuffs">
        <attribute key="decayTo" value="0"/>
        <attribute key="duration" value="60"/>
        <attribute key="showduration" value="1"/>
        <attribute key="manaGain" value="50"/>
        <attribute key="manaTicks" value="1000"/>
        <attribute key="healthGain" value="50"/>
        <attribute key="healthTicks" value="1000"/>
        <attribute key="increasehealingpercent" value="200"/>
        <attribute key="magiclevelPercent" value="115"/>
        <attribute key="maxManaPercent" value="125"/>
        <attribute key="skillShield" value="40"/>
        <attribute key="speed" value="20"/>
        <attribute key="maxHealthPercent" value="125"/>
        <attribute key="skillSword" value="15"/>
        <attribute key="SkillAxe" value="15"/>
        <attribute key="skillClub" value="15"/>
        <attribute key="skillFist" value="15"/>
        <attribute key="skillDist" value="15"/>
        <attribute key="slotType" value="ring"/>
        <attribute key="weight" value="200"/>
    </item>
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid


        if msgcontains(msg, "keyword") then
            selfSay("I will give you the item.", cid)
            local thing = doPlayerAddItem(cid, 6537, 1)
            doDecayItem(thing.uid) -- I have also tried doDecayItem(thing.uid, 1000), both have same effect

        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Code:
if(callback ~= nil and callback(cid, class, msg)) then -- LINE 455
Code:
NPChandler.lua http://pastebin.com/QNVtJhk4
 
Last edited:
finally! thanks help me!!!, only one thing i wand to add a item and money require to give you the item its possible? i try to add but i got a bug xD

EDIT:

i make it works, only the problem are remove item and money just remove the money hehehe here are the code



Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 onSay(cid, words, param) end

function creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end

         local thing = 0

    if(getPlayerItemCount(cid, 2006) == 1) then
        doPlayerRemoveItem(cid, 2006, 1)
         doPlayerRemoveMoney(cid, 20000)
        thing = thing + 1
    end
    if(thing == 0) then
            selfSay("You dont have a Empty Vial!.", cid)
        return true
    end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid


        if msgcontains(msg, "firebug") then
            selfSay("I will give you the item.", cid)
            local thing = doPlayerAddItem(cid, 5468, 1)
            doDecayItem(thing) -- I have also tried doDecayItem(thing.uid, 1000), both have same effect

        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
finally! thanks help me!!!, only one thing i wand to add a item and money require to give you the item its possible? i try to add but i got a bug xD

EDIT:

i make it works, only the problem are remove item and money just remove the money hehehe here are the code

EDIT 2: Solved Thanks a lot!!!
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 onSay(cid, words, param) end

function creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end

         local thing = 0

    if(getPlayerItemCount(cid, 2006) == 1) then
        doPlayerRemoveItem(cid, 2006, 1)
         doPlayerRemoveMoney(cid, 20000)
        thing = thing + 1
    end
    if(thing == 0) then
            selfSay("You dont have a Empty Vial!.", cid)
        return true
    end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid


        if msgcontains(msg, "firebug") then
            selfSay("I will give you the item.", cid)
            local thing = doPlayerAddItem(cid, 5468, 1)
            doDecayItem(thing) -- I have also tried doDecayItem(thing.uid, 1000), both have same effect

        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top