How to whitelist anything is any resource
In this short tutorial, you will learn how to add a whitelist to any aspect of a resource, using either a JSON file, or Ace Permissions. Once you have implemented either of these methods, it is as simple as wrapping your code in IF statements. For your convenience, code snippets have been provided, and some examples given at the end.
Prerequisites:
- A basic understanding of LUA
- A basic understanding of how resources are created
- A very basic understanding of JSON syntax
- Enough to know where commas need to go as to not break your file.
JSON Whitelist
To add a JSON whitelist to your resource, the first thing you will need to do is create the whitelist file. To do this, create a new file inside your resource folder, and name it something like whitelist.json
. Once you have done this, open up the __resource.lua
for your resource, and if you do not have a files
section, add one, like below:
Once you have done this, open your JSON file, and add the following code:
This entry will act as our template, which we will build upon. To get someone’s steam hexadecimal (steamhex), go to VacBanned.com, entry the person’s steam profile url, then copy the Steam3 ID (64bit) => (Hex), then replace it will the one from the template, making sure to keep the steam:
prefix, as this is required.
The next step is to create entries that we want whitelisting for; in this tutorial, we will be whitelisting two commands, and a client event. The way we will code the whitelist, is that any entries that are included in someone’s whitelist entry, will be granted (unless set to false), and any entries that are not included, will be denied. For example:
In the above example, person1
will have access to command1
, command2
, and event
; person2
will have access to command1
and event
; and person3
will only have access to event
. This will make more sense later on in the tutorial.
The next step is setting up the whitelist in our client script. To start, add the following code somewhere near the top of one of your client files:
We now need to replicate what we entered in the JSON file; following the example above:
Once you have entered these, ensure they are all set to false, and place the following code below the above code:
This will pass our whitelist object to the server script for populating. Once you have pasted this code, open a server script of your choice, and add the following code to it:
(Make sure to expand this gist)
Once you have done this, head back to your client script, and add this code:
We now have all we need to add whitelist checking to our script. Below is an example using the example set-up from above:
(Make sure to expand this gist)
You have added a JSON whitelist to your resource, well done.
Ace Permissions Whitelist
To add an Ace Permissions whitelist to your resource, the first thing you will need to do is create the whitelist file. To do this, create a new file inside your resource folder, and name it something like whitelist.cfg
. Once you have done this, open up your server.cfg
file, and add the following line above your resources:
Once you have done this, go back to your resource folder, and open the whitelist.cfg
file, once open, paste in this code:
In this tutorial, we will be whitelisting two groups: user
and advanced_user
. user
will have access to command1
, while advanced_user
will have access to command1
, command2
, and event
. To learn more about how this works, see the “Further Reading” section at the bottom of this post.
The next step is setting up the whitelist in our client script. To start, add the following code somewhere near the top of one of your client files:
Now, we need to replicate what we entered in the CFG file; following the example above:
Once you have entered these, ensure they are all set to false, and place the following code below the above code:
This will pass our whitelist object to the server script for populating. Once you have pasted this code, open a server script of your choice, and add the following code:
(Make sure to expand this gist)
Once you have done this, head back to your client script, and add this code:
We now have all we need to add whitelist checking to our script. Below is an example using the example code above:
(Make sure to expand this gist)
You have now added an Ace Permissions Whitelist to your resource, congratulations.
Examples:
JSON Example
Ace Example
JSON & Ace Example
Further Reading:
I hope you find this helpful; if you have any problems post in the comments below and I will do my best to assist you. If you think you have a better way of implementing either of the above, by all means please let me know and I will be happy to update the post for everyone’s benefit.