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

OnUse Lever = Remove a Stone

darkingman

New Member
Joined
Jul 4, 2013
Messages
7
Reaction score
0
Hi, so i was looking around for a script that will remove a stone or simply a non movable item that you cannot walk over with the ease of just clicking a lever. I do have programming knowledge but have never tried touching lua nor have i every tried to script anything for tibia before. I hope you can read this and understand what i am looking for ;)
 
server version?
you're gonna need to learn at least something before you start making a server, just telling you now
 
Well im working with 2 others that are currently mapping, we need this script to make some of our quests complete. I have made servers in the past but i mean i wouldnt say modifying already made scripts gave me any knowledge and that was infact 4 years ago. But uhm Server vision is 8.6
 
that's not a server version, that's a client version
need your server engine version
what tfs are you using? 1.2? 0.3.6? 0.4?
 
Place lever 1945 in map.
Put actionID in actions.xml on lever.
Make sure immoveable_object is on stack position 1.. Right above the floor tile. No borders/rocks underneath it.
XML:
<action actionid="45001" event="script" value="remove_immoveable_object.lua"/>
Lua:
local config = {
   immoveable_object_id = 3333,
   immoveable_object_pos = {x = 1111, y = 1111, z = 111, stackpos = 1},
   relocate_position = {x = 2222, y = 2222, z = 222} -- relocates items/creatures/players to a safe spot
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if item.itemid == 1945 then
       doTransformItem(item.uid, item.itemid + 1)
       doTransformItem(getThingfromPos(config.immoveable_object_pos).uid, 0)
   elseif item.itemid == 1946 then
       doTransformItem(item.uid, item.itemid - 1)
       doRelocate(config.immoveable_object_pos, config.relocate_position)
       doCreateItem(config.immoveable_object_id, 1, config.immoveable_object_pos)
   end   
   return true
end
 
Thank you ;) I got another question, how do i make it respawn after x time? In c++ i would declare a timer and go through a while loop and once the while loop is done it will respawn the rock. Can i do the same in lua?
 
Well, sorry for the mess
Lua:
local event = nil

local function Restore(id, pos, npos, uid)
    if getTileItemById(pos, id).uid ~= 1 then
        return doCreateItem(id, pos), doRelocate(pos, npos), doTransformItem(uid, 1945)
    end
end

function onUse(cid, item, frompos, item2, topos)

    local Stone = {
        id = 1000,
        duration = 10*1000,
        pos = {
            {x=100,y=100,z=7},
            {x=200,y=200,z=7},
        },
    }
  
    local t, n = item.itemid == 1945, getTileItemById(Stone.pos[1], Stone.id).uid

    if event ~= nil then
        stopEvent(event)
    end
  
    if t then
        if n ~= 0 and doRemoveItem(n) then
            event = addEvent(Restore, Stone.duration, Stone.id, Stone.pos[1], Stone.pos[2], item.uid)
        end
    else
        if n ~= 1 then
            doRelocate(Stone.pos[1], Stone.pos[2])
            doCreateItem(Stone.id, 1, Stone.pos[1])
        end
    end
  
    return true, doTransformItem(item.uid, t and 1946 or 1945)
end
 
Last edited:
What your looking for is addEvent, which is shown above. The method above is also using stopEvent.
At the moment, you can flip the switch back and forth multiple times, and it should replace the wall after x time, once you've stopped flipping the switch.
I'm not 100% sure, but I think the relocate activating second.. may move the stone to the relocate position..
If that is the case, just swap lines 32 and 33 around, so the relocate happens before the wall is created.
 
What your looking for is addEvent, which is shown above. The method above is also using stopEvent.
At the moment, you can flip the switch back and forth multiple times, and it should replace the wall after x time, once you've stopped flipping the switch.
I'm not 100% sure, but I think the relocate activating second.. may move the stone to the relocate position..
If that is the case, just swap lines 32 and 33 around, so the relocate happens before the wall is created.
Yeah you're right, doRelocate function should be called first.
Regarding the event, if the item is used and event is active, it should stop it. Also the event is only added if the stone is removed (which means if it isn't removed and he still pulls the lever, the event will not be called)
 
Back
Top