Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ XP Per Hour
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shigs
(27 posts) Bio
|
Date
| Wed 30 Jan 2008 07:23 PM (UTC) |
Message
| 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? | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Wed 30 Jan 2008 07:45 PM (UTC) |
Message
| 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 |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Shigs
(27 posts) Bio
|
Date
| Reply #2 on Wed 30 Jan 2008 07:48 PM (UTC) |
Message
| 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 ? | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #3 on Wed 30 Jan 2008 08:01 PM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shigs
(27 posts) Bio
|
Date
| Reply #4 on Wed 30 Jan 2008 08:04 PM (UTC) |
Message
| 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? | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #5 on Wed 30 Jan 2008 09:05 PM (UTC) Amended on Wed 30 Jan 2008 09:58 PM (UTC) by Nick Gammon
|
Message
| 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. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #6 on Wed 30 Jan 2008 10:01 PM (UTC) |
Message
|
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
21,196 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top