Reloading in Vanilla Quake with Animations?

Discuss programming in the QuakeC language.
Post Reply
thommoboy
Posts: 95
Joined: Mon Nov 21, 2011 6:35 am

Reloading in Vanilla Quake with Animations?

Post by thommoboy »

i have a reload code but how would i add animations to it?
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Reloading in Vanilla Quake with Animations?

Post by ceriux »

err.. im not to sure on this but maybe something like
if (self.reloading == 1 && self.weapon == x)
{
self.weaponframe = x;
if (time == time + 1)
self.weaponframes = self.weaponframe + 1;
};

prolly wrong... but it would be the first something i would try off the top of my head.

prolly throw in a check that the frame number doesn go over a certain number and if it does return;?
dr_mabuse
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Reloading in Vanilla Quake with Animations?

Post by dr_mabuse »

Mine looks like this:

The kar98k reloading animations starts at Frame 4 and ends at frame 17...
And yes, the code looks like a mess...

Code: Select all

void()	player_rkar98k1 =      [$stand1, player_rkar98k2	] {self.nextthink = time + 0.15; self.weaponframe=4;};
void()	player_rkar98k2 =	[$stand2, player_rkar98k3	] {self.nextthink = time + 0.15; self.weaponframe=5;};
void()	player_rkar98k3 =	[$stand3, player_rkar98k4	] {self.nextthink = time + 0.15; self.weaponframe=6;};
void()	player_rkar98k4 =	[$stand4, player_rkar98k5	] {self.nextthink = time + 0.15; self.weaponframe=7;
sound (self, CHAN_WEAPON, "weapons/kar98k_reload.wav", 1, ATTN_NORM);}; //plays the Reloading Sound
void()	player_rkar98k5 =	[$stand5, player_rkar98k6	] {self.nextthink = time + 0.15; self.weaponframe=8;};
void()	player_rkar98k6 =	[$stand5, player_rkar98k7	] {self.nextthink = time + 0.15; self.weaponframe=9;};
void()	player_rkar98k7 =	[$stand5, player_rkar98k8	] {self.nextthink = time + 0.15; self.weaponframe=10;};
void()	player_rkar98k8 =	[$stand5, player_rkar98k9	] {self.nextthink = time + 0.15; self.weaponframe=11;};
void()	player_rkar98k9 =	[$stand5, player_rkar98k10] {self.nextthink = time + 0.15; self.weaponframe=12;};
void()	player_rkar98k10 =	[$stand5, player_rkar98k11] {self.nextthink = time + 0.15; self.weaponframe=13;};
void()	player_rkar98k11 =	[$stand5, player_rkar98k12] {self.nextthink = time + 0.15; self.weaponframe=14;};
void()	player_rkar98k12 =	[$stand5, player_rkar98k13] {self.nextthink = time + 0.15; self.weaponframe=15;};
void()	player_rkar98k13 =	[$stand5, player_rkar98k14] {self.nextthink = time + 0.15; self.weaponframe=16;};
void()	player_rkar98k14 =	[$stand5, player_run		] {self.nextthink = time + 0.15; self.weaponframe=17;};
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Reloading in Vanilla Quake with Animations?

Post by Baker »

According to the docs, fteqcc can do ...

Code: Select all

#define name(a,b) ((a)*(b))
If so and if using that compiler, it may be possible to really streamline that code ...
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Reloading in Vanilla Quake with Animations?

Post by ceriux »

i should really learn quake animation macro's i just dont like them.
Jukki
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Re: Reloading in Vanilla Quake with Animations?

Post by Jukki »

I made a nice system for my game that handles the weaponframes. It is built from 2 functions. First one is called whenever you want to update the frames (like at the start of reload). You can set starting frame, ensing frame, speed of animation, function to be called during or at the end of animation (useful for stuf like reload canceling, weapons that has animation before the actual fire). Second function is called every frame and updates the frames (usualy every 0.1 secpnds (or what ever quake time) but incase i have speeden
Or slowen the frame then at that time of course. It also calls the function i have assinged with the animation at given frame/end of the animation. Prety cool system
That doesnt require macro stuff or interfence
With player
Frames

And not hard to code at all :)
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Re: Reloading in Vanilla Quake with Animations?

