Code: Select all
instant Trigger "GroupTrigger" {
dataBlock = "GroupTrigger";
name = "CaptureTrigger"; // "function <name>::onEnter(%this, %object)", "function <name>::onTrigger(%this, %object)", "function <name>::onLeave(%this, %object)"
position = "0 0 20";
rotation = "0 0 0";
boundingBox = "-1 -1 -1 1 1 1";
isSphere = "False";
};
};
//--- export object end ---//
$teamScoreLimit = 12;
exec(objectives);
$Game::missionType = "CTF";
$cdTrack = 2;
$cdPlayMode = 1;
function CaptureTrigger::onEnter(%this, %object)
{
messageAll(0, "CaptureTrigger works!");
}
It almost looks like you are trying to code Battlefield 2 style base capturing. Am I right?
If this is the case... You should use onTrigger, instead of onEnter.
onEnter is called once, when you enter the box.
onTrigger is called approximately 3 times per second, while you are in the box.
onLeave is never called, and I've tried several things to remedy this, such as incrementing a variable in onTrigger, and then evaluating the onLeave event if decrementing the same variable half a second later makes it equal to zero. It works, but can be thwarted by lag.
If you are attempting to implement BF2 style base capturing, I recommend using a variable that contains the trigger's object id and the player's team...
For instance:
Code: Select all
function CaptureTrigger::onTrigger(%this, %object)
{
%max = getNumTeams();
%team = GameBase::getTeam(%object);
schedule(sprintf("if($pwns[%1, %3]-- < "@ $pwns[%this, %team]++ @") CaptureTrigger::onLeave(%1, %2);", %this, %object, %team), 0.5); // ++ now, -- later. Interval must be greater than 1/3 seconds.
for(%i = 0; %i < %max; %i++)
%pwnt += ($pwns[%this, %i] < $pwns[%this, %team]); // count the teams that have less pwnage.
if(%pwnt == %max - 1) // if all others are pwnt, declare a winner!
{
echo($Server::teamName[%team] @" pwns "@ %this @".");
}
}