context: if(isPackage(GameModeDeathMatchPackage))
  	deactivatePackage(GameModeDeathMatchPackage);
  package GameModeDeathMatchPackage
  {
  	//this is called when save loading finishes 
  	function GameModeInitialResetCheck()
  	{
  		Parent::GameModeInitialResetCheck();
  		
  		//if there is no map list, attempt to create it
  		if($DM::numMaps == 0)
  			DM_BuildMapList();
  		
  		//if maplist is still empty, there are no maps
  		if($DM::numMaps == 0)
  		{
  			messageAll('', "\c5No DeathMatch maps available!");
  			return;
  		}
  		
  		if($DM::Initialized)
  			return;
  		
  		$DM::Initialized = true;
  		$DM::CurrentMap = -1;
  		
  		DM_NextMap();
  	}
  	
  	//when we're done loading a new map, reset the minigame
  	function ServerLoadSaveFile_End()
  	{
  		Parent::ServerLoadSaveFile_End();
  		
  		//new map has loaded, reset minigame
  		$DefaultMiniGame.scheduleReset(); //don't do it instantly, to give people a little bit of time to ghost
  	}
  	
  	function VehicleData::onEnterLiquid(%data, %obj, %coverage, %type)
  	{
  		Parent::onEnterLiquid(%data, %obj, %coverage, %type);
  		if($DM::killWater)
  		{
  			if(getWord(%obj.getPosition(), 2) < 10)
  			{
  				%obj.damage(%obj, %obj.getPosition(), 10000, $DamageType::Fall);
  				%obj.finalExplosion();
  			}
  		}
  	}
  	
  	function Armor::onEnterLiquid(%data, %obj, %coverage, %type)
  	{
  		Parent::onEnterLiquid(%data, %obj, %coverage, %type);
  		
  		if($DM::killWater)
  		{
  			%client = %obj.client;
  			if(isObject(%client))
  			{
  				if(%client.minigame != $DefaultMinigame)
  					return;
  			}
  			
  			if(getWord(%obj.getPosition(), 2) < 5.05)
  			{
  				%obj.hasShotOnce = true;
  				%obj.invulnerable = false;
  				%obj.damage(%obj, %obj.getPosition(), 10000, $DamageType::Fall);
  			}
  		}
  	}
  	
  	function MiniGameSO::Reset(%obj, %client)
  	{
  		$Pref::Server::DeathMatch::RoundLimit = mFloor($Pref::Server::DeathMatch::RoundLimit);
  		if($Pref::Server::DeathMatch::RoundLimit <= 0)
  			$Pref::Server::DeathMatch::RoundLimit = 1;
  		
  		$Pref::Server::DeathMatch::TimeLimit = mFloor($Pref::Server::DeathMatch::TimeLimit);
  		if($Pref::Server::DeathMatch::TimeLimit < 30)
  			$Pref::Server::DeathMatch::TimeLimit = 30;
  		
  		//count number of minigame resets, when we reach the limit, go to next map
  		$DM::ResetCount++;
  		if($DM::ResetCount > $Pref::Server::DeathMatch::RoundLimit)
  		{
  			$DM::ResetCount = 0;
  			DM_NextMap();
  		}
  		else
  		{
  			echo("Beginning round...");
  			messageAll('', "\c5Beginning round " @ $DM::ResetCount @ " of " @ $Pref::Server::DeathMatch::RoundLimit @ ".");
  			
  			for(%a = 0; %a < $DefaultMinigame.numMembers; %a++)
  			{
  				%member = $DefaultMinigame.member[%a];
  				if(isObject(%member))
  				{
  					//clear hud
  					%member.setDeathMatchBottomPrintInfo();
  
  					//reset key stuff
  					%member.DMHasKey_Red = false;
  					%member.DMHasKey_Yellow = false;
  					%member.DMHasKey_Green = false;
  					%member.DMHasKey_Blue = false;
  				}
  			}
  			
  			DM_Tick(($Pref::Server::DeathMatch::TimeLimit * 10), true);
  			DM_PrepareRound();
  			
  			Parent::Reset(%obj, %client);
  		}
  	}
  	
  	function GameConnection::spawnPlayer(%this)
  	{
  		if($DM::RoundRestarting)
  			return;
  		
  		Parent::spawnPlayer(%this);
  		if(%this.minigame == $DefaultMinigame)
  		{
  			%player = %this.player;
  			if(isObject(%player))
  				%this.DM_ApplyLoadout(%player);
  		}
  	}
  	
  	function messageClient(%client, %msg, %a, %slot, %item, %b, %c, %d, %e, %f, %g, %h, %i, %j)
  	{
  		if(isObject(%client) && %client.minigame == $DefaultMinigame)
  		{
  			if(%item == redKeyItem.getID()) //these should add a client var instead of giving you the keys
  			{
  				%client.player.tool[%slot] = 0;
  				%client.DMHasKey_Red = true;
  				return;
  			}
  			if(%item == yellowKeyItem.getID())
  			{
  				%client.player.tool[%slot] = 0;
  				%client.DMHasKey_Yellow = true;
  				return;
  			}
  			if(%item == greenKeyItem.getID())
  			{
  				%client.player.tool[%slot] = 0;
  				%client.DMHasKey_Green = true;
  				return;
  			}
  			if(%item == blueKeyItem.getID())
  			{
  				%client.player.tool[%slot] = 0;
  				%client.DMHasKey_Blue = true;
  				return;
  			}
  		}
  		
  		Parent::messageClient(%client, %msg, %a, %slot, %item, %b, %c, %d, %e, %f, %g, %h, %i, %j);
  	}
  	
  	function Player::ActivateStuff(%this) //this should allow you to utilise the client vars to trigger key matches
  	{
  		%client = %this.client;
  		%keyHas = %client.DMHasKey_Red + %client.DMHasKey_Yellow + %client.DMHasKey_Green + %client.DMHasKey_Blue;
  		
  		if(%keyHas >= 0)
  		{
  			%target = ContainerRayCast(%eye = %this.getEyePoint(), vectorAdd(%eye, vectorScale(%this.getEyeVector(),5)), $TypeMasks::FxBrickObjectType, %this);
  			if(%target)
  			{
  				%target = %target.getID();
  				
  				//edit of key code
  				if(%target.getType() & $TypeMasks::FxBrickAlwaysObjectType)
  				{
  					//determine if color matches or not via hue comparison
  
  					//get brick color
  					%brickRGBA = getColorIDTable(%target.getColorId());
  					%r = getWord(%brickRGBA, 0);
  					%g = getWord(%brickRGBA, 1);
  					%b = getWord(%brickRGBA, 2);
  					%brickH = getWord(RGBtoHSV(%r,%g,%b), 0);
  
  					%brickRGB = %r SPC %g SPC %b;
  					%brickRGB = vectorNormalize(%brickRGB);
  
  					if(%client.DMHasKey_Red)
  					{
  						//get red key color
  						%redKeyRGBA = redKeyImage.colorShiftColor;
  						%r = getWord(%redKeyRGBA, 0);
  						%g = getWord(%redKeyRGBA, 1);
  						%b = getWord(%redKeyRGBA, 2);
  						%redKeyH = getWord(RGBtoHSV(%r,%g,%b), 0);
  
  						%redKeyRGB = %r SPC %g SPC %b;
  						%redKeyRGB = vectorNormalize(%redKeyRGB);
  
  						//compare
  						%redhDiff = mAbs(%redKeyH - %brickH);
  						if(%redhDiff > 0.5)
  							%redhDiff = 1 - %redhDiff;
  
  						%redKeyMatch = 1;
  						if(%redhDiff > 0.1 || (%redKeyH >= 0 && %brickH < 0) || (%redKeyH < 0 && %brickH >= 0))
  							%redKeyMatch = 0;
  					}
  
  					if(%client.DMHasKey_Yellow)
  					{
  						//get yellow key color
  						%yellowKeyRGBA = yellowKeyImage.colorShiftColor;
  						%r = getWord(%yellowKeyRGBA, 0);
  						%g = getWord(%yellowKeyRGBA, 1);
  						%b = getWord(%yellowKeyRGBA, 2);
  						%yellowKeyH = getWord(RGBtoHSV(%r,%g,%b), 0);
  
  						%yellowKeyRGB = %r SPC %g SPC %b;
  						%yellowKeyRGB = vectorNormalize(%yellowKeyRGB);
  
  						//compare
  						%yellowhDiff = mAbs(%yellowKeyH - %brickH);
  						if(%yellowhDiff > 0.5)
  							%yellowhDiff = 1 - %yellowhDiff;
  
  						%yellowKeyMatch = 1;
  						if(%yellowhDiff > 0.1 || (%yellowKeyH >= 0 && %brickH < 0) || (%yellowKeyH < 0 && %brickH >= 0))
  							%yellowKeyMatch = 0;
  					}
  
  					if(%client.DMHasKey_Green)
  					{
  						//get green key color
  						%greenKeyRGBA = greenKeyImage.colorShiftColor;
  						%r = getWord(%greenKeyRGBA, 0);
  						%g = getWord(%greenKeyRGBA, 1);
  						%b = getWord(%greenKeyRGBA, 2);
  						%greenKeyH = getWord(RGBtoHSV(%r,%g,%b), 0);
  
  						%greenKeyRGB = %r SPC %g SPC %b;
  						%greenKeyRGB = vectorNormalize(%greenKeyRGB);
  
  						//compare
  						%greenhDiff = mAbs(%greenKeyH - %brickH);
  						if(%greenhDiff > 0.5)
  							%greenhDiff = 1 - %greenhDiff;
  
  						%greenKeyMatch = 1;
  						if(%greenhDiff > 0.1 || (%greenKeyH >= 0 && %brickH < 0) || (%greenKeyH < 0 && %brickH >= 0))
  							%greenKeyMatch = 0;
  					}
  
  					if(%client.DMHasKey_Blue)
  					{
  						//get blue key color
  						%blueKeyRGBA = blueKeyImage.colorShiftColor;
  						%r = getWord(%blueKeyRGBA, 0);
  						%g = getWord(%blueKeyRGBA, 1);
  						%b = getWord(%blueKeyRGBA, 2);
  						%blueKeyH = getWord(RGBtoHSV(%r,%g,%b), 0);
  
  						%blueKeyRGB = %r SPC %g SPC %b;
  						%blueKeyRGB = vectorNormalize(%blueKeyRGB);
  
  						//compare
  						%bluehDiff = mAbs(%blueKeyH - %brickH);
  						if(%bluehDiff > 0.5)
  							%bluehDiff = 1 - %bluehDiff;
  
  						%blueKeyMatch = 1;
  						if(%bluehDiff > 0.1 || (%blueKeyH >= 0 && %brickH < 0) || (%blueKeyH < 0 && %brickH >= 0))
  							%blueKeyMatch = 0;
  					}
  					
  					%keyMatch = %redKeyMatch + %yellowKeyMatch + %greenKeyMatch + %blueKeyMatch;
  					
  					if(%keyMatch >= 1)
  					{
  						%target.onKeyMatch(%this);
  						%client.setDeathMatchBottomPrintInfo();
  					}
  					else
  						%target.onKeyMismatch(%this);
  				}
  			}
  		}
  		
  		Parent::ActivateStuff(%this);
  	}
  	
  	function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
  	{
  		%client = %obj.client;
  		if(%col.canPickup && isObject(%client))
  		{
  
gt: 			if(%col.dataBlock $= "redKeyItem")