Firing animations

Discuss programming in the QuakeC language.
Post Reply
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Firing animations

Post by sniperz227 »

Hey im sorry but i still cant grasp the concept on how to animate. i have a file with 1-4 shootingand 5-10 reloading animations. How would i code in firing for a weapon i codded in myself in quake. its slot is called IT_M9 if you need it. thanks
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: Firing animations

Post by Nahuel »

basically the animations of the weapons (self.weapon) are called by "self.weaponframe"


For Example in W_attack:

Code: Select all

if (stuff.about.realoding.code)
ReloadPistol();
else
FirePistol();
So you need to write something like

Code: Select all

void() ReloadPistol =
{
self.weaponframe = 5;       
.........
and

Code: Select all

void()FirePistol =
{
self.weaponframe = 1;       
.........

Do not forget call all the animations, you can call it easy with "nextthink"
hi, I am nahuel, I love quake and qc.
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: Firing animations

Post by Seven »

Hello sniperz227,

I think there are 2 ways to play animations.

1.) The example, that Nahuel started. let me go a little deeper here:

Code: Select all

if (stuff.about.realoding.code)
{
self.weaponframe = 5   // to be sure to start with frame 1 in reloading animation
ReloadPistol();
}
else
{
self.weaponframe = 1   // to be sure to start with frame 1 in firing animation
FirePistol();
}

Code: Select all

void() ReloadPistol =
{
	self.weaponframe = self.weaponframe + 1;
	   if (self.weaponframe == 8)
                sound (self, CHAN_VOICE, "weapons/reload.wav", 1, ATTN_NORM);    // plays your reload sound for example
	   if (self.weaponframe >= 10)
		return;
	self.nextthink = time + 0.1;
};

Code: Select all

void() FirePistol =
{
	self.weaponframe = self.weaponframe + 1;
	   if (self.weaponframe == 3)
                sound (self, CHAN_VOICE, "weapons/boom.wav", 1, ATTN_NORM);    // plays your fireing sound for example
	   if (self.weaponframe >= 4)
		return;
	self.nextthink = time + 0.1;
};

2.) Do it the classic way:

Code: Select all

  $frame gun1 gun2 gun3 gun4 gun5 gun6 gun7 gun8 gun9 gun10

Code: Select all

void()	reload1	=[	$gun5,	reload2	] {};
void()	reload2	=[	$gun6,	reload3	] {};
void()	reload3	=[	$gun7,	reload4	] {};

void()	reload4	=[	$gun8,	reload5	] {
sound (self, CHAN_VOICE, "weapons/reload.wav", 1, ATTN_NORM);};    // plays your reload sound for example
void()	reload5	=[	$gun9,	reload6	] {};
void()	reload6	=[	$gun10,	reload6	] {gobacktoyourcode();};

Code: Select all

void()	fire1	=[	$gun1,	fire2	] {};
void()	fire2	=[	$gun2,	fire3	] {};
void()	fire3	=[	$gun3,	fire4	] {
sound (self, CHAN_VOICE, "weapons/boom.wav", 1, ATTN_NORM);    // plays your fireing sound for example
void()	fire4	=[	$gun4,	fire4	] {gobacktoyourcode();};
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Firing animations

Post by sniperz227 »

ok thanks for the help i get it know its just the old method i cant understand :P i did that and after that i assuming i had to add FirePistol(); into w_attack to actually get the naimation to play but it didnt?

Code: Select all

	else if (self.weapon == IT_SHOTGUN)
	{
		if (self.weaponframe = 1)
		{
		self.weaponframe = 1;
		FirePistol();
		}
		W_FireShotgun ();
		self.attack_finished = time + 0.5;
	}
	}
thats the code in w_attack

and this is the code in my animations.qc

Code: Select all

/*
===============================================================================================================================================
==================================Animations=================================================================================================== 
===============================================================================================================================================
*/



/*
====
 M9 
====
*/


//Firing Animations for M9 pistol 1-4 frames

void() FirePistol =
{
   self.weaponframe = self.weaponframe + 1; // increment weapon frame
      if (self.weaponframe == 3)
                sound (self, CHAN_VOICE, "weapons/boom.wav", 1, ATTN_NORM);    // plays your fireing sound for example
      if (self.weaponframe >= 4) // stop at frame 4 last firing frame
      return;
   self.nextthink = time + 0.1;
};
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: Firing animations

Post by Seven »

Hello sniperz227,

Slowly, these have just been sample lines.

If you change your w_attack() code like you did it, you will not be able to see the animation.
Your .weaponframe will always be resettet to "0", so if you put a "if (self.weaponframe = 1)"
it will never pass it.

Also my "sound" line was only an example. I believe you dont even have a "boom.wav" file, do you ?
I just wanted to show what you could do.

If you are not sure how to start, I would suggest to leave the original code as it is and start this way to at least see your gun in action:
Create frames in your .mdl model similar to the original weapon (lets say the shotgun).
Name the frames (inside QME for example) according the original frames: "shot1" till "shot7" (fill up with dummy frames if you have only 5)
Now replace the shotgun with your weapon model.

Next step would be to adjust the existig code according to the real frame count that you have (you said you have 5 ?).
You can include now also sound or effect code lines if you want.

Proceed step by step and try to make it happen in small steps.
If you change too much at once you will be confused/lost quickly.
I am also an unexperienced coder, who still have to learn a lot.

I can suggest to read LordHavocs weapon tutorial (especially if you want to play around with it).
It teaches you basic things. I know it is not exactly what you want to do, but maybe it helps:
http://inside3d.com/showtutorial.php?id=194

Also the reloading tutorial might be very interesting for you:
http://www.inside3d.com/showtutorial.php?id=249
(There is one small mistake inside though. Read about it here:
http://forums.inside3d.com/viewtopic.php?f=2&t=4451

Good luck.
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Firing animations

Post by sniperz227 »

ye well i changed my wepaonframe to 1 should that work? and i dont wanna use the old method i used your new one as you can see. i already have my reload code im just not going to put it in yet cuz i want to get firing in first.
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Firing animations

Post by sniperz227 »

nvm i got it i didnt realize that my animations werent on my gun when i exported it :P
dr_mabuse
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Firing animations

Post by dr_mabuse »

sorry for bumping an old topic, but i got also a small problem with my animations..

All my guns have firing and reloading animations, and they work as they should, but with one problem:
the reloading animations will stop when you pick up ammo and a new weapon...
Does anybody know how i can disable it? Maybe in the touch functions?
Alex
Posts: 24
Joined: Sun Feb 13, 2011 6:24 pm

Re: Firing animations

Post by Alex »

Hey Dr_Mabuse,
I could be wrong, but I'm pretty sure it has to do with W_SetCurrentAmmo() in weapons.qc and items.qc

Every time you pick up ammo or weapons this function is called, and in it the weaponframe is always set to zero. So if you're in the middle of reloading (say weaponframe 10 or 15) and pick up another gun it resets your weaponframe, even though the reloading function continues. It actually does the same thing with firing animations, you just generally don't notice it because they're usually short.

Try putting a condition in the W_SetCurrentAmmo function. Maybe something at the top like:

if ((self.currently_reloading) > 0) {
return;
}

Then at the last frame of every reloading animation I'd call W_SetCurrentAmmo() and reset self.currently_reloading to 0.

I think that should do the trick.

Alex
dr_mabuse
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Firing animations

Post by dr_mabuse »

where exactly in items.qc??

EDIT: looks like it is not working or i am to stupid lol...
Post Reply