exptracking.inc -- Exp tracker. Yay math =/

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot. MQ2Data format only!

Moderator: MacroQuest Developers

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

exptracking.inc -- Exp tracker. Yay math =/

Post by Preocts » Tue May 04, 2004 3:12 pm

Small bit of code I use everyday in my macros just so I can see the bottom line of my day's work. This could easily be expanded to report exp per hour, minute, and second. All the needed values are stored nicely inside an ini. Ini file name defined by a variable so it's a quick change to custom it.

Code: Select all

|**
  ExpReport.inc written by Preocts. Updated last: 05/01/2004

  This file tracks exp information. It is dependant on ini information. That
  information is stored in ${IniFileName} under keys [ExpTrack] and [Settings]
  *Should handle Exp, AA, Leadership, and RaidLeadership equally as well.
  [ExpTrack] is self creating.
  [Settings] is not required. Optional ValueNames include:
    Noise=0[default] no /echos to screen. 1 /echos to screen each kill

  REQUIRED OUTER VAR: IniFileName
  Should easy to understand what to set this to.

**|

#Event GainExp "You gain"
#Event GainExp "You regain some experience from resurrection"
#Event LoseExp "You have been slain"

Sub StartExpTrack
  /declare IniFileName string outer whatever.ini
  |Update the ini with current Exp and AAexp
  /ini "${IniFileName}" "ExpTrack" "PastExp" "${Me.PctExp}"
  /ini "${IniFileName}" "ExpTrack" "PastAA" "${Me.PctAAExp}"
  /ini "${IniFileName}" "ExpTrack" "PastLeader" "${Me.PctGroupLeaderExp}"
  /ini "${IniFileName}" "ExpTrack" "PastRaid" "${Me.PctRaidLeaderExp}"
/return

Sub Event_GainExp
| If nothing has changed: miscall, leave.
  /if (${Ini[${IniFileName},ExpTrack,PastExp,0]}==${CurrentExp} && ${Ini[${IniFileName},ExpTrack,PastAA,0]}==${CurrentAA}) /return

| This sub is just all math logic for calc'ing EXP gains. Gains, not loses.
| Thanks to Lax's new ${} phrasing this is done with ONE loop! Rock on your bad self Lax!
  /declare Past int local
  /declare Current int local ${Me.PctExp}
  /declare Count int local
  /declare Total int local
  /declare Change int local 0
  /declare ExpType string local Exp

  :FourLoop
    /varset Past ${Ini[${IniFileName},ExpTrack,Past${ExpType},0]}
    /varset Count ${Ini[${IniFileName},ExpTrack,${ExpType}Count,0]}
    /varset Total ${Ini[${IniFileName},ExpTrack,${ExpType}Total,0]}
    /if (${Past}!=${Current}) {
      /if (${Past}<${Current}) {
        /varcalc Change ${Current}-${Past}
      } else {
        /if (${Current}) {
          /varcalc Change (${Current}+100)-${Past}
        } else {
          /varcalc Change 100-${Past}
        }
      }
      /varcalc Count ${Count}+1
      /varcalc Total ${Total}+${Change}
      /if (${Ini[${IniFileName},Settings,Echo,0]}) {
        /echo You have gained ${Change}% ${ExpType} experience on that kill.
        /echo Total ${ExpType} changes: ${Count}, Total ${ExpType} Gained: ${Total}, Average per change: ${Math.Calc[${Total}/${Count}]}% ${ExpType} Exp
      }
    }
    /ini "${IniFileName}" "ExpTrack" "Past${ExpType}" ${Current}
    /ini "${IniFileName}" "ExpTrack" "${ExpType}Count" ${Count}
    /ini "${IniFileName}" "ExpTrack" "${ExpType}Total" ${Total}
    /if (${ExpType.Equal[Exp]}) {
      /varset ExpType AA
      /varset Current ${Me.PctAAExp}
      /varset Change 0
      /goto :FourLoop
    }
    /if (${ExpType.Equal[AA]}) {
      /varset ExpType Leader
      /varset Current ${Me.PctGroupLeaderExp}
      /varset Change 0
      /goto :FourLoop
    }
    /if (${ExpType.Equal[Leader]}) {
      /varset ExpType Raid
      /varset Current ${Me.PctRaidLeaderExp}
      /varset Change 0
      /goto :FourLoop
    }
/return

Sub Event_LoseExp
| More math, this time with EXP lose due to death.
  /declare PastExp int local ${Ini[${IniFileName},ExpTrack,PastExp,0]}
  /declare CurrentExp int local ${Me.PctExp}
  /declare ExpCount int local ${Ini[${IniFileName},ExpTrack,ExpCount,0]}
  /declare ExpTotal int local ${Ini[${IniFileName},ExpTrack,ExpTotal,0]}
  /declare ExpChange int local 0
  
