In this guide, you will learn how to create a one-time use command that allows users to collect a money reward.
1. Create a command
The first step is to create a new command, which you can learn to do in this guide.
2. Set a trigger
Users will collect their reward by using the
!collect command, so let's set that up as the trigger:
3. Craft the code
Now that we have the initial setup done, it's time to make the command actually work.
We will use:
The reward that users will receive is 100$ with template economy. Since the template economy uses the
money user var to store a user's balance, we will contribute to that var.
Getting user var
Let's get a user's balance and store it in a temporary variable called
Calculating new balance
Next, we'll add 100$ to the balance:
Saving the new balance
Now that we have the new balance, let's overwrite the current balance with the new one:
At this point, the command will successfully increase the balance, but we want to ensure that users can only collect the reward once.
Setting a variable
In order to prevent users from collecting multiple rewards, we need to save information about whether each user has already used the command.
Adding a condition
Now that we have a variable called
hasCollected that returns whether the user has already collected the reward, let's use it to prevent users from collecting the same reward multiple times by putting this code at the beginning of the command:
$onlyIf[$getUserVar[hasCollected]!=true;You cannot collect the same reward more than once!]
Let's see if it works correctly
You may not always limit executions to one per user, you can use other vars like
server vars to restrict the command to one execution per server.
You've learned how to make a command that can be used only one time!