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

How to create a lever with time? (exausted)

Loremaster7

New Member
Joined
Oct 16, 2017
Messages
29
Reaction score
4
In my code, clicking on the lever removes a stone, and the stone comes back in 10 seconds, but if you keep clicking on the lever an error occurs, I would need the lever works again only after 10 seconds. if the player clicks before 10 seconds the lever would not perform any function.

(my distro is The OTX Server Version: (2.X.S - 4) Otserver 7.72)

My Code:

Lua:
local time = 10
local stone_pos = {x = 2895, y = 2687, z = 8, stackpos=1}

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

stone = getThingfromPos(stone_pos)

if item.uid == 60116 and item.itemid == 1945 then

doRemoveItem(stone.uid,1304)
doTransformItem(item.uid,item.itemid+1)
addEvent(function()
            local stone = doCreateItem(1304, 1, stone_pos)
        end, time * 1000)


if item.uid == 60116 and item.itemid == 1946 then

doTransformItem(item.uid,item.itemid-1)

end

return true
end
end
 
Last edited:
Follow this tutorial to learn about events (have a lever example).

 
This might do the trick + avoiding the use of storage since if there is no stone on given position, the script ends:
Lua:
local config = {
    stonePos = {x = 2895, y = 2687, z = 8},
    stoneID = 1304,
    duration = 10, -- seconds
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local thing = getTileItemById(config.stonePos, config.stoneID).uid
    if thing == 0 then
        if item.itemid == 1946 then
            doTransformItem(item.uid, 1945)
        end
        return true
    end
    
    if item.itemid == 1945 then
        doRemoveItem(thing)
        addEvent(doCreateItem, config.duration * 1000, config.stonePos, 1, config.stoneID)
    end
    
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end
 
This might do the trick + avoiding the use of storage since if there is no stone on given position, the script ends:
Lua:
local config = {
    stonePos = {x = 2895, y = 2687, z = 8},
    stoneID = 1304,
    duration = 10, -- seconds
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local thing = getTileItemById(config.stonePos, config.stoneID).uid
    if thing == 0 then
        if item.itemid == 1946 then
            doTransformItem(item.uid, 1945)
        end
        return true
    end
 
    if item.itemid == 1945 then
        doRemoveItem(thing)
        addEvent(doCreateItem, config.duration * 1000, config.stonePos, 1, config.stoneID)
    end
 
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end

Is this a unique way to get the effect? Because I have another code with many functions and I do not understand how can add in it a way to work this (have more stones and other functions)

more simple only in one area?

In this example, I do not use a lever, I use a stone, and for a "stone" = 1285, I do not need to change an item, it's just a click but I need time to wait to be able to click the lever again...

new code:

Lua:
local time = 10
local stone_pos = {x = 2895, y = 2687, z = 8, stackpos=1}

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

stone = getThingfromPos(stone_pos)

if item.uid == 60116 and item.itemid == 1285 then

doRemoveItem(stone.uid,1304)
doTransformItem(item.uid,item.itemid)
addEvent(function()
            local stone = doCreateItem(1304, 1, stone_pos)
        end, time * 1000)
end
return true
end
 
Last edited:
Consequtive double posts within 24 hours is considered spamming. Edit your previous post instead of posting twice.
(and a message appears to get to know it's does work) message = "wait 10 seconds to be able to click the stone again"

(my distro is The OTX Server Version: (2.X.S - 4) Otserver 7.72)

Lever need time here:

Lua:
local time = 10
local tempo = 10

local lever_pos = {x = 2730, y = 2672, z = 7, stackpos=1}

local r1_pos = {x=2731, y=2673, z=7, stackpos=1}
local r2_pos = {x=2730, y=2673, z=7, stackpos=1}
local r3_pos = {x=2730, y=2672, z=7, stackpos=1}
local r4_pos = {x=2731, y=2672, z=7, stackpos=1}

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


local playerTile1 = {x=2731, y=2673, z=7}
local playerTile2 = {x=2730, y=2673, z=7}
local playerTile3 = {x=2730, y=2672, z=7}
local playerTile4 = {x=2731, y=2672, z=7}

local new = {x = 2732, y = 2672, z = 7}

getrock1 = getThingfromPos(r1_pos)
getrock2 = getThingfromPos(r2_pos)
getrock3 = getThingfromPos(r3_pos)
getrock4 = getThingfromPos(r4_pos)


    local lever = getThingfromPos(lever_pos)


    if item.uid == 60115 and item.itemid == 1304 then
 

        doRemoveItem(getrock1.uid,1303)
        doRemoveItem(getrock2.uid,1302)
        doRemoveItem(getrock3.uid,1300)
        doRemoveItem(getrock4.uid,1301)

        doSendMagicEffect(r1_pos, 2)
        doSendMagicEffect(r2_pos, 2)
        doSendMagicEffect(r3_pos, 2)
        doSendMagicEffect(r4_pos, 2)

        local lever = doCreateItem(1945, 1, lever_pos)
        doItemSetAttribute(lever, "uid", 60114)
        addEvent(function()
            if isCreature(getTopCreature(playerTile3).uid) then
            doTeleportThing(getTopCreature(playerTile3).uid, {x = 2732, y = 2672, z = 7})
            doSendMagicEffect(new, 10)
        end
            local lever = getThingfromPos(lever_pos)
            if lever then
                doRemoveItem(lever.uid, 1945)
            end
        end, time * 980)

        addEvent(function()
            if isCreature(getTopCreature(playerTile1).uid) then
            doTeleportThing(getTopCreature(playerTile1).uid, {x = 2732, y = 2673, z = 7})
        end
            local r1 = doCreateItem(1303, 1, r1_pos)
        doItemSetAttribute(r1, "aid", 60109)
        end, tempo * 1000)

        addEvent(function()
            if isCreature(getTopCreature(playerTile2).uid) then
            doTeleportThing(getTopCreature(playerTile2).uid, {x = 2732, y = 2673, z = 7})
        end
            local r2 = doCreateItem(1302, 1, r2_pos)
        doItemSetAttribute(r2, "aid", 60109)
        end, tempo * 1000)

        addEvent(function()
            if isCreature(getTopCreature(playerTile3).uid) then
            doTeleportThing(getTopCreature(playerTile3).uid, {x = 2732, y = 2672, z = 7})
        end
            local r3 = doCreateItem(1300, 1, r3_pos)
        doItemSetAttribute(r3, "aid", 60109)
        end, tempo * 1000)

        addEvent(function()
            if isCreature(getTopCreature(playerTile4).uid) then
            doTeleportThing(getTopCreature(playerTile4).uid, {x = 2732, y = 2672, z = 7})
        end
            local r4 = doCreateItem(1301, 1, r4_pos)
        doItemSetAttribute(r4, "aid", 60109)
        end, tempo * 1000)

    end

    return true
end

-- MERGE --

What items should remove the stone? 1945, 1285, .... ?
The stone "1304" is the lever... and this stone, remove 4 stones with time to back, and create one lever with time to disappear...
 
Last edited by a moderator:
Back
Top