Forum

Realistic Gatling Gun

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Realistic Gatling Gun

Postby dr_mabuse » Wed Sep 21, 2011 3:32 pm

Hi,

I Have my "IT_SUPER_NAILGUN" here, already coded with a "fake overhating" effect (overheats after 80 shots for 2 seconds, just a modified reloading code based on Reload Quake xD)..
And now i want to add the following and i want to know a good and efficient way to do the following:

- if you press you shootbutton, the nailgun doesnt start shooting for 2 seconds, only the barrel animations starts and a "warmup sound plays"
- after that the gun shoots normally (W_FireMiniGun)
- when yo stop shooting the barrel still rolls for 9 frames (cooldown)

Heres my "actual" mess:

Code: Select all
   else if (self.weapon == IT_SUPER_NAILGUN) //VENOM GUN!!!
   {
      if (self.magazine_wep_4 == 0)
      {



         sound (self, CHAN_AUTO, "weapons/venom_overheat.wav", 1, ATTN_NORM);
         self.attack_finished = time + 2.5;
         self.magazine_wep_4 = 80;
         player_minigun1 ();         
         
      }
      else
      {
         self.weaponmodel = "progs/v_nail2.mdl";
         player_minigun1 ();

         W_FireMiniGun ();
         sound (self, CHAN_AUTO, "weapons/venom_gs.wav", 1, ATTN_NORM);
         self.attack_finished = time + 0.085;
         self.magazine_wep_4 = self.magazine_wep_4 - 1;
         if (self.magazine_wep_4 == 0)
            centerprint (self, "OVERHEAT!!");



thx :D
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Realistic Gatling Gun

Postby Nahuel » Wed Sep 21, 2011 4:41 pm

Check this mod http://www.quakewiki.net/quake-1/mods/final-quake-real/
:) source not included but you can use the frikdec ( :lol: ). Just what you need :)
hi, I am nahuel, I love quake and qc.
User avatar
Nahuel
 
Posts: 492
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: Realistic Gatling Gun

Postby dr_mabuse » Wed Sep 21, 2011 4:51 pm

ya, i know that mod, but i dont want to decompile other ppls stuff ;)
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Realistic Gatling Gun

Postby Nahuel » Wed Sep 21, 2011 4:56 pm

dr_mabuse wrote:ya, i know that mod, but i dont want to decompile other ppls stuff ;)

you can read the code and see examples of the work
hi, I am nahuel, I love quake and qc.
User avatar
Nahuel
 
Posts: 492
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: Realistic Gatling Gun

Postby dr_mabuse » Wed Sep 21, 2011 5:40 pm

