 |
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Hakaku Server Help Squatter

Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: Thu Aug 21, 2008 1:19 am Post subject: hud/counter |
 |
|
|
|
In Devastation, we utilize a credits system that's displayed on the top left corner of a player's screen. It was originally ported by Hallowed from a bot plugin, but Hallowed's ceased development and I'm not sure what exactly is wrong code-wise after comparing both sources.
One of the problems is that the hud doesn't match the player's credits, meaning that the math part of the code is probablematic somewhere. Say if I have "8000000 credits", the hud will display "8000800". Here's an example screenshot of what it displays, and what it should be :
The second problem is displaying zeroes. I can edit some lines to make all zeroes appear (left and right - like in the above screenshot), but otherwise it doesn't display them at all.
I would really appreciate if someone could revise the code and explain why some of the numbers are not what they're suppose to be. I've attached the source here, and if it helps, the debuilt counter ini.
debuilt lvz ini
c_counter.ini - 6.7 KB
File downloaded or viewed 19 time(s)
Credits Counter hud
c_counter.c - 2.82 KB
File downloaded or viewed 27 time(s)
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 21, 2008 8:00 am Post subject: |
 |
|
|
|
well, the leading zeros ( 00000000999 ) are not supposed to appear, unless 'showZeroes' is true
There might be a small glitch if the jackpot is 0 and a player enters arena, the 0 probably won't be shown (not a big deal)
oh wait, if there are any zeros in the jackpot, they won't be displayed on EnterArena, because you make it refresh the jackpot using an 'old' jackpot of 0, and any 0's will be considered 'the same as before', so it won't update it.
adding an 'init' parameter would work.
local void sendCreds(Player *p, int old, int init)
{
Target target;
target.type = T_PLAYER;
target.u.p = p;
int credits = creds->GetCredits(p);
int i = 0, num, oldnum, zeroes, pastZero = 0;
//cleanUp(p,old);
//Put the jp on the screen.
obj->Toggle(&target, 2001, 1);
for (; i < 10; i++)
{
zeroes = 9 - i;
num = (int)((credits / (int)pow(10, zeroes)) % 10);
oldnum = (int)((old / (int)pow(10, zeroes)) % 10);
if (((num == 0) && (!showZeroes) && (i != 9) && (!pastZero)) || (num == oldnum && !init))
{
//Do nothing.
}
else
{
obj->Toggle(&target, calculateID(num, i), 1);
obj->Toggle(&target, calculateID(oldnum, i), 0);
pastZero = 1;
}
}
}
local void sendCreds(Player *p, int old)
{
sendCreds(p, old, 0);
}
local void cPlayerAction(Player *p, int action, Arena *arena)
{
if (action == PA_ENTERARENA)
{
sendCreds(p, 0, 1);
}
...
|
_________________ (Insert a bunch of dead links here)
|
|
Back to top |
|
 |
Hakaku Server Help Squatter

Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: Thu Aug 21, 2008 5:09 pm Post subject: |
 |
|
|
|
Well the problem is that whether or not ShowZeroes = 1 (or 0), it won't show them at all. So 18M credits will display just the 18.
If I re-order the following lines, it'll make all zeroes display (so 14M shows up as 0014000400 -- where the second four came from I don't know; but it's being read as a zero, so it won't refresh if I use credits [so 13M will look like 0013000400]).
obj->Toggle(&target, calculateID(oldnum, i), 0);
obj->Toggle(&target, calculateID(num, i), 1); |
With Sama's suggestion, it seems to display the proper zeroes (and I'm guessing the second 'sendCreds' was meant to be cUpdate, in which case it should say "sendCreds(p, old, 1);" to avoid refresh issues). But I'm still getting weird things like '11000100' for 11M, and this is my primary concern.
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 21, 2008 5:28 pm Post subject: |
 |
|
|
|
the 3rd digit from the right seems to really be a problem lol... let's see...
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 21, 2008 5:37 pm Post subject: |
 |
