• 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 Lever dont work

tatara

New Member
Joined
Jan 1, 2023
Messages
36
Reaction score
3
GitHub
Tatara
Hi, i have ot based on YurOTS 7.6 version.
i have added a lever to the map but its not useable. Can someone explain me how to make it work ? I have added aid and uid in map editor to lever 6368.
i have added action to lever in actions.xml - <action uniqueid="6368" script="reblever.lua" />
and also added script - reblever.lua
Lua:
function onUse(cid, item, frompos, item2, topos)
mpos = {x=62, y=320, z=0, stackpos=255}
    if item.itemid == 1945 then
        thing = getThingfromPos(mpos)
        if thing.itemid == 2688 and thing.type >= 0 then
             doSendMagicEffect(mpos,10)
            doRemoveItem(thing.uid,1)
            itemz = math.random(1,1580)
            if itemz == 1 then
            doCreateItem(2295,1,mpos)
            end
        end
    end   
end
could someone explain me what is wrong or what i forgot to do ?
 
If you're ever unsure, add prints to the script.
(also make sure to use local for things. That way they don't interfere with other scripts.)

Remove the actionId from the lever tho.. since you're using uniqueId, the actionId is not doing anything.

try with these prints.. and find out what they show in console.
Lua:
function onUse(cid, item, frompos, item2, topos)
    print("Lever was used...")
    local mpos = {x=62, y=320, z=0, stackpos=255}
    print(item.itemid)
    if item.itemid == 1945 then
        local thing = getThingfromPos(mpos)
        print(thing.itemid)
        print(thing.type)
        if thing.itemid == 2688 and thing.type >= 0 then
            doSendMagicEffect(mpos,10)
            doRemoveItem(thing.uid,1)
            local itemz = math.random(1,1580)
            print(itemz)
            if itemz == 1 then
                doCreateItem(2295,1,mpos)
            end
        end
    end  
end
 
If you're ever unsure, add prints to the script.
(also make sure to use local for things. That way they don't interfere with other scripts.)

Remove the actionId from the lever tho.. since you're using uniqueId, the actionId is not doing anything.

try with these prints.. and find out what they show in console.
Lua:
function onUse(cid, item, frompos, item2, topos)
    print("Lever was used...")
    local mpos = {x=62, y=320, z=0, stackpos=255}
    print(item.itemid)
    if item.itemid == 1945 then
        local thing = getThingfromPos(mpos)
        print(thing.itemid)
        print(thing.type)
        if thing.itemid == 2688 and thing.type >= 0 then
            doSendMagicEffect(mpos,10)
            doRemoveItem(thing.uid,1)
            local itemz = math.random(1,1580)
            print(itemz)
            if itemz == 1 then
                doCreateItem(2295,1,mpos)
            end
        end
    end
end
when i try to use lever, in engine it says "Lever was used.... 1945 0 0
but still lever to do switch
and ingame message is still you cannot use this object
 
when i try to use lever, in engine it says "Lever was used.... 1945 0 0
but still lever to do switch
and ingame message is still you cannot use this object
Right so you can definitely use the object, as the script is printing.

I just noticed there is a missing return true at the end of the script.. and is maybe why it's saying that.

Are you sure the position you set is correct, and there is an item on that tile?
Cuz those are the 2 reasons I could see it showing 0 & 0 for the prints.

It might be better to swap to getTileItemById since you're trying to find a specific item on the ground

So let's try this... and double check the mpos position

Lua:
local mpos = {x = 62, y = 320, z = 0, stackpos = 255}

function onUse(cid, item, frompos, item2, topos)
    print("Lever was used...")
    if item.itemid == 1945 then
        local thing = getTileItemById(mpos, 2688).uid
        if thing > 0 then
            print("item found successfully")
            doSendMagicEffect(mpos, 10)
            doRemoveItem(thing, 1) -- might have to change this to thing.uid.. not sure
            local itemz = math.random(1,1580)
            print(itemz)
            if itemz == 1 then
                doCreateItem(2295, 1, mpos)
            end
        else
            print("no item with id 2688 was on the mpos position")
        end
    end
    return true
end
 
Last edited:
now it says just lever was used in engine , but lever do not change look type and ingame says that cannot be used.
Right so you can definitely use the object, as the script is printing.

I just noticed there is a missing return true at the end of the script.. and is maybe why it's saying that.

Are you sure the position you set is correct, and there is an item on that tile?
Cuz those are the 2 reasons I could see it showing 0 & 0 for the prints.

It might be better to swap to getTileItemById since you're trying to find a specific item on the ground

So let's try this... and double check the mpos position

Lua:
local mpos = {x = 62, y = 320, z = 0, stackpos = 255}

function onUse(cid, item, frompos, item2, topos)
    print("Lever was used...")
    if item.itemid == 1945 then
        local thing = getTileItemById(mpos, 2688).uid
        if thing > 0 then
            print("item found successfully")
            doSendMagicEffect(mpos, 10)
            doRemoveItem(thing, 1) -- might have to change this to thing.uid.. not sure
            local itemz = math.random(1,1580)
            print(itemz)
            if itemz == 1 then
                doCreateItem(2295, 1, mpos)
            end
        else
            print("no item with id 2688 was on the mpos position")
        end
    end
    return true
end
 
local mpos = {x = 62, y = 320, z = 0, stackpos = 255}

function onUse(cid, item, frompos, item2, topos)
local thing = getThingfromPos(mpos)
if thing.itemid == 2229 and thing.type >= 10 then
doSendMagicEffect(mpos, 10)
doRemoveItem(thing.uid, 10)
doCreateItem(2295, 1, mpos)
doPlayerSendTextMessage(cid, 22, "Successfully crafted a No Limit Rune.")
doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
else
doPlayerSendTextMessage(cid, 22, "Could not find a 10 Flawless skulls on the pedastal.")
end
return true
end
Final edition that works great !
 
Back
Top