Jump to content

Working with data


Rougue90

Recommended Posts

I'm creating a gamemode (trying at least, learning), I'm in doubt about how to save information about points, cash, kills and deaths of players. Currently the scripts are working in this logic: User register account -> addAccountData() creating the respective information. Player make login -> GetAccountData() -> setElementData(). Player quit -> GetElementData() -> setAccountData()

I understood that the information is saved in internals, but if I want to make a ranking panel, or optimize the flow of information and the server it self, which option is more suitable? Use sqlQexecuteQuery and start saving and manipulating information in the registry or continue with the method I'm using?

Edited by Rougue90
Miss information
Link to comment

Storing player information such as points, cash, kills, and deaths in a database, rather than in the game's internal data, can be a more suitable option if you want to create a ranking panel or if you have performance concerns.

 

Using an SQL database to store player information, such as MySQL, allows you to easily retrieve and update player information, as well as run more complex queries and create more advanced systems. It also allows you to store this information even if the server restarts or the player logs out, you can use the SQL queries to update the data even when the player is not online.

 

One way to implement this in your gamemode would be to use the SQLite or MySQL library for Lua that is provided by the MTA community to perform SQL queries on a local or remote database. You can use the queries such as SELECT, UPDATE, INSERT and DELETE to get and manipulate the data.

 

When a player logs in, you would use an SQL SELECT query to retrieve their information from the database and set it as element data on the player. When the player logs out or quits, you would use an SQL UPDATE query to update their information in the database with the element data on the player.

 

It's important to note that, depending on the amount of players and how frequently the data is updated, this could put a lot of strain on the database and might slow down the server. To avoid this, it's good practice to use connection pooling, prepared statements and queries optimization.

 

Keep in mind that the method you're currently using can work, but it's limited by the fact that the data is only stored for as long as the server is running and the player is logged in.

@Rougue90

Link to comment
5 hours ago, LOOah said:

Keep in mind that the method you're currently using can work, but it's limited by the fact that the data is only stored for as long as the server is running and the player is logged in.

So even if i use OnPlayerQuit, you means that if i turned off the server with Player, the information of that players would get lost? Because if i close server's connection and is different from players leaving, right? Dont think it would be a problem, since the player can only play logged in.

 

5 hours ago, LOOah said:

When a player logs in, you would use an SQL SELECT query to retrieve their information from the database and set it as element data on the player. When the player logs out or quits, you would use an SQL UPDATE query to update their information in the database with the element data on the player.

Well, kind it is what is going on now, a part that i'm using functions from MTA.

Link to comment

 

 

Yes, if you turn off the server while a player is still logged in, their information will be lost as it is only stored in the server's memory. To prevent this, you can use an SQL database to store the player's information permanently, as I mentioned. When a player logs in, you can retrieve their information from the database and set it as element data on the player. When the player logs out or quits, you can update their information in the database with the element data on the player. This way, even if the server is turned off, the player's information will still be saved and can be retrieved when they log in again.

Edited by LOOah
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...