|
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Sun Mar 07, 2004 5:53 pm
Complex Round Counter |
Hello folks.
I'm trying to write a script that will accomplish the following:
1) Count combat rounds
2) Count total rounds
3) determine % in combat
4) determine how many more rounds needed in combat to get to 'desired' percent in combat.
1 & 2 are just easy triggers, so lets assume I have those stored in @CombatRounds and @TotalRounds.
3 is just a formula using the values from 1 and 2. so lets also assume I have that stored in @CombatPct.
4 is the hard part. Desired percent in combat will be set via an alias, so it will be stored as an int in @DesiredPct. (example #var DesiredPct {80})...
I don't want (@TotalRounds-@CombatRounds) because as combat rounds pass, so do total rounds (I can't assume time will stand still while I get some extra combat rounds in.) So I need to account for time lapse during combat.
I had something like this once before, but damned it if I tossed that .mud file... I'm going to keep working on this myself, just thought I'd throw it to you guys, and see if you can't get the answer before I do. When I get the answer, I'll post it.
Thanks in advance for you help :) |
|
|
|
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Sun Mar 07, 2004 6:34 pm |
I thought maybe an example might help...
Suppose, I had 6 rounds in combat out of a possible 10 rounds. And I desire to be at 80% combat time.
@CombatRounds = 6
@TotalRounds = 10
@CombatPct = 60%
if I fight for another 10 rounds, these numbers will be
@CombatRounds = 16
@TotalRounds = 20
@CombatPct = 80%
So, 10 would be the amount of rounds needed to reach desired percent in combat.
I figured this out only by trial and error. Now just to come up with the formula that makes this work for any values :) Thanks again, for any help you can provide me. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Mar 07, 2004 6:46 pm |
I am guessing your "% in combat" means '% of total mudding time spent in combat'. The first factor we don't have is an average round time. This should be computed once and then stored. You probably have this factor already as it is required to measure total rounds. The calculation would then be:
RoundsNeeded=%eval((100*@CombatRound-@DesiredPct*@TotalRounds)/(@DesiredPct-100))
As I am sure you can see @DesiredPct-100 will result in a negative number most of the time. You should use an #IF to ensure you are not wasting time doing this calculation when % in combat already exceeds @DesiredPct. Also you should ensure that you either guard against inputting @DesiredPct>99 or that you invalidate those values prior to calculating. |
|
|
|
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Sun Mar 07, 2004 7:39 pm |
awsome!! works perfectly. last time i had something like this, it wasn't nearly as small and clean as that single line. Thanks for the help. I'm trying to figure out WHY it works, now :)
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sun Mar 07, 2004 7:45 pm |
This is just algebra (stuff that many of us thought we'd never use)
CONSTANTS
CombatRounds = C
TotalRounds = T
DesiredPercent = D
VARIABLES
Rounds needed to achieve desired percent = X
FORMULAS
ActualPercent = 100C/T
ProjectedPercent = 100(C + X)/(T + X)
Since we want the ProjectedPercent to equal the DesiredPercent, solve for X in the equation
100(C + X)/(T + X) = D
100(C + X) = D(T + X)
100C + 100X = DT + DX
(100 - D)X = DT - 100C
X = (DT - 100C)/(100 - D)
In your example, we have the values:
C = 6, T = 10, D = 80
X = (80*10 - 100*6)/(100 - 80) = (800 - 600)/20 = 200/20 = 10
And you already verified that 10 was the number of extra rounds needed.
This is identical to Vijilante's formula except that the subtractions are reversed in both the numerator and denominator. I just thought it might help you to see how the formula is derived. |
|
|
|
|
|