init()
{
	// Draws a team icon over teammates
	level.drawfriend = [[level.drm_cvardef]]("scr_drawfriend", 1, 0, 1, "int");

	// Force respawning
	level.wwx_forcespawn = [[level.drm_cvardef]]("scr_forcerespawn",0,0,1,"int");

	// if death music is on, this overrides forcespawn
	if(level.wwx_forcespawn && level.wwx_deathmusic)
	{
		setCvar("scr_forcerespawn", "0");
		level.wwx_forcespawn = false;
	}

	// Auto Team Balancing
	level.teambalance = [[level.wwx_cvardef]]("scr_teambalance",1,0,1,"int");

	// Time limit per map
	level.timelimit = [[level.drm_cvardef]]("scr_" + level.wwx_currentgt + "_timelimit", 30, 0, 1440, "float");

	// Score limit per map
	level.scorelimit = [[level.drm_cvardef]]("scr_" + level.wwx_currentgt + "_scorelimit", 20, 0, 9999, "int");

	if(level.wwx_roundbased)
	{
		// round limit
		level.roundlimit = [[level.drm_cvardef]]("scr_" + level.wwx_currentgt+ "_roundlimit",5,0,21,"int");

		// round length
		level.roundlength = [[level.drm_cvardef]]("scr_" + level.wwx_currentgt+ "_roundlength",10,1,60,"float");

		// grace period
		level.graceperiod = [[level.drm_cvardef]]("scr_" + level.wwx_currentgt+ "_graceperiod",0,0,60,"float");

		// bomb timer?
		if(level.wwx_currentgt == "sd")
		{
			level.bombtimer = [[level.drm_cvardef]]("scr_sd_bombtimer",60,30,120,"int");
			level.planttime = [[level.drm_cvardef]]("scr_sd_planttime",5,1,30,"int");
			level.defusetime = [[level.drm_cvardef]]("scr_sd_defusetime",10,1,30,"int");
		}
	}
	else if(level.wwx_currentgt == "htf")
	{
		level.mode = [[level.drm_cvardef]]("scr_htf_mode", 0, 0, 3, "int");												// balance mode
		level.holdtime = [[level.drm_cvardef]]("scr_htf_holdtime", 90, 1, 999, "int");								// flag hold time
		level.flagrecovertime = [[level.drm_cvardef]]("scr_htf_flagrecovertime", 180, 0, 999, "int");			// flag recover time
		level.flagspawndelay = [[level.drm_cvardef]]("scr_htf_flagspawndelay", 15, 0, 999, "int");			// flag spawn delay
		level.randomflagspawns = [[level.drm_cvardef]] ("scr_htf_randomflagspawns", 1, 0, 2, "int");		// random flag spawn points
		level.forcerespawn = [[level.drm_cvardef]]("scr_forcerespawn",0,0,60,"int");							// Force respawning
		level.PointsForKillingPlayers = [[level.drm_cvardef]] ("scr_htf_pointsforkillingplayers", 1, -100, 100, "int");
		level.PointsForKillingFlagCarrier	= [[level.drm_cvardef]] ("scr_htf_pointsforkillingflagcarrier", 2, 0, 100, "int");
		level.PointsForStealingFlag = [[level.drm_cvardef]] ("scr_htf_pointsforstealingflag", 3, 0, 100, "int");
		level.PointsForHoldingFlag = [[level.drm_cvardef]] ("scr_htf_pointsforholdingflag", 2, 0, 100, "int");
		level.PointsForAssistingFlagCarrier	= [[level.drm_cvardef]] ("scr_htf_pointsforassistingflagcarrier", 1, 0, 100, "int");
		level.spawndistance = [[level.drm_cvardef]] ("scr_htf_spawndistance", 1000, 1, 999999, "int");
		level.flagprotectiondistance = [[level.drm_cvardef]] ("scr_htf_flagprotectiondistance", 800, 1, 999999, "int");
	}

	// player spawn delay?
	if(level.wwx_currentgt == "ctf" || level.wwx_currentgt == "htf") level.respawndelay = [[level.drm_cvardef]]("scr_" + level.wwx_currentgt + "_spawndelay",0,0,60,"int");

	// additional cvars for gametypes
	if(level.wwx_currentgt == "hq")
	{
		level.wwx_hq_radio_zradius = [[level.drm_cvardef]]("wwx_hq_radio_zradius", 6, 0, 12, "int") * 12;			// height radius for radio (in feet)
		level.wwx_hq_radio_spawntime = [[level.drm_cvardef]]("wwx_hq_radio_spawntime", 45, 0, 240, "int");	// spawn time for radio
		level.wwx_hq_radio_holdtime = [[level.drm_cvardef]]("wwx_hq_radio_holdtime", 120, 10, 1440, "int");	// holdtime for radio
		level.wwx_hq_respawn_time = [[level.drm_cvardef]]("wwx_hq_respawn_time", 10, 1, 240, "int");			// respawn time for player
		level.wwx_hqpoints_teamneut = [[level.drm_cvardef]]("wwx_hqpoints_teamneut", 10, 0, 999, "int");		// team neutralize radio points
		level.wwx_hqpoints_playerneut = [[level.drm_cvardef]]("wwx_hqpoints_playerneut", 2, 0, 999, "int");	// player neutralize radio points
		level.wwx_hqpoints_teamcap = [[level.drm_cvardef]]("wwx_hqpoints_teamcap", 0, 0, 999, "int");			// team radio capture points
		level.wwx_hqpoints_playercap = [[level.drm_cvardef]]("wwx_hqpoints_playercap", 2, 0, 999, "int");		// player radio capture points
		level.wwx_hqpoints_defpps = [[level.drm_cvardef]]("wwx_hqpoints_defpps", 1, 0, 999, "int");				// defending team points per second
	}
	else if(level.wwx_currentgt == "chq")
	{
		level.wwx_chq_radio_zradius = [[level.drm_cvardef]]("wwx_chq_radio_zradius", 6, 0, 12, "int") * 12;			// height radius for radio (in feet)
		level.wwx_chq_radio_spawntime = [[level.drm_cvardef]]("wwx_chq_radio_spawntime", 45, 0, 240, "int");	// spawn time for radio
		level.wwx_chq_radio_holdtime = [[level.drm_cvardef]]("wwx_chq_radio_holdtime", 120, 60, 1440, "int");	// holdtime for radio
		level.wwx_chqpoints_teamneut = [[level.drm_cvardef]]("wwx_chqpoints_teamneut", 10, 0, 999, "int");		// team neutralize radio points
		level.wwx_chqpoints_playerneut = [[level.drm_cvardef]]("wwx_chqpoints_playerneut", 2, 0, 999, "int");		// player neutralize radio points
		level.wwx_chqpoints_teamcap = [[level.drm_cvardef]]("wwx_chqpoints_teamcap", 0, 0, 999, "int");			// team radio capture points
		level.wwx_chqpoints_playercap = [[level.drm_cvardef]]("wwx_chqpoints_playercap", 2, 0, 999, "int");		// player radio capture points
		level.wwx_chqpoints_defpps = [[level.drm_cvardef]]("wwx_chqpoints_defpps", 1, 0, 999, "int");					// defending team points per second
	}
	else if(level.wwx_currentgt == "ctf")
	{
		level.wwx_ctfpoints_teamcf = [[level.drm_cvardef]]("wwx_ctfpoints_teamcf", 1, 0, 999, "int");			// team capture points
		level.wwx_ctfpoints_playercf = [[level.drm_cvardef]]("wwx_ctfpoints_playercf", 10, 0, 999, "int");	// player capture points
		level.wwx_ctfpoints_playerrf = [[level.drm_cvardef]]("wwx_ctfpoints_playerrf", 2, 0, 999, "int");		// player return flag points
	}
	else if(level.wwx_currentgt == "sd")
	{
		level.wwx_sdpoints_plant = [[level.drm_cvardef]]("wwx_sdpoints_plant", 0, 0, 999, "int");			// points for planting a bomb
		level.wwx_sdpoints_defuse = [[level.drm_cvardef]]("wwx_sdpoints_defuse", 0, 0, 999, "int");		// points for defusing a bomb
	}
	else if(level.wwx_currentgt == "ihtf")
	{
		level.HoldTimeToScore = [[level.drm_cvardef]]("scr_ihtf_holdtimetoscore", 10, 1, 99999, "int");	// flag hold time	
		level.PointsForHoldingFlag = [[level.drm_cvardef]]("scr_ihtf_pointsforholdingflag", 2, 0, 100, "int");
		level.flagspawndelay = [[level.drm_cvardef]]("scr_ihtf_flagspawndelay", 15, 0, 9999, "int");
		level.respawndelay = [[level.drm_cvardef]]("scr_ihtf_respawndelay", 10, 0, 600, "int");	// Remove spawnpoint which is used by the flag?
		level.forcerespawn = [[level.drm_cvardef]]("scr_forcerespawn",0,0,60,"int");		// Force respawning
	}
	else if(level.wwx_currentgt == "vip")
      {
	      level.vipmaxsmokenades = 9;
	      level.vipmaxfragnades = 9;
	      level.respawndelay = [[level.drm_cvardef]] ("scr_vip_respawndelay", 10, 0, 600, "int");
	      level.vipdelay = [[level.drm_cvardef]] ("scr_vip_vipdelay", 5, 0, 600, "int");
	      level.vipvisiblebyteammates = [[level.drm_cvardef]] ("scr_vip_vipvisiblebyteammates", 1, 0, 1, "int");
	      level.vipvisiblebyenemies = [[level.drm_cvardef]] ("scr_vip_vipvisiblebyenemies", 1, 0, 1, "int");
	      level.pointsforkillingvip = [[level.drm_cvardef]] ("scr_vip_pointsforkillingvip", 5, -999, 999, "int");
	      level.pointsforprotectingvip = [[level.drm_cvardef]] ("scr_vip_pointsforprotectingvip", 3, -999, 999, "int");
	      level.vippoints = [[level.drm_cvardef]] ("scr_vip_vippoints", 2, -999, 999, "int");
	      level.vippointscycle = [[level.drm_cvardef]] ("scr_vip_vippoints_cycle", 3, 0, 600, "int");
	      level.vipprotectiondistance = [[level.drm_cvardef]] ("scr_vip_vipprotectiondistance", 800, 0, 999999, "int");
	      level.vipprotectiontime = [[level.drm_cvardef]] ("scr_vip_vipprotectiontime", 15, 0, 600, "int");
	      level.vippistol = [[level.drm_cvardef]] ("scr_vip_vippistol", 1, 0, 1, "int");
	      level.vipsmokenades = [[level.drm_cvardef]] ("scr_vip_vipsmokenades", 3, 0, level.vipmaxsmokenades, "int");
	      level.vipsmokeradius = [[level.drm_cvardef]] ("scr_vip_vipsmokeradius", 380, 0, 999999, "int");
	      level.vipsmokeduration = [[level.drm_cvardef]] ("scr_vip_vipsmokeduration", 70, 0, 600, "int");
	      level.vipfragnades = [[level.drm_cvardef]] ("scr_vip_vipfragnades", 0, 0, level.vipmaxfragnades, "int");
	      level.viphealth = [[level.drm_cvardef]] ("scr_vip_viphealth", 150, 0, 9999, "int");
	      level.vipbinoculars = [[level.drm_cvardef]] ("scr_vip_binoculars", 1, 0, 1, "int");
	      level.forcerespawn = [[level.drm_cvardef]] ("scr_forcerespawn", 0, 0, 1, "int");
      }
	else if(level.wwx_currentgt == "cnq")
      {
	      level.timelimit = [[level.drm_cvardef]]("scr_cnq_timelimit", 30, 0, 1440, "float");
	      setCvar("ui_cnq_timelimit", level.timelimit);
	      makeCvarServerInfo("ui_cnq_timelimit", "30");
	      level.scorelimit = [[level.drm_cvardef]]("scr_cnq_scorelimit", 100, 0, 9999, "int");
	      setCvar("ui_cnq_scorelimit", level.scorelimit);
	      makeCvarServerInfo("ui_cnq_scorelimit", "100");
      }
      else if(level.wwx_currentgt == "ons")
      {
	      level.respawndelay = [[level.drm_cvardef]]("scr_dom_respawndelay", 10, 1, 60, "int");
	      level.pointscaptureflag = [[level.drm_cvardef]]("scr_dom_pointscaptureflag", 5, 1, 50, "int");
	      level.flagcapturetime = [[level.drm_cvardef]]("scr_dom_flagcapturetime", 20, 1, 45, "int");
	      level.spawndistance = [[level.drm_cvardef]]("scr_dom_spawndistance", 250, 1, 99999, "int");
	      level.flagsnumber = [[level.drm_cvardef]]("scr_dom_flagsnumber", 5, 0, 99, "int");
	      level.flagtimeout = [[level.drm_cvardef]]("scr_dom_flagtimeout", 120, 1, 9999, "int");
	      level.flagpoints = [[level.drm_cvardef]]("scr_show_flagpoints", 1, 0, 1, "int");
	      level.roundlimit = [[level.drm_cvardef]]("scr_dom_roundlimit",5,0,21,"int");
	      level.timelimit = [[level.drm_cvardef]]("scr_dom_timelimit", 30, 0, 1440, "float");
	      setCvar("ui_dom_timelimit", level.timelimit);
	      makeCvarServerInfo("ui_dom_timelimit", "30");
	      setCvar("ui_dom_roundlimit", level.roundlimit);
	      makeCvarServerInfo("ui_dom_roundlimit", "5");
	      level.graceperiod = [[level.drm_cvardef]]("scr_dom_graceperiod",0,0,60,"float");
	      level.roundlength = [[level.drm_cvardef]]("scr_dom_roundlength",10,1,60,"float");
	      level.allow_flagtimeout = [[level.drm_cvardef]]("scr_dom_allow_flagtimeout", 120, 1, 9999, "int");
      }
      else if(level.wwx_currentgt == "dom")
      {
	      level.respawndelay = [[level.drm_cvardef]]("scr_dom_respawndelay", 10, 1, 60, "int");
	      level.pointscaptureflag = [[level.drm_cvardef]]("scr_dom_pointscaptureflag", 5, 1, 50, "int");
	      level.flagcapturetime = [[level.drm_cvardef]]("scr_dom_flagcapturetime", 20, 1, 45, "int");
	      level.spawndistance = [[level.drm_cvardef]]("scr_dom_spawndistance", 250, 1, 99999, "int");
	      level.flagsnumber = [[level.drm_cvardef]]("scr_dom_flagsnumber", 5, 0, 99, "int");
	      level.flagtimeout = [[level.drm_cvardef]]("scr_dom_flagtimeout", 120, 1, 9999, "int");
	      level.flagpoints = [[level.drm_cvardef]]("scr_show_flagpoints", 1, 0, 1, "int");
	      level.roundlimit = [[level.drm_cvardef]]("scr_dom_roundlimit",5,0,21,"int");
	      level.timelimit = [[level.drm_cvardef]]("scr_dom_timelimit", 30, 0, 1440, "float");
	      setCvar("ui_dom_timelimit", level.timelimit);
	      makeCvarServerInfo("ui_dom_timelimit", "30");
	      setCvar("ui_dom_roundlimit", level.roundlimit);
	      makeCvarServerInfo("ui_dom_roundlimit", "5");
	      level.graceperiod = [[level.drm_cvardef]]("scr_dom_graceperiod",0,0,60,"float");
	      level.roundlength = [[level.drm_cvardef]]("scr_dom_roundlength",10,1,60,"float");
	      level.allow_flagtimeout = [[level.drm_cvardef]]("scr_dom_allow_flagtimeout", 120, 1, 9999, "int");
      }
	else if(level.wwx_currentgt == "lms")
      {
	      level.timelimit = [[level.drm_cvardef]]("scr_lms_timelimit", 30, 0, 1440, "float");
	      setCvar("ui_lms_timelimit", level.timelimit);
	      makeCvarServerInfo("ui_lms_timelimit", "30");
	      setCvar("ui_lms_scorelimit", level.scorelimit);
	      makeCvarServerInfo("ui_lms_scorelimit", "20");
	      level.minplayers = [[level.drm_cvardef]]("scr_lms_minplayers", 4, 3, 64, "int");
	      level.joinperiodtime = [[level.drm_cvardef]]("scr_lms_joinperiod", 15, 1, 120, "int");
	      level.gamestarted = false;
	      level.joinperiod = false;
	      level.jointimeleft = level.joinperiodtime;
	      level.duelperiodtime = [[level.drm_cvardef]]("scr_lms_duelperiod", 60, 1, 120, "int");
	      setCvar("ui_lms_duelperiod", level.duelperiodtime);
	      makeCvarServerInfo("ui_lms_duelperiod", "60");
	      level.dueltimeleft = level.duelperiodtime;
	      level.endingmatch = false;
	      level.killwinner = [[level.drm_cvardef]]("scr_lms_killwinner",0,0,1,"int");
	      level.killometer = [[level.drm_cvardef]]("scr_lms_killometer",60,1,1200,"int");
	      setCvar("ui_lms_killometer", level.killometer);
	      makeCvarServerInfo("ui_lms_killometer", "60");
      }
	else if(level.wwx_currentgt == "esd")
      {
	      level.timelimit = [[level.drm_cvardef]] ("scr_esd_timelimit", 0, 0, 1440, "float");
	      setCvar("ui_timelimit", level.timelimit);
	      makeCvarServerInfo("ui_timelimit", "0");

	      level.scorelimit = [[level.drm_cvardef]] ("scr_esd_scorelimit", 10, 0, 9999, "int");
	      setCvar("ui_scorelimit", level.scorelimit);
	      makeCvarServerInfo("ui_scorelimit", "10");

	      level.roundlimit = [[level.drm_cvardef]] ("scr_esd_roundlimit", 0, 0, 999, "int");
	      setCvar("ui_roundlimit", level.roundlimit);
	      makeCvarServerInfo("ui_roundlimit", "0");

	      level.graceperiod = [[level.drm_cvardef]]("scr_esd_graceperiod", 15, 0, 60, "float");

	      level.roundlength = [[level.drm_cvardef]]("scr_esd_roundlength", 4, level.graceperiod / 60, 1440, "float");
            setCvar ("ui_roundlength", level.roundlength);
	      makeCvarServerInfo ("ui_roundlength", "4");

	      level.bombtimer = [[level.drm_cvardef]] ("scr_esd_bombtimer", 60, 30, 120, "int");
	      setCvar ("ui_esd_bombtimer", level.bombtimer);
	      ww2x\_wwx_utils::storeServerInfoDvar("ui_esd_bombtimer");

	      level.teambalance = [[level.drm_cvardef]] ("scr_teambalance", 0, 0, 1, "int");
	      level.lockteams = false;

	      level.plantscore = [[level.drm_cvardef]] ("scr_esd_plantscore", 0, 0, 99, "int");
	      setCvar ("ui_esd_plantscore", level.plantscore);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_plantscore");

	      level.defusescore = [[level.drm_cvardef]] ("scr_esd_defusescore", 0, 0, 99, "int");
	      setCvar ("ui_esd_defusescore", level.defusescore);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_defusescore");

	      level.defendscore = [[level.drm_cvardef]] ("scr_esd_defendscore", 0, 0, 99, "int");
	      setCvar ("ui_esd_defendscore", level.defendscore);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_defendscore");

	      level.planttime = [[level.drm_cvardef]] ("scr_esd_planttime", 5, 0, 60, "int");
	      setCvar ("ui_esd_planttime", level.planttime);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_planttime");

	      level.defusetime = [[level.drm_cvardef]] ("scr_esd_defusetime", 10, 0, 60, "int");
	      setCvar ("ui_esd_defusetime", level.defusetime);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_defusetime");

	      level.respawn = [[level.drm_cvardef]] ("scr_esd_respawn", 0, 0, 1, "int");
	      setCvar ("ui_esd_respawn", level.respawn);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_respawn");

	      level.respawndelay = [[level.drm_cvardef]] ("scr_esd_respawndelay", 10, 0, 600, "int");
	      setCvar ("ui_esd_respawndelay", level.respawndelay);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_respawndelay");

	      level.DefendersRespawnDelayPenalty = [[level.drm_cvardef]] ("scr_esd_defendersrespawndelaypenalty", 0, 0, 999, "int");
	      setCvar ("ui_esd_DefendersRespawnDelayPenalty", level.DefendersRespawnDelayPenalty);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_DefendersRespawnDelayPenalty");

	      level.endround_deadteam = [[level.drm_cvardef]] ("scr_esd_endround_deadteam", 1, 0, 1, "int");
	      setCvar ("ui_esd_endround_deadteam", level.endround_deadteam);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_endround_deadteam");

	      level.esd_mode = [[level.drm_cvardef]] ("scr_esd_mode", 0, 0, 4, "int");
	      setCvar ("ui_esd_mode", level.esd_mode);
	      ww2x\_wwx_utils::storeServerInfoDvar ("ui_esd_mode");
	
	      level.forcerespawn = [[level.drm_cvardef]]("scr_forcerespawn", 0, 0, 1, "int");
      }
	else if(level.wwx_currentgt == "lib")
      {
	      level.scorelimit = [[level.drm_cvardef]] ("scr_lib_scorelimit", 10, 0, 9999, "int");
	      setCvar("ui_lib_scorelimit", level.scorelimit);
	      storeServerInfoDvar("ui_lib_scorelimit");

	      level.roundlength = [[level.drm_cvardef]]("scr_lib_roundlength", 30, 0, 1440, "int");
	      setCvar("ui_lib_roundlength", level.roundlength);
	      storeServerInfoDvar("ui_lib_roundlength");

	      level.graceperiod = [[level.drm_cvardef]]("scr_lib_graceperiod", 20, 10, level.roundlength * 60, "int");

            level.objiconlib = [[level.drm_cvardef]]("scr_lib_dooricon", 1, 0, 1, "int");
      }
}

