Jump to content

[HELP]Car sytem.


ibootleeg

Recommended Posts

Is possible to create a system in which the player complete the purchase of a car, this car gets saved to your account?

Example: I bought this car after I assure him, after I quit the server it will be saved in my account when I get back on the server, I could stick it again somewhere without having to buy again. Like money save :D

Link to comment

I reccommend you use sqlite. I will show you some basic ways to use it to your advantage. The first thing your gonna need to do is connect to the database, and create the table if it doesnt exist for what you want to start, and include the variables in there, like so

addEventHandler ( "onResourceStart", getRootElement(), function(res) 
    db = dbConnect("sqlite", "vehicles.db") 
    dbExec(db, "CREATE TABLE IF NOT EXISTS vehicle(owner TEXT, x INT, y INT, z INT, xr INT, yr INT, zr INT)") 
end) 

Basically what we did above is create a database and then chec kif the table exists, and if not create it with those certain collums. Now lets say you want to insert a new line of data when someone buys car ( i wont say how to do this, im just showing you how to save. ). You would do that with a dbquery, heres an example.

  
 dbExec(db, "INSERT INTO `vehicles`(`owner`, 'x','y','z','xr','yr','zr') VALUES(?,?,?,?,?,?,?)",  playerAccountNameHere, carx, cary, carz, carxrot, caryrot, carzrot)  
  

This is pretty self explanitory ^

Now i will show you how to update and remove.

Update

  
 dbExec(db, "UPDATE `vehicles` SET x =   ? WHERE owner=?", ownerDataHere) 
  
  

DELETe

  
dbExec(db, "DELETE FROM 'vehicles' WHERE owner= ?", carOwner ) 
  

These are the bare basics but this should be enough to get you started. Just google "Multi theft auto dbexec" and such to learn it better.

Link to comment
@Damien_Teh_Demon -

You forgot to add the vehicle model, and it's not a very good method to use INT for x, y, z, rx, ry, and rz. You should use something like FLOAT.

Again, im not trying to make something for him, but yeah, i just wanna give him a idea on how to save data, not a step by step manual on how to save a vehicle's position :) , and thanks for the float tip, i just assumed to use int, ill be changing that on my scripts now xD

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