Game Development Community

Objective-based Spawn Captures

by sixb0nes · in Torque Game Engine · 09/09/2005 (9:09 am) · 0 replies

Hello,

I've put together a function for assigning a team to a spawn point based on a nearby trigger. I would like to know if this method is sound, and if there is a better way to accomplish the same thing. The basic idea was to place a trigger beside each spawn point, and have it "search out" the nearest spawn to determine if it's one that can be captured.

I was unsure if there were any similar triggers on the spawn point itself, and unless I setup a schedule for each one to scan for a player, this was the only other approach I could think of.

function captureTrigger::onEnterTrigger(%this,%trigger,%obj)
{     
   %groupName = "MissionGroup/PlayerDropPoints";
   %group = nameToID(%groupName);
	
	// Obtain the player's team.
	%clientTeam = %obj.client.team.teamId;	
   
   // Iterate through all the spawn points.
   if (%group != -1) {      
      for( %groupIndex = 0; %groupIndex < %group.getCount(); %groupIndex++ ) {      	      	
      	%spawn = %group.getObject(%groupIndex);	
      	
// Check to see if we don't already own the spawn point, and it isn't for observers.
      	if((%spawn.teamId != %clientTeam) && (%spawn.teamId != 0)) {
      		
// Grab the distance to the spawn.  Since a spawn is directly beside each trigger
// in my mission files, it is safe to assume the distance to the closest spawn will 
// always be within a certain range.
      		%distance = VectorDist(%spawn.getPosition(),%obj.getPosition());      		
      		if(%distance < 15) {
      			
      			// For now, insta-capture.
		messageAll('MsgClientCaptureObjective', '\c2%1 has captured objective %2!',
      				%obj.client.name,
      				%spawn.description);
      				
      			// Update the team allowed to spawn at this location.
      			%spawn.teamId = %clientTeam;
				}
			}
      }
   }
}

Be nice, I'm only a few weeks green :))