// ============================================================= //
// ==================<    ADVANCED HOSTING    >================= //
// ==================<   by #Octothorp team   >================= //
// ============================================================= //
// =========================< SETTINGS >======================== //
// ============================================================= //
private const string SERVER_NAME = "My Server";				 // set your server name
private const bool KILL_HOST_ON_START = false;				 // set to true to remove yourself on round start
// ============================================================= //
private const bool SHOW_POPUP_AD = true;				 // set to true to show popup message in the beginning of round
private Color POPUP_TEXT_COLOR = new Color(255, 0, 0);			 // set the text's color in RGB scale
private int POPUP_AD_TIME = 1000 * 7;					 // set to 0 to always display popup ad
// ============================================================= //
private const bool SHOW_CHAT_ADS = true;				 // set to true tp display chat ads periodically
private const bool CHAT_ADS_DISPLAY_ONE_ON_START = true;		 // set to true to display one chat message at start
private const bool CHAT_ADS_RANDOM_ORDER = true;			 // set to true to enable shuffling ad lines
private const int CHAT_ADS_INTERVAL = 1000 * 60;			 // delay between two chat ads
// ============================================================= //
// ============================================================= //
// ============================================================= //

private string POPUP_AD_CONTENT =	// use ("...\n" + "...") to make a new line
	"-==== SERVER RULES ====-\n" +
	" - Rule #1\n" +
	" - Rule #2\n" +
	" - Rule #3\n" +
	" - Rule #4\n" +
	" - Rule #5\n" +
	"-====================-";

private string[] CHAT_ADS_CONTENT = new string[]{
	"Ad #1",
	"Ad #2",
	"Ad #2"
};

// |=============================| //
// |===< HERE COMES THE CODE >===| //
// V=============================V //

Random rand = new Random();

public void OnStartup(){
	if (KILL_HOST_ON_START) Game.GetActiveUsers()[0].GetPlayer().Kill();

	if (SHOW_CHAT_ADS){
		CreateTimer(CHAT_ADS_INTERVAL, 0, "Chat_DisplayAd", "");
		if (CHAT_ADS_DISPLAY_ONE_ON_START) Chat_DisplayAd(new TriggerArgs(null, null, false));
	}

	if (SHOW_POPUP_AD){
		Game.ShowPopupMessage(POPUP_AD_CONTENT, POPUP_TEXT_COLOR);
		if (POPUP_AD_TIME != 0) CreateTimer(POPUP_AD_TIME, 1, "Popup_HideAd", "");
	}
}

private int m_curMessageNum = -1;
public void Chat_DisplayAd(TriggerArgs args){
	if (CHAT_ADS_RANDOM_ORDER) m_curMessageNum = rand.Next(CHAT_ADS_CONTENT.Length);
	else {
		if (m_curMessageNum == CHAT_ADS_CONTENT.Length - 1) m_curMessageNum = 0;
		else m_curMessageNum ++;
	}

	Game.RunCommand("/MSG " + SERVER_NAME + ": " + CHAT_ADS_CONTENT[m_curMessageNum]);
}

public void Popup_HideAd(TriggerArgs args){
	Game.HidePopupMessage();
}

private void CreateTimer(int interval, int count, string method, string id) {
	IObjectTimerTrigger timerTrigger = (IObjectTimerTrigger)Game.CreateObject("TimerTrigger"); 
	timerTrigger.SetIntervalTime(interval);
	timerTrigger.SetRepeatCount(count);
	timerTrigger.SetScriptMethod(method);
	timerTrigger.CustomId = id;
	timerTrigger.Trigger();
}