Forum

Defining a STAT_

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Defining a STAT_

Postby DusterdooSmock » Wed Oct 20, 2010 1:15 am

I used this tutorial (http://www.moddb.com/games/solitude/tutorials/adding-reloading-to-quake) to add reloading to quake, and then i added my own animations to it, it works fine, but now i'm trying to add a bullet counter to my engine.

I already have the code for the counter itself but i have to make a STAT_ that shows the count of self.pistolclip, not self.ammo_shells.

How would i go about doing this?
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby Jukki » Wed Oct 20, 2010 2:39 pm

do you want to replace quakes ammo with clip ammo or make another counter with clip?

Actualy i am thinking how to do this too lol. Well now i dont need to ask XD
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby Spike » Wed Oct 20, 2010 3:48 pm

the easy way from QC is to writebyte(msg_foo, svc_updatestat); writebyte(msg_foo, stat_mine); writelong(msg_foo, myvaluehere);

probably msg_foo=msg_one.
stat_mine is whatever value you want. if its <32 you'll not break network compatibility. DP, FTE, and other QW clients have specific interpretations for many <32 stats. CSQC states that 32-128 are for mod use. If you don't care about compatibility then it doesn't matter, just be aware that you might end up changing DP/FTE's zoom and stuff :)
myvaluehere is whatever value your mod wants to send for that stat.

then you can send what you want, when you want to send it. don't flood it! make it a function to be used to set a field and delta check it. that works too. logically you're limited to integer values, though really all that matters is that its 4 bytes. you can mangle them clientside if you really wanted to send a float instead, but you'd need a union or a *(float*)&cl.stats[foo] or something. If you want to send a full 32bit int bitmask, send two shorts, the first is the lower 16 bits, the second is the upper (floats can only retain precision to about 24 bits).

An NQ engine will flood the client with regular stat updates once per frame, but at least its only one byte per stat (see svc_clientdata), while QuakeWorld deltas them, but knowing this isn't too important.

The QC-directed stat sending is the easiest to explain. An engine could easily be configured to send fields, but that's far far more lines of code (field access with delta storage+delta code, or protocol changes, depending on how you want it).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby DusterdooSmock » Wed Oct 20, 2010 5:21 pm

@Spike thanks for the help, but i figured out how to do it.

I just used the normal STAT_AMMO function, and made the self.pistolclip the current ammo when the bullets are taken away or the clip is reloaded. (don't know if that's the right way to do it, but it works!)
:D
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby Jukki » Wed Oct 20, 2010 5:23 pm

hmm spike. Could you lil explain to this no c noob how to do that lol. I am only coder on our team XD
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby DusterdooSmock » Wed Oct 20, 2010 9:58 pm

Jukki wrote:hmm spike. Could you lil explain to this no c noob how to do that lol. I am only coder on our team XD


Code: Select all
if (cl.stats[STAT_ACTIVEWEAPON] == IT_SHOTGUN)
{
if (cl.stats[STAT_AMMO] >= 12)
{
// Draw the image that shows the 12th bullet
}
if (cl.stats[STAT_AMMO] >= 11)
{
// Draw the image that shows the 11th bullet
}


And so on... :D

Then, in the QC, just set your clip's value to self.curentammo when bullets are taken away, or the clip is refilled.

In W_FireShotgun:

From:
Code: Select all
self.pistolclip = self.pistolclip -1;


To:
Code: Select all
self.currentammo = self.pistolclip = self.pistolclip -1;


The second part of the reload that i had to change was in the main reload function:

From:
Code: Select all
self.currentammo = self.ammo_shells; // Update the current ammo


To:
Code: Select all
self.currentammo = self.pistolclip; // Update the current ammo


*Credit to Mexicouger for helping me with the ammo counter code.
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby Jukki » Thu Oct 21, 2010 3:38 am

thx, but oesnt this make it so that it replaces ammo conter with clip one. I want so there are both
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby DusterdooSmock » Thu Oct 21, 2010 1:40 pm

Jukki wrote:thx, but oesnt this make it so that it replaces ammo conter with clip one. I want so there are both


Yeah, that's the counter for the clip count, not the self.ammo_shells...

If you still have the standard Quake HUD in your mod, then you will see both, otherwise you will only see the count of ammo that is in your weapon's clip.
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby Jukki » Sun Oct 24, 2010 1:16 pm

thank you. Now i need to display my ammo_colt
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby DusterdooSmock » Sun Oct 24, 2010 3:54 pm

Jukki wrote:thank you. Now i need to display my ammo_colt


Is your ammo_colt the count of ammo in the clip, or the count of ammo in the inventory?
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby Jukki » Sun Oct 24, 2010 3:56 pm

DusterdooSmock wrote:
Jukki wrote:thank you. Now i need to display my ammo_colt


Is your ammo_colt the count of ammo in the clip, or the count of ammo in the inventory?


inventory

i have for evey weapon their own ammo_ and clip

like ammo_colt and pistolclip
ammo_ray and rayclip etc
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest