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

Automatic Events?

ELEM3NT

LUA Status: Beginner
Joined
Mar 12, 2009
Messages
191
Reaction score
0
Location
In your room without you knowing.
Okay well I'm looking for someone to like make a globalevent script that during each 30 minutes a tp appears during a certain spot which people can go into. But, say there is 3 events. Like for example 1)Pacman, 2)Snake, 3)RunAwayFromDaCop. Idk, well yea. And each 30 minutes it randomly chooses from those 3 events. Say its Pacman itll say like "Pacman events now starting! 2 Minutes left!" A tp appears at a spot and then teleports you to that spawn area. Then they play the Pacman event thingy, the last person in there the script will know and broadcast like "XXXX has won the event!" then that person gets 10 event tokens are something. I'm just wanting to learn this first before I actually start looking for actual events, cuz I know they're a b*tch to make. I tried looking for an event system somewhere but I can't find any.

Thank You, goodbye.:thumbup:
 
LUA:
local t = {
	[1] = {name='Pacman', tp={x=1, y=1, z=1} tpto={x=1, y=1, z=1}},
	[2] = {name='Snake'}, tp={x=1, y=1, z=1}, tpto={x=1, y=1, z=1}},
	[3] = {name='RunAwayFromTheCop'}, tp={x=1, y=1, z=1}, tpto={x=1, y=1, z=1}}
}

function onThink(cid, interval)
local r, m = t[math.random(1,3)], 2
	if r[1] then
		doCreateTeleport(1387, t[1].tpto, t[1].tp)
		doBroadcastMessage("The " .. t[1].name .. " teleport has been created and will remove in" .. m .. " minutes.")
		addEvent(onRemove, m * 60 * 1000)
	elseif r[2] then
		doCreateTeleport(1387, t[2].tpto, t[2].tp)
		doBroadcastMessage("The " .. t[2].name .. " teleport has been created and will remove in" .. m .. " minutes.")
		addEvent(onRemove2, m * 60 * 1000)
	elseif r[3] then
		doCreateTeleport(1387, t[3].tpto, t[3].tp)
		doBroadcastMessage("The " .. t[3].name .. " teleport has been created and will remove in" .. m .. " minutes.")
		addEvent(onRemove3, m * 60 * 1000)
	return true
end

function onRemove()
	doRemoveItem(getTileItemById(t[1].tp, 1387).uid)
	doBroadcastMessage('The' .. t[1].name .. ' teleport has been removed.')
return true
end

function onRemove2()
	doRemoveItem(getTileItemById(t[2].tp, 1387).uid)
	doBroadcastMessage('The' .. t[2].name .. ' teleport has been removed.')
	return true
end

function onRemove3()
	doRemoveItem(getTileItemById(t[3].tp, 1387).uid)
	doBroadcastMessage('The' .. t[3].name .. ' teleport has been removed.')
	return true
end
try this,
+REP if helped
 
Last edited:
Okay uh, I tried your script, I made it to this:

events.lua
LUA:
  local t =  {
        [1] = {name='Grab Dat Cheese', tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [2] = {name='Testing'}, tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [3] = {name='Other Testing'}, tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},	
}

function onThink(cid, interval)
local r, m = t[math.random(1,3)], 2
        if r[1] then
                doCreateTeleport(1387, t[1].tpto, t[1].tp)
                doBroadcastMessage("The " .. t[1].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove, m * 60 * 1000)
        elseif r[2] then
                doCreateTeleport(1387, t[2].tpto, t[2].tp)
                doBroadcastMessage("The " .. t[2].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove2, m * 60 * 1000)
        elseif r[3] then
                doCreateTeleport(1387, t[3].tpto, t[3].tp)
                doBroadcastMessage("The " .. t[3].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove3, m * 60 * 1000)
        return true
end

function onRemove()
        doRemoveItem(getTileItemById(t[1].tp, 1387).uid)
        doBroadcastMessage('The' .. t[1].name .. ' teleport has been removed.')
return true
end

function onRemove2()
        doRemoveItem(getTileItemById(t[2].tp, 1387).uid)
        doBroadcastMessage('The' .. t[2].name .. ' teleport has been removed.')
        return true
end

function onRemove3()
        doRemoveItem(getTileItemById(t[3].tp, 1387).uid)
        doBroadcastMessage('The' .. t[3].name .. ' teleport has been removed.')
        return true
end