Decompiling gives me a mess, isnt there a easier way? :(
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Realistic Gatling Gun

Postby frag.machine » Thu Sep 22, 2011 12:24 am

dr_mabuse wrote:Decompiling gives me a mess, isnt there a easier way? :(


The easy way is to ask someone how to do. Soon or later you may even get your answer, and actually there's nothing wrong with that, but you won't learn much from that in the end.

The hard way is trial and error. It's boring, time spending and sometimes frustrating, but eventually you'll manage to put things together in a way that works. And you will have learned how and why. And when you start to code your next cool weapon or monster or mod, you'll feel more confident and will manage to create it with a bit less difficulty.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Re: Realistic Gatling Gun

Postby leileilol » Thu Sep 22, 2011 4:21 am

The old tritian gatling gun did overheating.

it's easy to overheat the gatling - make a .float that increases every shot, make this .float decrease when you're not shooting, and when this .float reaches a point, prevent the firing for a long nextthink
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: Realistic Gatling Gun

Postby apolluwn » Thu Sep 22, 2011 7:43 am

dr_mabuse wrote:- if you press you shootbutton, the nailgun doesnt start shooting for 2 seconds, only the barrel animations starts and a "warmup sound plays"
- after that the gun shoots normally (W_FireMiniGun)


Off the top of my head this should get it started... It's neither good nor efficient (or even a good way to do this really...), but you should be doing that yourself. :)

Code: Select all
.float warmup;          //time when warm up is done
.float is_firing;          //set this when a weapon is firing
.float overheat;          //when 0 == overheated
.float overheat_time;            //how long before you can fire after overheating
.float is_firing;          //set this when a weapon is firing


Add is_firing in W_WeaponFrame
Code: Select all
void() W_WeaponFrame =
{
   if (time < self.attack_finished)
      return;

   if (self.impulse)
      ImpulseCommands ();
   
        // check for attack
   if (self.button0)
   {
      SuperDamageSound ();

      W_Attack ();
      self.is_firing  = 1;         //we are firing
   }
   else { self.is_firing = 0; };                   //we are not firing
};


Some basic logic for warm up/spin up via a modified W_FireSuperSpikes...
Code: Select all
void() W_FireSuperSpikes =
{
   local vector   dir;
   local entity   old;

   if(self.is_firing)   // if we hold down the attack button it will be 1 and run this
   {      
      bprint(ftos(self.overheat), "\n");           // count overheat down and spam your screen   
   }
   else                             // this is initially set to 0 when first firing / pressing down the attack button
   {                        // so we shall use it to initialize some stuff
      // re/set to 40
      self.overheat = 80;
      //re/set warmup
      self.warmup = time + 2;      
   }
   
   if(time > self.warmup && time > self.overheat_time)
   {
      if(self.overheat > 0) // we are not overheated. we are warmed up and firing
      {   
            sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
         self.attack_finished = time + 0.2;
         self.currentammo = self.ammo_nails = self.ammo_nails - 2;
         dir = aim (self, 1000);
         launch_spike (self.origin + '0 0 16', dir);
         newmis.touch = superspike_touch;
         setmodel (newmis, "progs/s_spike.mdl");
         setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);      
         self.punchangle_x = -2;
         self.overheat = self.overheat - 1;            
      }
      else // play overheat sound
      {
         bprint("Overheated.\n");
         sound (self, CHAN_WEAPON, "weapons/gatlin_overheat.wav", 1, ATTN_NORM);
         self.overheat_time    = time + 3;
                  
         self.weaponframe       = 0;                              // force no animation
         self.effects                 = self.effects - EF_MUZZLEFLASH;                            // stop the muzzle flash light
      }
   }
   else // we are not warmed up or we are overheated
   {
      if (time < self.warmup) // not warmed up
      {
         self.attack_finished = time;
         self.effects           = self.effects - EF_MUZZLEFLASH;                                         // stop the muzzle flash light         
         bprint("Warming up.\n");                                                                                       // screen rapist
         sound (self, CHAN_WEAPON, "weapons/gatlin_spin_up.wav", 1, ATTN_NORM);
         
      }
      else if(time < self.overheat_time) // overheated
      {
         bprint("AH! It burns! It burns!\n");                                                                          // screen rapist
         sound (self, CHAN_WEAPON, "weapons/gatlin_overheat_fire.wav", 1, ATTN_NORM);
         
         self.weaponframe       = 0;                              // force no animation
         self.effects                 = self.effects - EF_MUZZLEFLASH;                            // stop the muzzle flash light                  
      }
   }
};


dr_mabuse wrote:- when yo stop shooting the barrel still rolls for 9 frames (cooldown)


Something like this -might- work, but if it does then I imagine it will not work very well and will probably mess stuff up. Well... actually all of this will probably mess crap up, but maybe it will give you some ideas. ;)

Code: Select all
   if(time > self.attack_finished)
   if (self.isfiring == 0 && self.spindown == 1)
   {
      self.think = spin_down;
      self.nextthink = 0.25;
   }

Code: Select all
var float counts = 0;  //not because i'm lazy
void spin_down()
{
      if(self.spindown == 0)
      {
         self.weaponframe = 0;
         return;
      }
   
      if(self.weaponframe >= 9)
      {
         self.weaponframe  = 0;
         self.spindown       = 0;
         counts          = 0;
         return;
      }      
      self.weaponframe = self.weaponframe + 1;
      counts = counts + 1;                                   // really...
      self.attack_finished =    time + (counts/50);    // well maybe
}
apolluwn
 
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Re: Realistic Gatling Gun

Postby dr_mabuse » Thu Sep 22, 2011 8:50 am

thx, i will give it a try :D

i had problems last night with my mod (the animations only play when i pressed a button lol)...

EDIT: Ok this was a bad idea.... I got the Gatling gun working, but the Frikbots cant handle it...
:lol: :lol: :lol:
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Realistic Gatling Gun

Postby Electro » Thu Sep 22, 2011 10:33 am

Don't use .think and .nextthink on the player.
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Re: Realistic Gatling Gun

Postby dr_mabuse » Thu Sep 22, 2011 4:54 pm

thanks @ all for the tips, i got now the gatling ALMOST done i want xD
i am a beginner in quakec and want to do all on my own (ok, wit some tipps xD) and not decompile and copy/pasting others stuff :D

using the Quake / Kurok QC Code as a base for the beginning is ok for me...

And using decompiled stuff confuses me:

if ((self.weaponframe >= FL_SWIM)) // Why swim?? oO
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Realistic Gatling Gun

Postby Nahuel » Thu Sep 22, 2011 5:20 pm

dr_mabuse wrote:thanks @ all for the tips, i got now the gatling ALMOST done i want xD
i am a beginner in quakec and want to do all on my own (ok, wit some tipps xD) and not decompile and copy/pasting others stuff :D

using the Quake / Kurok QC Code as a base for the beginning is ok for me...

And using decompiled stuff confuses me:

if ((self.weaponframe >= FL_SWIM)) // Why swim?? oO

FL_SWIM is defined in defs.qc as a number. You can search in defs.qc and you will find
Code: Select all
float   FL_SWIM               = 2;

FL_SWIM means "2" in the "decompiled" qc. All the floats are interpreted in this way :lol:
hi, I am nahuel, I love quake and qc.
User avatar
Nahuel
 
Posts: 492
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: Realistic Gatling Gun

Postby dr_mabuse » Thu Sep 22, 2011 5:25 pm

lulz, ok xD

the SWIM has confusing me xD
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Re: Realistic Gatling Gun

Postby apolluwn » Fri Sep 23, 2011 12:36 am

I didn't mean for that to be code that was good to go and just copy-pasted...

It was just an example of what you might need to do... this is why I put all the prints and comments in there so you could see where it was in the code had you copied it into a clean source or similar to see how it worked or were just reading it...

If you really want weapons that need to activate after a certain time period/do some conditional animation/etc then you'll really want to consider revamping the weapon system itself. Particularly if you want to have animations before firing and after firing. It really will just be a pain in the ass the way it is set up right now (mostly if you are planning on having more weapons that need "special functionality") since it runs through W_WeaponFrame which then calls W_Attack to find what weapon is currently being used then calls the function that triggers the animation before a weapon state could be set.

This is fine for the standard quake weapons, but not for what you are wanting to do...

You can see that in the above code it forces the weaponframe to be 0 whenever it is warming up, overheated/ing, etc. This is because it is always trying to run the animation function (player_nail1) to increment the weapon frame before it calls W_FireSuperSpikes (within the animation function).

For the super nailgun it goes something like W_WeaponFrame (impulse commands and catches firing) -> W_Attack (see which weapon is being used call animation function) -> player_nail1 (animation/etc) -> W_FireSpikes (this is the nailgun code called from animation to play sounds, modify ammo count, and several other things) -> W_FireSuperSpikes (called from W_FireSpikes if the weapon is the super nailgun and not the nailgun) -> launch_spike (creates the entity projectile gives it a model etc).

I think you can see how this could be troublesome for what you are trying to do.

Quake wants to increment the weapon frame and create a muzzle flash before it even tries to actually "fire" the weapon.

You should probably call the animation from the weapons function rather than before it... This would allow you to get/set/pass the state so it plays the correct animations, effects, etc. You could probably make a generic animation function to pass the weapon state and the current weapon to. Then you could use the weapon state to pass the frames you wanted played to the actual animation function and the animation speed(s) into the weapon animation think function.

There would be a lot more to it than that, but if you were up to it you'd have a much better way of making weapons do what you wanted them to if they need additional capabilities beyond the standard behavior.

The only reason the above code would "work" is because it either constantly sets the weaponframe back to 0 and removes the muzzleflash or just allows the animation to go without ever playing the sound or running launch_spike. It's basically crapping all over the way it naturally works...
apolluwn
 
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Re: Realistic Gatling Gun

Postby dr_mabuse » Fri Sep 23, 2011 9:02 am

Thanks for the nice text :)

And i think i keep my Gatling Gun the "classic" way, because the Frikbots seems to have Problems with the "Warmup" stuff.
I will keep the overheating and reloading.
The next problem was the Kurok QC code my mod was based on, it was a big mess...
I "re-started" doing my mod on "vanilla" quakec code last night, and using a smarter reloading routine for the weapons.
User avatar
dr_mabuse
 
Posts: 80
Joined: Sat Sep 03, 2011 6:07 pm

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest