Inside3D!
     

Reload working.... kinda
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Mon Jan 04, 2010 6:01 am    Post subject: Reload working.... kinda Reply with quote

as the title says my reload isnt working how i want it to.
first when i start the game it doesnt start with 8 in the clip
but just by reloading(impulse 40) it fixes that.
So now i got 8 rounds in my clip, i shoot, now theres 7, i shoot again, still 7...... i dont know what wrong. (i know Ith help me with some of it, i understand a little more now so im reasking some questions)

Here is the shotgun code
Green = altered
Blue = added
Code:
void() W_FireShotgun =
{
   local vector dir;

   sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);   

   self.punchangle_x = -2;
   
   [color=green]self.currentammo = self.ammo_pistol - 1;[/color]
   dir = aim (self, 100000);
   FireBullets (6, dir, '0.04 0.04 0');
};


Here is the impulse command

Code:
if (self.impulse==40)
  {
 
   if (self.weapon == IT_SHOTGUN)
       {
       if (self.ammo_shells < 8)
         {
         self.currentammo = self.ammo_shells = self.ammo_pistol;
         self.ammo_shells = 0;
         }
       else
         {
         self.currentammo = self.ammo_pistol = 8;
         self.ammo_shells = self.ammo_shells - 8;
         }
       }
     }
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Jan 04, 2010 11:23 am    Post subject: Reply with quote

You've gotta subtract 1 from the pistol ammo variable in the fire function, not from the current ammo value. Then set the current ammo variable to the pistol ammo variable. The current ammo value is just for show, really, it's the number that's rendered is all.
Back to top
View user's profile Send private message
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Mon Jan 04, 2010 7:24 pm    Post subject: Reply with quote

More specifically:

Code:
self.currentammo = self.ammo_pistol = self.ammo_pistol - 1;


Also, to have your gun start fully loaded when you spawn, just put something like this in PutClientInServer() (located in client.qc), preferably after when DecodeLevelParms(); is called:

Code:
self.ammo_pistol = 8;

_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Tue Jan 05, 2010 6:42 am    Post subject: Reply with quote

Thanks you guys it worked.... kinda.
It subtracts ammo just fine now.
And the self.ammo_pistol = 8 in the client kinda worked, when i start the game it shows 25, then i shoot then it shows 7....

second, how would i get it so that if i shoot on an empty clip it would automatically reload.

third how can i get it to reload and only take the difference from my shells? example 5 bullets in clip, i reload, it only take 3 from shells?

fourth how would i get reload (impulse 40) it to call upon the reload frames of the model?

and fifth, how would i put the delay in so you can shoot or anything during the reload animation.

Sorry for all the dumb questions, i am trying to learn coding and i understand some of it, but the best way for me to learn is to just do it. I hope you don't mind seeing me here to ask a lot of questions....
Back to top
View user's profile Send private message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Tue Jan 05, 2010 8:51 am    Post subject: Reply with quote

Sometimes you do have to plan things out in normal English logically before your can just jumping into hacking your mod.

In the engine, it strictly updates these fields in SV_WriteClientdataToMessage,
Code:

   MSG_WriteByte (msg, ent->v.currentammo);
   MSG_WriteByte (msg, ent->v.ammo_shells);
   MSG_WriteByte (msg, ent->v.ammo_nails);
   MSG_WriteByte (msg, ent->v.ammo_rockets);
   MSG_WriteByte (msg, ent->v.ammo_cells);

These are for the HUD, so that's our given.

You may need to create supporting variables, and keep the originals as the cache to communicate with the protocol.


self.ammo_shells_sg
self.ammo_shells_ssg

self.ammo_nails_ng
self.ammo_nails_sng

self.ammo_rockets_gl
self.ammo_rockets_rg

self.ammo_cells_lg

self.current_ammo should be equal to these when switching weapons.

I'm thinking these could be updated for each gun as its used, (in-hand) for both reloading and firing.

