You can use it to setup all manner of bases in TDM. Most practical setup would be a walled city with doors on either side.
It even works with the "cryo door" which is too small for a herc, but a tank can fit through pretty easily.
Code revised again. Now it allows for you to turn the team checking on and off by variable, and automatically turns it off in DM.
Code:
$doorDistance = 40;
//Distance from door to herc, should be meters.
$doorTiming = 1.5;
//Amount of time to run the door checks
$DoorPath = "MissionGroup/Doors";
//SimGroup where doors are stored in the map
$doorTeam = "false";
//Door will only open if door team and player team color match if set to true.
if($server::TeamPlay == "false")
{
$doorTeam = "false";
}
//Sets doors to open for any team color in Death Match.
function countDoors()
//This function counts through the doors and then fires the distanceCheck function on each one
{
//The next section finds the ID number of the first door in the Doors group of the map
//It then fires the distanceCheck function on that door, then it goes to the next door
//and repeats
%doorPath = $DoorPath;
%door = getNextObject(%doorPath, 0);
while(%door != 0)
{
distanceCheck(%door);
%door = getNextObject(%doorPath,%door);
}
schedule("countDoors();",$doorTiming);
}
function distanceCheck(%this)
{
//The next section will find the total number of players in the server, then go through
//them one by one to see if they are in a vehicle or not.
%vehicleCount = 0;
%count = playerManager::getPlayerCount();
for(%i = 0; %i < %count; %i++)
{
%player = playerManager::getPlayerNum(%i);
%vehicle = playerManager::playerNumtoVehicleId(%player);
if(%vehicle != "") //If a player has a vehicle continue to run.
{
%playerTeam = getTeam(%vehicle);
%doorTeam = getTeam(%this);
//The next section gets the x,y,z coordinates of the door and the herc.
%doorX = getPosition(%this, x);
%doorY = getPosition(%this, y);
%doorZ = getPosition(%this, z);
%vehicleX = getPosition(%vehicle, x);
%vehicley = getPosition(%vehicle, y);
%vehiclez = getPosition(%vehicle, z);
%x = %doorX - %vehicleX;
%y = %doorY - %vehicleY;
%z = %doorZ - %vehicleZ;
//The next section checks to see if the numbers are negative numbers.
//If they are it multiplies them by -1 to make them a positive number.
//This will be needed to do our math for the distance check.
if(%x < 0)
{
%x = %x * -1;
}
if(%y < 0)
{
%y = %y * -1;
}
if(%z < 0)
{
%z = %z * -1;
}
//The next section checks to see if there is a herc within the trigger distance.
//If there is it adds 1 to the vehicleCount variable.
if(%x <= $doorDistance && %y <= $doorDistance && %z <= $doorDistance)
{
if($doorTeam == "true")
{
if(%playerTeam == %doorTeam)
{
%vehicleCount++;
if(%this.open != "true")
{
say(%player,0,"Access Granted");
}
}
}
else
{
%vehicleCount++;
if(%this.open != "true")
{
say(%player,0,"Access Granted");
}
}
}
}
}
//The next section checks to see if the door is closed and if a vehicle is within range.
//If so it sets the variable for the door to open and opens the door.
if(%this.open != "true" && %vehicleCount > 0)
{
%this.open = "true";
playAnimSequence(%this, 0, true);
}
//The next section checks to see if the door is open and all vehicles are out of range.
//If so it sets the variable for the door to closed and closes the door.
else if (%this.open == "true" && %vehicleCount == 0)
{
%this.open = "false";
playAnimSequence(%this, 0, false);
}
}
countDoors();
Bookmarks