Sunshine Auto's - by rulk

Started by rulk, Sep 10, 2015, 07:00 PM

Previous topic - Next topic

rulk

Hya chaps,

Here is a complete Buycar/Sellcar script for public use.

please let me know of any issues you may have. I have fully tested it on both 64 and 32 bit systems.

Commands are used with the '/' prefix and are as follows;
  • car
    - View information on that vehicle
  • forsale
    - View vehicles that are forsale
  • buycar
    - Purchase a vehicle
  • sellcar
    - Sell a vehicle
  • mycars
    - View your purchased vehicles
  • sharecar
    - Share a vehicle
  • delshare
    - Delete a shared vehicle
  • sharedcars
    - View your shared vehicles

-------------------------
       Included Files:
-------------------------
  • sunshine.nut
    - The main class
  • sql_create.nut
    - This iterates all server vehicles and adds them to a sql dump file, for you to import as a table into your database
  • s_cmds.nut
    - Example in-game command triggers.

-------------------------
       How it works:
-------------------------
  • Reads the vehicle entries in the database, and creates a class instance for every entry.
  • Places this instance into an array element, and sets the object properties.
  • All changes can be done via the array now. ( no need to query the database, apart from loading/saving )
  • The array index represents the in-game VehicleID.
For example: VehicleID 1, is in array index 1.
VehicleID 2, is in array index 2.
VehicleID 3, is in array index 3.
... etc etc etc ...
  • Object-Properties - These can be set or retrieved in the same manor as any other class properties. ( all properties return null if no value is set )
Current properties are;
  • VehicleID
  • VehicleModel
  • VehicleCat
  • VehiclePrice
  • IsPurchased
  • IsShared
-------------------------
      INSTALL:
-------------------------

** NOTE:
            You must first run 'sql_create.nut' and import the table to your database.
        REMEMBER TO RUN IT AFTER YOU HAVE CREATED YOUR VEHICLES!!

1. Load the class
>> dofile("sunshine.nut");

2. Load the database data into the array.
>> SunshineAutos.LoadDatabase("sunshine.db");

3. We must save the array to the database on a regular basis ( once every 5 hours )
   I reccomend triggering it in an event that is used frequently.
>> SunshineAutos.SaveDatabase("sunshine.db");

** NOTE:
            Put s_cmds.nut in the same directory as you server.exe, or change the file paths.

-------------------------
STEP-BY-STEP INSTALL GUIDES
-------------------------
Method One - Using the old server.conf
Method Two - You created your vehicles using CreateVehicle()
Using the example Script


DOWNLOAD
We are all god's children.

FinchDon

For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Thijn

#2
Awesome work.

One thing I noticed is your use of string.find() for comparison. Is there a reason why you wouldn't just use == for comparison?
If someone was called Poop, and the vehicle is owned by PoopHead it will return true wouldn't it?



Mirror: http://vcmp.thijn.ovh/files/sunshine.zip

KAKAN

oh no

KAKAN

Thanks for the MIRROR, the site he gave was not working
oh no

Thijn

Another quick question about your sql_create script. You use "100,000" as price, which isn't an integer.

KAKAN

Hmm, The database is not working
oh no

KAKAN

#7
OOps, I haven't executed the SQL file yet, thanks working

EDIT:-
The DB file is empty, and i don't know how to add, so please do tell me
oh no

rulk

Quote from: Thijn on Sep 11, 2015, 05:40 AMOne thing I noticed is your use of string.find() for comparison. Is there a reason why you wouldn't just use == for comparison?
If someone was called Poop, and the vehicle is owned by PoopHead it will return true wouldn't it?


Thank you thijn, I have Just tested and this is not the case. you had me worried for a min hehe


Quote from: Thijn on Sep 11, 2015, 05:49 AMAnother quick question about your sql_create script. You use "100,000" as price, which isn't an integer.

This is very true, Thank you.  I have updated the default price in sql_create.nut to be an integer. re--download from the link at the top.

Thank you for the mirror thijn.
We are all god's children.

rulk

Quote from: KAKAN on Sep 11, 2015, 06:08 AMOOps, I haven't executed the SQL file yet, thanks working

EDIT:-
The DB file is empty, and i don't know how to add, so please do tell me

Hya KAKAN,

The Database is empty on purpose, you have to run sql_create.nut which gathers all your server vehicles into a sql dump file called blah.sql.

Then using your sql browser, select file -> import from sql file -> blah.sql.

A new table will then be created.

Hope this helps.

rulk
We are all god's children.

Drake

Hey @rulk ,
go through your private messages please.

KAKAN

I have tried rulk , still then not working
oh no

rulk

#12
Quote from: KAKAN on Sep 11, 2015, 01:18 PMI have tried rulk , still then not working

whats not working exactly chap ?

1. Put sql_create.nut in the same directory as your server.exe

2. Open server.cfg, and put/change sqgamemode sql_create.nut

3. Run the server and a file named blah.sql is created in that directory

4. Open your sql browser and select 'import from sql file' and select blah.sql

5. A new table is now created containing all your vehicles.

we have now finished with sql_create.nut and blah.sql.

Next, run the example script by doing the following;

1. Put s_cmds.nut in the same directory as your server.exe

2. Open server.cfg, and put/change sqgamemode s_cmds.nut

3. Run the server and jump in-game.


hope this helps,

rulk
We are all god's children.

KAKAN

I have vehicles using function.nut, how can i use it, I don't have any vehicles using server.conf file.
oh no

rulk

Quote from: KAKAN on Sep 11, 2015, 01:48 PMI have vehicles using function.nut, how can i use it, I don't have any vehicles using server.conf file.

Thank you @KAKAN for bringing this to my attention.  Yes you can by doing the following.

// Create your vehicles
dofile("CreateVehicles.nut");

// Load the sql_create file
dofile("sql_create.nut" );

// Call the main function from that file, to create blah.sql
sql_create();
We are all god's children.