| If nothing has changed: miscall, leave.
  /if (${PastExp}==${CurrentExp}) /return
  /if (${PastExp}>${CurrentExp}) {
    /varcalc ExpChange ${PastExp}-${CurrentExp}
  } else {
    /varcalc ExpChange (${PastExp}+100)-${CurrentExp}
  }
  /varcalc ExpTotal ${ExpTotal}-${ExpChange}
  /varcalc ExpCount ${ExpCount} + 1
  /if (${Ini[${IniFileName},Settings,Echo,0]}) {
    /echo Ouch, You have lost ${ExpChange}% experience because of death.
    /echo Total Exp Changes: ${ExpCount}, Total Exp Gained: ${ExpTotal}, Average per change: ${Math.Calc[${ExpTotal}/${ExpCount}]}% Exp
  }
  /ini "${IniFileName}" "ExpTrack" "PastExp" ${CurrentExp}
  /ini "${IniFileName}" "ExpTrack" "ExpCount" ${ExpCount}
  /ini "${IniFileName}" "ExpTrack" "ExpTotal" ${ExpTotal}
/return

Edit: Fixxed spelling erros
Last edited by Preocts on Tue May 04, 2004 7:03 pm, edited 1 time in total.

SeanRare
decaying skeleton
decaying skeleton
Posts: 5
Joined: Mon Apr 19, 2004 3:52 pm
Location: Salt Lake City, UT

Possible Bug

Post by SeanRare » Tue May 04, 2004 5:49 pm

Great idea! I want to get home and try it out. At first glance, I think you might have a problem on your second GainExp event:

Code: Select all

"#Event GainExp "You regain some experience rom resurrection"
Probably want that "rom" to be "from". :)

Anyway. Great submission and really clean code. Already thinking I'll add a Sub ShowExpProgress so I can do a status check whenever I want. Thanks!

GreenPlastik
orc pawn
orc pawn
Posts: 28
Joined: Thu May 27, 2004 4:40 pm

if i wanted to use this by itself

Post by GreenPlastik » Fri May 28, 2004 10:12 pm

i'm not sure what macros i would run this in cus i don't currently run any other than tradeksill or mob killin. how would i turn this into a macro on it's own?

s16z
a ghoul
a ghoul
Posts: 97
Joined: Thu Apr 01, 2004 12:03 pm

Post by s16z » Fri May 28, 2004 11:58 pm

Code: Select all

#include ExpReport.inc

Sub Main
    /declare IniFileName string outer myinifilename.ini

    /call  StartExpTrack

  :DaLoop
    /doevents
    /goto :DaLoop

    /return

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Thu Jul 08, 2004 5:12 pm

I attempted to use this, with the above "macro" to see how it worked; it doesn't.

I keep getting an error about IniFileName already being declared and even though it doesn't exit it doesn't do anything.

My intent is to get enough understanding so that I can add it into other macros as pleases me.

Can someone help with how to get this working. It seems so simple, but who knows, maybe I'm missing something easy. And it is not "myinifilename.ini" as I changed that for my character. It does make an ini file for my character.

Drumstix42
a grimling bloodguard
a grimling bloodguard
Posts: 808
Joined: Mon May 03, 2004 4:25 pm

Post by Drumstix42 » Thu Jul 08, 2004 9:57 pm

Did you change this line?
/declare IniFileName string outer whatever.ini

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Thu Jul 08, 2004 10:31 pm

Yes, I did, and thought I made that clear in my previous post.

I get a file with my exp listed in it: aChallenged1.ini which would not be the case if I had not. No, not the acutal file name, but no one in thier right mind is going to post their real char name.

It is tracking my overall xp, but the section I'm trying to figure out is why it does not /echo the xp as it happens, like it is supposed to....

Code: Select all

/if (${Ini[${IniFileName},Settings,Echo,0]}) { 
        /echo You have gained ${Change}% ${ExpType} experience on that kill. 
        /echo Total ${ExpType} changes: ${Count}, Total ${ExpType} Gained: ${Total}, Average per change: ${Math.Calc[${Total}/${Count}]}% ${ExpType} Exp 
      }
and

Code: Select all

/if (${Ini[${IniFileName},Settings,Echo,0]}) { 
    /echo Ouch, You have lost ${ExpChange}% experience because of death. 
    /echo Total Exp Changes: ${ExpCount}, Total Exp Gained: ${ExpTotal}, Average per change: ${Math.Calc[${ExpTotal}/${ExpCount}]}% Exp 
  }
Those just are not happening.

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Thu Jul 08, 2004 10:33 pm

Ok, I'm an idiot, I missed a freaking toggle that needs to be set. Default is off. Thanks, made me take the time and look again.

Teach me to mess with fairly well documented files! :oops:

Now I'm trying to figure out how to turn it on. It's late and I should probably work on it in the morning.

Edit: found it. Just an addition to the ini file:
[Settings]
Noise=1

A Troll
a lesser mummy
a lesser mummy
Posts: 30
Joined: Fri May 21, 2004 10:04 am

Post by A Troll » Sun Jul 11, 2004 9:01 am

What im doing wrong ? Ther ini file is created but get some errors

--exp.mac----------------------------------------------------------------------

Code: Select all

#include ExpReport.inc 

Sub Main 
    /declare IniFileName string outer meexp.ini 

    /call StartExpTrack 

  :DaLoop 
    /doevents 
    /goto :DaLoop 

    /return 
--ExpReport.inc----------------------------------------------------------------------

Code: Select all

|** 
  ExpReport.inc written by Preocts. Updated last: 05/01/2004 

  This file tracks exp information. It is dependant on ini information. That 
  information is stored in ${IniFileName} under keys [ExpTrack] and [Settings] 
  *Should handle Exp, AA, Leadership, and RaidLeadership equally as well. 
  [ExpTrack] is self creating. 
  [Settings] is not required. Optional ValueNames include: 
    Noise=0[default] no /echos to screen. 1 /echos to screen each kill 

  REQUIRED OUTER VAR: IniFileName 
  Should easy to understand what to set this to. 

**| 

#Event GainExp "You gain" 
#Event GainExp "You regain some experience from resurrection" 
#Event LoseExp "You have been slain" 

Sub StartExpTrack 
  /declare IniFileName string outer meexp.ini 
  |Update the ini with current Exp and AAexp 
  /ini "${IniFileName}" "ExpTrack" "PastExp" "${Me.PctExp}" 
  /ini "${IniFileName}" "ExpTrack" "PastAA" "${Me.PctAAExp}" 
  /ini "${IniFileName}" "ExpTrack" "PastLeader" "${Me.PctGroupLeaderExp}" 
  /ini "${IniFileName}" "ExpTrack" "PastRaid" "${Me.PctRaidLeaderExp}" 
/return 
and the rest of the script

--meexp.ini-------------------------------------------------------------------------------

Code: Select all

[Settings]
Noise=1
[ExpTrack]
PastExp=21.21
PastAA=58.79
PastLeader=2.50
PastRaid=0.00


Getting following error msg if i start script with /mac exp

/declare 'IniFileName' failed. Name already in use.
ExpReport.inc@21 (StartExpTrack): /declare IniFileName string outer meexp.ini
exp.mac@6 (Main): /call StratExpTrack

Terramantian
a ghoul
a ghoul
Posts: 120
Joined: Thu May 13, 2004 6:20 pm

Post by Terramantian » Sun Jul 11, 2004 9:20 am

you don't need to declare IniFileName in the .mac cause it's already declared in the .inc. You're trying to do it twice.

A Troll
a lesser mummy
a lesser mummy
Posts: 30
Joined: Fri May 21, 2004 10:04 am

Post by A Troll » Sun Jul 11, 2004 3:25 pm

Seems to wrok now , but no output in MQ Window.....
Even if i try to /echo some of the ini vars in eq. All time i got NULL

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Sun Jul 11, 2004 9:06 pm

Same issue I have been having. No echo, and I have added the [Settings] Noise=1

Anyone able to help move this forward?

hiipii
a ghoul
a ghoul
Posts: 93
Joined: Sat Jun 19, 2004 5:01 pm

Post by hiipii » Sun Jul 11, 2004 10:00 pm

isregard this post :D
Last edited by hiipii on Sun Jul 11, 2004 10:07 pm, edited 1 time in total.

hiipii
a ghoul
a ghoul
Posts: 93
Joined: Sat Jun 19, 2004 5:01 pm

Post by hiipii » Sun Jul 11, 2004 10:06 pm

Instead of adding
[Settings]
Noise=1
add
[Settings]
Echo=1
I'm pretty sure that is the problem

A Troll
a lesser mummy
a lesser mummy
Posts: 30
Joined: Fri May 21, 2004 10:04 am

Post by A Troll » Mon Jul 12, 2004 12:55 pm

Nope, tried both settings and nothing happends
Even if i try in EQ
/echo ${Total} ---> NULL
/echo ${Exp} ---> NULL
/echo ${Me.PctAAExp} --->89,04

seems like this not working anymore.
Ini File iss created and stores my Exp but dont update every fight