• 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 My Script don't works. (lever)

Loremaster7

New Member
Joined
Oct 16, 2017
Messages
29
Reaction score
4
Hello, friends i want a lever to remove another lever, but when I restart it again, do not miss the unique ID

Script lever 1:

function onUse(cid, item, frompos, item2, topos)
wall1 = {x=389, y=379, z=13, stackpos=1}
getwall1 = getThingfromPos(wall1)

lever = 1946

if item.uid == 6001 and item.itemid == 1945 then
doRemoveItem(getwall1.uid,1)
doTransformItem(item.uid,item.itemid+1)
elseif item.uid == 6001 and item.itemid == 1946 then
doTransformItem(item.uid,item.itemid-1)
doCreateItem(1946, 1, wall1)
doItemSetAttribute(doCreateItem(lever, 1, wall1), "uid", 6002)

end

return 1
end

*******

Script lever 2:

function onUse(cid, item, frompos, item2, topos)
wall1 = {x=388, y=378, z=13, stackpos=1}
getwall1 = getThingfromPos(wall1)

lever = 1945


if item.uid == 6002 and item.itemid == 1946 then
doRemoveItem(getwall1.uid,1)
doTransformItem(item.uid,item.itemid-1)
elseif item.uid == 6002 and item.itemid == 1945 then
doTransformItem(item.uid,item.itemid+1)
doCreateItem(1945,1,wall1)
doItemSetAttribute(doCreateItem(lever, 1, wall1), "uid", 6001)

end

return 1
end

*******
Actions ID's:

<action uniqueid="6001" script="leverA.lua" />
<action uniqueid="6002" script="leverB.lua" />

********

The two levers remove each one, one...

Example:

A remove B
B remove A

Two levers...

Help! Please...

This script working 50% because in Otserver have a bug... The lever doubles ...

zExypep.png


My server is OTX 7.72!
 
Last edited:
Solution
Thats a mistake because you are creating two items on this lines on both scripts:
Script lever 2:

function onUse(cid, item, frompos, item2, topos)
wall1 = {x=388, y=378, z=13, stackpos=1}
getwall1 = getThingfromPos(wall1)
lever = 1945
if item.uid == 6002 and item.itemid == 1946 then
doRemoveItem(getwall1.uid,1)
doTransformItem(item.uid,item.itemid-1)
elseif item.uid == 6002 and item.itemid == 1945 then
doTransformItem(item.uid,item.itemid+1)
doCreateItem(1945,1,wall1)
doItemSetAttribute(doCreateItem(lever, 1, wall1), "uid", 6001)
end
return 1
end

--------------
Maybe you can try this, I hope to help you, you may need to make only one script for both levers:

Lua:
function onUse(cid, item, frompos...
Thats a mistake because you are creating two items on this lines on both scripts:
Script lever 2:

function onUse(cid, item, frompos, item2, topos)
wall1 = {x=388, y=378, z=13, stackpos=1}
getwall1 = getThingfromPos(wall1)
lever = 1945
if item.uid == 6002 and item.itemid == 1946 then
doRemoveItem(getwall1.uid,1)
doTransformItem(item.uid,item.itemid-1)
elseif item.uid == 6002 and item.itemid == 1945 then
doTransformItem(item.uid,item.itemid+1)
doCreateItem(1945,1,wall1)
doItemSetAttribute(doCreateItem(lever, 1, wall1), "uid", 6001)
end
return 1
end

--------------
Maybe you can try this, I hope to help you, you may need to make only one script for both levers:

Lua:
function onUse(cid, item, frompos, item2, topos)
    local wall1 = {x=389, y=379, z=13, stackpos=1}
    local getwall1 = getThingfromPos(wall1)
    if item.uid == 6001 and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doTransformItem(item.uid,item.itemid+1)
    elseif item.uid == 6001 and item.itemid == 1946 then
        doTransformItem(item.uid,item.itemid-1)
        local lever = doCreateItem(1946, 1, wall1)
        doItemSetAttribute(lever, "uid", 6002)
    end
    return true
end
function onUse(cid, item, frompos, item2, topos)
    local wall1 = {x=388, y=378, z=13, stackpos=1}
    local getwall1 = getThingfromPos(wall1)
    if item.uid == 6002 and item.itemid == 1946 then
        doRemoveItem(getwall1.uid,1)
        doTransformItem(item.uid,item.itemid-1)
    elseif item.uid == 6002 and item.itemid == 1945 then
        doTransformItem(item.uid,item.itemid+1)
        local lever = doCreateItem(1945,1,wall1)
        doItemSetAttribute(lever, "uid", 6001)
    end
    return true
end

Something like this

Lua:
function onUse(cid, item, frompos, item2, topos)
    local wall1 = {x=389, y=379, z=13, stackpos=1}
    local wall2 = {x=388, y=378, z=13, stackpos=1}
    local getwall1 = getThingfromPos(wall1)
    local getwall2 = getThingfromPos(wall2)
    if item.itemid == 1945 then
        if item.uid == 6001 then
            doRemoveItem(getwall1.uid,1)
        elseif item.uid == 6002 then
            doRemoveItem(getwall2.uid,1)
        end
        doTransformItem(item.uid,item.itemid+1)
    elseif item.itemid == 1946 then
        if item.uid == 6001 then
            local lever = doCreateItem(1945, 1, wall1)
            doItemSetAttribute(lever, "uid", 6002)
        elseif item.uid == 6002 then
            local lever = doCreateItem(1946, 1, wall2)
            doItemSetAttribute(lever, "uid", 6001)
        end
        doTransformItem(item.uid,item.itemid-1)
    end
    return true
end
 
Last edited:
Solution
When you create the lever on either location, it will go on top of other items.
You'll want to add in the function doRelocate before adding the lever back onto that location,
so peoples items don't mistakenly get stuck underneath the newly created lever,
and also so it doesn't ruin the function 'getThingfromPos' that your currently using to find the lever.

Cheers!

Xikini
 
Thats a mistake because you are creating two items on this lines on both scripts:
Script lever 2:

function onUse(cid, item, frompos, item2, topos)
wall1 = {x=388, y=378, z=13, stackpos=1}
getwall1 = getThingfromPos(wall1)
lever = 1945
if item.uid == 6002 and item.itemid == 1946 then
doRemoveItem(getwall1.uid,1)
doTransformItem(item.uid,item.itemid-1)
elseif item.uid == 6002 and item.itemid == 1945 then
doTransformItem(item.uid,item.itemid+1)
doCreateItem(1945,1,wall1)
doItemSetAttribute(doCreateItem(lever, 1, wall1), "uid", 6001)
end
return 1
end

--------------
Maybe you can try this, I hope to help you, you may need to make only one script for both levers:

Lua:
function onUse(cid, item, frompos, item2, topos)
    local wall1 = {x=389, y=379, z=13, stackpos=1}
    local getwall1 = getThingfromPos(wall1)
    if item.uid == 6001 and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doTransformItem(item.uid,item.itemid+1)
    elseif item.uid == 6001 and item.itemid == 1946 then
        doTransformItem(item.uid,item.itemid-1)
        local lever = doCreateItem(1946, 1, wall1)
        doItemSetAttribute(lever, "uid", 6002)
    end
    return true
end
function onUse(cid, item, frompos, item2, topos)
    local wall1 = {x=388, y=378, z=13, stackpos=1}
    local getwall1 = getThingfromPos(wall1)
    if item.uid == 6002 and item.itemid == 1946 then
        doRemoveItem(getwall1.uid,1)
        doTransformItem(item.uid,item.itemid-1)
    elseif item.uid == 6002 and item.itemid == 1945 then
        doTransformItem(item.uid,item.itemid+1)
        local lever = doCreateItem(1945,1,wall1)
        doItemSetAttribute(lever, "uid", 6001)
    end
    return true
end

Something like this

Lua:
function onUse(cid, item, frompos, item2, topos)
    local wall1 = {x=389, y=379, z=13, stackpos=1}
    local wall2 = {x=388, y=378, z=13, stackpos=1}
    local getwall1 = getThingfromPos(wall1)
    local getwall2 = getThingfromPos(wall2)
    if item.itemid == 1945 then
        if item.uid == 6001 then
            doRemoveItem(getwall1.uid,1)
        elseif item.uid == 6002 then
            doRemoveItem(getwall2.uid,1)
        end
        doTransformItem(item.uid,item.itemid+1)
    elseif item.itemid == 1946 then
        if item.uid == 6001 then
            local lever = doCreateItem(1945, 1, wall1)
            doItemSetAttribute(lever, "uid", 6002)
        elseif item.uid == 6002 then
            local lever = doCreateItem(1946, 1, wall2)
            doItemSetAttribute(lever, "uid", 6001)
        end
        doTransformItem(item.uid,item.itemid-1)
    end
    return true
end
Thank you very much!!! It worked!!!
 
The follow-up thread in the next couple months should be entertaining.
 
When you create the lever on either location, it will go on top of other items.
You'll want to add in the function doRelocate before adding the lever back onto that location,
so peoples items don't mistakenly get stuck underneath the newly created lever,
and also so it doesn't ruin the function 'getThingfromPos' that your currently using to find the lever.

Cheers!

Xikini
Thank you!!
 
Back
Top