Game Development Community

Setting scoring timer

by Columbia College Chicago (#0006) · in Torque Game Engine Advanced · 12/06/2007 (3:10 pm) · 4 replies

Alright, I am making a simple team game where there's basically two triggers set up, one for the blue team and one for the red team, that when they enter them, the team scores. I have the scoring setup just using global variables, $RedScore and $BlueScore. Now, I can set an onEnterTrigger to increment that number, however, what I want to do is:

1. Set a timer so the player has to stand within the trigger for a set time (probably 5 seconds) before it actually increments the score. One way that has been suggested is to just set an onTickTrigger, creating a variable that's set to 5, and having it decrease by one every second, setting the tick rate at 1000 ms. I will have no problem doing it that way, but if there's a better, easier and more efficient way to do so, I'd rather do that.

2. I need a way so a team can't simply stand around the trigger and keep entering it and scoring, without resetting the round each time. Basically I want a team to be able to stand in the trigger, wait the 5 seconds to score, and then have that trigger be disabled for approx. 30 seconds before it can be used again. I am not sure of a way to set that up, and my only solution at this point seems to be teleporting the enemy players to another spot on the map. If there's a way to deactivate the trigger for a set period of time, that would be my preferred option.

Thanks again for any and all help. I'm new to the community, so forgive me if this info can be found easily somewhere that I just don't know about.

#1
12/06/2007 (3:36 pm)
Thats a simple job for scripting and scheduling a function.
Schedule allows you to execute a function at a later time.

What you now would need are global values that define if the player is in the trigger (set in the on enter and on leave trigger). you then could check that each 100 / X00 milliseconds using schedule and raise a field on that specific trigger. and when the field reached a given bordervalue, give a score to the team that is in, reset the field to -1 and start a schedule at around 30000 milliseconds.

This function of that schedule does nothing else than to set that field back to 0 again.

As long as the field is <0, it simply does not start the "count up".
#2
12/06/2007 (3:41 pm)
Do you happen to have what you said in code-form? Haha. I think I can follow the logic, but an example script of this would definitely help.
#3
12/07/2007 (10:01 am)
Http://www.garagegames.com/mg/forums/result.thread.php?qt=22272

this thread got some example code. if you can't find what you want then you can just search for "schedule" with the search function.
#4
12/08/2007 (6:15 pm)
Thanks for the help with this guys. I actually got it figured out a couple days ago. I basically just made a series of triggers and variables to create a timer. Here's the code below. I'm not sure if there was an easier way, and I haven't made incredibly detailed comments, but it's a general idea of how to do it (probably the long way):

function RedTeamScoreZone::onEnterTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object enters the %trigger
   // area, the object is passed as %obj.  The default onEnterTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onEnterTrigger(%this,%trigger,%obj);
   
   if (%obj.client.team.scoreActive)
   {
      if (%obj.client.team.name $= "Blue")
      { 
         %obj.client.team.scoreTimerRunning = true;
         %obj.client.team.scoreTimer = 5;
         $BlueTeam = %obj;              
      }
   }

}

function RedTeamScoreZone::onTickTrigger(%this,%trigger)
{
   // This trigger creates an if statement to first determine if the player is
   // on the correct team to score in that zone.  It then increments the global
   // variable $RedScore by one and displays a message to all clients that the
   // red team has scored.  The nested if statement performs a string compare
   // and if the value of $RedScore equals 10, the victory conditions are met
   // the cycleGame() function is called to end the current game and start a new
   // game.
   Parent::onTickTrigger(%this,%trigger);
   
   if ($Team2.scoreActive)
   {
      if ($BlueTeam.client.team.name $= "Blue")
         {
            if ($BlueTeam.client.team.scoreTimerRunning)
            {
            $BlueTeam.client.team.scoreTimer--;
            }         
                     
            if ($BlueTeam.client.team.scoreTimer <= 0)
            {
            $BlueScore++;            
            // $RedTeam.client.team.scoreTimer = 5;
            $Team2.scoreActive = false;
            
            schedule(30000, BlueTeamScoreZone, BlueTeamActiveSwitch, %obj);
      
            MessageAll('MsgScore', 'The Blue Team has scored.',
            $BlueTeam.client.name,
            $BlueTeam.client.team.name,
            $BlueTeam.client.team.teamId,
            $BlueTeam.client,
            $BlueTeam.client.sendGuid,
            $BlueTeam.client.score,
            $BlueTeam.client.isAiControlled(),
            $BlueTeam.client.isAdmin,
            $BlueTeam.client.isSuperAdmin);                 
      
            if($BlueScore $= "10")
               {
                  cycleGame();
               }
            }
   
         }
   
   }
}

function RedTeamScoreZone::onLeaveTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object leaves the %trigger
   // area, the object is passed as %obj.  The default onLeaveTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onLeaveTrigger(%this,%trigger,%obj);
   
      if (%obj.client.team.name $= "Blue")
      { 
         %obj.client.team.scoreTimerRunning = false;
         %BlueTeam = 0;
      }
}