Post by DusterdooSmock »

ceriux wrote:i should really learn quake animation macro's i just dont like them.
There is actually a simpler way to use Quake's animation macros...

Code: Select all

$frame reload1 reload2

void() player_reload1 = [$reload1, player_reload2] {self.weaponframe = 10;};  //Replace 10 with your start frame.
void() player_reload2 = [$reload2, player_reload3] {self.weaponframe = (self.weaponframe + 1);};  //This advances the frame count by 1.
void() player_reload3 = 
{
      if(self.weaponframe == 17)  //If the animation has reached its end....
      {
            self.weaponframe = 0;  //Set the frame back to the idle frame.
            return;  //Exit this function.
      }
      else  //If the animation still has some frames left to play...
      {
            player_reload2();  //Continue the animation..
            return;  //Exit this function.
      }
};
Then your animation can be played by calling "player_reload1();" when the player reloads his weapon.

This isn't the best way to play animations, but if you're like me, and you like to keep things somewhat similar to the way that they were originally written, then this is the way to go..

EDIT: You can also add nextthinks to the animations to either speed up the rate at which frames are played, or slow them down. Like this:

Code: Select all

void() player_reload1 = [$reload1, player_reload2]
{
      self.weaponframe = 10;
      self.nextthink = (time + 0.03);
};
Last edited by DusterdooSmock on Fri Jan 13, 2012 8:55 pm, edited 1 time in total.
dr_mabuse
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Reloading in Vanilla Quake with Animations?

Post by dr_mabuse »

Nice..

BTW: Do you have problems when picking up ammo or new weapons?
My reloading animations are stopping when i picking up ammo and i still dont know how i can fix this the easy way xD
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Re: Reloading in Vanilla Quake with Animations?

Post by DusterdooSmock »

dr_mabuse wrote:Nice..

BTW: Do you have problems when picking up ammo or new weapons?
My reloading animations are stopping when i picking up ammo and i still dont know how i can fix this the easy way xD
You would have to use a "reload_time" float or something similar.

Code: Select all

.float reload_time;
Then each time the frame is set or advanced you would add your desired time to the "reload_time". Like this:

Code: Select all

void() player_reload2 = [$reload2, player_reload3]
{
      self.weaponframe = (self.weaponframe + 1);
      self.reload_time = (time + 0.2);
      self.nextthink = (time + 0.03);
};


The reason I used 0.2 for "reload_time" is because every time the frame is advanced, the "reload_time" will be reset. It is best to add the "reload_time" line to every function in your animation so that there will be a final delay of 0.2 when the animation is finished. It makes it look nicer.

And in your W_WeaponFrame function, you would have something like this:

Code: Select all

if(self.reload_time > time)
      return;
This prevents the player from firing or entering impulses while he is reloading. It may be what you are searching for, but I don't know, because I have never had the issue that you are talking about...
dr_mabuse
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Reloading in Vanilla Quake with Animations?

Post by dr_mabuse »

thanks, i will try it, finally something i can use ;)

My little mod will have pickupable items like original Quake (ammo, weapons etc..), and everytime i reload and pick up ammo some seconds later the animations will stop...
But i think your post will help me :D
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Re: Reloading in Vanilla Quake with Animations?

Post by DusterdooSmock »

dr_mabuse wrote:thanks, i will try it, finally something i can use ;)

My little mod will have pickupable items like original Quake (ammo, weapons etc..), and everytime i reload and pick up ammo some seconds later the animations will stop...
But i think your post will help me :D
No problem, but you may also want to check your weapon pickup functions for anything related to the players .weaponframe, or anything related to "player_run", and remove it, as it could be setting the frames back to 0, and or pausing them, depending on how your systems for animations and weapon pickups work.
Post Reply