and the error on my console is this:

Code:
[14/05/2010 21:43:27] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/events.lua:4: unexpected symbol near '['
[14/05/2010 21:43:27] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/events.lua)
[14/05/2010 21:43:27] data/globalevents/scripts/events.lua:4: unexpected symbol near '['
[14/05/2010 21:43:27] Reloaded global events.

I have no idea why though, anybody? BUMP. :peace:
 
LUA:
  local t =  {
        [1] = {name='Grab Dat Cheese', tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [2] = {name='Testing'}, tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [3] = {name='Other Testing'}, tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}}     
}

function onThink(cid, interval)
local r, m = t[math.random(1,3)], 2
        if r[1] then
                doCreateTeleport(1387, t[1].tpto, t[1].tp)
                doBroadcastMessage("The " .. t[1].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove, m * 60 * 1000)
        elseif r[2] then
                doCreateTeleport(1387, t[2].tpto, t[2].tp)
                doBroadcastMessage("The " .. t[2].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove2, m * 60 * 1000)
        elseif r[3] then
                doCreateTeleport(1387, t[3].tpto, t[3].tp)
                doBroadcastMessage("The " .. t[3].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove3, m * 60 * 1000)
        return true
end

function onRemove()
        doRemoveItem(getTileItemById(t[1].tp, 1387).uid)
        doBroadcastMessage('The' .. t[1].name .. ' teleport has been removed.')
return true
end

function onRemove2()
        doRemoveItem(getTileItemById(t[2].tp, 1387).uid)
        doBroadcastMessage('The' .. t[2].name .. ' teleport has been removed.')
        return true
end

function onRemove3()
        doRemoveItem(getTileItemById(t[3].tp, 1387).uid)
        doBroadcastMessage('The' .. t[3].name .. ' teleport has been removed.')
        return true
end
 
Hmmmm. Well i've tried your script just now and got the same error. I noticed that there are these '}' symbols here:

LUA:
        [2] = {name='Testing'}, tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [3] = {name='Other Testing'}, tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}}

If you can notice theres a } after {name='Testing'}, tp etc~~~~
I took them out and now I get this error:
Code:
[15/05/2010 04:45:10] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/events.lua:40: 'end' expected (to close 'function' at line 7) near '<eof>'
[15/05/2010 04:45:10] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/events.lua)
[15/05/2010 04:45:10] data/globalevents/scripts/events.lua:40: 'end' expected (to close 'function' at line 7) near '<eof>'

Heres the script I used:

LUA:
  local t =  {
        [1] = {name='Grab Dat Cheese', tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [2] = {name='Testing', tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}},
        [3] = {name='Other Testing', tp={x=951, y=1024, z=7}, tpto={x=947, y=1025, z=7}}    
}

function onThink(cid, interval)
local r, m = t[math.random(1,3)], 2
        if r[1] then
                doCreateTeleport(1387, t[1].tpto, t[1].tp)
                doBroadcastMessage("The " .. t[1].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove, m * 60 * 1000)
        elseif r[2] then
                doCreateTeleport(1387, t[2].tpto, t[2].tp)
                doBroadcastMessage("The " .. t[2].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove2, m * 60 * 1000)
        elseif r[3] then
                doCreateTeleport(1387, t[3].tpto, t[3].tp)
                doBroadcastMessage("The " .. t[3].name .. " event has started, the tp is in the depot and will be removed in" .. m .. " minutes.")
                addEvent(onRemove3, m * 60 * 1000)
        return true
end

function onRemove()
        doRemoveItem(getTileItemById(t[1].tp, 1387).uid)
        doBroadcastMessage('The' .. t[1].name .. ' teleport has been removed.')
return true
end

function onRemove2()
        doRemoveItem(getTileItemById(t[2].tp, 1387).uid)
        doBroadcastMessage('The' .. t[2].name .. ' teleport has been removed.')
        return true
end

function onRemove3()
        doRemoveItem(getTileItemById(t[3].tp, 1387).uid)
        doBroadcastMessage('The' .. t[3].name .. ' teleport has been removed.')
        return true
end

So if you can fix this, feel free to do so. Thanks!:peace:
 
LUA:
  local t =  {
        [1] = {name='Pacman', tp={x=1, y=1, z=1}, tpto={x=1, y=1, z=1}},
        [2] = {name='Snake', tp={x=1, y=1, z=1}, tpto={x=1, y=1, z=1}},
        [3] = {name='RunAwayFromTheCop', tp={x=1, y=1, z=1}, tpto={x=1, y=1, z=1}}
}

