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

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#1

Post by Vincent(PDP) » Sun Oct 12, 2014 3:04 pm

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%
}
Last edited by Vincent(PDP) on Sun Oct 12, 2014 9:06 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

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

#2

Post by Ijon Tichy » Sun Oct 12, 2014 3:32 pm

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)
Last edited by Ijon Tichy on Sun Oct 12, 2014 3:35 pm, edited 1 time in total.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#3

Post by Vincent(PDP) » Sun Oct 12, 2014 3:37 pm

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
Last edited by Vincent(PDP) on Sun Oct 12, 2014 3:39 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

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

#4

Post by Ijon Tichy » Sun Oct 12, 2014 3:55 pm

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
Last edited by Ijon Tichy on Sun Oct 12, 2014 3:56 pm, edited 1 time in total.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#5

Post by Vincent(PDP) » Sun Oct 12, 2014 4:28 pm

So like ((HitRatio % Shots) * 100) / Shots?

And it would give, in this case, 770? (Or 771)
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#6

Post by Vincent(PDP) » Sun Oct 12, 2014 5:50 pm

Thank you! It worked perfectly!
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

EnemyOfMan
 
Posts: 32
Joined: Mon Jul 30, 2012 10:13 pm

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

#7

Post by EnemyOfMan » Sun Oct 12, 2014 8:31 pm

If you ever manage to finish this I would love to use it. This would be great in conjunction with RGA 2.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#8

Post by Vincent(PDP) » Sun Oct 12, 2014 8:53 pm

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.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#9

Post by Watermelon » Sun Oct 12, 2014 8:59 pm

Great job

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

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#10

Post by Vincent(PDP) » Sun Oct 12, 2014 9:01 pm

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. (:
Last edited by Vincent(PDP) on Sun Oct 12, 2014 9:05 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#11

Post by Watermelon » Mon Oct 13, 2014 12:04 am

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.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#12

Post by Vincent(PDP) » Mon Oct 13, 2014 6:31 am

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?
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#13

Post by Watermelon » Mon Oct 13, 2014 3:46 pm

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.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#14

Post by Vincent(PDP) » Mon Oct 13, 2014 6:51 pm

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:
Last edited by Vincent(PDP) on Mon Oct 13, 2014 7:18 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

EnemyOfMan
 
Posts: 32
Joined: Mon Jul 30, 2012 10:13 pm

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

#15

Post by EnemyOfMan » Mon Oct 13, 2014 11:02 pm

Loving this so far, can't wait for the release.

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#16

Post by Watermelon » Thu Oct 16, 2014 12:39 pm

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).

User avatar
Torr Samaho
Lead Developer
Posts: 1543
Joined: Fri May 25, 2012 6:03 pm
Location: Germany

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

#17

Post by Torr Samaho » Thu Oct 16, 2014 7:14 pm

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.

User avatar
ibm5155
Addicted to Zandronum
Posts: 1641
Joined: Tue Jun 05, 2012 9:32 pm
Location: Somewhere, over the rainbow

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

#18

Post by ibm5155 » Fri Oct 17, 2014 12:25 am

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?
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!

<this post is proof of "Decline">

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#19

Post by Watermelon » Fri Oct 17, 2014 1:06 am

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.

Post Reply