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

[GlobalEvents] Auto Command

ELEM3NT

LUA Status: Beginner
Joined
Mar 12, 2009
Messages
191
Reaction score
0
Location
In your room without you knowing.
Hello there, can anyone make me a globalevents script thats kinda like an auto broadcast? Like the globalevent script will selfsay itsself to activate another command. Umm, like the clean script back in the day, an NPC selfsays "/clean" then it cleans every 30 minutes. I want something like that but with globalevents, but heres the thing, for example say there was 3 different cleans, like /clean 1, /clean 2, /clean 3. I want the globalevents to do the command but randomly out of the 3. Im wanting this script because I have a talkaction script, /startevent1, /startevent2, /startevent3, and each script has different events in it. I can do the script manually but I also want a globalevent script to do it automatic. So kinda heres an example:

GlobalEvent Script: math.random(/startevent1,/startevent3) or something like that. Haha!

PleaseAndThankYou!^_^
 
Well you can't execute a talkaction by using a global event..
We need the event script to transform them to globalevent.
 
Heres what is the talkactions script

/startevent1:
LUA:
local minutes = 2 -- how many minutes you want before it removes the portal
local tp = {x=952, y=1021, z=7} -- the place where the portal will appear
local tpto = {x=949, y=1025, z=7} -- the pos of where the portal will lead you
local message = 'The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.' -- the message that will appear once activated.
local removemessage = 'The Maze Event portal has been removed.' -- the message that will appear once tp is removed.


function onSay(cid, words, param)
        doCreateTeleport(1387, tpto, tp)
                doBroadcastMessage(message)
                        return addEvent(onRemove, minutes*60*1000)
end

function onRemove()
                local it = getTileItemById(tp, 1387).uid
        if it > 0 then
                doRemoveItem(it)
        doBroadcastMessage(removemessage)
return true
end
end

And uh, What if it I made it a NPC script to do this? And just place the NPC out of the map so it can just do these events. Is this possible instead of a globalevents script?

@wesoly136, Um I don't really understand your script cuz I'm a noob, lol, can you please explain it more? Thanks :D
 