function onThink(cid, interval)
local r, m = t[math.random(1,3)], 2
        if r[1] then
                doCreateTeleport(1387, t[1].tpto, t[1].tp)
                doBroadcastMessage("The " .. t[1].name .. " teleport has been created and will remove in" .. m .. " minutes.")
                addEvent(onRemove, m * 60 * 1000)
        elseif r[2] then
                doCreateTeleport(1387, t[2].tpto, t[2].tp)
                doBroadcastMessage("The " .. t[2].name .. " teleport has been created and will remove in" .. m .. " minutes.")
                addEvent(onRemove2, m * 60 * 1000)
        elseif r[3] then
                doCreateTeleport(1387, t[3].tpto, t[3].tp)
                doBroadcastMessage("The " .. t[3].name .. " teleport has been created and will remove in" .. m .. " minutes.")
                addEvent(onRemove3, m * 60 * 1000)
        return true
end

function onRemove()
        doRemoveItem(getTileItemById(t[1].tp, 1387).uid)
        doBroadcastMessage('The' .. t[1].name .. ' teleport has been removed.')
return true
end

function onRemove2()
        doRemoveItem(getTileItemById(t[2].tp, 1387).uid)
        doBroadcastMessage('The' .. t[2].name .. ' teleport has been removed.')
        return true
end

function onRemove3()
        doRemoveItem(getTileItemById(t[3].tp, 1387).uid)
        doBroadcastMessage('The' .. t[3].name .. ' teleport has been removed.')
        return true
end 
end

should work now
 
Code:
local t = {
	[{1, 2}] = {name = "Pacman", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, mintes = 2},
	[{2, 3}] = {name = "Snake", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, minutes = 2},
	[{3, 4}] = {name = "RunAwayFromDaCop", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, minutes = 2}
}
local areas = {
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}},
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}},
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}}
}
local function check()
	local thisTable = {}
	for _, f in ipairs(areas) do
		for x = f.from.x, f.to.x do
			for y = f.from.y, f.to.y do
				for z = f.from.z, f.to.z do
					local pos = {x = x, y = y, z = z}
					local player = getTopCreature(pos).uid
					if player > 0 and isPlayer(player) then table.insert(thisTable, player) else table.remove(thisTable, player) end
				end
			end
		end
	end
	for _, j in ipairs(thisTable) do
		if #j > 0 and #j < 2 then
			doBroadcastMessage(getCreatureName(j[1]) .. " has won the event!")
			doTeleportThing(j[1], getTownTemplePosition(getPlayerTown(j[1])), true)
		end
	end
	return addEvent(function() check end, 5)
end
function onThink(interval, lastExecution)
	for event, r in pairs(t) do
		local rand = math.random(5)
		if rand >= event[1] and rand <= event[2] then
			doCreateTeleport(1387, r.teleportTo, r.teleportPos)
			doBroadcastMessage(r.name .. " events now starting! 2 Minutes left!")
			local it = getTileItemById(r.teleportPos, 1387).uid
			addEvent(function() doRemoveItem(it) end, r.minutes * 60)
			check()
		end
		break
	end
	return true
end
XD fuk
 
Last edited:
Alright, Xeon, I used your script and I got this error:

Code:
[15/05/2010 14:54:24] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/events.lua:30: '=' expected near 'end'
[15/05/2010 14:54:24] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/events.lua)
[15/05/2010 14:54:24] data/globalevents/scripts/events.lua:30: '=' expected near 'end'

It has to do something with this I think?
LUA:
	return addEvent(function() check end, 5)
 
Code:
local t = {
	[{1, 2}] = {name = "Pacman", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, mintes = 2},
	[{2, 3}] = {name = "Snake", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, minutes = 2},
	[{3, 4}] = {name = "RunAwayFromDaCop", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, minutes = 2}
}
local areas = {
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}},
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}},
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}}
}
local function check()
	local thisTable = {}
	for _, f in ipairs(areas) do
		for x = f.from.x, f.to.x do
			for y = f.from.y, f.to.y do
				for z = f.from.z, f.to.z do
					local pos = {x = x, y = y, z = z}
					local player = getTopCreature(pos).uid
					if player > 0 and isPlayer(player) then table.insert(thisTable, player) else table.remove(thisTable, player) end
				end
			end
		end
	end
	for _, j in ipairs(thisTable) do
		if #j > 0 and #j < 2 then
			doBroadcastMessage(getCreatureName(j[1]) .. " has won the event!")
			doTeleportThing(j[1], getTownTemplePosition(getPlayerTown(j[1])), true)
		end
	end
	return addEvent(check, 5)
