// -- using conf/ScriptConfig.conf

// run this file to broadcast immediately (the timer will not change if you do!)

#permission=255

#onload

	// check if this script should be loaded.
	if ?{or,?{not ?{isset enable}} ?{not ${enable}}}
		log ** AutoBroadcast: skipped loading.	
		return
	endif
    
    // convert secs into msecs
    set,timer ${secs}
    mul,timer 1000
    
    // we need this variable later as "array-index"
    set,x 0
	
	// unregister the timer if it has been registered before
	removeevent event_{${@myname}}
    
    // register the timer.
    // script name is "autobroadcast", so the event name will be "event_autobroadcast" and the script command to call will be "autobroadcast"
    // so we basically register ourselves
    addevent,event_{${@myname}},${timer} ${@myname}
	
	// yay we are loaded :)
    log ** AutoBroadcast loaded. ${textcount} Texts.
    
#endonload

// --- begin of the script body ---

// every call the value of x gets increased by 1
add,x 1

// broadcast the text number x
CMD ${cmd} ${text${x}}

// if x = textcount: reset text counter x to 0 (using the modulo operator)
mod,x ${textcount}


