
setWeaponStatus(v_team, lever)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doWeaponStatusChange(lever);

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doWeaponStatusChange(lever);

	if(v_team == "" && self.sessionstate == "playing")
		self thread doWeaponStatusChange(lever);
}

doWeaponStatusChange(lever)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");
	
	if(lever) self disableWeapon();
	else self enableWeapon();
}

setPlayerModel(v_team, modeltype)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(modeltype == "original")
	{
		self thread maps\mp\gametypes\_teams::model();
		if(isdefined(self.wwx_newmodel)) self.wwx_newmodel = undefined;
		return;
	}	

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doModelChange(modeltype);

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doModelChange(modeltype);

	if(v_team == "" && self.sessionstate == "playing")
		self thread doModelChange(modeltype);
}

doModelChange(modeltype)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	self detachall();
	self setModel(modeltype);
	self.wwx_newmodel = true;
}

setWarp(v_team, playerpos)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doWarp(playerpos);

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doWarp(playerpos);

	if(v_team == "" && self.sessionstate == "playing")
		self thread doWarp(playerpos);
}

doWarp(playerpos)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	self.wwx_warptrue = true;
	self.origin = playerpos;

	if(level.wwx_flagbased && isdefined(self.flag))
	{
		self maps\mp\gametypes\ctf::dropflag();
	}

	while(isplayer(self) && self.wwx_warptrue)
	{
		ix = self.origin[0];
		iy = self.origin[1];
		iz =  960; // 80ft drop

		startpoint = self.origin + ( 0, 0, 24);
		trace = bulletTrace(startpoint, (startpoint + (0,0,iz)), false, undefined);
		pos = trace["position"];
		iz = pos[2];

		endpoint = ( ix, iy, iz);	
		distance = distance(startpoint, endpoint);

		self.wwx_anchor = spawn ("script_model",(0,0,0));
		self.wwx_anchor.origin = self.origin;
		self.wwx_anchor.angles = self.angles;
		self linkto (self.wwx_anchor);

		lifttime = distance/100 + randomint(6);
		self.wwx_anchor.origin = startpoint;
		self.wwx_anchor moveto (endpoint, lifttime);

		wait lifttime;
		self thread warpTimer(5);
		wait 5;

		if(isPlayer(self))
		{
			self unlink();
			self.health = 1;
			if(isdefined(self.wwx_anchor)) self.wwx_anchor delete();
		}
	}
	
	wait 10;

	// still here?, stupid map!.....blow them up
	if(isPlayer(self) && self.sessionstate == "playing")
	{
		playfx(level.wwx_effect["barrel"], self.origin);
		self playsound("mortar_explosion1");
		wait 0.05;
		self.wwx_cmdmondeath = true;
		if(isPlayer(self)) self suicide();
	}
}

warpTimer(time)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	while(isplayer(self) && time > 0)
	{
		wait 1;
		time--;
	}

	// if up and down stop thread
	if(isplayer(self) && self.wwx_warptrue) self.wwx_warptrue = false;
}

setLockStatus(v_team, porigin, lever)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doAnchor(lever, porigin);

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doAnchor(lever, porigin);

	if(v_team == "" && self.sessionstate == "playing")
		self thread doAnchor(lever, porigin);
}

doAnchor(lever, porigin)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(lever)
	{	
		self.anchor = spawn("script_origin", porigin);
		self linkTo(self.anchor);
	}
	else
	{
		self unlink();
		if(isdefined(self.anchor)) self.anchor delete();
	}
}

setSuicide(v_team)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doSuicide();

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doSuicide();

	if(v_team == "" && self.sessionstate == "playing")
		self thread doSuicide();
}

doSuicide()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");	

	wait .25;
	if(isPlayer(self))
	{
		self.wwx_cmdmondeath = true;
		self suicide();
	}
}

setSmite(v_team, porigin)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doSmite(porigin);

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doSmite(porigin);

	if(v_team == "" && self.sessionstate == "playing")
		self thread doSmite(porigin);
}

doSmite(porigin)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	wait 1.5;
	playfx(level.wwx_effect["barrel"], porigin);

	if(isPlayer(self))
	{
		self playsound("artillery_explosion");
		self.wwx_cmdmondeath = true;
		self suicide();
	}
}

setZombie(v_team, porigin)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing")
		self thread doZombie(porigin);

	if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing")
		self thread doZombie(porigin);

	if(v_team == "" && self.sessionstate == "playing")
		self thread doZombie(porigin);
}

doZombie(porigin)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	self.origin = porigin;

	self ww2x\_wwx_main::popHead( (-0.2 + randomFloat(0.4), -0.2 + randomFloat(0.4),1), 100 + randomInt(100));
	self.wwx_zombie = true;

	while(isAlive(self) && self.sessionstate != "spectator")
	{
		wait 1 + randomInt(5);
		playfxontag(level.wwx_effect["flesh"], self, "j_neck");
	}
}

setTorch(v_team)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	porigin = self.origin;

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing") self thread doTorch(porigin);
	else if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing") self thread doTorch(porigin);
	else if(v_team == "" && self.sessionstate == "playing") self thread doTorch(porigin);
}

doTorch(porigin, special, eAttacker)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(!isDefined(special)) special = false;

	self thread doFire();

	for(i = 0; i < 10; i++)
	{
		if(isPlayer(self) && special) self thread [[level.callbackPlayerDamage]](eAttacker, eAttacker, randomInt(2) + 2, 1, "MOD_PROJECTILE", "planebomb_mp", undefined, (0,0,1), "none",0);
		wait 1;
	}

	if(special) return;

	if(isPlayer(self))
	{
		self.wwx_cmdmondeath = true;
		playfx(level.wwx_effect["bodygroundfire"], porigin);
		self suicide();
	}
}

setFire(v_team)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing") self thread doFire();
	else if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing") self thread doFire();
	else if(v_team == "" && self.sessionstate == "playing") self thread doFire();
}

doFire()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	for(;;)
	{
		wait 0.25;
		if(isPlayer(self))
		{
			playfxontag(level.wwx_effect["bodyarmfire"], self, "j_elbow_le");
			playfxontag(level.wwx_effect["bodyarmfire"], self, "j_elbow_ri");
			playfxontag(level.wwx_effect["bodytorsofire"], self, "torso_stabilizer");
		}		
	}
}

setSpank(v_team)
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	if(v_team == "allies" && self.pers["team"] == "allies" && self.sessionstate == "playing") self thread doSpank();
	else if(v_team == "axis" && self.pers["team"] == "axis" && self.sessionstate == "playing") self thread doSpank();
	else if(v_team == "" && self.sessionstate == "playing") self thread doSpank();
}

doSpank()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	self thread ww2x\_wwx_main::spankme(15);
	self shellshock("default", 15);	
}

setCheater()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");
	self endon("wwx_dead");

	self setClientCvar("sensitivity", "20");
	self setClientCvar("com_maxfps", "1");
	self setClientCvar("r_displayRefresh", "60 Hz");
	self setClientCvar("r_mode", "640x480");
	self setClientCvar("cl_maxpackets", "10");
	self setClientCvar("cl_packetdup", "5");
	self setClientCvar("rate", "1000");
	self setClientCvar("snaps", "1");
	self setClientCvar("snd_volume", "0");
}