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

TFS 0.X Callback function on script?

clario

OTS based on Heroes III Might and Magic
Joined
Feb 4, 2018
Messages
98
Reaction score
5
Hello there ! i make something like that :
local switchIds = {
[1945] = {trans = 1946, stoneId = 1304},
[1946] = {trans = 1945, stoneId = 9022}
}

local stonePos = {x = 926, y = 1332, z = 9, stackpos = 1}

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

local SWITCH = switchIds[item.itemid]

if not SWITCH then
return false
end

local COFFIN = getThingFromPos(stonePos)

if not COFFIN then
return doPlayerSendCancel(cid, "Could not find stone.")
end

doTransformItem(item.uid, SWITCH.trans)
doTransformItem(COFFIN.uid, SWITCH.coffinId)
addEvent(Remove, 20 * 1000, stonePos)
if getTileItemById(stonePos, 1304).uid > 0 then
doTransformItem(item.uid, 1945)
else
doPlayerSendCancel(cid, "It seems the lever has been already used.")
end
return true
end
and if i trun swich on , theres a callback bug (and stone dont back to POS :{x = 926, y = 1332, z = 9, stackpos = 1}

what can i do there?
 
I don't understand how the code works, could you explain line by line? Also, preferrably use
Lua:
[code="lua"]
function tag.
 
can we at least know what this script is suppose to do, it looks like a bunch of stuff that you copy and pasted from other scripts into one....

Lua:
local COFFIN = getThingFromPos(stonePos)

if not COFFIN then
return doPlayerSendCancel(cid, "Could not find stone.")
end

the statement above will most likely never be executed... COFFIN = getThingFromPos(stonePos).... you are never comparing the ID of the thing on stone pos to something else, It just checks if you found something on this position...

I do also think that using arrays like these below for such a simple task is useless...
Lua:
local switchIds = {
[1945] = {trans = 1946, stoneId = 1304},
[1946] = {trans = 1945, stoneId = 9022}
}


Also,
Lua:
if getItemAttribute(item.uid, 'aid') ~= 2230 then
return false
end
I have not seen your actions.xml file, but if the script is executed when you use item with AID 2230, this is a useless statement...

You should try writing your own script from scratch instead of copy pasting, and try to understand what is the meaning of every line instead of copying blocks of code from here and there and expecting it to works without understanding anything.
 

Similar threads

Back
Top