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

switch dont work properly ? how to fix it ?

clario

OTS based on Heroes III Might and Magic
Joined
Feb 4, 2018
Messages
98
Reaction score
5
i will show by images and scripts !
First of all i want coffin open by using switch
i add :
<action actionid="2222" event="script" value="quests/coffin1.lua"/>
in the data\actions
then i add
function onUse(cid, item, frompos, item2, topos)
switch1 = {x=658, y=843, z=7, stackpos=1}
getcoffin1 = getThingfromPos(x=684, y=858, z=7)

if item.uid = 2222 and item.itemid ==>1945 then
doRemoveItem(coffin1.uid,1)
doCreateItem(7524,1,coffin1)
doTransformItem(item.uid,item.itemid+1)

elseif item.uid = 2222 and item.itemid ==>1946 then
doRemoveItem(coffin1.uid,1)
doCreateItem(7522,1,coffin1)
doTransformItem(item.uid,item.itemid-1)
else
doPlayerSendCancel(cid,"Sorry, not possible.")
end

return 1
end

in data\actions\scripts\quests
how its look in game?

JnzsK

Imgur: The magic of the Internet

OT serv application:

UMrjz

Imgur: The magic of the Internet
 
change

Code:
if item.uid = 2222 and item.itemid ==>1945 then

to

Code:
if getItemAttribute(item, 'aid') == 2222 and item.itemid == 1945 then
 
Lua:
local switchIds = {
    [1945] = {trans = 1946, coffinId = 7524},
    [1946] = {trans = 1945, coffinId = 7522}
}

local coffinPos = {x = 684, y = 858, z = 7, stackpos = 1}

function onUse(cid, item, frompos, item2, topos)
    if getItemAttribute(item.uid, 'aid') ~= 2222 then
        return false
    end

    local SWITCH = switchIds[item.itemid]
  
    if not SWITCH then
        return false
    end
  
    local COFFIN = getThingFromPos(coffinPos)
  
    if not COFFIN then
        return doPlayerSendCancel(cid, "Could not find coffin.")
    end
  
    doTransformItem(item.uid, SWITCH.trans)
    doTransformItem(COFFIN.uid, SWITCH.coffinId)
return true
end
 
Last edited:
It's also worth mentioning that you're using wrong operator in your if-statement (==>)

There are so many things wrong I didn't want to get into all of it. Hopefully he will look how I did it figure it all out. The very first thing I would mention is, he shouldn't have removed the levers from their original script with would make it so he didn't have to transform the switch himself everytime.
 
  • local switchIds = {
  • [1945] = {trans = 1946, coffinId = 7524},
  • [1946] = {trans = 1945, coffinId = 7522}
  • }
  • local coffinPos = (x = 684, y = 858, z = 7, stackpos = 1)
  • function onUse(cid, item, frompos, item2, topos)
  • if getItemAttribute(item, 'aid') ~= 2222 then
  • return false
  • end
  • local SWITCH = switchIds[item.itemid]
  • if not SWITCH then
  • return false
  • end
  • local COFFIN = getThingFromPos(coffinPos)
  • if not COFFIN then
  • return doPlayerSendCancel(cid, "Could not find coffin.")
  • end
  • doTransformItem(item.uid, SWITCH.trans)
  • doTransformItem(COFFIN.uid, SWITCH.coffinId)
  • return true
  • end
this one
 
It says item not found at the bottom.

Change

Code:
if getItemAttribute(item, 'aid') ~= 2222 then
        return false
    end

to

Code:
if getItemAttribute(item.uid, 'aid') ~= 2222 then
        return false
    end
 
Back
Top