end
function onThink(interval, lastExecution)
	for event, r in pairs(t) do
		local rand = math.random(5)
		if rand >= event[1] and rand <= event[2] then
			doCreateTeleport(1387, r.teleportTo, r.teleportPos)
			doBroadcastMessage(r.name .. " events now starting! 2 Minutes left!")
			local it = getTileItemById(r.teleportPos, 1387).uid
			addEvent(function() doRemoveItem(it) end, r.minutes * 60)
			check()
		end
		break
	end
	return true
end
 
Xeon, thanks so much for all your help! I don't get any console errors anymore but.... I still get an error once the event is activated. Like such:

Code:
[16/05/2010 01:03:43] [Error - GlobalEvent Interface] 
[16/05/2010 01:03:43] In a timer event called from: 
[16/05/2010 01:03:43] data/globalevents/scripts/events.lua:onThink
[16/05/2010 01:03:43] Description: 
[16/05/2010 01:03:43] (luaDoRemoveItem) Item not found
[16/05/2010 01:03:44] > Broadcasted message: "Pacman event is now starting! TP is in depot. 2 Minute remaining.".

Also, heres the big thing. Is it easier for it to be a global event or talkaction? Because if anyone is willingly nice enough to the script as a talkaction. Like it'll be simplier also because I only want it to be like /startevent pacman, /startevent snakes, /startevent runawayfromdacops. It'll each be in different scripts so I can manually start it if I wanted to. Also, it can be automatically made + random too if someone can also make me a script that does that event but random from pacman,snakes,runawayfromdacops. So like a globalevent that does: /startevent ~~~~ randomly from the 3. Kinda hard to explain it all haha. But if its easier for the globalevent script then i'll just name the talkaction scripts like /startevent 1, /startevent 2, etc. So thank you you read all this. Hopefully someone is nice enough to make me this.

Goodbye:peace:
 
Code:
local t = {
	[{1, 2}] = {name = "Pacman", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, mintes = 2},
	[{2, 3}] = {name = "Snake", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, minutes = 2},
	[{3, 4}] = {name = "RunAwayFromDaCop", teleportPos = {x = 100, y = 200, z = 7}, teleportTo = {x = 100, y = 200, z = 7}, minutes = 2}
}
local areas = {
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}},
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}},
	{from = {x = 100, y = 200, z = 7}, to = {x = 100, y = 200, z = 7}}
}
local function check()
	local thisTable = {}
	for _, f in ipairs(areas) do
		for x = f.from.x, f.to.x do
			for y = f.from.y, f.to.y do
				for z = f.from.z, f.to.z do
					local pos = {x = x, y = y, z = z}
					local player = getTopCreature(pos).uid
					if player > 0 and isPlayer(player) then table.insert(thisTable, player) else table.remove(thisTable, player) end
				end
			end
		end
	end
	for _, j in ipairs(thisTable) do
		if #j > 0 and #j < 2 then
			doBroadcastMessage(getCreatureName(j[1]) .. " has won the event!")
			doTeleportThing(j[1], getTownTemplePosition(getPlayerTown(j[1])), true)
		end
	end
	return addEvent(check, 5)
end
local function remove(pos)
	local it = getTileItemById(pos, 1387).uid
	if it > 0 then
		doRemoveItem(it)
	end
end
function onThink(interval, lastExecution)
	for event, r in pairs(t) do
		local rand = math.random(5)
		if rand >= event[1] and rand <= event[2] then
			doCreateTeleport(1387, r.teleportTo, r.teleportPos)
			doBroadcastMessage(r.name .. " events now starting! 2 Minutes left!")
			addEvent(remove, r.minutes * 60, r.teleportPos)
			check()
		end
		break
	end
	return true
end
 
Gah!! I'm sorry guys. It's alright you need to do anything for me anymore. Im just really tired couldn't really think. I didn't really reread over what I typed now that I did it does seem like im being a bossy stuck-up. "Is there anyway you can make the script I asked for?" That sounds fucked up. haha! Sorry.
 
Back
Top