BF2 Style CTF
by mb · 11/13/2006 (4:35 pm) · 8 comments
Download Code File
After doing the teamplay implementation resource, you can add this code to make a bf2 style capture the flag triggers. It's pretty basic right now, you can add whatever you want when a player or players enter the trigger IE: animations of a flag going up/down & giving points to players, etc... whatever you like.
example\starter.fps\server\scripts
AreaTrigger.cs
Remember to copy/paste the code into wordpad, then select all and copy/paste into your code editor. Otherwise you'll have to do a lot of editing
After saving the code, go into the game hit f11. Place as many triggers as you want (I've only tested 2). Then save the mission and run into the trigger and it should show up on-screen. You need two players on seperate teams to fully test it, or you can just change teams. Enjoy.
After doing the teamplay implementation resource, you can add this code to make a bf2 style capture the flag triggers. It's pretty basic right now, you can add whatever you want when a player or players enter the trigger IE: animations of a flag going up/down & giving points to players, etc... whatever you like.
example\starter.fps\server\scripts
AreaTrigger.cs
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// This is the trigger
datablock TriggerData(AreaTrigger)
{
tickPeriodMS = 50;
team1InZone = 0;
team2InZone = 0;
team1Flag = 0;
team2Flag = 0;
};
//-----------------------------------------------------------------------------
function AreaTrigger::onEnterTrigger(%this,%trigger,%obj)
{
// If both teams are in the zone do nothing.
if ( ((%this.team1InZone >=1) && (%this.team2InZone >=1)) )
{
return;
echo( "BOTH TEAMS ARE IN TRIGGER - DO NOTHING!!!");
}
else
{
if (%obj.client.team.teamID == 1)// team 1 entered zone
{
echo( "TEAM 1 entered the trigger");
%trigger.team1InZone++;
}
if (%obj.client.team.teamID == 2)// team 2 entered zone
{
echo( "TEAM 2 entered the trigger");
%trigger.team2InZone++;
}
}
Parent::onEnterTrigger(%this,%trigger,%obj);
}
function AreaTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
if (%obj.client.team.teamID == 1) // team 1 left zone
{
%trigger.team1InZone--; // decrement team1InZone
if ( %trigger.team1InZone <= 0) // dont ever go below zero
{
%trigger.team1InZone = 0;
}
echo( "TEAM 1 left the trigger:" @ %trigger.team1InZone);
}
if (%obj.client.team.teamID == 2)// team 2 left zone
{
%trigger.team2InZone--;
if ( %trigger.team2InZone <= 0) // dont ever go below zero
{
%trigger.team2InZone = 0;
}
echo( "TEAM 2 left the trigger" @%trigger.team2InZone);
}
Parent::onLeaveTrigger(%this,%trigger,%obj);
}
function AreaTrigger::onTickTrigger(%this,%trigger)
{
//-----------------------------------------------------------------------
// onTickTrigger
//
// 1. If both teams are in the zone do nothing.
// 2. Loop thru all the objects in the trigger.
// 3. Set %obj to be the current object that is being used in the for loop.
// 4. Check if the %obj is a client.
// 5. If it is not a client then do nothing.
// 6. If the %obj is a client then check if its on Team 1.
// 7. Check if the Team 2 Flag is up. If it is up bring it down (varys on how many of that team is in the zone. (Do this until the flag is down)
// 8. Dont let the flag variable go below zero.
// 9. Check if the Team 1 Flag is up. If it is not up, then bring it up 1. (Do this until the flag is up)
// 10. 10. Dont let the flag variable go above 100.
// 11. Do steps 6,7,8,9,10 but this time for Team 2. Lower team 1 flag, Raise team 2 flag.
//echo( "onTickTrigger");
//$center = %trigger.getWorldBoxCenter(); // gets the center of the trigger
// 1. If both teams are in the zone do nothing.
if ( ((%this.team1InZone >=1) && (%this.team2InZone >=1)) )
{
echo( "Both teams in zone, do nothing.");
return;
}
else
{
// 2.loop thru all the objects in the trigger
for(%x=0; %x < %trigger.getNumObjects(); %x++)
{
// 3. Set %obj to be the current object that is being used in the for loop.
%obj = %trigger.getObject(%x);
// 4. Check if the %obj is a client.
if (! %obj.client)
{
// 5. If it is not a client then do nothing.
return;
}
else
{
// 6. If the %obj is a client then check if its on Team 1.
if (%obj.client.team.teamID == 1) // team 1 entered zone
{
// 7. Check if the Team 2 Flag is up. If it is up bring it down 1. (Do this until the flag is down)
if (%trigger.team2Flag != 0)
{
%trigger.team2Flag = ( %trigger.team2Flag - %trigger.team1InZone ); // If team 2 flag is not 0 then bring it down
// 8. Dont let the flag variable go below zero.
if ( %trigger.team2Flag <= 0)
{
%trigger.team2Flag = 0;
}
// print message to client
%message = "team2Flag: " @ %trigger.team2Flag;
%time = 1;
%lines = 1;
centerPrint( %obj.client, %message, %time, %lines );
//echo( "team2Flag: " @ %trigger.team2Flag);
}
else
{
// 9. Check if the Team 1 Flag is up. If it is not up, then bring it up 1. (Do this until the flag is up)
if (%trigger.team1Flag < 100) // if team 1 flag is not 100 then bring it up 1
{
%trigger.team1Flag = ( %trigger.team1Flag + %trigger.team1InZone );
// 10. Dont let the flag variable go above 100.
if ( %trigger.team1Flag >= 100)
{
%trigger.team1Flag = 100; // dont ever go above 100
}
// print message to client
%message = "team1Flag: " @ %trigger.team1Flag;
%time = 1;
%lines = 1;
centerPrint( %obj.client, %message, %time, %lines );
//echo( "team1Flag: " @ %trigger.team1Flag);
}
}
}
// 11. repeat for team 2
if (%obj.client.team.teamID == 2) // team 2 entered zone
{
if (%trigger.team1Flag != 0) //if team 1 flag is still up, bring it down 1
{
%trigger.team1Flag = ( %trigger.team1Flag - %trigger.team2InZone );
if ( %trigger.team1Flag <= 0) // dont ever go below zero
{
%trigger.team1Flag = 0;
}
// print message to client
%message = "team1Flag: " @ %trigger.team1Flag;
%time = 1;
%lines = 1;
centerPrint( %obj.client, %message, %time, %lines );
//echo( "team1Flag: " @ %trigger.team1Flag);
}
else
{
if (%trigger.team2Flag < 100) // if team 2 flag is not 100 then bring it up 1
{
%trigger.team2Flag = ( %trigger.team2Flag + %trigger.team2InZone );
if ( %trigger.team2Flag >= 100) // dont ever go above 100
{
%trigger.team2Flag = 100;
}
// print message to client
%message = "team2Flag: " @ %trigger.team2Flag;
%time = 2;
%lines = 1;
centerPrint( %obj.client, %message, %time, %lines );
//echo( "team2Flag: " @ %trigger.team2Flag);
}
}
}
}
}
}
Parent::onTickTrigger(%this,%trigger);
}Remember to copy/paste the code into wordpad, then select all and copy/paste into your code editor. Otherwise you'll have to do a lot of editing
After saving the code, go into the game hit f11. Place as many triggers as you want (I've only tested 2). Then save the mission and run into the trigger and it should show up on-screen. You need two players on seperate teams to fully test it, or you can just change teams. Enjoy.
About the author
#2
You can easily modify the code for that by checking which team has more players in the trigger and then do the raise flag up down.
something like::
11/16/2006 (12:07 pm)
@stefanYou can easily modify the code for that by checking which team has more players in the trigger and then do the raise flag up down.
something like::
if ( (%this.team1InZone > %this.team2InZone ))
{
// call a function, or put a variable here.. or put code here for raising flag for team 1
return;
}
else if ( (%this.team2InZone > %this.team1InZone ))
{
// call a function, or put a variable here.. or put code here for raising flag for team 1
return;
}
#3
12/27/2006 (12:22 pm)
this is a great resource and I will be using it in my upcoming game...I'll give you credit....
#4
01/11/2007 (6:40 am)
Cool, thanks :D
#5
Dropped right into 1.5.
Yes, it's simple, but it's a great place to start for conquest style games.
01/23/2007 (7:56 pm)
Great resource!Dropped right into 1.5.
Yes, it's simple, but it's a great place to start for conquest style games.
#6
Cant wait to play with it.
02/09/2007 (10:53 am)
Just been pointed the way to this gem. Looks great!!!!!!!!!Cant wait to play with it.
#7
03/01/2007 (12:33 pm)
I updated this resource a few weeks after making this one. I finally got around to posting it. I'll put a link here once its approved. It adds models that change out when you capture an area, and uses simsets so you can have many as many areas that you want.
#8
03/06/2007 (7:23 am)
Version II with models: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12430 
Torque Owner Stefan Lundmark