adding a timer

Locked
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

adding a timer

Post by nexus024 »

Ok, what I am wanting to do is add a timer for how long the flag is held before its either dropped from being killed or captured. Then it will display something like "name captured the flag! (held for xx:xx)." Ive created a cvar (flag_held) for enabling/disabling when the timer should be activated. I have added my timer to the ClientTimerActions function in g_action.c since it is run once every second. Here is what I have...

Code: Select all

if ( flag_held.integer = 0 ) {
  sec = 0;
  min = 0;
}
else if { flag_held.integer = 1 ) {
  if ( sec = 59 ) {
    sec = 0;
    min += 1;
  }
  else 
    sec += 1;
}
I set flag_held.integer to 0/1 in g_team.c when it says the client got the flag, captured the flag, or flag was dropped due to being killed. The problem I am having is that my seconds integer isn't being incremented in g_action.c. It shows to only be set to 1 throughout the duration of having the flag. Also, it shows in game that the flag was held for 0:0. I set it using this command...

Code: Select all

PrintMsg( NULL, "%s" S_COLOR_WHITE " captured the %s flag! (held for %i:%i)\n", cl->pers.netname, TeamName(OtherTeam(team)), sec, min);
Any ideas?
Kaz
Posts: 1077
Joined: Wed Mar 08, 2006 3:43 am

Re: adding a timer

Post by Kaz »

else if (flag_held.integer == 1)

== checks for equality, = assigns value
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: adding a timer

Post by nexus024 »

rofl, my bad.
Kaz
Posts: 1077
Joined: Wed Mar 08, 2006 3:43 am

Re: adding a timer

Post by Kaz »

:D
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: adding a timer

Post by nexus024 »

Do you know the point at where the flag is touched?
Kaz
Posts: 1077
Joined: Wed Mar 08, 2006 3:43 am

Re: adding a timer

Post by Kaz »

You might want to look at Pickup_Powerup in g_items.c, or its parent, Touch_Item
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: adding a timer

Post by nexus024 »

Thanks.

Just out of curiousity, if you wanted to implement a timer in a similar fashion, how would you all implent it? Is there an easier approach than what I am attempting to do?
Locked