Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
hud/counter

 
Post new topic   Reply to topic Printable version
 View previous topic  Freq Post :: Post How do you get the registration form i...  View next topic  
Author Message
Hakaku
Server Help Squatter


Joined: Apr 07 2006
Posts: 299
Location: Canada
Offline

PostPosted: Thu Aug 21, 2008 1:19 am    Post subject: hud/counter Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Thu Aug 21, 2008 8:00 am    Post subject: Reply to topic Reply with quote

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.
Code: Show/Hide
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
View users profile Send private message Add User to Ignore List
Hakaku
Server Help Squatter


Joined: Apr 07 2006
Posts: 299
Location: Canada
Offline

PostPosted: Thu Aug 21, 2008 5:09 pm    Post subject: Reply to topic Reply with quote

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]).
Code: Show/Hide
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
View users profile Send private message Add User to Ignore List Send email
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Thu Aug 21, 2008 5:28 pm    Post subject: Reply to topic Reply with quote

the 3rd digit from the right seems to really be a problem lol... let's see...
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Thu Aug 21, 2008 5:37 pm    Post subject: Reply to topic Reply with quote

with the init, you'd also need to add an 'if':

Code: Show/Hide

...
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
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Thu Aug 21, 2008 5:40 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Thu Aug 21, 2008 6:08 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email
Hakaku
Server Help Squatter


Joined: Apr 07 2006
Posts: 299
Location: Canada
Offline

PostPosted: Thu Aug 21, 2008 10:57 pm    Post subject: Reply to topic Reply with quote

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:
Code: Show/Hide
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):
Code: Show/Hide
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
View users profile Send private message Add User to Ignore List Send email
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Fri Aug 22, 2008 6:49 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
tcsoccerman
Server Help Squatter


Age:33
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Fri Aug 22, 2008 2:49 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Fri Aug 22, 2008 3:25 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 29 page(s) served in previous 5 minutes.

phpBB Created this page in 0.722140 seconds : 35 queries executed (95.6%): GZIP compression disabled