Page 1 of 1

[SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 3:04 pm
by Vincent(PDP)
I'm working on a stats mod for Doom, which will be able to calculate your hit ratio with it's remainder (I.e "Hit ratio: 67,36%").

I've tried different ways to do it but it just won't work. When I have fired 1395 shots and hit 1336 monsters, Zandronum will say that my hit ratio is 95,1075% but if I calculate it using a calculator, the calculator displays 95,77060931899642 (95,77 for short).

It seems to me it's the modulus operator (%) that's the problem.
Any suggestions?

Code:

Code: Select all

Int Shots = GetCVar("x_doomstats_shots");
Int Missed = GetCVar("x_doomstats_missed");
Int Hits = Shots - Missed;

If(Hits != 0 && Shots != 0)
{
    Int HitRatio = (Hits * 100); //133600
    Int HitRatioRemainderInt = (HitRatio % Shots); //1075  ??? 
    Int HitRatioComplete = HitRatio / Shots; //95
    Str HitRatioStr = StrParam(s:HitRatioComplete, s:",", d:HitRatioRemainderInt, s:"%"); //95,1075% - Should be 95,77%
}

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 3:32 pm
by Ijon Tichy
uh

can't you just do (hits * 100) / shots?

the fractional part is probably going to have to be foregone due to ACS being a gigantic pile of SHIT and not supporting proper data types, although I guess for up to 32767 shots you could convert it to a fixed, divide it by shots, then multiply the result by 100 (((hits << 16) / shots) * 100)

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 3:37 pm
by Vincent(PDP)
Ijon Tichy wrote: uh

can't you just do (hits * 100) / shots?

the fractional part is probably going to have to be foregone due to ACS being a gigantic pile of SHIT and not supporting proper data types, although I guess for up to 32767 shots you could convert it to a fixed, divide it by shots, then multiply the result by 100 (((hits << 16) / shots) * 100)
Ugh. :E

Then I guess I'll have to go with my current solution:

Code: Select all


...
HitRatioRemainder = CustomModulus(HitRatio, Shots);
...

Function Str CustomModulus(Int a, Int b)
{
    Int InitialLength = StrLen(StrParam(d:(a / b)));
    Int x = ((a * 100) / b);
    Str y = GetChars(StrParam(d:x), InitialLength, StrLen(StrParam(d:x)));
    
    Return y;
}

Function Str GetChars(Str String, Int start, Int end)
{
    Str Result = "";
    For(Int i=start; i<end; i++)
    {
        Result = StrParam(s:Result, c:GetChar(String, i));
    }
    
    Return Result;
}  
It works until (a * 100) goes over the integer limit at 2147483647

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 3:55 pm
by Ijon Tichy
well I've been messing around and there's a pretty obvious in retrospect in solution once I started looking at what the modulus actually does

just multiply the modulus by 100 and divide it by shots again
bam, there's your fractional part in hundredths

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 4:28 pm
by Vincent(PDP)
So like ((HitRatio % Shots) * 100) / Shots?

And it would give, in this case, 770? (Or 771)

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 5:50 pm
by Vincent(PDP)
Thank you! It worked perfectly!

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 8:31 pm
by EnemyOfMan
If you ever manage to finish this I would love to use it. This would be great in conjunction with RGA 2.

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 8:53 pm
by Vincent(PDP)
EnemyOfMan wrote: If you ever manage to finish this I would love to use it. This would be great in conjunction with RGA 2.
Then a little screenie for you. :3

[spoiler]Image[/spoiler]

- Note: You will be able to change the list's position.

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 8:59 pm
by Watermelon
Great job

Question: What about chat and obituaries that display at the top left corner?

RE: Calculate your hit ratio, including remainder. [Stats mod]

Posted: Sun Oct 12, 2014 9:01 pm
by Vincent(PDP)
Watermelon wrote: Question: What about chat and obituaries that display at the top left corner?
Got your answer here :)
Vincent(PDP) wrote: - Note: You will be able to change the list's position.

