Jump to content

Car System questions


Recommended Posts

How could i do a car system where people can buy cars, Each card would have a ID. They would be reswaned by a /reswanedcar command. Cars could also have the color changed/Mods. Also they wont explode when damaged. Also the heath of the car will be saves. Also /park would save the pos. With Locks/Unlocks also being saved. I'm not really sure how to go about doing this. I kind of have a idea of using a forloop in a sql database. The reswaning is the part i'm not really sure how that would work to put the cars on the map, Then load its data looping in a sql database. I'm also not sure how to read/write to a Sql database. Also making the car not damage to the point they explode. The rest i think i can do on my own. So i just need help with the three parts, I think so far. To get me started. The rest would be reading/writing to the car Id. Which i think would be easy after i get the 1st three things.

Link to comment

You seem to have no knowledge about Lua at all. It will be hard to go straight into coding your "car system"... And that's what most of beginers here do. If you can't script at all then why do you want to create scripts that advanced? I can lead you there:

- https://wiki.multitheftauto.com/wiki/Main_Page

- http://www.lua.org/pil/index.html

- https://wiki.multitheftauto.com/wiki/Scr ... troduction

- SQL functions which let you save/load data in/from SQLite DB: https://wiki.multitheftauto.com/wiki/Ser ... _functions

Link to comment

Thanks 5Op for the links. Here is what i have so far. I haven't ran it yet but i wanted to know what the community thinks of it so far. Its just a start. I might even want to open source this if its good when its done to my likings. I also am not sure if i have to many end in the spawn function but i think i might be okay with it. I guess the CarID could be the ElementID when the car got created from the store. If this looks great. Then i plan on to make it so it will add the settings to the ElementID. I think i'll have to use something like Setelement. The SQL i'm not really sure if its right or wrong. I just wrote this in NotePad, If not i could always use the SQLite Database Browser @ http://sqlitebrowser.sourceforge.net . I also think i'll be okay with scripting. I scripted in Lsl before. So i think i'm getting used to the Syntax. Then all the functions are on the wiki.

function Spawn() --This will place all the cars on the map.
local result = executeSQLQuery("SELECT car FROM Cars WHERE name=?", playerName)
   if(#result == 0) then
        outputChatBox ( "There is no cars on this server.  You should spend your Money on some.", root, 255, 255, 255 )
   else
        createVehicle (CarID , Carfloatx, Carfloaty, Carfloatz , carrx, carry, carrz , numberplate)
   end
end   
addCommandHandler ("SpawnCars", Spawn)
 
function createSQL() --keep this only in here temp. Then later we can delete this, so we don't replace the database.
-- create our table, if it doesn't already exist
executeSQLCreateTable ( "Cars", "CarId NUMERIC NOT NULL, Owner TEXT, Carfloatx VARCHAR(50),Carfloaty VARCHAR(50),Carfloatz VARCHAR(50), carrx VARCHAR(50), carry VARCHAR(50), carrz VARCHAR(50),Lights VARCHAR(3),Locked VARCHAR(3),PaintJob VARCHAR(50), numberplate VARCHAR( UNIQUE" )
end
addCommandHandler ("createSQL", Spawn)

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