• 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 Adding time to this script

sick

Member
Joined
Feb 5, 2009
Messages
258
Reaction score
6
Location
Lithuania, Vilnius
So i got this script: when i use the lamp the ladder appears, when i use it again, ladder disappears, however, I need to add a line that if lamp was used 1 time and ladder appeared, ladder would disappear automatically after 1 min.

Thanks in advance :thumbup:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local gatePosition = {x=912, y=992, z=7, stackpos=1}
	local getGate = getThingFromPos(gatePosition)
	
	if(item.uid == 6658) then
		if(item.itemid == 2069 and getGate.itemid == 0) then
			doCreateItem(1386, 1, gatePosition)
			doTransformItem(item.uid, item.itemid-1)
		elseif(item.itemid == 2068 and getGate.itemid == 1386) then
			doRemoveItem(getGate.uid, 1)
			doTransformItem(item.uid, item.itemid+1)
		else
			doPlayerSendCancel(cid, "The lamp seems to be already used recently.")
		end
	end
	return TRUE
end
 
Lua:
function createWall()
	doCreateItem(1386, 1, gatePosition)
	return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local gatePosition = {x=912, y=992, z=7, stackpos=1}
	local getGate = getThingFromPos(gatePosition)
	local time = 60 --- seconds.
	
	if(item.uid == 6658) then
		if(item.itemid == 2069 and getGate.itemid == 0) then
			doCreateItem(1386, 1, gatePosition)
			doTransformItem(item.uid, item.itemid-1)
		elseif(item.itemid == 2068 and getGate.itemid == 1386) then
			doRemoveItem(getGate.uid, 1)
			doTransformItem(item.uid, item.itemid+1)
			addEvent(createWall, time * 1000, gatePosition)
		else
			doPlayerSendCancel(cid, "The lamp seems to be already used recently.")
		end
	end
	return true
end
 
Lua:
local pos = {x=912, y=992, z=7}
local event = 0

local function reset(itP)
	doRemoveItem(getTileItemById(pos, 1386).uid)
	doTransformItem(getTileItemById(itP, 2068).uid, 2069)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 2069 then
		doCreateItem(1386, 1, pos)
		doTransformItem(item.uid, 2068)
		event = addEvent(reset, 60 * 1000, toPosition)
	elseif item.itemid == 2068 then
		stopEvent(event)
		reset(toPosition)
	end
	return true
end
 
The first part works, but after 1 minute it tries to remove the ladder and the error appears :
PHP:
[27/09/2010 22:10:44] [Error - Action Interface] 
[27/09/2010 22:10:44] In a timer event called from: 
[27/09/2010 22:10:44] data/actions/scripts/other/lamp.lua:onUse
[27/09/2010 22:10:44] Description: 
[27/09/2010 22:10:44] (luaDoRemoveItem) Item not found
 
try
Lua:
local pos = {x=95, y=139, z=7}
local event = 0
 
local function reset(itP)
if getTileItemById(itP, 1386).uid > 0 then
	doRemoveItem(getTileItemById(itP, 1386).uid)
	end
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 2068 then
		doCreateItem(1386, 1, pos)
		doTransformItem(item.uid, 2069)
		event = addEvent(reset, 60 * 1000, pos)
	elseif item.itemid == 2069 then
		stopEvent(event)
		reset(pos)
		doTransformItem(getTileItemById(toPosition, 2069).uid, 2068)
	end
	return true
end
 
Well it works kind of, however the lamp does not change id after the ladder disappears and this leads to the need of pressing lamp 2 times and people couldn't understand later what to do. They will come to the quest, see the turned on lamp, uses it, lamp turns off and nothing. They may not have enough brain to use the lamp 2 times, thats why i need it to change it's id...
 
sure
you have lol didnt you say if you close lamp --> ledder will be removed??? ,,, and the if you lighted it --> this to start event again. ???

And if the lamp is lighted and no one turned off then the ledder will disappear, so sure you have to close the lamp after that and open it again so the event start or this isnt logic?
 
Its easy for me when i will know how to do it, but if random people will try using already Turned On lamp once, it will turn off and they will leave it, cause most of the actions are done with just 1 mouse press
 
that is what you asked for .....


This how you will do
Lua:
local pos = {x=95, y=139, z=7}
local event = 0
 
local function reset(itP)
if getTileItemById(itP, 1386).uid > 0 then
	doRemoveItem(getTileItemById(itP, 1386).uid)
	end
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == 2068 or item.itemid == 2069 then
	if getTileItemById(pos, 1386).uid < 1 then
		doCreateItem(1386, 1, pos)
	    event = addEvent(reset, 60 * 1000, pos)
	else 
		stopEvent(event)
		reset(pos)
	end
end
	return doTransformItem(item.uid, (item.itemid == 2068 and 2069 or 2068))
end

and put this line :
Code:
<action actionid="xxx" event="script" value="xxx.lua"/>
so the action id you pu here yu put on item
 

Similar threads

Back
Top