• 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 stopEvent causes server crash!

feverdog

Active Member
Joined
Mar 10, 2008
Messages
229
Reaction score
36
As the title says, the stopEvent function causes my TFS 0.3.7 to crash.. I have tried everything and more but it crashes. I have tried to reproduce addEvent with coroutines, but when I use socket.sleep the entire server freezes and I couldn't find a way to make it Thread Safe.

Distro: TFS 0.3.7
Platform: Windows

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}} -- todo: see stackpos

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, event = {} -- armazenamento
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

	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
            
			stopEvent(event)
			event = 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

			stopEvent(event)
			doTransformItem(item.uid, LEVER.OFF)
		end
	end
 
	init(item)
	return true
end

I have no idea what to do, thanks in advance.
 
Dont declare event as local and check if it exists before stopping it (if(event ~= nil)then stopEvent(event) end)
 
Hello EvulMastah, thanks for the tips but it keeps crashing =s

Maybe something to do with the environment? =s I have tried to use setfenv and getenv with no success here and still got crashes.
 
Last edited:
Could you paste here a crash log?
I guess it should help us to resolve your problem.
 
Back
Top Bottom