Check points when using points?


I haven’t been able to find this elsewhere, so apologies if this is somewhere here already. I have found that users in my channel check their points a lot, especially after using commands. To save on chat clutter, I’d like to integrate it so when people spend their points, they will see how many points they have left.

For example, I want to make a command for when people use their points via cost or payment so that it will work something like:

User: !jumpredeem
Bot: One jump has been redeemed for (price). User’s remaining points: (SOMETHING HERE).

Rather than currently they see they have redeemed it for (price) then use the !points command to check their remaining points.

I can see in the points section the command is pointsstring, but this doesn’t seem to work in the command section of the panel. How do I make it work?

Thank you a bunch!


I’ve edited this message because I was informed my code was, generally, wrong.

However, I believe that I do have a “proper” solution for you:

!addcom jumpredeem (runcode setTimeout(function() { $.say('One jump has been redeemed for (price). User\'s remaining points: ' + $.getPointsString($.getUserPoints(event.getSender())));}, 500);)

Modifying the command

As you may notice, the command is setup a bit differently than your average one. If you want to make changes, be careful as the wrong ones will actually break the command.

You will always need it wrapped with (runcode ) at the minimal. This tells the bot to run the command as raw code instead of parsing it as text.

I’ve also added in a timeout function, setTimeout(function() { }, 500) into the code because the 500ms (you can tweak it) is long enough for the bot to handle the actual point deduction before the message is sent. This should resolve the issue Scania posted in the reply under this one. Note that this will make the command seem slightly delayed. Feel free to shorten/extend the 500 MS (milliseconds). Don’t go lower than 1.

You also need $.say(' '); because this is the part that actually posts the message into chat. You’ll notice it has single quotes (this: ' ) in it because that’s what creates a string, and the string variable is what is sent to chat. So all text, generally, must be wrapped in the quotes.

The exception is other code. Which you can see with the + $.getPointsString($.getUserPoints(event.getSender())). The + is needed, as it “adds” to the string you’ve defined. $.getPointsString(points) is a function that returns # your_points_name, based on the number put in place of the word points. In our case we use $.getUserPoints(username), which is another function that returns the number of points a username has. We use event.getSender() for the username as the event object contains the command sender’s username, among other things.


The points change is ran after the command is sent to avoid any slowdowns by db writes, so this is like impossible unless manually codded for a specific command, or maybe adding a tag that takes the current points and have and subtract it by the cost.


Thank you so much! This worked perfectly. Your explanation as to why it works is also super helpful so I can edit things around as I need.

You’re actually the bestest :smiley: