Jump to content

Saving a character system to MySQL


kPkPT

Recommended Posts

Hey guys,

So i am doing a roleplay gamemode from scratch. However, i like to think about what i'm going to do and how i am going to do it before i even start. Obviously it would need a character system, however i don't see how i will link several characters to one account? How can i actually do it with MySQL? I currently got my login and register system done and i got a database with a users table set.

 

Best regards,

Vasco

Link to comment
40 minutes ago, kPkPT said:

Hey guys,

So i am doing a roleplay gamemode from scratch. However, i like to think about what i'm going to do and how i am going to do it before i even start. Obviously it would need a character system, however i don't see how i will link several characters to one account? How can i actually do it with MySQL? I currently got my login and register system done and i got a database with a users table set.

 

Best regards,

Vasco

create table for players skins

executeSQLQuery("CREATE TABLE IF NOT EXISTS playersskins (plracc TEXT, skin TEXT, addons TEXT)")
---or
dbExec(db connection,'CREATE TABLE IF NOT EXISTS players (plracc TEXT, skin TEXT, addons TEXT)')
--------------
---then when you want to get it do that
dbPoll(db connection,'SELECT * FROM playersskins WHERE plracc=?',the player acc name)
-----and dont forget to use (split)
---and alos if you want to insert the addons do something like that
dbExec(db connection,'INSERT INTO playersskins VALUES(?,?,?)',plr acc string,skin id number,tostring(addition..','..addition1..','....etc))

 

Link to comment
Just now, Master_MTA said:

create table for players skins


executeSQLQuery("CREATE TABLE IF NOT EXISTS playersskins (plracc TEXT, skin TEXT, addons TEXT)")
---or
dbExec(db connection,'CREATE TABLE IF NOT EXISTS players (plracc TEXT, skin TEXT, addons TEXT)')
--------------
---then when you want to get it do that
dbPoll(db connection,'SELECT * FROM playersskins WHERE plracc=?',the player acc name)
-----and dont forget to use (split)
---and alos if you want to insert the addons do something like that
dbExec(db connection,'INSERT INTO playersskins VALUES(?,?,?)',plr acc string,skin id number,tostring(addition..','..addition1..','....etc))

 

It is not just the skins, i want several stuff stored. For each character i need about 20 variables or more.

Link to comment
18 minutes ago, Master_MTA said:

 

9 minutes ago, Master_MTA said:

so you can do  it like i was say or you can use loop? and tables 

Well yea but, on a roleplay server i will need alot of stuff saved like vehicles and the global user data wich is used on all the players characters. I thought about making a table and adding all characters there with a column named "username" or "serial" and cross the player username and serial with the ones there. However how can i read a table top to bottom and get all the characters belonging to that player?

Link to comment
8 minutes ago, Master_MTA said:

something like that


for k=1,#table.(serial or acc or any thing you want) do
  if getPlayerSerial(player that you want get he is skins)==table.serial[k] then
  setElementModel(player,table.skins[k])---or something like that  
  end
  end

 

#table being the dbpoll or dbquery right?

Link to comment

2 tables, account and character.

Use primary key in account table that will reference the account a character is created from. Look at the term "1 to many relationship" to better understand.

Account table should look something like this: accountID, username, password

Character: characterID, accountID, health, skin, whatever

Vehicles: vehicleID, characterID, model etc.

That's the best way, this way your data is normalized.

Link to comment
22 minutes ago, pa3ck said:

2 tables, account and character.

Use primary key in account table that will reference the account a character is created from. Look at the term "1 to many relationship" to better understand.

Account table should look something like this: accountID, username, password

Character: characterID, accountID, health, skin, whatever

Vehicles: vehicleID, characterID, model etc.

That's the best way, this way your data is normalized.

So i see it now, i watched a video about it. However, how can i get all the characters saved after that in the code? Or any other tables data that i might need.

Also, is this the best method for not wasting so much CPU resources?

Edited by kPkPT
Link to comment

Data normalization is all about one thing, no duplicate data allowed. If you don't have duplicates and the tables are indexed properly, you're not querying useless information thus saving time and resources.

"SELECT * FROM characters WHERE account_id = 2" -> returns all characters created by account number 2.

You can also use join if you want to get data from both tables:

"SELECT * FROM characters INNER JOIN accounts ON characters.accountID = accounts.accountID WHERE accounts.accountID = 2"

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...