#Hello! Welcome to Supertable!
Just know that it is a pre-requisite to have MySQL-Async and of course also require root access to this database.
Also note that this plugin depends entirely on MySQL-Async and it would not be possible without that resource.
Features
- Duplicate User prevention
- Set/Get methods for all reasonable columns
- Clean wrapper to use in your own projects
- Async! MySQL!
- Moddable (Isn’t hard to add your own columns / methods if you know SQL)
- Open Source (If I did something wrong, yell at me)
- Server/Net Events for use on client / server.
- Constant updates and functional extensions are on their way soon!
Planned Features
- Optimization
Public Mods that use Supertable
Step 1) Download MySQL…
You can do so by visiting the following link and downloading the version that is 405mb in size here: https://dev.mysql.com/downloads/windows/installer/5.7.html
Setting it up should be fairly straight forward and if you have any problems there are guides for this. Please make sure you secure your password and keep it to yourself. This password is something that will be stored as raw text in the server.cfg file.
You can do the same thing on linux by following the guide here:
There are instructions online on how to manage your database on Linux. I unfortunately cannot go into the basics of setting up a MySQL database for this tutorial. That’s on you. Just make sure the db / schema is named:
fivem_server
when you do create it.
Step 2) Install MySQL-Async
For this next part, you’ll need to use @Brouznouf’s MySQL-Async library.
You can find this here: https://github.com/brouznouf/fivem-mysql-async/tree/master
He provides very thorough instructions on setting it up so please refer to that for any information specifically referring to MySQL-Async!
The Server.cfg should look something similar to this however (Note the database=fivem_server part)
set mysql_connection_string "server=localhost;database=fivem_server;userid=root;password=testpassword"
Step 3) Install Supertable
supertable-master.zip (4.6 KB)
Simply download the project as a zip and drop the supertable folder into your resources folder and it should be ready to go after you add this to your server.cfg:
start supertable
You’ll also need to add this tag to the __resource.lua file if you plan on using any of the cleaned up methods for your server scripts:
server_script '@supertable/superwrapper.lua'
Alright, so you’ve gotten it all setup now, what can it do? It has some basic functions built in, like checking if a user is banned as they connect, being able to update values for certain columns like: banned, money, bank, and a users steam-name! Functionality is constantly being added however due to the nature of the project I am trying to limit how much functionality I force on people. Requests are welcome as always!
How To Use - Client
Everything on the client side is Event based. This means you need to directly interface with the server in-order to modify anything regarding the database (safety against injection). You retrieve data from the server by explicitly requesting it.
Here are some client script examples:
money = 0 -- Create a global variable to pass data into
TriggerServerEvent('GetUserMoney')
AddEventHandler('ReceiveUserMoney', function(value)
money = value -- Pass the value into the global variable.
end)
Or to add money to the client’s player:
TriggerServerEvent('UpdateUserMoney', value)
Here are all the events that are registered for usage from the client via TriggerServerEvent:
- SET:
('UpdateUserMoney')
('UpdateUserBank')
('UpdateUserBan')
('UpdateUserJob')
('UpdateUserModel')
- GET:
('GetUserMoney')
('GetUserBank')
('GetUserJob')
('GetUserModel')
Of course, these GET events are paired with their complimentary CLIENT Event’s that you can listen for. They all pass back the expected value.
RegisterNetEvent('ReceiveUserMoney')
RegisterNetEvent('ReceiveUserBank')
RegisterNetEvent('ReceiveUserJob')
RegisterNetEvent('ReceiveUserModel')
How To Use - Server
Alright, so as I mentioned you need to include the superwrapper.lua to gain access to these methods.
CreateUser(player)
UpdateUserMoney(player, amount)
UpdateUserBank(player, amount)
UpdateUserName(player)
UpdateUserBan(player, value) -- 0 = unbanned ... 1 = banned...
UpdateUserJob(player, job)
UpdateUserModel(player, modelhash)
And of course, you can retrieve data by using:
value = GetUserMoney(source, function(res)
value = res
end)
The alternative functions you can call in a similar fashion are:
UserExists(player, resultCallBack)
IsUserBanned(player, resultCallBack)
GetUserMoney(player, resultCallBack)
GetUserBank(player, resultCallBack)
GetUserSteamID(player)
GetUserJob(player, resultCallBack)
GetUserModel(player, resultCallBack)
Everything above is Async!
Bonus
If you’re looking to install MySQL on Linux: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04
#Changelog
- July 24th, 2017 - 1.2
Updated Retrieve methods to work via event handlers for client scripts.
Added More documentation on this page for usage (example file now has examples too!)
Conclusion
Thanks for checking it out, and have a great day! And apologies if I forgot to credit anyone. This community is awesome and there are so many names to keep track of! Thanks to the help of many people, mostly @Brouznouf, @Scott, and @indium and @samgreeeeeeen