† Wolfgang H. Franke
[counter]

jjaf.de » kingpin » mods

timer

intro

This page explains how to implement timer-module in kingpin-modifications by copy-and-pasting the following blocks of code to the resp. locations. Ask for making maps for timer-module.

Timer is only a module, not a modification itself as it only represents one function, not a whole gameplay, but can therefore be added to every modification.

supplemental files

Map designers will need timer.def-file for making maps using timers. Install by placing in ~/kingpin/kprad/-directory.

intructions

g_spawn.c

Add to other function declarations:

void SP_target_timer (edict_t *ent); // jjaf.de timer

Add to spawns[]-array:

/*jjaf*/{"target_timer", SP_target_timer},

g_target.c

Add to declarations:

#define MAX_CLIENTS 256 // absolute limit
#define MAX_EDICTS 2048 // must change protocol to increase more

int timerValue[MAX_EDICTS][MAX_CLIENTS]; // stores frame-# of all timers

Add these three functions to others in same sequence:

/*QUAKED target_timer (.5 .5 .5) ? STOP
http://jjaf.de/kingpin/mods/timer/1.0.1/
When triggered will start/stop a stopwatch

property-checks:
"STOP": If set will stop the watch otherwise will start it.

property-fields:
  required:
    "team": target ID to match resp. timer that start/stops.
    "targetname": ID for triggers.
*/
/* jjaf.de timer
 * GetPlayerID helper-function 1.0.1
 */
int GetPlayerID (edict_t *ent)
{
 int index;
 int ID;

 ID = 0;
 for (index = 0; index < maxclients->value; index++)
 {
  if (game.clients[index].pers.connected)
  {
   ID++;
   if (game.clients[index].pers.netname == ent->client->pers.netname)
   {
    return ID;
   }
  }
 }
 return ID;
}
/* jjaf.de timer
 * use function 1.0.1
 */
void target_timer_use (edict_t *self, edict_t *other, edict_t *activator)
{
 // int elapsed;     // temp. var for calculating diff (start - stop)
 char elapsed[16];     // temp. var for calculating diff (start - stop)
 int TeamID;
 int PlayerID;

 // init
 TeamID = atoi(self->team);
 PlayerID = GetPlayerID(activator);

 // activated by player?
 if (activator && activator->client)
 {
  if (self->spawnflags & 1)

  // stop
  {
   if (timerValue[TeamID][PlayerID] > 0)

   // was started
   {
    // elapsed = (level.framenum - timerValue[TeamID][PlayerID]);
    Com_sprintf (elapsed, sizeof(elapsed), "%.1f", ((float)(level.framenum - timerValue[TeamID][PlayerID]) / 10));
    gi.cprintf(NULL, PRINT_HIGH, "jjaf.de timer: player %s stopped timer %i delta = %s s\n", activator->client->pers.netname, TeamID, elapsed);
    timerValue[TeamID][PlayerID] = 0;
   }

   // was _not_ started
   else
   {
    gi.cprintf(NULL, PRINT_HIGH, "jjaf.de timer: player %s stopped timer %i without prior starting!\n", activator->client->pers.netname, TeamID);
   }
  }
  else

  // start
  {
   timerValue[TeamID][PlayerID] = level.framenum;
   gi.cprintf(NULL, PRINT_HIGH, "jjaf.de timer: player %s started timer %i\n", activator->client->pers.netname, TeamID);
  }
 }
}

 

 

/* jjaf.de timer
 * spawning function 1.0.1
 */
void SP_target_timer (edict_t *self)
{
 // validity checks: check for required property-fields
 if (!self->team)
  gi.dprintf("jjaf.de timer: no team %s at %s\n", self->classname, vtos(self->s.origin));

 if (!self->targetname)
  gi.dprintf("jjaf.de timer: no targetname %s at %s\n", self->classname, vtos(self->s.origin));

 self->svflags |= SVF_NOCLIENT; // server-side target only
 self->use = target_timer_use; // function to call when triggered
 self->nextthink = 0;   // no thinking, just triggered
 self->think = NULL;
}

references

  1. mod coder needed,for "simple" mod