I am also planning to add deaths, kills, damage taken, time standing still and so on...

And I've already got the anticheat code done by encrypting the CVars. (:

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Mon Oct 13, 2014 12:04 am
by Watermelon
Oops my bad.

Also since the account system should be working for 2.0 fully, I suggest maybe storing them server and clientside if you can, that way migration is easier if possible.

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Mon Oct 13, 2014 6:31 am
by Vincent(PDP)
Watermelon wrote: Oops my bad.

Also since the account system should be working for 2.0 fully, I suggest maybe storing them server and clientside if you can, that way migration is easier if possible.
Wait, are you saying I won't be able to store the values clientside in 2.0? D:
Or can you explain a little more what you mean?

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Mon Oct 13, 2014 3:46 pm
by Watermelon
Vincent(PDP) wrote:
Watermelon wrote: Oops my bad.

Also since the account system should be working for 2.0 fully, I suggest maybe storing them server and clientside if you can, that way migration is easier if possible.
Wait, are you saying I won't be able to store the values clientside in 2.0? D:
Or can you explain a little more what you mean?
Are you using ConsoleCommand to store things on the client? If so, that will be removed due to very bad security issues with the function. The database would take care of this anyways.

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Mon Oct 13, 2014 6:51 pm
by Vincent(PDP)
Watermelon wrote:
Vincent(PDP) wrote:
Watermelon wrote: Oops my bad.

Also since the account system should be working for 2.0 fully, I suggest maybe storing them server and clientside if you can, that way migration is easier if possible.
Wait, are you saying I won't be able to store the values clientside in 2.0? D:
Or can you explain a little more what you mean?
Are you using ConsoleCommand to store things on the client? If so, that will be removed due to very bad security issues with the function. The database would take care of this anyways.
Yes I am, but wasn't Torr working on a SetCVar function to replace that? ):
I would really like to work with CVars :)


EDIT:
But isn't the account system for teamgames only?

EDIT 2:
And how do you create an account btw? :razz:

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Mon Oct 13, 2014 11:02 pm
by EnemyOfMan
Loving this so far, can't wait for the release.

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Thu Oct 16, 2014 12:39 pm
by Watermelon
Vincent(PDP) wrote: Yes I am, but wasn't Torr working on a SetCVar function to replace that? ):
I would really like to work with CVars :)
This should be, but I'm unsure how limited it may actually be. I'm guessing you should be able to do exactly what you did before.

Vincent(PDP) wrote: EDIT:
But isn't the account system for teamgames only?
Account system is for anything you want it to be :D

Vincent(PDP) wrote: EDIT 2:
And how do you create an account btw? :razz:
So far there isn't a central location, we're hoping to have it ready for when 2.0 comes out. Right now we are testing the account system with AlexMax's Funcrusher servers for duel ELO and all (test example at auth.funcrusher.net).

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Thu Oct 16, 2014 7:14 pm
by Torr Samaho
Vincent(PDP) wrote: Yes I am, but wasn't Torr working on a SetCVar function to replace that? ):
I would really like to work with CVars :)
That's already in 2.0 :). See here for more details. So you can already check whether it is sufficient for your needs.

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Fri Oct 17, 2014 12:25 am
by ibm5155
hmmm, I may need to update my map if setcvar is going to be removed, sinc I'm using it to store players configuration and also the map database (that's too bad that when a server reset/crash it reset it :( )
with the database, would it be abble to use a single online database for more than one server? and, how people would store that data, on zandornum.com?

RE: [SOLVED] Calculate your hit ratio, including remainder. [Stats mod]

Posted: Fri Oct 17, 2014 1:06 am
by Watermelon
ibm5155 wrote: hmmm, I may need to update my map if setcvar is going to be removed, sinc I'm using it to store players configuration and also the map database (that's too bad that when a server reset/crash it reset it :( )
with the database, would it be abble to use a single online database for more than one server? and, how people would store that data, on zandornum.com?
If you intend to share database information between two completely different computers, you'll need to write your own program(s) to do that.