[Release] Supertable [1.3] - A Lightweight MySQL database manager for FX-Server [ST]

#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

9 Likes

Hey super ! Thanks for the release ! But I was asking myself why don’t you just say you need to require “resources/DbManager/supewrapper” ? :slight_smile:

1 Like

Does fx-server support requires? Basically what happens is I use Server_Exports to export internal functions and make them accessible by other resources. Afterwards, I make a neat little wrapper that cleanly wraps these export functions for easier readability / usage. The person wanting to use the database manager can just use the regular exported functions (which is how FX-Server handles these things) but I created a simple wrapper that the user can basically include in their mod by adding

server_script '@supertable/supewrapper.lua'

to their __resource.lua. There are no “includes” necessary for this. If they wanted to use my script without referencing my wrapper they certainly could (I just don’t see why they would want to) by doing:

exports['supertable']:Super_Create_User(player)

And as long as my database manager is running on the server they’ll have access to that command.

You may be confusing this with cfx-server which is the older version. fx-server isn’t exactly publicly released yet but there are a few people using it and I figured that this would help them out.

Yeah pretty sure the new FX-server doesn’t work with requires.

Personally, I am waiting for a bit more documentation on the new server before switching.

What exactly is this new “FX-Server” everyone is speaking of. I am noticing alot of changes with ESM 4.0 and what not. Curious as to where I could find this fx-server to do some testing.

https://wiki.fivem.net/wiki/Running_FXServer

1 Like

Yeah it takes a few minutes to setup but it’s pretty nice!

add GET jobs fonction, I thinks it’s nice

1 Like

Added that feature, enjoy!

If anyone has any feature requests let me know. Pemrissions possibly next? Inventory?

thanks my friend. You’re the best

1 Like

Added support for custom PED models with set/get methods.

More to come soon. Suggestions welcome as always!

Finally out of the WIP phase of the mod, ServerEvents and NetEvents (Client) are ready to go! There is an example of implementation in the test.lua file!

Update to 1.1!

  • Huge stability update! Had an issue where if you had two mods that included Supertable events would trigger twice, 3 mods, thrice, etc. Moved all register events into the server.lua file so you never accidentally include multiple copies again!

  • Fixes for some minor implementation issues with a few events.

  • Organized for better readability :slight_smile:

Thanks for checking it out and let me know if you have any questions / concerns!

I’m currently starting to use this in a project I’m working on. I’m not to the point where I’m using your exports or functions but I’ll be implementing this in my project. Looks convenient!

Thanks :slight_smile:

Never a problem! Glad to hear :slight_smile:

When you finish it let me know and I can ad your mod to the list of mods that work with it! I’m currently creating an admin commands / permission system for it ^^

And most important feature I’m adding next is steam I’d authorization exclusively (toggleable) as well as IP logging.

Any questions I’m always on the FiveM Discord!

Update on this somewhat, turns out the FX-Server crew are implementing their own Permissions system. I’ll be sure to integrate mine with the native one so that it works with as many plugins as possible. Apologies for the delay.

1.2 Release! Thanks to @JinkLeft on the forums here I was able to fix up the way the client communicates with the server to relay / read information.

I’ve added a ton of documentation as well for the various use cases on server / client as well!

1 Like

Hey I just wanted to say thanks for creating this and for the updates!

I’ve been using it for the last few days and its been great.

1 Like

Glad to hear! Let me know what you do with it / if you need any support im always around! (Also I highly recommend updating! Old stuff is broken a little bit :stuck_out_tongue: )