1 Screenshot

About This File

Basic MySQL Gamemode

Github Linkhttps://github.com/MrPancakers/ragemp-mysql

Resource Thread

 

Discord: MrPancakers#9283

This is a template of a very basic login/registration system you can implement into your game mode to get started. This template only stores usernames, passwords(encrypted with BCrypt), position and money so anything extra will need to be implemented yourself. This is intended for beginners so the code is pretty basic and nothing fancy has been done so it is easily readable.

If you find any issues, leave a comment on my thread or leave a comment on this resource.

Installation

You'll need to have a MySQL server setup, either using WAMP/XAMPP/or from a server. To keep this short I will not go through setting these up, simply Google 'How to set up WAMP' for example to get it set up.

  1. Unzip the source and place it inside of your server files folder.
  2. Open your command prompt and change your directory to your server folder. Then do 'npm install' to install the required node_modules.
  3. Create a new database and call it whatever you want (Inside the script it is called 'ragemp-mysql'). Once created, import the ragemp-mysql.sql into your newly created database.
  4. Go to packages/mysql/mysql.js and open it. At the top is the connection info, change this to whatever your IP and MySQL username/password is. If you're hosting this locally and you haven't made/changed the MySQL info, the default should be fine.
  5. You're all set to go.

What's New in Version 1.2   See changelog

Released

  • You can now retrieve player money clientside (player.money changed to player.data.money)
  • Renamed the browser variable from browser1 to loginBrowser
  • Changed /updatemoney to /setmoney
  • Basic error handling for /setmoney (Should now return a message if you didn't put anything in or you didn't put a number in)
  • Fixed error for those who quit before logging in
  • Shortened player position values, now only goes to 2 decimal places
  • Added health and armour to the database to further show examples
  • Added /sethealth and /setarmour for more examples of usage
  • Added double checking for user passwords on registration to avoid typos in passwords when registering
  • Added error handling on MySQL queries
  • Like 6



User Feedback

Recommended Comments

16 hours ago, Agelil said:

Login and registration isn't work

What issue are you running into? If you prefer Discord to chat my username is MrPancakers#9283 or you can find me on the RageMP discord. I tested this out before publishing and should be 100% working.

Share this comment


Link to comment
Share on other sites

Is there any way to use the EntityData´s with the MySQL Script? For example I store the Players money in NAPI.Data.GetEntityData(player, "Money") and would like to safe that in the database

Share this comment


Link to comment
Share on other sites
3 hours ago, Jadeclon said:

Is there any way to use the EntityData´s with the MySQL Script? For example I store the Players money in NAPI.Data.GetEntityData(player, "Money") and would like to safe that in the database

If you're looking to store variables like that, all you'd have to do is send a query to the database. I don't know much C# so I can't really type it out. Check out the auth.js file for examples of sending queries.  The loadAccount function inside auth.js shows how data from the database is loaded onto the player as well.

Share this comment


Link to comment
Share on other sites

Loading packages
        "mysql" loaded
Error: Error: Cannot find module 'mysql'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Server\ragemp\server-files\packages\mysql\mysql.js:1:75)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)

I dont understand what to do in the second step

( Open your command prompt and change your directory to your server folder. Then do 'npm install' to install the required node_modules. )

Share this comment


Link to comment
Share on other sites
On 8/8/2018 at 8:52 PM, Xarot said:

Loading packages
        "mysql" loaded
Error: Error: Cannot find module 'mysql'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Server\ragemp\server-files\packages\mysql\mysql.js:1:75)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)

I dont understand what to do in the second step

( Open your command prompt and change your directory to your server folder. Then do 'npm install' to install the required node_modules. )

You need to install a NodeJS package called MySQL, command prompt is on your computer, when you open that up, you need to change your directory "cd C:/your/server/directory' and then do 'npm install mysql'

Share this comment


Link to comment
Share on other sites

'npm' is not recognized as an internal or external command,
operable program or batch file.

[EDIT]

Fixed, working! Thx.

Edited by Fusion99

Share this comment


Link to comment
Share on other sites

how to get money in MySQL Gamemode [Login/Registration System]

the code not working: player.getMoney(250);

