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

Help with Add Event

Toast

New Member
Joined
Feb 28, 2008
Messages
150
Reaction score
0
Is there a reason I can only use this script once on TFS 0.3.2
its a addevent to change back a lever. I tryed to make the same script for other levers but is only letting 1 work and ideas?

One will work and all the rest only remove the walls not change lever back.
Thank for any help

PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014
function onUse(cid, item, frompos, item2, topos)
    local getwall1 = getThingfromPos(wall1)
    local getwall2 = getThingfromPos(wall2)
    local getwall3 = getThingfromPos(wall3)
    if item.uid == leverUID and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doRemoveItem(getwall2.uid,1)
        doRemoveItem(getwall3.uid,1)
        doTransformItem(item.uid,item.itemid+1)
        addEvent(resetLever, 1*60*1000)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
    end
return 1
end
function resetLever()
    local lever = getThing(leverUID)
    if lever.itemid == 1946 then   
        doCreateItem(1025,1,wall1)
        doCreateItem(1025,1,wall2)
        doCreateItem(1025,1,wall3)
        doTransformItem(lever.uid,lever.itemid-1)
    end
end
 
Last edited:
Use code tags!

It must work try it :D


PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014
function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)
if item.uid == leverUID and item.itemid == 1945 then
doRemoveItem(getwall1.uid,1)
doRemoveItem(getwall2.uid,1)
doRemoveItem(getwall3.uid,1)
doTransformItem(item.uid,item.itemid+1)
addEvent(resetLever, 1*60*1000)
else
doPlayerSendCancel(cid,"Sorry, not possible.")
end
return 1
end
function resetLever()
local leverPos = {x=841, y=1063, z=12, stackpos=1}
local leverGet = getThingFromPos(leverpos)
if leverGet.itemid == 1946 then
doCreateItem(1025,1,wall1)
doCreateItem(1025,1,wall2)
doCreateItem(1025,1,wall3)
doTransformItem(leverGet.uid,lever.itemid-1)
end
end

USE CODE TAGS PLEASE!
 
Use code tags!

It must work try it :D


PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014
function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)
if item.uid == leverUID and item.itemid == 1945 then
doRemoveItem(getwall1.uid,1)
doRemoveItem(getwall2.uid,1)
doRemoveItem(getwall3.uid,1)
doTransformItem(item.uid,item.itemid+1)
addEvent(resetLever, 1*60*1000)
else
doPlayerSendCancel(cid,"Sorry, not possible.")
end
return 1
end
function resetLever()
local leverPos = {x=841, y=1063, z=12, stackpos=1}
local leverGet = getThingFromPos(leverpos)
if leverGet.itemid == 1946 then
doCreateItem(1025,1,wall1)
doCreateItem(1025,1,wall2)
doCreateItem(1025,1,wall3)
doTransformItem(leverGet.uid,lever.itemid-1)
end
end

USE CODE TAGS PLEASE!

Thank you for you help its removeing the walls then has this error in console. And its not resetting the lever.
I copted your script and just edited the lever position.
thanks for any help.

Lua Script Error: [Action Interface]
in a timer event called from:
data/actions/scripts/Dreamers/dreamer1.lua:eek:nUse

attempt to index a nil value
stack traceback
[C]:in function 'getThingFromPos'
data/action/scripts/Dreamers/dreamer1.lua:22: in function <data/actions/scripts/Dreamers/dreamer1.lua:20>
 
Last edited:
Code:
getThingFromPos(leverpos)

change to:

Code:
getThingfromPos(leverPos)

Thanks for your help but now im getting this error in console.


Lua Script Error: [Action Interface]
in a timer event called from:
data/actions/scripts/Dreamers/dreamer1.lua:eek:nUse

data/action/scripts/Dreamers/dreamer1.lua:27:
attempt to index global 'lever' <a nil value>
stack traceback:
data/action/scripts/Dreamers/dreamer1.lua:27: in function <data/actions/scripts/Dreamers/dreamer1.lua:20>
 
PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014

function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)

	if item.uid == leverUID and item.itemid == 1945 then
		doRemoveItem(getwall1.uid,1)
		doRemoveItem(getwall2.uid,1)
		doRemoveItem(getwall3.uid,1)
		doTransformItem(item.uid,item.itemid+1)
		addEvent(resetLever, 1*60*1000)
	else
	doPlayerSendCancel(cid,"Sorry, not possible.")
	end
