• 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 timed lever

skrm

New Member
Joined
Mar 15, 2008
Messages
67
Reaction score
0
Code:
function onUse(cid, item, frompos, item2, topos)
wall1 = {x=225, y=285, z=15, stackpos=1}
getwall1 = getThingfromPos(wall1)

if item.uid == 5016 and item.itemid == 1945 then
doRemoveItem(getwall1.uid,1)
doTransformItem(item.uid,item.itemid+1)
elseif item.uid == 5016 and item.itemid == 1946 then
doCreateItem(6290,1,wall1)
doTransformItem(item.uid,item.itemid-1) 
else
doPlayerSendCancel(cid,"Sorry, not possible.")
end
end



i want this script to reset the lever after 10 mins and the wall to re-apear after it has been used. anyone know how to do it?
 
Last edited by a moderator:
I guess it should look smth like that:
Code:
function onUse(cid, item, frompos, item2, topos)
	local wall1 = {x=225, y=285, z=15, stackpos=1}
	local getwall1 = getThingfromPos(wall1)

	[b]local function reset()
		doTransformItem(item.uid,item.itemid-1)
		doCreateItem(6290,1,wall1)
	end[/b]

	if item.uid == 5016 and item.itemid == 1945 then
		doRemoveItem(getwall1.uid,1)
		doTransformItem(item.uid,item.itemid+1)
		[b]addEvent(reset,10*60*1000,{})[/b]
	elseif item.uid == 5016 and item.itemid == 1946 then
		doCreateItem(6290,1,wall1)
		doTransformItem(item.uid,item.itemid-1) 
	else
		doPlayerSendCancel(cid,"Sorry, not possible.")
	end
end
I added the bold parts. It should work but I'm doesn't test it. And the time (10*60*1000) might be incorrect, so change it if You want.
 
that script works all good, untill it resets the first time.
the lever turns into an item 1944 after it gets reset, so im guessing thats becuase tehre are 2: doTransformItem(item.uid,item.itemid-1)

which is taking it from a 1946 to a 1944, so how to fix that?
 
Try this one
PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local wallPos = {x=225, y=285, z=15, stackpos=1}
	local getWall = getThingfromPos(wallPos)

	local function reset()
		doTransformItem(item.uid,item.itemid-1)
		doCreateItem(6290,1,wallPos)
	end

	if item.itemid == 1945 then
		doRemoveItem(getWall.uid,1)
		doTransformItem(item.uid,item.itemid+1)
		addEvent(reset,10*60*1000,{})
	elseif and item.itemid == 1946 and getWall.uid == 0 then
		doCreateItem(6290,1,wallPos)
		doTransformItem(item.uid,item.itemid-1) 
	else
		doPlayerSendCancel(cid,"Sorry, not possible.")
	end
end
 
slawkens, it the same i think. Only few more unnecessary if. In my and your script is mistake in the 6 line. There should be 1945 not item.itemid-1. Now it should work
 
o_O! Possible, fast edit.
Anyway, i'm not sure if it will work as it should.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local wallPos = {x=225, y=285, z=15, stackpos=1}
    local getWall = getThingfromPos(wallPos)

    local function reset()
        doTransformItem(item.uid,item.itemid-1)
        doCreateItem(6290,1,wallPos)
    end

    if item.itemid == 1945 then
        doRemoveItem(getWall.uid,1)
        doTransformItem(item.uid,item.itemid+1)
        addEvent(reset,10*60*1000,{})
    elseif item.itemid == 1946 and getWall.uid == 0 then
        doCreateItem(6290,1,wallPos)
        doTransformItem(item.uid,item.itemid-1) 
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
    end
end
 
Nah, me neither. I've tried to make a script like this before. But I just kept getting weird errors. I asked Souldrainer to help me, but not even he could find out what was wrong with it. o_O But I can't see anything that's wrong with your script atm. Slawkens.
 
I have no idea why it work now:
Code:
function onUse(cid, item, fp, itemEx, tp)
	local wallPos = {x=171, y=386, z=7, stackpos=1}
    	local getWall = getThingfromPos(wallPos)
	
	local function reset(uid)
		item = getThingfromPos(uid)
	     	doTransformItem(item.uid,1945)	
     		doCreateItem(6290,1,wallPos)
	end			

    if item.itemid == 1945 then
        doRemoveItem(getWall.uid,1)
        doTransformItem(item.uid,1946)
        addEvent(reset,1000,tp)
    elseif item.itemid == 1946 then
        doCreateItem(6290,1,wallPos)
        doTransformItem(item.uid,item.itemid-1) 
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
    end
end
I guess it is impossible to set as parameter item.uid but i saw many scripts where it works properly. Anyway it works now. Just change time.
 
Back
Top