• 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 TFS 0.2.15 I'm loosing my mind...

Fermantor

Active Member
Joined
Dec 16, 2009
Messages
209
Solutions
4
Reaction score
33
Location
Germany
Here is a part of my script... the important part. It's an action

pick.lua
Lua:
elseif itemEx.uid == 17104 then
     doTransformItem(itemEx.uid, 2249)
     addEvent(doTransformItem, 1000*5, itemEx.uid, 3615)
     doSendMagicEffect(toPosition, CONST_ME_POFF)
     return TRUE
elseif ...
The problem seems to be in this line
Code:
  addEvent(doTransformItem, 1000*5, itemEx.uid, 3615)
It always says, can't find Item() blablabla

I'm loosing my mind here, because in others scripts this addEvent() works, the only difference is, I'm using "itemEx" here instead of "item". I have tried everything, to find the error... writing the direct uid of the item, let me print the itemEx.uid and it is the right one, but he always tells me, he can't find the item.
Any ideas?
 
Last edited:
Solution
What you are telling me, makes absolutely no sense. Because in this script, it's just working fine...

normal on use action
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if getPlayerStorageValue(cid, 5502) == 9 and getPlayerStorageValue(cid, item.uid) == -1 then
            doSendMagicEffect(fromPosition, CONST_ME_HITBYFIRE)
            doTransformItem(item.uid, 1484)
            addEvent(doTransformItem, 1000*60*2, item.uid, 1485)
            setPlayerStorageValue(cid, item.uid, 1)
            local status = TRUE
            for i = 1, #firehellBasin do
                if getPlayerStorageValue(cid, firehellBasin[i]) == -1 then
                    return true
                end
            end...
Lua:
elseif itemEx.uid == 17104 then
   doTransformItem(itemEx.uid, 2249)
   addEvent(function(itemEx.uid)
       doTransformItem(itemEx.uid, 3615)
   end, 5 * 1000, itemEx.uid)
   doSendMagicEffect(toPosition, CONST_ME_POFF)
   return true
elseif ..
 
Still not working... this makes no sense.
I'm using this line in the normal script and it works fine
Lua:
doTransformItem(17104, 3615)
Then I use the EXACT SAME line in addEvent() and it tells me "doTransformItem() item not found."
How is that even possible? I'm using the same code, without any variable parameters. Still not working in addEvent().
Is there anything special about this function?
 
item unique ids are references
once it's referenced the counter goes up, meaning you cant pass item uid through addEvent since the counter goes up as soon as you referenced it to pass it through
instead you should pass position through addEvent, and use getTileItemById(pos, itemid) to get the item
also pls use return true not return TRUE
 
item unique ids are references
once it's referenced the counter goes up, meaning you cant pass item uid through addEvent since the counter goes up as soon as you referenced it to pass it through
instead you should pass position through addEvent, and use getTileItemById(pos, itemid) to get the item
also pls use return true not return TRUE

What you are telling me, makes absolutely no sense. Because in this script, it's just working fine...

normal on use action
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if getPlayerStorageValue(cid, 5502) == 9 and getPlayerStorageValue(cid, item.uid) == -1 then
            doSendMagicEffect(fromPosition, CONST_ME_HITBYFIRE)
            doTransformItem(item.uid, 1484)
            addEvent(doTransformItem, 1000*60*2, item.uid, 1485)
            setPlayerStorageValue(cid, item.uid, 1)
            local status = TRUE
            for i = 1, #firehellBasin do
                if getPlayerStorageValue(cid, firehellBasin[i]) == -1 then
                    return true
                end
            end
            setPlayerStorageValue(cid, 5502, 10)
        end
    return true
end

But I tried what you said and changed the script to this, still the same error. Item not found
Lua:
elseif itemEx.uid == 17104 then
        doTransformItem(itemEx.uid, 2249)
        -- addEvent(doTransformItem, 1000*5, 17104, 3615)
        addEvent(function(Pos) doTransformItem(getTileItemById(Pos, 2249), 3615)end, 5 * 1000, toPosition)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
        return TRUE
elseif ...
 
What you are telling me, makes absolutely no sense. Because in this script, it's just working fine...

normal on use action
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if getPlayerStorageValue(cid, 5502) == 9 and getPlayerStorageValue(cid, item.uid) == -1 then
            doSendMagicEffect(fromPosition, CONST_ME_HITBYFIRE)
            doTransformItem(item.uid, 1484)
            addEvent(doTransformItem, 1000*60*2, item.uid, 1485)
            setPlayerStorageValue(cid, item.uid, 1)
            local status = TRUE
            for i = 1, #firehellBasin do
                if getPlayerStorageValue(cid, firehellBasin[i]) == -1 then
                    return true
                end
            end
            setPlayerStorageValue(cid, 5502, 10)
        end
    return true
end

But I tried what you said and changed the script to this, still the same error. Item not found
Lua:
elseif itemEx.uid == 17104 then
        doTransformItem(itemEx.uid, 2249)
        -- addEvent(doTransformItem, 1000*5, 17104, 3615)
        addEvent(function(Pos) doTransformItem(getTileItemById(Pos, 2249), 3615)end, 5 * 1000, toPosition)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
        return TRUE
elseif ...
it does make sense, each time an object is added to the script environment such as creatures or items, they have unique ids that count up from a base value
each time the item is added to the script environment it counts up and gets added to a temporary list full of ids, so the engine can find the specific item by uid
but once the item goes out of the onUse scope, it gets removed from that list so technically you're still able to access the item table and the uid is technically valid, it's already been removed from the list so you can't use it after that
tldr; it gets used and removed once onUse finishes executing
Lua:
elseif itemEx.uid == 17104 then
        doTransformItem(itemEx.uid, 2249)
        -- addEvent(doTransformItem, 1000*5, 17104, 3615)
        addEvent(function(pos) doTransformItem(getTileItemById(pos, 2249).uid, 3615) end, 5 * 1000, toPosition)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
        return TRUE
elseif ...
getTileItemById(pos, 2249) returns an item table, not a unique id which is why you're still getting the error
 
Solution
getTileItemById(pos, 2249) returns an item table, not a unique id which is why you're still getting the error
It works! It finally WORKS!!!!! Thank you my friend. I hope I wasn't too rude with what I said, I didn't meant to be.

I still don't really understand why it's working on the other action script, but nvm. Programming/scripting is sometimes a bit weird imo. I know everything is logical and has a reason why it behaves like that, but still...

If you could then tell me, why "true" is better than "TRUE"? :)
 
It works! It finally WORKS!!!!! Thank you my friend. I hope I wasn't too rude with what I said, I didn't meant to be.

I still don't really understand why it's working on the other action script, but nvm. Programming/scripting is sometimes a bit weird imo. I know everything is logical and has a reason why it behaves like that, but still...

If you could then tell me, why "true" is better than "TRUE"? :)
item stays in the list but itemEx doesn't, your other script is using item.uid

its not better, it's just less stupid
no idea why people use TRUE when true is the default lua value, TRUE is just an alias
+ it has a sweet color if you're using a modern text editor
 
Back
Top