Jump to content

New to the Server Scene, and have some questions.


Solid8

Recommended Posts

Hi,

I am new to MTA server scene and was wondering about a couple of things.

 

Custom Database, good idea?

Is it better to use a SQL Database, or just the default SQLite for storing users?

 

Where is it best to store Stats, Weapons and Owned Vehicles?

Should i store it in an SQL Database, or is there some other place that is better? and if i should store it in an SQL Database should i put it all in the same table that contains the usernames and passwords? Or should i keep the usernames and passwords in one table, Stats in one table and Weapons and Vehicles in one table?

 

I'm sorry if this is the wrong place to post this, as i said I'm new to this scene. Appreciate every reply i get 9_9

 

Thanks :D

Link to comment

An external database would probably be better since you could integrate it easily to other services like forums, Though you could not use internal.db and registry.db related functions like setAccountData, resetAccountPassword, getAccounts, etc. which you could actually make by yourself, so not a big deal just a little bit of work there.

About the storage of account data like stats, weapons, vehicles and all that, I'd prefer to use another database, so you've got it all organized. 

It's your choice after all.

Link to comment
12 hours ago, Dimos7 said:

Yes i good idea have a sql database you need have different  table for account Vehicles99ui etc

Thanks for your reply :D, i have decided to setup a custom database.

11 hours ago, MadnessReloaded said:

An external database would probably be better since you could integrate it easily to other services like forums, Though you could not use internal.db and registry.db related functions like setAccountData, resetAccountPassword, getAccounts, etc. which you could actually make by yourself, so not a big deal just a little bit of work there.

About the storage of account data like stats, weapons, vehicles and all that, I'd prefer to use another database, so you've got it all organized. 

It's your choice after all.

Thanks for your reply :D, yeah i don't think it will be hard to create those functions, so i have decided to make a custom database. Thanks for your Insight 9_9

  • Like 1
Link to comment

I know your question has already been answered but I'd like to add to it.
If you use a database or not really depends on what you want to. If you were to merely store a few values it would be way too much work, however since you asked for weapons, vehicles and the like a database is more or less a must have.

You should also do yourself a favour and not mix the default MTA functions (setAccountData, getAccountData, ...) and your custom functions. Doing that will get messy really quick. The only functions I would maybe use are the account functions; e.g createAccount, ... that would allow you to use the integrated ACL. However you could also create your own rights system...needless to mention that is a lot of work.

Link to comment
13 hours ago, 3aGl3 said:

I know your question has already been answered but I'd like to add to it.
If you use a database or not really depends on what you want to. If you were to merely store a few values it would be way too much work, however since you asked for weapons, vehicles and the like a database is more or less a must have.

You should also do yourself a favour and not mix the default MTA functions (setAccountData, getAccountData, ...) and your custom functions. Doing that will get messy really quick. The only functions I would maybe use are the account functions; e.g createAccount, ... that would allow you to use the integrated ACL. However you could also create your own rights system...needless to mention that is a lot of work.

 

5 hours ago, koragg said:

If you won't integrate the things to some website then there's nothing stopping you from using the default MTA functions. Easier and can do pretty much anything.

Thanks Guys :D, i will think about what i will do further.

Link to comment
7 hours ago, koragg said:

If you won't integrate the things to some website then there's nothing stopping you from using the default MTA functions. Easier and can do pretty much anything.

Except that you don't have full access to the integrated databases.
Please explain how you want to efficiently store owned vehicles etc. with setAccountData and getAccountData. When using your own SQL database you can create a table for vehicles and a record for each vehicle...I don't even want to think about how you'd store a vehicle in account data. Let alone multiple.

Link to comment

There's quite a few methods of saving data in MTA Lua.

Local Saving
1. Lua Table (Temporary data, works similar to ram, where all data is destroyed when script stops)
2. SQLite (Saving to internal server database)