return 1
end

function resetLever()
local leverPos = {x=841, y=1063, z=12, stackpos=1}
local leverGet = getThingfromPos(leverpos)

	if leverGet.itemid == 1946 then
		doCreateItem(1025,1,wall1)
		doCreateItem(1025,1,wall2)
		doCreateItem(1025,1,wall3)
		doTransformItem(leverGet.uid,leverGet.itemid-1)
	end
end
 
PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014

function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)

	if item.uid == leverUID and item.itemid == 1945 then
		doRemoveItem(getwall1.uid,1)
		doRemoveItem(getwall2.uid,1)
		doRemoveItem(getwall3.uid,1)
		doTransformItem(item.uid,item.itemid+1)
		addEvent(resetLever, 1*60*1000)
	else
	doPlayerSendCancel(cid,"Sorry, not possible.")
	end
return 1
end

function resetLever()
local leverPos = {x=841, y=1063, z=12, stackpos=1}
local leverGet = getThingfromPos(leverpos)

	if leverGet.itemid == 1946 then
		doCreateItem(1025,1,wall1)
		doCreateItem(1025,1,wall2)
		doCreateItem(1025,1,wall3)
		doTransformItem(leverGet.uid,leverGet.itemid-1)
	end
end

Thanks for the help but it brings up this error.

Lua Script Error: [Action Interface]
in a timer event called from:
data/actions/scripts/Dreamers/dreamer1.luanUse

attempt to index a nil value
stack traceback
[C]:in function 'getThingFromPos'
data/action/scripts/Dreamers/dreamer1.lua:22: in function <data/actions/scripts/Dreamers/dreamer1.lua:20>
 
@up
read again josejunior23's post.

Thank but I did and when I did what he told me to it didnt reset lever and made this error in console.
But thanks for trying to help.


Lua Script Error: [Action Interface]
in a timer event called from:
data/actions/scripts/Dreamers/dreamer1.luanUse

data/action/scripts/Dreamers/dreamer1.lua:27:
attempt to index global 'lever' <a nil value>
stack traceback:
data/action/scripts/Dreamers/dreamer1.lua:27: in function <data/actions/scripts/Dreamers/dreamer1.lua:20>
 
... post errors.
PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014

function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)

    if item.uid == leverUID and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doRemoveItem(getwall2.uid,1)
        doRemoveItem(getwall3.uid,1)
        doTransformItem(item.uid,item.itemid+1)
        addEvent(resetLever, 1*60*1000)
    else
    doPlayerSendCancel(cid,"Sorry, not possible.")
    end
return 1
end

function resetLever()
local leverPos = {x=841, y=1063, z=12, stackpos=1}
local leverGet = getThingfromPos(leverPos)

    if leverGet.itemid == 1946 then
        doCreateItem(1025,1,wall1)
        doCreateItem(1025,1,wall2)
        doCreateItem(1025,1,wall3)
        doTransformItem(leverGet.uid,leverGet.itemid-1)
    end
end
 
... post errors.
PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014

function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)

    if item.uid == leverUID and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doRemoveItem(getwall2.uid,1)
        doRemoveItem(getwall3.uid,1)
        doTransformItem(item.uid,item.itemid+1)
        addEvent(resetLever, 1*60*1000)
    else
    doPlayerSendCancel(cid,"Sorry, not possible.")
    end
return 1
end

function resetLever()
local leverPos = {x=841, y=1063, z=12, stackpos=1}
local leverGet = getThingfromPos(leverPos)

    if leverGet.itemid == 1946 then
        doCreateItem(1025,1,wall1)
        doCreateItem(1025,1,wall2)
        doCreateItem(1025,1,wall3)
        doTransformItem(leverGet.uid,leverGet.itemid-1)
    end
end

There is no errors but its only letting 1 lever reset.
The other levers remove the walls fine but dont reset.
And theres no errors at all in console or game.

Heres the 2 scripts Im useing.
All the positions are correct. as are the UID numbers.
Any ideas why its only letting 1 lever reset?
Thanks for all your help and time.

PHP:
local wall1 = {x=841, y=1061, z=12, stackpos=1}
local wall2 = {x=841, y=1062, z=12, stackpos=1}
local wall3 = {x=841, y=1063, z=12, stackpos=1}
local leverUID = 15014

function onUse(cid, item, frompos, item2, topos)
local getwall1 = getThingfromPos(wall1)
local getwall2 = getThingfromPos(wall2)
local getwall3 = getThingfromPos(wall3)

    if item.uid == leverUID and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doRemoveItem(getwall2.uid,1)
        doRemoveItem(getwall3.uid,1)
        doTransformItem(item.uid,item.itemid+1)
        addEvent(resetLever, 1*60*1000)
    else
    doPlayerSendCancel(cid,"Sorry, not possible.")
    end
return 1
end

function resetLever()
local leverPos = {x=840, y=1061, z=12, stackpos=1}
local leverGet = getThingfromPos(leverPos)

    if leverGet.itemid == 1946 then
        doCreateItem(1025,1,wall1)
        doCreateItem(1025,1,wall2)
        doCreateItem(1025,1,wall3)
        doTransformItem(leverGet.uid,leverGet.itemid-1)
    end
end

PHP:
local wall1 = {x=838, y=1060, z=12, stackpos=1}
local wall2 = {x=839, y=1060, z=12, stackpos=1}
local wall3 = {x=840, y=1060, z=12, stackpos=1}
local wall4 = {x=841, y=1060, z=12, stackpos=1}
local leverUID = 15011

function onUse(cid, item, frompos, item2, topos)
    local getwall1 = getThingfromPos(wall1)
    local getwall2 = getThingfromPos(wall2)
    local getwall3 = getThingfromPos(wall3)
    local getwall4 = getThingfromPos(wall4)

    if item.uid == leverUID and item.itemid == 1945 then
        doRemoveItem(getwall1.uid,1)
        doRemoveItem(getwall2.uid,1)
        doRemoveItem(getwall3.uid,1)
        doRemoveItem(getwall4.uid,1)
        doTransformItem(item.uid,item.itemid+1)
        addEvent(resetLever, 1*60*1000)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
    end
return 1
end

function resetLever()
local leverPos = {x=838, y=1061, z=12, stackpos=1}
local leverGet = getThingfromPos(leverPos)

    if leverGet.itemid == 1946 then   
        doCreateItem(1026,1,wall1)
        doCreateItem(1026,1,wall2)
        doCreateItem(1026,1,wall3)
        doCreateItem(1026,1,wall4)
        doTransformItem(leverGet.uid,leverGet.itemid-1)
    end
end
 
Here is the script:

Code:
local wallpos = {
	{x=841, y=1061, z=12, stackpos=1},
	{x=841, y=1062, z=12, stackpos=1},
	{x=841, y=1063, z=12, stackpos=1}
	}
local leverPos = {
	{x=840, y=1061, z=12, stackpos=1}, -- lever one.
	{x=840, y=1061, z=12, stackpos=1}, -- lever two.
	{x=840, y=1061, z=12, stackpos=1}  -- lever three.
	}
local leverAID = 15014 -- Levers actionid.
local resetLeverDelays = {1*60*1000, 1*30*1000, 1*10*1000} -- When the levers will reset.

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.actionid == leverUID and item.itemid == 1945 then
		for _, position in ipairs(wallpos) do -- This loop selects the tables from wallpos. 
			local wall = getThingfromPos(position) -- This one get the thing from the selected position.
			while wall.itemid ~= 0 do -- This loop is only here to check id there is any dupplicated walls or items in that position. 0 = no item.
				doRemoveItem(wall.uid, 1)
				wall = getThingfromPos(position) -- Get the thing again from that position(To check if there is anything there.)
			end
		end
		doTransformItem(item.uid, item.itemid+1)
		for delay, position in ipairs(wallpos) do
			addEvent(resetLever, resetLeverDelays[delay], position)
		end
		addEvent(createWall, 1*60*1000)
	else
		return FALSE -- If the onUse function return false, it'll look like the player is using an item that doesn't any script.
	end
return TRUE -- This one is VERY nessesary. Without it, the script will never return anything.
end

function resetLever(position) --This function reset the levers only.
	local lever = getThingfromPos(position)
	if lever.itemid == 1946 then
		doTransformItem(lever.uid, lever.itemid-1)
	end
end  

function createWall()
	for _, position in ipairs(wallpos) do
		doCreateItem(1025, 1, position)
	end
end
 
Back
Top