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

stopEvent causes server crash!

feverdog

Active Member
Joined
Mar 10, 2008
Messages
229
Reaction score
36
The title says it all.. I'm using TFS 0.3.7, any help is appreciated.

Code:
local EXPIRY = 5 -- tempo em minutos para voltar ao normal
local LEVER_AID = 9500
local LEVER = { OFF = 1945,
	ON = 1946,
	POS = {x=1059, y=1200, z=9, stackpos=2}}

local GATE_ITEMID = 1546
local GATES_POS = {
	{x=1053, y=1193, z=9, stackpos=2},
	{x=1053, y=1194, z=9, stackpos=2},
}

local MONSTER_NAME = 'Legione Gladiator'
local MONSTERS_POS = {
	{x=1059, y=1197, z=9},
	{x=1061, y=1195, z=9},
}

local monsters = {}
local EVENT_ID = 91025643328
function onUse(cid, item, fromPosition, itemEx, toPosition)

	if (item.aid ~= LEVER_AID) then
		return false
	end

	if not(jlibs.isInArray(LEVER, item.itemid)) then
		return false
	end

	init(item)
	return true
end

function init(item)

	item = getThingFromPos(LEVER.POS)
	if (item.itemid == LEVER.OFF) then
		for _, pos in ipairs(GATES_POS) do
			local gate = getThingFromPos(pos)
			if (gate.itemid == GATE_ITEMID) then
				doRemoveItem(gate.uid, 1)
			end
		end

		for _, pos in ipairs(MONSTERS_POS) do
			local monster = doCreateMonster(MONSTER_NAME, pos)
			table.insert(monsters, monster)
		end

		local event = getStorage(EVENT_ID)
		if (event ~= nil) then
			stopEvent(event)
			doSetStorage(EVENT_ID, nil)
		end

		doSetStorage(EVENT_ID, addEvent(init, EXPIRY*1000, item))
		doTransformItem(item.uid, LEVER.ON)

	elseif (item.itemid == LEVER.ON) then
		for _, pos in ipairs(GATES_POS) do
			local gate = getThingFromPos(pos)
			if not(gate.itemid == GATE_ITEMID) then
				doCreateItem(GATE_ITEMID, 1, pos)
			end
		end

		for i, uid in ipairs(monsters) do
			doRemoveCreature(uid)
			monsters[i] = nil
		end

		local event = getStorage(EVENT_ID)
		if (event ~= nil) then
			stopEvent(event)
			doSetStorage(EVENT_ID, nil)
		end

		doTransformItem(item.uid, LEVER.OFF)
	end
end

Thanks in advance!
 
Hello, thanks for answering.. what do you mean with my stopEvents aren't events?
I really can't figure it out..
 
Back
Top