Forum

CSQC - display extra player stuff?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

CSQC - display extra player stuff?

Postby Orion » Thu Oct 16, 2008 3:26 am

Hi, I'm making a mod where you buy weapons, earn money by hitting the enemies, and it's teamplay only. When a player dies, it becomes white, visible, but non-solid and can't shoot. A round ends if all players of a team is dead, then it resets, 3 seconds of cease-fire, and a new round starts. Or, a round may end if 3 minutes pass. The team with more players alive wins. If both teams have the same number of players alive, then the round ends tied and no point is given to any team.

Ok, let's go to the important thing. I want to make my cash, cease-fire time, buy time and round time display at the bottom of my screen, right near the hud, without overriding centerprint (because I use centerprint for the menu to buy weapons).

I'm not good on csqc, but I really want that. It would be sweet. =)

Also, I have the csqc source code here.

And, if needed, here are the vars I use which I want to display with csqc:

Code: Select all
.float money;
float ceasefire, buy_time, round_time;


Thanks.
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby GiffE » Thu Oct 16, 2008 8:54 pm

You can use csqc for the menu's aswell and it will look even better :D.

Why not calculate the ceasefire time, buy time and round time, using the time variable in csqc? its no different than ssqc.
Other than that you could use addstat (EXT_CSQC) to add float var's for the player and update them every second. But it seems unnessary.

.float money on the other hand should be done with addstat.

Here's how to use it:

First the builtin needs to be added to dpextensions.qc:
I added this to the bottom of dpextensions.qc:
Code: Select all
// EXT_CSQC
// AddStat
void(float index, float type, ...) AddStat = #232; // third parameter is an entity field
float AS_STRING          = 1;
float AS_FLOAT_TRUNCATED = 2; // int value
float AS_FLOAT           = 8;


The index is the player stat index that will be used to get this variable from the client.
1-32 are reserved, if I recall correctly.

You only need to call this function once so place in worldspawn (ssqc)
add:
Code: Select all
AddStat(33,AS_FLOAT_TRUNCATED, money);


this will make the money fieldfloat variable on the server's ssqc be sent to csqc using the index "33".

now in csqc when ever you want to get the money, call:
Code: Select all
money = getstati(33);
Last edited by GiffE on Thu Oct 16, 2008 11:43 pm, edited 1 time in total.
GiffE
 
Posts: 170
Joined: Sun Oct 08, 2006 3:39 pm
Location: USA, CT

Postby Orion » Thu Oct 16, 2008 10:07 pm

Ok I got it.
But in what csqc function should I call this exactly?

Because I tried it in CSQC_UpdateView() (view.qc) and Iotandassignment to world entity error.

God damn keyboard! :x
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby Spike » Thu Oct 16, 2008 10:52 pm

CSQC isn't so object oriented as ssqc. There would be too many different sorts of object that its not quite so feasable.
Regarding reading stats, typically you only need them that frame, and they're by nature a single value per frame. Thus I don't really recommend storing stats in entity fields for the most part.
If you're drawing it on the hud, chances are its only ever needed in a single function.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Orion » Fri Oct 17, 2008 12:28 am

Look:

Code: Select all
// cash
   cash = getstati(33);
   str3 = ftos(cash);
   len = strlen(str3);
   if (len < 1)
      str4 = "000";
   else if (len < 2)
      str4 = strcat("  ", str3);
   else if (len < 3)
      str4 = strcat(" ", str3);
   else
      str4 = str3;
      
   str4 = strconv(CONV_SAME, CONV_SAME, CONV_REDSPECIAL, str4);
   
   Sbar_DrawString(240, -24, str4, sbar_alpha_fg);


I got the status bar csqc source and I put these lines, a fith small golden number appeared beside the cells number, but it's always zero, and you always start with 250 money...
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby Spike » Fri Oct 17, 2008 3:05 am

then you didn't do the AddStat bit properly.

Seeing as its a special stat, you have to tell the server to actually send it in the ssqc, which can be retrieved with the getstat function. Which you are doing. The fact that it is always 0 means that it probably isn't getting sent by the server, which means your AddStat call in the ssqc isn't working right for some reason.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Orion » Fri Oct 17, 2008 2:26 pm

I did just like Giffe said, I put that AddStat() line at the vwry top of worldspawn(), just after InitBodyQue():

Code: Select all
AddStat (33, AS_FLOAT_TRUNCATED, money);


Shall I put it in another place of worldspawn()?

Thanks!
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby GiffE » Fri Oct 17, 2008 6:28 pm

Orion wrote:I did just like Giffe said, I put that AddStat() line at the vwry top of worldspawn(), just after InitBodyQue():

Code: Select all
AddStat (33, AS_FLOAT_TRUNCATED, money);


Shall I put it in another place of worldspawn()?

Thanks!


Weird. It worked for me in worldspawn, I used it for ammo but the process is the same for money.
print out
Code: Select all
print("cash: ",ftos(cash), "\n");

See if the value of cash is sent.
GiffE
 
Posts: 170
Joined: Sun Oct 08, 2006 3:39 pm
Location: USA, CT


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest