Script stats

Add stat tracking to your script!

By Loading...

In this tutorial I’m going to go over how to add stats tracking to your scripts 📊

First of all, if you need more information that is not here, you should check the APIClient documentation.

With that said, let’s begin!

To add stats to your script you need to have a script id assigned to your script, so if your script wasn’t uploaded yet you can’t. You can however add the logic in advance and SCRIPT_ID is added to the top of your script as soon as you first upload it.

On the website, when you are adding the script or editing later you will notice you have options to customize the stats limits at the bottom. This limits are for every 5 minutes of the script running and any data sent to my API that doesn’t fall within those limits will be rejected.

You should have some margin, but I would say 20% is fine. Say your script earns 100k xp/h minimum and 200k xp/h maximum.

You will want the minimum xp to have a 20% margin which would mean 80k xp/h minimum and you would need to convert that to 5mins:

 6666 = 80000/60*5

Let’s set it to 6500 for some extra margin and to have a nice round number but it’s up to you really.

As for the maximum xp, 20% margin would be 240k xp/h max and converted to 5 mins would be:

20000 = 240000/60*5

We can set the max xp to 20000.

Do the same for GP and save your settings. With that the configuration on the website is done.

You should always use the average XP/GP you get with your activity which is what prevents people abusing it and spam fake stats. This means that some legit submissions will be rejected if the user was just lucky, imagine for example, pickpocketting elves, GP limit is 3M/H which is 150k per 5 minutes. People can get lucky and get a Enhanced crystal seed in the first 5 minutes and suddenly their script wants to report they earned 3M in 5 minutes which will get rejected. But if you were to allow 3M reports every 5 minutes, anyone could just spam that and fill your script stats with garbage stats.

Now onto the script!

Depending on what you use of Wasplib, and what you want to track you might not even need anything at all. For example, if you use WaspLib’s TBaseScript types, the XPBar methods like XPBar.EarnedXP() and XPBar.WaitXP() track the xp for you and finally TBaseScript.PrintReport() will submit your stats. So if you only track xp and use those, you are done.

If your don’t use TBaseScript, or need a custom way of tracking XP (e.g. whatever you are doing earns you XP tickets like brimhaven agility arena) or need to track GP you has some more work to do.

The method you need is APIClient.UpdatePayload() and it’s important you understand how you have to use it. It has 3 parameters, xp, gp and time. You should never have to touch time, it’s used internally and unless you have a good reason for it, don’t touch it. Anyway! This 3 parameters are used to update a internal tracked and should be used in small increments since the last time you used APIClient.UpdatePayload().

Imagine this scenario:

  • You start your script
  • Earn 100 XP and 2000 GP
  • Update payload: APIClient.UpdatePayload(100, 2000, 0)
  • Script keeps running and you earn 300 XP and 3000 GP more
  • Since the start of the script you’ve earned 400 XP and 5000 GP
  • But when you are updating the payload you must only add the amount you earned since the last time you updated it
  • So we update it: APIClient.UpdatePayload(300, 3000, 0)

It’s up to you to track this differences.

Now lastly, if you are not using TBaseScript.PrintReport() you will need to submit stats yourself somewhere. This has to be done once in a while and it’s frequency has to fall between 5 and 15 minutes and you can do it with the following line:

APICLient.SubmitStats(APICLient.GetUUID());

Again, this is only required if you don’t use TBaseScript.PrintReport(). It’s very important you do it in a frequency between 5 minutes and 15 minutes and it will also be up to you to track. If you have some kind of stats report on your script that fires every 5 minutes, that’s perfect to drop this in.

If you happen to call this too frequently, my server will rate limit you and once that happens your stats will be ignored for the next hour. If you call it too slowly, the server will also ignore it, it’s hard to verify submitted stats as “legit” on longer time frames. Several bad submissions might also get you rate limited for 1 hour.

Some things that the server always rejects are:

  • Negative XP
  • Negative Time
  • Submissions that don’t fall within your 5 minutes limits range.

You can submit negative GP, which is nice to track things that lose you money, e.g. construction:

StatsPayload.Update(0, -500, 0);

When a good stats submission is received by the server you should see the following in Simba:

[APIClient]: HTTPCode: 200 - ? User and script stats were successfully updated!

If you get an error instead, it should tell you what’s wrong.

And with that you are done, you have stats tracking added to your script😁