spawnprotection()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");
      if(level.wwx_currentgt == "lib" && isDefined(self.in_jail) && self.in_jail) return;

	count = 0;
	beepcount = 0;
	rangex = 0;
	spos = self.origin;
	stimer = level.wwx_spwn_time;

	if(level.wwx_spwn_hud)
	{
		self.wwx_spwpro = newClientHudElem(self);
		self.wwx_spwpro.x = 160;
		self.wwx_spwpro.y = 428;
		self.wwx_spwpro.alignX = "center";
		self.wwx_spwpro.alignY = "middle";
		self.wwx_spwpro.alpha = 1;
		self.wwx_spwpro setShader("gfx/hud/hud@health_cross.tga",40,40);
	}

	self.wwx_invulnerable = true;
	self.wwx_spawnprotected = true;

	msg1 = &"SPAWNPROTECTION_ENABLED";
	msg2 = ww2x\_wwx_utils::time_convert(stimer);

	switch(level.wwx_spwn_msg)
	{
		case 0: self iprintln(msg1); self iprintln(msg2); break;
		case 1: self iprintlnbold(msg1); self iprintlnbold(msg2); break;
		default:
		{
			self thread ww2x\_wwx_utils::wwx_hud_announce(msg1, 0);
			self thread ww2x\_wwx_utils::wwx_hud_announce(msg2, 1);
			break;
		}
	}

	if(level.wwx_spwn_wepdisable) self disableWeapon();

	// Invisible Spawn Protection ON
      if(level.invisable_spawnpro)
      self hide();

	while(isAlive(self) && self.wwx_invulnerable && !isdefined(self.teamhaschanged) && self.sessionstate == "playing" && count < (stimer * 20) && !((self attackButtonPressed() || self meleeButtonPressed()) && self getCurrentWeapon()!="none" ) )
	{
		if(level.wwx_spwn_range && !isdefined(self.wwx_isparachuting))
		{
			distmoved = distance(spos, self.origin);
			if(distmoved > level.wwx_spwn_range)
			{
				rangex = 1;
				count = (stimer * 20);
			}
		}

		if(isdefined(self.wwx_isparachuting))
			count = 0;

                 if(level.wwx_spawnpro_timer)
                 {
                 sptime = (int(stimer - ((count - stimer) / 20)));
                 if(!isDefined(self.wwx_sptimer))
                 {
                 self.wwx_sptimer = newClientHudElem(self);
                 self.wwx_sptimer.x = 160;
                 self.wwx_sptimer.y = 458;
                 self.wwx_sptimer.alignx = "center";
                 self.wwx_sptimer.aligny = "middle";
                 //self.wwx_sptimer.alpha = 0.8;
                 self.wwx_sptimer.color = (1, 0, 0);
                 self.wwx_sptimer.fontScale = 3;
                 //self.wwx_sptimer.label = &"MENU_SPAWN_PROTECTION";
                 }
                 self.wwx_sptimer setvalue(sptime); 
                 }

		wait 0.05;
		count++;
		beepcount++;

                 if(isDefined(self.wwx_sptimer)) self.wwx_sptimer destroy(); //Destroyed SPTimer

		if(beepcount == 20)
		{
			if(level.wwx_spwn_headicon)
			{
				self.headicon = game["headicon_protect"];
				self.headiconteam = "none";
			}
			beepcount = 0;
		}
	}

	msg3 = undefined;

	if(self attackButtonPressed() && (!isdefined(self.teamhaschanged))) msg3 = &"SPAWNPROTECTION_FIRE_BUTTON_PRESSED";
	if(self.sessionstate == "playing" && rangex == 1) msg3 = &"SPAWNPROTECTION_MOVED_AWAY_AREA";

	if(isdefined(msg3))
	{
		switch(level.wwx_spwn_msg)
		{
			case 0: self iprintln(msg3); break;
			case 1: self iprintlnbold(msg3); break;
			default:
			{
				self thread ww2x\_wwx_utils::wwx_hud_announce(msg3, 0);
				break;
			}
		}
	}

	// restore the headicon if changed
	if(level.wwx_spwn_headicon && self.sessionstate == "playing")
	{
			self thread ww2x\_wwx_utils::restoreHeadicon(game["headicon_protect"]);
	}

	msg4 = &"SPAWNPROTECTION_DISABLED";

	switch(level.wwx_spwn_msg)
	{
		case 0: self iprintln(msg4); break;
		case 1: self iprintlnbold(msg4); break;
		default:
		{
			self thread ww2x\_wwx_utils::wwx_hud_announce(msg4, 0);
			break;
		}
	}

	if(isdefined(self.wwx_spwpro))
		self.wwx_spwpro destroy();

	// Invisible Spawn Protection OFF
	if(level.invisable_spawnpro)
      self show();

	if(level.wwx_spwn_wepdisable) self enableWeapon();
	self.wwx_spawnprotected = undefined;
	self.wwx_invulnerable = false;
}

punish(reason)
{
	level endon("wwx_gameover");
	self endon("wwx_dead");
	self endon("disconnect");

	if(isDefined(self.wwx_spwn_punish)) return;
	self.wwx_spwn_punish = true;

	if(isPlayer(self))
	{
		if(reason == "abusing")
		{
                  if(level.wwx_linux_server == 2)
                  {
			iprintln(&"SPAWNPROTECTION_PUNISH_ABUSER_MSG", self.name);
			self iprintlnbold(&"SPAWNPROTECTION_PUNISH_ABUSER_PMSG");
                  }
                  else
                  {
			iprintln(&"SPAWNPROTECTION_PUNISH_ABUSER_MSG", self);
			self iprintlnbold(&"SPAWNPROTECTION_PUNISH_ABUSER_PMSG");
                  }
		}

		if(reason == "attacking")
		{
                  if(level.wwx_linux_server == 2)
                  {
			iprintln(&"SPAWNPROTECTION_PUNISH_ATTACKER_MSG", self.name);
			self iprintlnbold(&"SPAWNPROTECTION_PUNISH_ATTACKER_PMSG");
                  }
                  else
                  {
			iprintln(&"SPAWNPROTECTION_PUNISH_ATTACKER_MSG", self);
			self iprintlnbold(&"SPAWNPROTECTION_PUNISH_ATTACKER_PMSG");
                  }                  
		}
	}

	pun = randomInt(100);

	if(pun < 50)
	{
		if(isPlayer(self)) self disableWeapon();
		wait 5;
	}
	else for(i = 0; i < 5; i++)
	{
		if(isPlayer(self)) self ww2x\_wwx_weapons::dropcurrentweapon();
		wait 1;
	}

	if(isPlayer(self))
	{
		if(reason == "abusing") self iprintlnbold(&"SPAWNPROTECTION_FREE_ABUSER_PMSG");
		else if(reason == "attacking") self iprintlnbold(&"SPAWNPROTECTION_FREE_ATTACKER_PMSG");

		self enableWeapon();
		self.wwx_spwn_punish = undefined;
	}
}