LUA:
local t = {
	[1] = {swords='/startevent 1',ewords='/endevent 1',minutes = 2, tp={x=952, y=1021, z=7}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
	[2] = {swords='/startevent 2',ewords='/endevent 2',minutes = 2, tp={x=952, y=1021, z=7}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
	[3] = {swords='/startevent 2',ewords='/endevent 3',minutes = 2, tp={x=952, y=1021, z=7}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
	}


function onSay(cid, words, param)
local tile = getTileItemById(tp, 1387).uid > 0
	if words == t[1].swords then
		doCreateTeleport(1387, t[1].tpto, t[1].tp)
		doBroadcastMessage(t[1].msg)
	elseif words == t[1].ewords then
		if getTileItemById(tp, 1387).uid > 0 then
			doRemoveItem(tile)
			return doBroadcastMessage(t[1].rmsg)
		end
	elseif words == t[2].swords then
		doCreateTeleport(1387, t[2].tpto, t[2].tp)
		doBroadcastMessage(t[2].msg)
	elseif words == t[2].ewords then
		if getTileItemById(tp, 1387).uid > 0 then
			doRemoveItem(tile)
			return doBroadcastMessage(t[2].rmsg)
		end
	elseif words == t[3].swords then
		doCreateTeleport(1387, t[3].tpto, t[3].tp)
		doBroadcastMessage(t[3].msg)
	elseif words == t[3].ewords then
		if getTileItemById(tp, 1387).uid > 0 then
			doRemoveItem(tile)
			return doBroadcastMessage(t[3].rmsg)
		end
	end
	return true
end

try this
 
@unknown666

Your script:
LUA:
local t = {
        [1] = {swords='/startevent 1',ewords='/endevent 1',minutes = 2, tp={x=952, y=1021, z=7}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
        [2] = {swords='/startevent 2',ewords='/endevent 2',minutes = 2, tp={x=952, y=1021, z=7}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
        [3] = {swords='/startevent 2',ewords='/endevent 3',minutes = 2, tp={x=952, y=1021, z=7}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
        }


function onSay(cid, words, param)
local tile = getTileItemById(tp, 1387).uid > 0
        if words == t[1].swords then
                doCreateTeleport(1387, t[1].tpto, t[1].tp)
                doBroadcastMessage(t[1].msg)
        elseif words == t[1].ewords then
                if getTileItemById(tp, 1387).uid > 0 then
                        doRemoveItem(tile)
                        return doBroadcastMessage(t[1].rmsg)
                end
        elseif words == t[2].swords then
                doCreateTeleport(1387, t[2].tpto, t[2].tp)
                doBroadcastMessage(t[2].msg)
        elseif words == t[2].ewords then
                if getTileItemById(tp, 1387).uid > 0 then
                        doRemoveItem(tile)
                        return doBroadcastMessage(t[2].rmsg)
                end
        elseif words == t[3].swords then
                doCreateTeleport(1387, t[3].tpto, t[3].tp)
                doBroadcastMessage(t[3].msg)
        elseif words == t[3].ewords then
                if getTileItemById(tp, 1387).uid > 0 then
                        doRemoveItem(tile)
                        return doBroadcastMessage(t[3].rmsg)
                end
        end
        return true
end
works but its not really the thing I'm looking for.. :/
 
I don't have any errors, I'm just looking for the script that does another script. Sorry, it's just really hard to explain.

I think it has to be an npc script instead of a globalevents. So I just make a npc named Auto Eventer, then I just put him somewhere in the map and each 30 minutes that npc will execute the command /startevent1. But i have 3 events. So the npc will do /startevent2 or /startevent3 or /starevent1 in one 30 minutes. Then on the next 30 minutes will be /startevent1. Or /startevent2 or /startevent3. It'll just be random from the 3. And if possible, I can add more then 3 randoms? Thanks. Wrote this on my phone so sorry if errors.
Bye bye.
 
@topic
I transformed and shortened the script of unknown666 to globalevent.
PHP:
local t =  {
        [1] = {minutes = 1, tp={x=1000, y=1000, z=7, stackpos=255}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
        [2] = {minutes = 1, tp={x=1000, y=1000, z=7, stackpos=255}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
        [3] = {minutes = 1, tp={x=1000, y=1000, z=7, stackpos=255}, tpto={x=949, y=1025, z=7}, msg='The Maze Event has started! To begin, enter the portal in depot, 2 minutes remaining.',rmsg='The Maze Event portal has been removed.'},
    }
local howLongToSleep = 2 --in intervals


_EVENT,_SLEEP_EVENT,_EVENT_DURATION = 0,0,0
function onThink(interval, lastExecution, thinkInterval)
	local random_event = math.random(1,#t)
	
	if not(_SLEEP_EVENT <= 0) then
		_SLEEP_EVENT = _SLEEP_EVENT-1
		return true
	end
	
	if _EVENT ~= 0 then
		if _EVENT_DURATION <= 0 then
			local tile = getTileItemById(t[_EVENT].tp, 1387).uid 
			local a = tile > 0 and (doRemoveItem(tile) and doBroadcastMessage(t[_EVENT].rmsg)) or true
			_EVENT = 0
			_SLEEP_EVENT = howLongToSleep
			return true
		else
			_EVENT_DURATION = _EVENT_DURATION-1
			return true
		end
	end
	_EVENT,_EVENT_DURATION = random_event,t[random_event].minutes-1
	return doCreateTeleport(1387, t[random_event].tpto, t[random_event].tp) and doBroadcastMessage(t[random_event].msg)
end

Globalevents.xml
Code:
<globalevent name="Event" interval="60" event="script" value="events.lua"/>

In config just set the tp position where tp should appear and the toposition where it should lead and the event of the special event.

I also added a function to make the event sleep between 2 events.
Just set howLongToSleep to the number of minutes.
Example:
if howLongToSleep is == 2 then after a event ended the next event will occure in 3 minutes. (2 minutes slept)
 
Last edited by a moderator:
@unknown666
I know that it is not possible to do that, that's why I asked if it's possible if it's a NPC script.. It's just really hard to explain! Sorry! :(

@Rhux, actually uh, I know that probably works Rhux, but it's still impossible to make a globalevents do a talkactions script, so is it possible to do it as a NPC script?
 
Last edited:
Back
Top