please help me :(

 

sorry for bad english...

Share this comment


Link to comment
Share on other sites

Its very good login panel, but it will be great if you add the possibility to use different account name than you fivem nickname, so if you change your nickname you can use your account with the other nickname, that would be awesome.

Share this comment


Link to comment
Share on other sites
1 hour ago, TitoRukas said:

Its very good login panel, but it will be great if you add the possibility to use different account name than you fivem nickname, so if you change your nickname you can use your account with the other nickname, that would be awesome.

That's something people can do themselves. This resource is so people are able to see how MySQL works in an easy to understand way and are able to get started quickly in using an account system so they don't have to spend time making it themselves, implementing a feature like that will start to go outside of the purpose of this resource. Of course, you can just download it and alter that for yourself and get it running on your own server.

I should mention we're not on FiveM by the way 😉

Edited by MrPancakers

Share this comment


Link to comment
Share on other sites
7 hours ago, MrPancakers said:

That's something people can do themselves. This resource is so people are able to see how MySQL works in an easy to understand way and are able to get started quickly in using an account system so they don't have to spend time making it themselves, implementing a feature like that will start to go outside of the purpose of this resource. Of course, you can just download it and alter that for yourself and get it running on your own server.

I should mention we're not on FiveM by the way 😉

Lol, I had a mental explosion, FiveM is crap.

I will try to do it myself

Share this comment


Link to comment
Share on other sites

 

Hello thank you for your work, when have started like me it's appreciable have learns relatively quickly. At this time I encountered a few small problems but I resolved most. I already had the following problem Error: Can not find module 'mysql' ... well trying to give you said how to do it was easy but now I had this concern: Error: Can not find module 'bcrypt-nodejs' I thought ok the solution must be the same type I then proceed in the same way and surprise it did not work at all ... that's what I have for now: 

Loading packages         "mysql" loaded Error: Can not find module 'bcrypt-nodejs'  

 

so maybe it comes from: c #: disabled and i should have the past in enabled ...

well no it's not that either ....

 

for the installation of npm bcrypt I install in the same place as for the mysql ... by that I really do not see ... the little beginner to try what he could ... before coming to see j I try to solve by myself but if someone has an idea

 

Edited by tedchop

Share this comment


Link to comment
Share on other sites
18 hours ago, tedchop said:

 

Hello thank you for your work, when have started like me it's appreciable have learns relatively quickly. At this time I encountered a few small problems but I resolved most. I already had the following problem Error: Can not find module 'mysql' ... well trying to give you said how to do it was easy but now I had this concern: Error: Can not find module 'bcrypt-nodejs' I thought ok the solution must be the same type I then proceed in the same way and surprise it did not work at all ... that's what I have for now: 

Loading packages         "mysql" loaded Error: Can not find module 'bcrypt-nodejs'  

 

so maybe it comes from: c #: disabled and i should have the past in enabled ...

well no it's not that either ....

 

for the installation of npm bcrypt I install in the same place as for the mysql ... by that I really do not see ... the little beginner to try what he could ... before coming to see j I try to solve by myself but if someone has an idea

 

All you need to do is type 'npm install' inside the server directory, you don't need to do each module one by one, make sure you read step 2 carefully

"Open your command prompt and change your directory to your server folder. Then do 'npm install' to install the required node_modules."

Share this comment


Link to comment
Share on other sites

I installed everything I needed to install, including NodeJS and so on, but the console reports the following error:

(node:2696) [DEP0096] DeprecationWarning: timers.unenroll() is deprecated. Please use clearTimeout instead.

Apart from that no MySQL connection can be established although the data is 1:1 correct.

I hope you can help me!

Edited by Schreibfxhler

Share this comment


Link to comment
Share on other sites
On 6/14/2019 at 6:26 PM, HAOXIANGHU said:

Registered account does not respond, the button is hidden.

Happens to me too -- Sometimes it works fine, sometimes not.

Share this comment


Link to comment
Share on other sites
15 hours ago, MyNameIsJeff said:

Happens to me too -- Sometimes it works fine, sometimes not.

It's to do with your database not being connected, your connection to the database has dropped after your server started or your database is very slow.

Share this comment


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.