|
|
|
with the init, you'd also need to add an 'if':
...
else
{
obj->Toggle(&target, calculateID(num, i), 1);
if (oldnum != num) //Don't hide it if you just turned it on
obj->Toggle(&target, calculateID(oldnum, i), 0);
pastZero = 1;
} |
Quote: | (and I'm guessing the second 'sendCreds' was meant to be cUpdate, in which case it should say "sendCreds(p, old, 1);" to avoid refresh issues). | Not really, I meant it to be an overloaded function so any older code could still use the 2 arguments function, but yeah, you don't really need that.
And cUpdate should have 'sendCreds(p, old, 0);' since you want it to update from previous display. The 'init' argument only makes it ignore what the previous value is and display all digit.
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 21, 2008 5:40 pm Post subject: |
 |
|
|
|
Make it print i, num, and oldnum for each iteration of the 'for', that might help to narrow down the bug with that wrong digit
oh, and print 'calculateID(num, i)' and 'calculateID(oldnum, i)' too
|
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:42 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Thu Aug 21, 2008 6:08 pm Post subject: |
 |
|
|
|
The pow() function looks bad in there. Without running it, it is either that or you are sending the wrong old value.
Attached is a simple little file that will calculate the values a bit nicer. I left it in the printf() format, as you can easily add in the toggling abilities.
credit_toggle.c - 1.29 KB
File downloaded or viewed 22 time(s)
|
|
Back to top |
|
 |
Hakaku Server Help Squatter

Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: Thu Aug 21, 2008 10:57 pm Post subject: |
 |
|
|
|
Samapico wrote: | Make it print i, num, and oldnum for each iteration of the 'for', that might help to narrow down the bug with that wrong digit
oh, and print 'calculateID(num, i)' and 'calculateID(oldnum, i)' too |
Here was the result for 17M:
I - 0 NUM - 0 OLDNUM - 0 CNUM - 2010, CONUM - 2010
I - 1 NUM - 0 OLDNUM - 0 CNUM - 2020 CONUM - 2020
I - 2 NUM - 1 OLDNUM - 0 CNUM - 2031 CONUM - 2030
I - 3 NUM - 7 OLDNUM - 0 CNUM - 2047 CONUM - 2040
I - 4 NUM - 0 OLDNUM - 0 CNUM - 2050 CONUM - 2050
I - 5 NUM - 0 OLDNUM - 0 CNUM - 2060 CONUM - 2060
I - 6 NUM - 0 OLDNUM - 0 CNUM - 2070 CONUM - 2070
I - 7 NUM - 7 OLDNUM - 0 CNUM - 2087 CONUM - 2080
I - 8 NUM - 0 OLDNUM - 0 CNUM - 2090 CONUM - 2090
I - 9 NUM - 0 OLDNUM - 0 CNUM - 2100 CONUM - 2100 |
And after losing 1M (although displaying 16000700):
I - 0 NUM - 0 OLDNUM - 0 CNUM - 2010 CONUM - 2010
I - 1 NUM - 0 OLDNUM - 0 CNUM - 2020 CONUM - 2020
I - 2 NUM - 1 OLDNUM - 1 CNUM - 2031 CONUM - 2031
I - 3 NUM - 6 OLDNUM - 7 CNUM - 2046 CONUM - 2047
I - 4 NUM - 0 OLDNUM - 0 CNUM - 2050 CONUM - 2050
I - 5 NUM - 0 OLDNUM - 0 CNUM - 2060 CONUM - 2060
I - 6 NUM - 0 OLDNUM - 0 CNUM - 2070 CONUM - 2070
I - 7 NUM - 0 OLDNUM - 0 CNUM - 2080 CONUM - 2080
I - 8 NUM - 0 OLDNUM - 0 CNUM - 2090 CONUM - 2090
I - 9 NUM - 0 OLDNUM - 0 CNUM - 2100 CONUM - 2100 |
From what I can tell, the old number is being sent correctly, while it seems i=7 is being interpreted as i=3 (and i=5 as i=8), which would explain why the number is repeated.
Anyhow, I'll give MGB's suggestion a shot.
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Fri Aug 22, 2008 6:49 am Post subject: |
 |
|
|
|
Make sure the lvz is correct, I guess. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
 |
tcsoccerman Server Help Squatter
Age:33 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Fri Aug 22, 2008 2:49 pm Post subject: |
 |
|
|
|
It's starting to occur to me that a general number displaying module would be a good idea.
Expect one from me in the near future.
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Fri Aug 22, 2008 3:25 pm Post subject: |
 |
|
|
|
I have something like that for mervbot and c++ though
As MGB did, the approach of using /= 10 every iteration is better than the pow(). Even if it doesn't make much sense, it's really the only place I could see that something goes wrong ?.o
|
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can 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 You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 29 page(s) served in previous 5 minutes.
|