Page 1 of 2
Requesting scores
Posted: Sun Apr 07, 2013 7:48 pm
by Sheepsquatch
I'm a noobie coder. I love Q3 and attempting to make mods.
My question has to do with sending and receiving the scores on the client side.
I've made a mini scoreboard to be printed in console. Works with a bind or if it's typed into console.
My problem has to do with receiving up to date scores.
Checking my code with /developer 1 I see the scoreboard is printed prior to receiving the score.
Using trap_SendClientCommand( "score" ); still shows me I receive the score after the mini scoreboard has been printed.
While using /developer 1 and pressing the tab button I see the score is received before displaying the regular scoreboard.
How can I do this for my mini scoreboard ?
I've tried not displaying the regular scoreboard and sending the trap_SendClientCommand( "score" ); before printing my scoreboard and no luck.
Thanx in advance, I love iD's work, you guys rock.
Re: Q3 coding question
Posted: Mon Apr 08, 2013 9:29 pm
by UglyFoot
I see there is a delay time of 2 seconds to get the updated scores. To know more search trap_SendClientCommand ("score") in all files.
What I would do is save cg.scoresRequestTime value at the time you want to show the scores in cg.lastScoresRequestTime, and two seconds later (cg.lastScoresRequestTime + 2000) display them, but it would be very slow, two seconds is a lot.
I am surprised that are two seconds, maybe it's because I use the original code. Is this in ioquake faster?
Re: Q3 coding question
Posted: Mon Apr 08, 2013 11:55 pm
by Sheepsquatch
Thank very much for replying, I tried the following and it didn't work :
if ( cg.scoresRequestTime + 2000 < cg.time ) {
cg.lastScoresRequestTime = cg.scoresRequestTime;
cg.scoresRequestTime = cg.time;
if (cg.lastScoresRequestTime + 2000 < cg.time)
trap_SendClientCommand( "score" );
}
Or did you mean something else. I'm using the original code also.
Thanx again =).
Re: Q3 coding question
Posted: Wed Apr 10, 2013 5:40 pm
by UglyFoot
It's something like that. This code in CG_DrawActiveFrame:
Code: Select all
if (( cg.miniBoardRequestTime + 2000 < cg.time ) && cg.showMiniBoard) {
// show yor miniboard;
cg.showMiniBoard=qfalse;
}
And this in your command function:
Code: Select all
cg.miniBoardRequestTime=cg.scoresRequestTime;
cg.showMiniBoard=qtrue;
I changed the name to cg.miniBoardRequestTime to make it more clear.
As CG_DrawActiveFrame runs in each frame, after two seconds of the last scores request it will display your board, and cg.showMiniBoard will cause only be shown once.
Re: Q3 coding question
Posted: Wed Apr 10, 2013 9:10 pm
by Sheepsquatch
OK big thanx. I wasn't thinking. I had the key bind in consoldcmds that triggered the CG_MiniScoreboard(); in the scoreboard file. So I wasn't always in CG_DrawActiveFrame or CG_Draw. My mobo burnt out Monday =(. I'm on my laptop and have to copy over my source etc. So I dunno when I can try. I truly appreciate all your help.
Re: Q3 coding question
Posted: Thu Apr 11, 2013 10:59 pm
by UglyFoot
Ok, let me know if it works

Re: Q3 coding question
Posted: Sat Apr 13, 2013 12:54 pm
by Sheepsquatch
I'm dying to try this, but I can't on my laptop. Well I can't compile the source on Win7. I've googled and find out what to change to compile .qvms. I could make .dll but didn't test. Ugh I'm in hell without my computer.
Re: Q3 coding question
Posted: Mon Apr 15, 2013 1:12 am
by UglyFoot
If you need help to compile .qvms you can take a look at this
tutorial.
Re: Q3 coding question
Posted: Wed Apr 17, 2013 12:01 am
by Sheepsquatch
I tried several times yesterday to get the qvms compiled with no luck. I appreciate your link, didn't work. Sadly my motherboard was supposed to arrived today but didn't 'cause the guy shipped yesterday. Gonna have to wait to test your suggestion. Ugh this is hell =(.
Re: Q3 coding question
Posted: Sat Apr 20, 2013 9:12 pm
by Sheepsquatch
UglyFoot I was finally able to test your idea. Still didn't work =(. The scores are received after printing the scoreboard.
Re: Q3 coding question
Posted: Sun Apr 21, 2013 6:10 pm
by UglyFoot
You're right, it doesn't work. I've tried it and I see it is because cg.scoresRequestTime doesn't update while not seeing the scoresboard. In other words: The scores aren't updated when you're not looking at the scoresboard, so cg.scoresRequestTime keeps unchanged.
To display the updated scoresboard you'll have to request it if it wasn't requested in the last two seconds.
It may also happen that in two seconds haven't been updated and you'll have to wait something more like 2.3 or 2.5 seconds. In that case you just have to change the 2000 by 2300 or 2500.
When something doesn't work you have to print key values to understand what is happening.
Re: Q3 coding question
Posted: Sun Apr 21, 2013 8:42 pm
by Sheepsquatch
Still no luck.
Even putting trap_SendClientCommand( "score" ); just before printing the scores still doesn't receive the scores before printing.
I think I may have to use cg.showScores = qtrue; but put a check in the scoreboard not to display so I receive the scores first. But I can't now I have to go out, hopefully later.
Maybe you'll have a better idea before I try again.
Truly appreciate your continued help.
Re: Q3 coding question
Posted: Mon Apr 22, 2013 9:16 pm
by UglyFoot
The problem is that if cg.scoresRequestTime isn't updated (because you're not watching the scoresboard) this code is useless, because the condition is true right after running your command.
Code: Select all
if (( cg.miniBoardRequestTime + 2000 < cg.time ) && cg.showMiniBoard) {
// show yor miniboard;
cg.showMiniBoard=qfalse;
}
It's not enough to request the scores before displaying the mini scoresboard as the scores takes some time to come. I think you have to request scores right after you run the command and set the right value to cg.miniBoardRequestTime to solve the problem.
Re: Q3 coding question
Posted: Fri Apr 26, 2013 1:40 pm
by Sheepsquatch
Very close the following :
CG_ScoresDown_f();
cg.showScores = qfalse;
CG_PrintMiniScoreboard();
Will send the scores first not display the regular scoreboard. But the miniscoreboard isn't printed unless I press the key bind twice =(.
Scores are received first. Even with cg.showScores = qfalse; commented out ( the scoreboard appears ) but the bind has to be press twice.
Any ideas ? I appreciate all your help and advice Uglyfoot. Thank you.
Re: Q3 coding question
Posted: Fri Apr 26, 2013 8:32 pm
by UglyFoot
I don't know why you have to press the key twice but try this in your function:
Code: Select all
if (cg.scoresRequestTime + 2000 < cg.time) cg.miniBoardRequestTime = cg.time;
else cg.miniBoardRequestTime=cg.scoresRequestTime;
cg.showMiniBoard=qtrue;
and in CG_DrawActiveFrame:
Code: Select all
if (( cg.miniBoardRequestTime + 2000 < cg.time ) && cg.showMiniBoard) {
// show yor miniboard;
cg.showMiniBoard=qfalse;
}
Re: Q3 coding question
Posted: Fri Apr 26, 2013 8:56 pm
by Sheepsquatch
I don't know why I have to press it twice either =(. I'll try your code. Every time I use the cg.miniBoardRequestTime it creates the two second delay. I'll let you know. Thank you.
Re: Q3 coding question
Posted: Fri Apr 26, 2013 10:02 pm
by Sheepsquatch
Sadly one you add the requestime the scores are received after printing the miniscoreboard.
Searching the cgame files I found in local.h :
// add commands to the local console as if they were typed in
// for map changing, etc. The command is not executed immediately,
// but will be executed in order the next time console commands
// are processed
Re: Q3 coding question
Posted: Sat Apr 27, 2013 6:13 pm
by UglyFoot
Mini scoresboard should be printed 2 seconds after you have pressed the key. If they aren't the actual scores then try more than 2 seconds, like 10 seconds, and lower it until it works.
Re: Q3 coding question
Posted: Sat Apr 27, 2013 9:32 pm
by Sheepsquatch
Still not working. The key bind needs to be pressed twice.
let me run down what I've done with your advice.
I've added the following to local.h :
int miniBoardRequestTime;
int showMiniBoard;
cg_draw.c in CG_DrawActiveFrame:
if (( cg.miniBoardRequestTime + 2000 < cg.time ) && cg.showMiniBoard) {
// show yor miniboard;
cg.showMiniBoard=qfalse;
}
Finally most importantly in cg_consolecmds.c in my function :
static void CG_MiniScores_f( void ) {
if (cg.scoresRequestTime + 2000 < cg.time)
cg.miniBoardRequestTime = cg.time;
else
cg.miniBoardRequestTime = cg.scoresRequestTime;
cg.showMiniBoard = qtrue;
// @uglyfoot without this your code doesn't do anything
CG_ScoresDown_f();
cg.showScores = qfalse;
CG_PrintMiniScoreboard();
}
Please let me know what you see wrong. Big thanx.
Re: Q3 coding question
Posted: Sun Apr 28, 2013 12:10 am
by UglyFoot
Ok, try this:
In local.h:
Code: Select all
int miniBoardRequestTime;
qboolean showMiniBoard;
In CG_DrawActiveFrame:
Code: Select all
if (( cg.miniBoardRequestTime + 2000 < cg.time ) && cg.showMiniBoard) {
CG_PrintMiniScoreboard();
cg.showMiniBoard=qfalse;
}
In cg_consolecmds.c:
Code: Select all
static void CG_MiniScores_f( void ) {
if (cg.scoresRequestTime + 2000 < cg.time)
cg.miniBoardRequestTime = cg.time;
else
cg.miniBoardRequestTime = cg.scoresRequestTime;
cg.showMiniBoard = qtrue;
}
Re: Q3 coding question
Posted: Sun Apr 28, 2013 8:48 am
by Eraser
Off-topic comment here, but maybe it's a good idea to change the topic title to something that's more descriptive of the content of the thread. Makes it easier for future readers to find the info again in case they need it. In the Q3W programminb discussion forum, it's fairly obvious that if you have a question, it's about Q3 coding

