XP Per Hour

Posted by Shigs on Wed 30 Jan 2008 07:23 PM — 7 posts, 30,947 views.

#0
Now when I kill a Mob, I get told how much experince I've gained.

You got * xp.

I want to take %1 - add it up and then use it to work out the XP for that Hour,

And display it in the format of

00:00 - 2000XP
01:00 - 200XP
02:00 - 34500XP

As well as accumilating a figure that saves stat of the xp earned and how many hours it took so I can then work out a general average xp per hour.

How do I go about doing this?
USA #1
There have been several topics about this throughout the years, but I will repeat the basics real quick.

The basic way to total is to set up a variable in the script file which will let you total everything locally in the script environment. Next, tie a function to a trigger to start totalling.


totalxp = 0

function addxp( sName, sLine, wildcards )
  totalxp = totalxp + wildcards[1]
end -- addxp

Alternatively, you can put the total xp into a MUSHclient variable, and access it with GetVariable and SetVariable functions.

As for splitting things up by hour, take a look at the GetInfo function, specifically GetInfo( 301 ) and GetInfo( 304 ), then just dump it into a table.
http://www.gammon.com.au/scripts/function.php?name=GetInfo
#2
But if I place that function within the trigger-script area, It won't be executed will it, because thats merely a function reffrence and not a function call.

So why wouldn't I just place

totalxp = totalxp + %1 ?
Australia Forum Administrator #3
Shaun was referring to putting the word addxp into your "script" box for the trigger. That way the function is executed when the script fires.

An alternative is to "send to script" and do the add like you said.
#4
So I'd place


totalxp = 0

function addxp( sName, sLine, wildcards )
  totalxp = totalxp + wildcards[1]
end -- addxp


In my script window and then place, addxp in my triggers script window, which would then add the experince to my totalxp variable.

But surely each time the scripts invoked, it'll reset totalxp to = 0 and then I'll only be getting the xp just earned?
USA #5
Take a look at this thread: http://www.gammon.com.au/forum/?id=8411

Nothing goes in the "send" area, but addxp would need to be put in the "script" box. This will cause the trigger to call the addxp function every time it fires. That block of code will go into your script file (as defined in the window that pops up when you press ctrl-shift-6). This file is loaded once, which initializes the variable at 0, then the addxp function will change it progressively.
Amended on Wed 30 Jan 2008 09:58 PM by Nick Gammon
Australia Forum Administrator #6
Quote:

But surely each time the scripts invoked, it'll reset totalxp to = 0 and then I'll only be getting the xp just earned?


In a script file, stuff outside functions is only executed when the script is loaded, and thus it will zero your total xp once.

Then the function is called when the trigger fires, which adds to the xp.

However if you want to remember xp over different executions (ie. over many days) then you need to "serialize" the data somehow. Using a MUSHclient variable is one way, because the variable is saved when you save the world file (however you would need to remember to save the world).

There are other approaches, using a plugin which saves its state is one of them.