Page 1 of 1

Starttimer / Stoptimer [q3geoball]

Posted: Sat Apr 28, 2007 11:32 am
by Landix
Hi there again, :paranoid:

i want to have a function following.

when starting a level a item should start a timer @ the end
of the level should be a item to stop the timer.

When the player not fast enough he should teleportet
to the beginning of the map, and the timer should reset.

When he is fast enough he can go to the next level.

Have somebody do this? Or can anybody help me out with that?

target_starttimer target_stoptimer !?

Posted: Sat Apr 28, 2007 12:31 pm
by ^misantropia^
Yep.

1. Create two new trigger entities.
2. Add a field 'starttimer' to the gclient_t structure in game/g_local.h
3. When the player touches the trigger_starttimer, set said field to level.time (and check if starttimer > 0 so it doesn't constantly reset in the vicinity of the trigger).
4. In G_RunFrame, check if (starttimer > 0 && level.time - starttimer > treshold)
5. If true, reset the starttimer, find the info_player_deathmatch and teleport the client there.

If the player touches the trigger_stoptimer, set starttimer to 0.

Posted: Sat Apr 28, 2007 12:44 pm
by Landix
You answer really fast, and i will thank you for that, but
i think i can not do this so.

I need really help for this thingie.

i thought somebody have already done this.
And share the code with me.

:icon23:

Posted: Mon Apr 30, 2007 6:01 pm
by Landix
g_spawn.c

Code: Select all

void SP_target_timer (edict_t *ent); 
Add to spawns[]-array:

Code: Select all

{"target_timer", SP_target_timer},
g_target.c

Add to declarations:

Code: Select all

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

    int timerValue[MAX_EDICTS][MAX_CLIENTS];
Add these three functions to others in same sequence:

Code: Select all

    /*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;
    }


    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;
    }
I have this from jjaf.de

Can i use this so!
Or can me somebody write it, that it for q3 works?

Posted: Mon Apr 30, 2007 8:31 pm
by ^misantropia^
Well... you could use it, but it's based on the Q2 source. If you put a little work in it, you might be able to adjust it to your needs. Conceptually, not that much changed between Q2 and Q3.

Posted: Tue May 01, 2007 6:59 am
by Landix
I will try this out.

alternative target_counter will do the same thing.

i will try this to.

Thx for answering me.