storeServerInfoDvar(dvar)
{
	if (!isdefined (game["serverinfodvar"]))
		game["serverinfodvar"] = [];

	game["serverinfodvar"][game["serverinfodvar"].size] = dvar;
}

setServerInfoDvars()
{
	self endon ("disconnect");

	for (i= 0; i < game["serverinfodvar"].size; i ++)
	{
		dvar = game["serverinfodvar"][i];
		val = getCvar (dvar);
		self setClientCvar (dvar, val);
		wait 0.05;
	}
}

createClock()
{
	level.clock = newHudElem();

	clockx = 8;
	clocky = 2;
	halign = "left";
      font = 2;

	if(level.wwx_logopic)
	{
		clockx = 320;
		halign = "center";
            font = 2;
	}
      if(level.wwx_logopic && (level.wwx_currentgt == "lms" || level.wwx_currentgt == "htf" || level.wwx_currentgt == "ihtf" || level.wwx_currentgt == "dom" || level.wwx_currentgt == "ons"))
      { 
            clockx = 616;
            clocky = 1;
            font = 2;
      }

	level.clock.alignX = halign;
	level.clock.alignY = "top";
	level.clock.x = clockx;
	level.clock.y = clocky;
	level.clock.font = "default";
	level.clock.sort = 0;
	level.clock.fontscale = font;

	if(level.wwx_timeannouncer != 2 && isDefined(level.clock)) level.clock.color = (0,1,0);
}
