How to read client values in QC

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Mexicouger
Posts: 514
Joined: Sat May 01, 2010 10:12 pm
Contact:

How to read client values in QC

Post by Mexicouger »

I have been trying to get this to work for a few weeks now, but I just can't get it to work. My base is Darkplaces.
What I am trying to do is to read a value from the QC, and load it into the cl.stats array for future use. It won't seem to work however.

This is what I have so far. I don't know if I'm on the right track or not.

in Progdefs.h, in entvars_s, I added:

Code: Select all

float experience;
In cl_parse.c, in the function CL_ParseClientdata I added this:
if (cls.protocol == PROTOCOL_DARKPLACES5)
{
cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
cl.stats[STAT_HEALTH] = MSG_ReadShort();
cl.stats[STAT_AMMO] = MSG_ReadShort();
cl.stats[STAT_EXP] = MSG_ReadShort();
cl.stats[STAT_SHELLS] = MSG_ReadShort();
cl.stats[STAT_NAILS] = MSG_ReadShort();
cl.stats[STAT_ROCKETS] = MSG_ReadShort();
cl.stats[STAT_CELLS] = MSG_ReadShort();
cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
}
else if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_NEHAHRABJP || cls.protocol == PROTOCOL_NEHAHRABJP2 || cls.protocol == PROTOCOL_NEHAHRABJP3 || cls.protocol == PROTOCOL_NEHAHRABJP || cls.protocol == PROTOCOL_NEHAHRABJP2 || cls.protocol == PROTOCOL_NEHAHRABJP3 || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
{
cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
if (cls.protocol == PROTOCOL_NEHAHRABJP || cls.protocol == PROTOCOL_NEHAHRABJP2 || cls.protocol == PROTOCOL_NEHAHRABJP3)
cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? (unsigned short)MSG_ReadShort() : 0;
else
cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
cl.stats[STAT_HEALTH] = MSG_ReadShort();
cl.stats[STAT_AMMO] = MSG_ReadByte();
cl.stats[STAT_EXP] = MSG_ReadByte();
cl.stats[STAT_SHELLS] = MSG_ReadByte();
cl.stats[STAT_NAILS] = MSG_ReadByte();
cl.stats[STAT_ROCKETS] = MSG_ReadByte();
cl.stats[STAT_CELLS] = MSG_ReadByte();
if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
else
cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
}
Then in sv_main.c in the function SV_WriteClientdataToMessage, I added:

Code: Select all

stats[STAT_EXP] = (int)ent->fields.server->experience;

Then in QC, I have:

Code: Select all

.float experience;
However, this doesn't work. I think I have spent too much time on this 1 particular thing. ALOT of good came out of it though, because I learned quite a bit about Quakes entities.

Help would be greatly appreciated
Post Reply