External
3. TXT (Saving strings to a txt file and then loading them again with loadstring()(), not very organized and needing to save functions)
4. JSON (Converting lua tables to JSON with toJSON() function, then saving the result of the toJSON() function into a JSON file and loading it again by reading the file and using fromJSON() function on the buffered content)
5. XML (Saving nodes into xml and then loading them again with MTA's premade xml functions)
6. MySQL (Best method for saving data, goes into an external database, load/read time is fast, downside being that it relies on a MySQL Server)
4. LUA (Similar to txt, converting a chunk of a script into a string and then exporting it to a file to be loaded later on with fileRead and loadstring()(), used when transporting scripts)

I hoped that this has helped you, lots of choices to choose from, good luck and have a nice day.

  • Like 1
Link to comment
9 hours ago, 3aGl3 said:

Except that you don't have full access to the integrated databases.
Please explain how you want to efficiently store owned vehicles etc. with setAccountData and getAccountData. When using your own SQL database you can create a table for vehicles and a record for each vehicle...I don't even want to think about how you'd store a vehicle in account data. Let alone multiple.

local table = {}

table.insert (table,{model,{upg1,upg2,upg3,upg4}})

setAccountData (account,"Vehicles",toJSON (table))
local table = fromJSON (getAccountData(account,"Vehicles"))

Not complicated at all and far easier.

Edited by MadnessReloaded
Link to comment
9 minutes ago, MadnessReloaded said:

local table = {}

table.insert (table,{model,{upg1,upg2,upg3,upg4}})

setAccountData (account,"Vehicles",toJSON (table))
local table = fromJSON (getAccountData(account,"Vehicles"))

Not complicated at all and far easier.

Fair enough, on the storing side but what if I wanted to get every Sultan owner?
On SQL I run a simple query that returns me a table with all players that own one, while like this I'd have to run a lua script that grabs every ones vehicles account data and then insert everyone into a table after going through all players...

Link to comment
local vehicles = getElementsByType('vehicle')
for i=1,#vehicles do
	local name = getVehicleNameFromModel(getElementModel(vehicles[i]))
	if name == 'sultan' then
    	local driver = getVehicleOccupant(vehicles[i])
    	if driver then
      		return driver
      	end
    end
	return false
end

 

Link to comment
10 minutes ago, 3aGl3 said:

Fair enough, on the storing side but what if I wanted to get every Sultan owner?
On SQL I run a simple query that returns me a table with all players that own one, while like this I'd have to run a lua script that grabs every ones vehicles account data and then insert everyone into a table after going through all players...

Yeah, looping through all accounts and all the vehicle data would not be as efficient but whatever, it works, the performance would not be considerably affected anyway. I do recommend a MySQL database, though.

Edited by MadnessReloaded
Link to comment
22 hours ago, 3aGl3 said:

Except that you don't have full access to the integrated databases.
Please explain how you want to efficiently store owned vehicles etc. with setAccountData and getAccountData. When using your own SQL database you can create a table for vehicles and a record for each vehicle...I don't even want to think about how you'd store a vehicle in account data. Let alone multiple.

 

14 hours ago, ShayF said:

There's quite a few methods of saving data in MTA Lua.

Local Saving
1. Lua Table (Temporary data, works similar to ram, where all data is destroyed when script stops)
2. SQLite (Saving to internal server database)

External
3. TXT (Saving strings to a txt file and then loading them again with loadstring()(), not very organized and needing to save functions)
4. JSON (Converting lua tables to JSON with toJSON() function, then saving the result of the toJSON() function into a JSON file and loading it again by reading the file and using fromJSON() function on the buffered content)
5. XML (Saving nodes into xml and then loading them again with MTA's premade xml functions)
6. MySQL (Best method for saving data, goes into an external database, load/read time is fast, downside being that it relies on a MySQL Server)
4. LUA (Similar to txt, converting a chunk of a script into a string and then exporting it to a file to be loaded later on with fileRead and loadstring()(), used when transporting scripts)

I hoped that this has helped you, lots of choices to choose from, good luck and have a nice day.

 

12 hours ago, MadnessReloaded said:

local table = {}

table.insert (table,{model,{upg1,upg2,upg3,upg4}})

setAccountData (account,"Vehicles",toJSON (table))
local table = fromJSON (getAccountData(account,"Vehicles"))

Not complicated at all and far easier.

 

12 hours ago, 3aGl3 said:

Fair enough, on the storing side but what if I wanted to get every Sultan owner?
On SQL I run a simple query that returns me a table with all players that own one, while like this I'd have to run a lua script that grabs every ones vehicles account data and then insert everyone into a table after going through all players...

 

12 hours ago, ShayF said:

local vehicles = getElementsByType('vehicle')
for i=1,#vehicles do
	local name = getVehicleNameFromModel(getElementModel(vehicles[i]))
	if name == 'sultan' then
    	local driver = getVehicleOccupant(vehicles[i])
    	if driver then
      		return driver
      	end
    end
	return false
end

 

 

12 hours ago, MadnessReloaded said:

Yeah, looping through all accounts and all the vehicle data would not be as efficient but whatever, it works, the performance would not be considerably affected anyway. I do recommend a MySQL database, though.

 

Thank guys really appreciate your input :), nice to see that this community is full with non-toxic and smart people. Thanks again guys :D

  • Like 1
  • Thanks 1
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...