Just a thought

Re: Q3 coding question
Posted: Tue Apr 30, 2013 1:02 am
by Sheepsquatch
@Uglyfoot,
WOW Big thanx ! Ugh coding while tired isn't a smart idea. I shoulda realized with qtrue / qfalse I need the qboolean =(.
Really brilliant code. Love how you prevent looping of the scoreboard.
I still had to add
CG_ScoresDown_f();
cg.showScores = qfalse;
before cg.showMiniBoard = qtrue; otherwise the scores aren't updated.
Really appreciate your help.
@Eraser I honestly couldn't think of a proper title when I made the thread. I knew it wasn't descriptive but I really wanted help. Just thought it would pique someone's interest.
Didn't know I could change the title, I'll try now.
Re: Requesting scores
Posted: Tue Apr 30, 2013 5:08 am
by Eraser
It wasn't meant as complaint, just a suggestion

Glad you found the solution to your problem.
Re: Requesting scores
Posted: Tue Apr 30, 2013 12:21 pm
by Sheepsquatch
@Eraser
Hehe it's ok I didn't take it as a complaint. When I made the thread I couldn't think of anything better, and was worried I wouldn't get any help.
Re: Requesting scores
Posted: Tue Apr 30, 2013 4:08 pm
by UglyFoot
You're right, I forgot a line:
Code: Select all
static void CG_MiniScores_f( void ) {
if (cg.scoresRequestTime + 2000 < cg.time) {
trap_RequestScores;(?) (I don't remember the function name)
cg.miniBoardRequestTime = cg.time;
}
else
cg.miniBoardRequestTime = cg.scoresRequestTime;
cg.showMiniBoard = qtrue;
}
If it still doesn't work look what CG_ScoresDown_f() does and try to fix your function.