For example the shotgun, when reloading you're taking away from self.ammo_shells and adding it to self.ammo_shells_sg. Then in w_attack determine what gun you are holding, then check that gun's ammo, before firing, then subtract that gun's ammo apon firing. Ammo touch functions should work fine because it still updates the original self.ammo_* values. So the only time the old ammo_shells gets modified is within reload and item pickup.

Okay now let's try some code examples.
Ghost_Fang wrote:

Sorry for all the dumb questions, i am trying to learn coding and i understand some of it, but the best way for me to learn is to just do it. I hope you don't mind seeing me here to ask a lot of questions....

If we have to hear your "i just wanna do it now" questions, we are gonna make you read enough to teach you aswell Razz

Here's a generic reload function that may not be complete or even in working order but hey, its an example an you can make it work for your mod...

Code:

void () W_Reload_Ammo =
{
   local float clip;
   
   if ((self.health <= 0))
   {
      return;
   }

   if (self.weapon == IT_AXE)
   {
      return;
   }

   if (!(self.button0))//Don't reload while firing!
   {
      self.attack_finished = (time + 1);// delay firing while reloading
      if ((self.weapon == IT_SHOTGUN))
      {
          if ((self.ammo_shells >=20))
             clip = 20;
          else
             clip = self.ammo_shells;
                
         self.ammo_shells = (self.ammo_shells - clip);                  
         self.ammo_shells_sg = (self.ammo_shells_sg + clip);
            
         if (self.ammo_shells_sg > 100)
            self.ammo_shells_sg = 100;
               
         self.currentammo = self.ammo_shells_sg;
      }


Ghost_Fang wrote:

second, how would i get it so that if i shoot on an empty clip it would automatically reload.

Roughly in W_Attack before W_CheckNoAmmo() something like

if ((self.weapon != IT_AXE) && (self.currentammo < 1) { W_Reload_Ammo(); }


Ghost_Fang wrote:

third how can i get it to reload and only take the difference from my shells? example 5 bullets in clip, i reload, it only take 3 from shells?

Code:

             if ((self.ammo_shells >=20))
                clip = 20;
             else
                clip = self.ammo_shells;

will take a full clip of 20 shells or whatever you have left...

Ghost_Fang wrote:

fourth how would i get reload (impulse 40) it to call upon the reload frames of the model?


self.weaponframe = $reload

Ghost_Fang wrote:

and fifth, how would i put the delay in so you can shoot or anything during the reload animation.


self.attack_finished = (time + 1);// delay firing while reloading
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Wed Jan 06, 2010 5:01 am    Post subject: Reply with quote

Ok the reason i am doing this in "forum mode" is because no one has given me GOOD qc tutorials, i have only read 1 good one and it was short and i learned quite a lot. (This one http://www.angelfire.com/ult/td/tuts.html)

Quote:
In the engine, it strictly updates these fields in SV_WriteClientdataToMessage,
Code:

MSG_WriteByte (msg, ent->v.currentammo);
MSG_WriteByte (msg, ent->v.ammo_shells);
MSG_WriteByte (msg, ent->v.ammo_nails);
MSG_WriteByte (msg, ent->v.ammo_rockets);
MSG_WriteByte (msg, ent->v.ammo_cells);

These are for the HUD, so that's our given.


Sooo, what about it? do i change ammo_shells to ammo_pistol?

Quote:
For example the shotgun, when reloading you're taking away from self.ammo_shells and adding it to self.ammo_shells_sg. Then in w_attack determine what gun you are holding, then check that gun's ammo, before firing, then subtract that gun's ammo apon firing. Ammo touch functions should work fine because it still updates the original self.ammo_* values. So the only time the old ammo_shells gets modified is within reload and item pickup.


Hmm, i know exatly what you mean in english, but as far as coding thats probably out of my league atm.


Quote:
Here's a generic reload function that may not be complete or even in working order but hey, its an example an you can make it work for your mod...


I'd rather not stray from my current code if you dont mind, it is pretty much complete minus the few questions and one glitch.
Quote:

Roughly in W_Attack before W_CheckNoAmmo() something like

if ((self.weapon != IT_AXE) && (self.currentammo < 1) { W_Reload_Ammo(); }


I should have phrased that question better, not automaticly reload technically, i meant if my clip is empty and i shoot, instead of shooting it reloads(like most FPSs these days.
Wouldnt a simple:
Code:
if (self.ammo = 0) && (fire weapon)
             self.impulse = 40
work?
if so the only problem for me with that is i dont know the code for firing a weapon.

Quote:
will take a full clip of 20 shells or whatever you have left...


Hmm, maybe you answered my question, honestly im not sure, but heres the scenario: i have 5 bullets in my clip, 8 bullets is a full clip, i reload with 5 bullets in my clip, and i only want it to take 3 from the shells.

Quote:
self.weaponframe = $reload


Thank you! the first thing i 100% understand lol.
well, just $reload? or $reload1 $reload2 $reload3 etc. (in the code)

Quote:

self.attack_finished = (time + 1);// delay firing while reloading


Just stick that in impulse 40?
Back to top
View user's profile Send private message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Wed Jan 06, 2010 7:53 am    Post subject: Reply with quote

Ghost_Fang wrote:

Sooo, what about it? do i change ammo_shells to ammo_pistol?

Only, if you dont want to see it on the HUD.

Ghost_Fang wrote:

I'd rather not stray from my current code if you dont mind, it is pretty much complete minus the few questions and one glitch.


I posted more code than u did, so unless your holding out, all u have is a pocket full of questions. Wink

Ghost_Fang wrote:

if ((self.weapon != IT_AXE) && (self.currentammo < 1) { W_Reload_Ammo(); }

I should have phrased that question better, not automaticly reload technically, i meant if my clip is empty and i shoot, instead of shooting it reloads(like most FPSs these days.

Wouldnt a simple:
Code:
if (self.ammo = 0) && (fire weapon)
             self.impulse = 40


Ya, that's exactly what I understood "click. shunk shunk shunk locknLoad!"

Impulse 40 would in this case call W_Reload_Ammo() anyways..
BTW, when comparing use == not =
" if (self.ammo == 0) "

Ghost_Fang wrote:

if so the only problem for me with that is i dont know the code for firing a weapon.

W_Attack

Ghost_Fang wrote:

Hmm, maybe you answered my question, honestly im not sure, but heres the scenario: i have 5 bullets in my clip, 8 bullets is a full clip, i reload with 5 bullets in my clip, and i only want it to take 3 from the shells.

Ya I got ya, reload 5 rockets then press FIRE and hit reload again...

Code:

//R00k: reload function for Ghost_Fang
void () W_Reload_Ammo =
{
   local float c;

   if ((self.health <= 0))
   {
      return;
   }
   
   if (self.weapon == IT_AXE)
   {
      return;
   }
   
   if (!(self.button0))//Don't reload while firing!
   {
      if (self.weapon == IT_SHOTGUN)
      {
         c = (5 - self.ammo_shells_sg);
         if (self.ammo_shells < c)
         c = self.ammo_shells;
         self.ammo_shells = (self.ammo_shells - c);                 
         self.ammo_shells_sg = (self.ammo_shells_sg + c);
         self.currentammo = self.ammo_shells_sg;
      }
      else
      {   
         if (self.weapon == IT_SUPER_SHOTGUN)
         {
            c = (3 - self.ammo_shells_ssg);
            if (self.ammo_shells < c)
            c = self.ammo_shells;
            self.ammo_shells = (self.ammo_shells - c);                 
            self.ammo_shells_ssg = (self.ammo_shells_ssg + c);
            self.currentammo = self.ammo_shells_ssg;
         }
         else
         {   
            if (self.weapon == IT_NAILGUN)
            {
               c = (25 - self.ammo_nails_ng);
               if (self.ammo_nails < c)
               c = self.ammo_nails;
               self.ammo_nails = (self.ammo_nails - c);                 
               self.ammo_nails_ng = (self.ammo_nails_ng + c);
               self.currentammo = self.ammo_nails_ng;
            }
            else
            {   
               if (self.weapon == IT_SUPER_NAILGUN)
               {
                  c = (25 - self.ammo_nails_sng);
                  if (self.ammo_nails < c)
                  c = self.ammo_nails;
                  self.ammo_nails = (self.ammo_nails - c);                 
                  self.ammo_nails_sng = (self.ammo_nails_sng + c);
                  self.currentammo = self.ammo_nails_sng;
               }
               else
               {   
                  if (self.weapon == IT_GRENADE_LAUNCHER)
                  {
                     c = (3 - self.ammo_rockets_gl);
                     if (self.ammo_rockets < c)
                     c = self.ammo_rockets;
                     self.ammo_rockets = (self.ammo_rockets - c);                 
                     self.ammo_rockets_gl = (self.ammo_rockets_gl + c);
                     self.currentammo = self.ammo_rockets_gl;
                  }
                  else
                  {   
                     if (self.weapon == IT_ROCKET_LAUNCHER)
                     {
                        c = (5 - self.ammo_rockets_rl);
                        if (self.ammo_rockets < c)
                        c = self.ammo_rockets;
                        self.ammo_rockets = (self.ammo_rockets - c);                 
                        self.ammo_rockets_rl = (self.ammo_rockets_rl + c);
                        self.currentammo = self.ammo_rockets_rl;
                     }
                     else
                     {   
                        if (self.weapon == IT_LIGHTNING)
                        {
                        c = (24 - self.ammo_cells_lg);
                        if (self.ammo_cells < c)
                        c = self.ammo_cells;
                        self.ammo_cells = (self.ammo_cells - c);                 
                        self.ammo_cells_lg = (self.ammo_cells_lg + c);
                        self.currentammo = self.ammo_cells_lg;
                     }
                  }
               }
            }
         }
      }
   }
     // delay firing while reloading but still keep the delay of each weapon's refire...
   self.attack_finished = time + (time - self.attack_finished + 1);
   player_reload(); //Reload animations in Player.qc
}

The line that says c = (5 - self.ammo_shells_sg); limits the amount of shells we can load at once to 5(shots). This also means you have to reload after you run out. It's probably not the best idea to have it AUTO-reload or else its just going to behave like Quake yet with a 1 second pause after those shots. You can obviously choose your own value here as you see fit. The LG though i wouldnt go much below 24.
You still need to modify a few more functions in Weapons.qc, add a roload animation sequence to player.qc, add some sounds maybe to the above code, etc... but this gives you a push in the right direction.. Smile
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Wed Jan 06, 2010 10:04 pm    Post subject: Reply with quote

wow ok, a few more questions.
for YOUR code to i need to add anything into defs?
i finally understand(i think) what you meant by cache.
so i shoot, -1 from my pistol, BUT +1 to the cache and so on per shot. and when i reload it adds to my pistol however much is in the cache and at the same time subtracts it from ammo_shells?
if not oh well.

and for the code you provided for me, where would i put it?
would i make a new .qc file?
Back to top
View user's profile Send private message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Thu Jan 07, 2010 7:04 pm    Post subject: Reply with quote

Ghost_Fang wrote:
wow ok, a few more questions.
for YOUR code to i need to add anything into defs?

open up progs.src under DEFS.QC add defs2.qc
make a new file in your mod's source folder and name it def2.qc
put all your defines for your mod there. This keeps the original defs.qc left alone. Making changes in that file at this point can cause you more headaches than necessary.

you will need to create the ammo clip variables for each weapon. the "cache" is the original ammo_shells etc. example:
.float ammo_shells_sg;

The . tells the engine its a field of type FLOAT this way it can be used like self.ammo_shells_sg

Ghost_Fang wrote:

i finally understand(i think) what you meant by cache.
so i shoot, -1 from my pistol, BUT +1 to the cache and so on per shot. and when i reload it adds to my pistol however much is in the cache and at the same time subtracts it from ammo_shells?
if not oh well.


When you shoot the shotgun, -1 from self.ammo_shells_sg, period.
When you reload, -1 from self.ammo_shells, +1 gun in hand, which would be self.ammo_shells_sg.
A.> it loads up to 5 shells in 1 clip or the amount of shells between 1 - 5 for the empty slots available in the clip.
B.> if you have less ammo_shells than free slots (5 - ammo_shells_sg) it will load the rest of the ammo u have from ammo_shells into ammo_shells_sg.

Ghost_Fang wrote:

and for the code you provided for me, where would i put it?
would i make a new .qc file?

void() W_Reload_Ammo =
W_ is a hint for weapons.qc Wink

You may want to take a step back and learn a bit of syntax from C or at least look through the quakeC source. If you have ZERO coding experience it's only going to get worse as you progress with the making of your mod. And during your modding, expect to spend more time coding than playing. So, if you play games 5 hours a day, all that time will be eaten up coding/testing instead. Sad
Back to top
View user's profile Send private message
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Thu Jan 07, 2010 7:26 pm    Post subject: Reply with quote

lol yeah your time will defiantly be taken up by modding most defiantly but for someone like me i enjoy modding more than playing most of the time. every now and then i need a break. but thats about it. believe me i had 0 experience in coding of any type and im just now getting pretty good at it. take a look through defs.qc to get an idea of what a lot of the things do and when you cant figure something find a function which does something similar . like if you need to call a trace look at the ax function. if you cant find anything in pre existing code look at the tutorial section for something similar as well. as long as you can figure out what your codes supposed to consist of you should be able to figure it out most time from pre existing code.
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Thu Jan 07, 2010 7:36 pm    Post subject: Reply with quote

i know a fair amount of coding.
its just i dont know if i add this, where do i put it and if i add this do i need to add anything else elsewhere? its stuff like that. And looking at your code i pretty know what it does, its just i dont have enough knowledge myself to do things i want to.

Aside from coding, i got a question, say you have a quake mod with stuff stuff like new models, you replace the model and match up all the frame groups and orders, name it the same file, same name skin etc. but it doesnt play the animation....

But thanks a lot for the code! I'll work on it and try to learn from it. Very Happy P.s. i dont play games for hours, in fact before i asked my origonal question i spent 3 hours trying by myself to fix it.
Back to top
View user's profile Send private message
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Thu Jan 07, 2010 8:01 pm    Post subject: Reply with quote

you want to make sure the frames are in the same order and have the same amount of frames. you shouldnt have to edit the qc if its a model that has all the same stuff.
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Thu Jan 07, 2010 8:08 pm    Post subject: Reply with quote

yea its weird, thats why im asking cause i matched everything up, the names of the frame groups and eveything
Back to top
View user's profile Send private message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Fri Jan 08, 2010 8:30 am    Post subject: Reply with quote

Would you want to spend 5 years making this mod?
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Fri Jan 08, 2010 7:38 pm    Post subject: Reply with quote

its not all the same mod.

I am currently working on 3

iHalo - assistant head of development, modeler, mapper, i picked up texturing, and (attempting) coding. (aka Jack of all Trades as the call me on the forums)

Left 4 Quake - Modeler and (attempting) coding

Gateway - Modeler and mapper

and i dont get what made you ask that question.
and @anyone who reads: dont get the wrong impression about me either, i know quite a bit about quake and quake modding (the artistic side of it) its just the coding is got me stumped (and i dont like it) but im sure thats the part that stumps most people.

If i just knew the basics, like ALL the basics, like a big tutorial that said what each function does and the command is and where it needs to go etc. If i can learn what the code is for each little thing is in the game (or have a reference guide of it) i might be able to everything myself in time. All the tutorials i've seen(i've seen many) just seem incomplete to me.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group