OpenArena Message Boards

OpenArena Contributions => Development => Topic started by: WarMocK on February 16, 2014, 06:08:18 am



Title: Programming issue: adding a timer
Post by: WarMocK on February 16, 2014, 06:08:18 am
Hello everyone,
I started working with OA's code some time ago (only programmed tools and user interfaces for Linux on C/C++ basis so far), and I'd like to try something with the weapons.
Specifically, I want to change the gauntlet's "scanning" attack into a sequence of 3 strikes, with a 300 ms intervall, to change the weapon into a sword. Furthermore, I want to add a delay for firing the grenade launcher to simulate the usage of a hand grenade. The problem is: I don't know how to tell the system to wait for a specific time after the fire button has been pressed before the projectile entity is spawned or the hitscan from the gauntlet is executed. You guys got any advise for me? That'd be awesome.

Thanks in advance. :3


Title: Re: Programming issue: adding a timer
Post by: Suicizer on February 16, 2014, 07:14:23 am
My advice; learn to write in C++.


Title: Re: Programming issue: adding a timer
Post by: Neon_Knight on February 16, 2014, 08:35:51 am
I've sent a PM to the codeguys. They'll drop here, I guess.

EDIT: You should consider this subforum: http://openarena.ws/board/index.php?board=59.0


Title: Re: Programming issue: adding a timer
Post by: stigmha on February 17, 2014, 02:40:04 am
Hi, I am currently out traveling so I am bit limited on resources and time... but here it goes. I think it might be a good idea for you to read up on quake Entities (http://wiki.ioquake3.org/Entities) and to run through ioquake3's modding tutorials (http://wiki.ioquake3.org/Hello,_Qworld). Then you should spend some time digging into the implementation of the other weapons and learn how they're implemented.


Title: Re: Programming issue: adding a timer
Post by: WarMocK on February 17, 2014, 12:26:18 pm
Alright, found a solution that works, at least in terms of delaying the shot:

I recycled the kamikaze timer a bit, and created a timer that is triggered by the weapon fire function normally, but uses a blank entity that executes the firing effect after a given amount of milliseconds. Tested it with rocket fire and now with lightning fire, looks pretty awesome when you fire 3 rockets in a row, and melting down a foe with 3 lightning bolts ain't too bad either.  ;D

in g_combat.c:
Code:
void Gauntlet_Timer( gentity_t *self, int delay ) {
gentity_t *ent;

ent = G_Spawn();
ent->classname = "gauntlet timer";
VectorCopy(self->s.pos.trBase, ent->s.pos.trBase);
ent->r.svFlags |= SVF_NOCLIENT;
ent->think = FireTheGauntlet;
ent->nextthink = level.time + delay;
}

and

Code:
void FireTheGauntlet( gentity_t *ent ) {
Weapon_LightningFire( ent );
G_FreeEntity(ent);
}

In g_weapon.c, I modified the gauntlet case to:
Code:
case WP_GAUNTLET:
Weapon_LightningFire( ent );
Gauntlet_Timer ( ent, 300 );
Gauntlet_Timer ( ent, 600 );
break;
Only issue I have now is that the spawn vector isn't updated for the fire sequences after the initial shot, which almost made me blow up myself as the second and third rocket exploded inside me.^^
Need to figure that one out tonight, or whenever I feel like coding again.