• 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 change item on different location

Exoltes

Novia OTserv Developer
Joined
Jul 2, 2009
Messages
563
Reaction score
47
Location
Belgium
I'm working on a 8.54 Open Tibia Server using The Forgotten Server - Version 0.2.7 (Mystic Spirit).

I've made the following script but I keep getting errors when I try to change an item on a different location then the item I'm using.

Server\data\actions\actions.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <!-- Quests -->
    <action uniqueid="65535" script="quests/Ice Change.lua"/>
</actions>

Server\data\actions\scripts\quests\Ice Change.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function doTransformBack(Position, itemid, transformid)
     return doTransformItem(getTileItemById(Position, transformid).uid, itemid)
end

        if itemEx.itemid == 1945 and item.actionid == 65535 then
           local rand = math.random(1, 1)
           if rand == 1 then
            doSendMagicEffect(toPosition,CONST_ME_ICEAREA)
            doTargetCombatHealth(0, cid, COMBAT_ICEDAMAGE, -1000, -1000, CONST_ME_ICEAREA)
            doTransformItem(itemEx.uid, 7021)
            doTransformItem({x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017, 7025)
            addEvent(doTransformBack, 1*20*1000, toPosition, itemEx.itemid, 7021)
            addEvent(doTransformBack, 1*20*1000, {x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017, 7025)
end
end
     return TRUE
end

When i use it i get the following error:
Console
Code:
[17/06/2015 11:57:04] Lua Script Error: [Action Interface] 
[17/06/2015 11:57:04] data/actions/scripts/quests/Ice Change.lua:onUse

[17/06/2015 11:57:04] luaDoTransformItem(). Item not found

After the delay I get the next error:
Console
Code:
[17/06/2015 11:57:24] Lua Script Error: [Action Interface] 
[17/06/2015 11:57:24] in a timer event called from: 
[17/06/2015 11:57:24] data/actions/scripts/quests/Ice Change.lua:onUse

[17/06/2015 11:57:24] luaDoTransformItem(). Item not found
If someone could look at this, that would be great :)

Thanks in advance.
 
Add the addEvent lines above the doTransformItem lines.

You can add function doTransformBack just above function onUse btw.
 
I made the changes as i think how you ment them. but got the same result, same errors same ingame changes.

Code:
local function doTransformBack(Position, itemid, transformid)
    return doTransformItem(getTileItemById(Position, transformid).uid, itemid)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

        if itemEx.itemid == 1945 and item.actionid == 65535 then
           local rand = math.random(1, 1)
           if rand == 1 then
            doSendMagicEffect(toPosition,CONST_ME_ICEAREA)
            doTargetCombatHealth(0, cid, COMBAT_ICEDAMAGE, -1000, -1000, CONST_ME_ICEAREA)
            addEvent(doTransformBack, 1*20*1000, toPosition, itemEx.itemid, 7021)
            addEvent(doTransformBack, 1*20*1000, {x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017, 7025)
            doTransformItem(itemEx.uid, 7021)
            doTransformItem({x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017, 7025)
end
end
     return TRUE
end

The problem will be somewhere in these 2 lines so if you have any other ideas on how to resolve this that would be great :)
Code:
            addEvent(doTransformBack, 1*20*1000, {x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017, 7025)
            doTransformItem({x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017, 7025)
 
You need to get the uid of the item in the first parameter of doTransformItem.
Code:
doTransformItem(getTileItemById({x = toPosition.x-1, y = toPosition.y, z = toPosition.z}, 7017).uid, 7025)
Also make sure the itemids and positions are correct.
 
Thx it works :)

Now lets hope I can run it on 400+ items :D

I cried victory too soon :D

Just ran into changing water/grass tiles and they have a different id everytime the server starts, is there a way to check for the id by location?
 
Last edited by a moderator:
I cried victory too soon :D

Just ran into changing water/grass tiles and they have a different id everytime the server starts, is there a way to check for the id by location?
Code:
getTileThingByPos(pos)
 
Getting the following error in the console:
Code:
[18/06/2015 14:15:24] Lua Script Error: [Action Interface] 
[18/06/2015 14:15:24] data/actions/scripts/quests/Ice Change.lua:onUse

[18/06/2015 14:15:24] luaDoTransformItem(). Item not found

[18/06/2015 14:15:30] Lua Script Error: [Action Interface] 
[18/06/2015 14:15:30] in a timer event called from: 
[18/06/2015 14:15:30] data/actions/scripts/quests/Ice Change.lua:onUse

[18/06/2015 14:15:30] luaDoTransformItem(). Item not found

data/actions/scripts/quests/Ice Change.lua
Code:
local function doTransformBack(Position, itemid, transformid)
    return doTransformItem(getTileItemById(Position, transformid).uid, itemid)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if itemEx.itemid == 1945 and item.actionid == 65535 then
            doSendMagicEffect(toPosition,CONST_ME_ICEAREA)
            doTargetCombatHealth(0, cid, COMBAT_ICEDAMAGE, -1000, -1000, CONST_ME_ICEAREA)
            addEvent(doTransformBack, 1*6*1000, toPosition, itemEx.itemid, 7021)
            doTransformItem(itemEx.uid, 7021)

addEvent(doTransformBack, 1*6*1000, {x = 757, y = 1016, z = 7}, getTileThingByPos({x = 757, y = 1016, z = 7}), 670)
doSendMagicEffect({x = 757, y = 1016, z = 7},CONST_ME_ICEAREA)
doTransformItem(getTileItemById({x = 757, y = 1016, z = 7}, getTileThingByPos({x = 757, y = 1016, z = 7})).uid, 670)

end
     return TRUE
end

Maybe there is a way to stop my server from randomizing the tiles? Because it will be hard to find the tile id when there are multiple items on top of eachother.
 
Last edited by a moderator:
You can get the itemid or uniqueid like this.
Code:
getTileThingByPos({x = 757, y = 1016, z = 7, stackpos = 0}).itemid
getTileThingByPos({x = 757, y = 1016, z = 7, stackpos = 0}).uid
With this script you can just only use the second one since getTileItemById also gets the uid.
stackpos 0 is ground, 1 first item, 2 second item etc.
 
Alright. I think the problem you were having is:

The script was reading to change the item back into itself with the last addEvent script...

I am not sure but this may fix your problem:

Code:
local function doTransformBack(Position, itemid, transformid)
    return doTransformItem(getTileItemById(Position, transformid).uid, itemid)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if itemEx.itemid == 1945 and item.actionid == 65535 then
            doSendMagicEffect(toPosition,CONST_ME_ICEAREA)
            doTargetCombatHealth(0, cid, COMBAT_ICEDAMAGE, -1000, -1000, CONST_ME_ICEAREA)
            addEvent(doTransformBack, 1*6*1000, toPosition, itemEx.itemid, 7021)
            doTransformItem(itemEx.uid, 7021)
           
        local pos = {x = 757, y = 1016, z = 7}
        item_check = getTileThingByPos(pos).uid
           
           
doSendMagicEffect(pos,CONST_ME_ICEAREA)
doTransformItem(getTileItemById(pos, getTileThingByPos(pos)).uid, 670)
addEvent(doTransformBack, 1*6*1000, pos, item_check, 670)
end
     return true
end
 
Fixed the border problem with just remapping :p

But im trying to freeze my lake and snow over my grass now but it seems i got my server to crash cuz of it :D

Code:
addEvent(doTransformBack, 2*6*1000, {x = 716, y = 1003, z = 6}, getTileThingByPos({x = 716, y = 1003, z = 6, stackpos = 0}).uid, 671)
doSendMagicEffect({x = 716, y = 1003, z = 6},CONST_ME_ICEAREA)
doTransformItem(getTileItemById({x = 716, y = 1003, z = 6}, getTileThingByPos({x = 716, y = 1003, z = 6, stackpos = 0}).itemid).uid, 671)

The change from water to ice works but at the moment it has to turn back my server crashes.

Any help is welcome :)
Thanks in advance.

Nvm found it allready :D

had to change
Code:
addEvent(doTransformBack, 2*6*1000, {x = 716, y = 1003, z = 6}, getTileThingByPos({x = 716, y = 1003, z = 6, stackpos = 0}).uid, 671)

into
Code:
addEvent(doTransformBack, 2*6*1000, {x = 716, y = 1003, z = 6}, getTileThingByPos({x = 716, y = 1003, z = 6, stackpos = 0}).itemid, 671)
 
Last edited:
Ran into another problem :D

With this fuction one id will be checked and this id will be used on all tiles with the 'getTileThingByPos' fuction in it.
For example first tile is id '4612' the fuction takes this id changes it. But for the next tile it will take the same id which doesnt match and the second tile wont change and give an error.

Any idea on how to fix this?

If not maybe there is a way to disable the fact that the server randomizes certain sets of tiles? So I can make all tiles static and just do it id by id.
 
The script allready has 1986 lines so can't really post it here :p

But while trying to cut it to post here I found the problem :D I made a wrong cell reference while writing the script in excell which ended up mixing the coordinates and thats why it bugged.
So thx once again! Now I hope I can finish the whole island and get the script 100% working without any more setbacks :)
 
For future referance Exoltes.....When the error is delay'd that usually mean that it is an error in you addEvent line....

The delay is how long you set the delay for the addEvent...

So if you get no error, delay, then an error. You messed up your addEvent script.
 
Back
Top