« [ GameMode ] ADM Script v1.0
Sunshine Auto's - by rulk
[ #D~ Tools ] Textdraw & Sprite Editor! »

rulk

  • Full Member
  • Shine Jesus Shine
  • Posts: 119
Sunshine Auto's - by rulk
« on September 10th, 2015, 08:00 PM »Last edited on May 2nd, 2016, 01:07 PM
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

  • Sr. Member
  • Posts: 252
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Thijn

  • VC:MP Beta Tester
  • Posts: 1,688
Re: Sunshine Auto's - by rulk
« Reply #2, on September 11th, 2015, 06:40 AM »Last edited on September 11th, 2015, 06:44 AM
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

  • Wiki Contributor
  • Posts: 3,343
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

Thijn

  • VC:MP Beta Tester
  • Posts: 1,688
Re: Sunshine Auto's - by rulk
« Reply #5, on September 11th, 2015, 06:49 AM »
Another quick question about your sql_create script. You use "100,000" as price, which isn't an integer.

KAKAN

  • Wiki Contributor
  • Posts: 3,343
Re: Sunshine Auto's - by rulk
« Reply #7, on September 11th, 2015, 07:08 AM »Last edited on September 11th, 2015, 07:10 AM
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
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

rulk

  • Full Member
  • Shine Jesus Shine
  • Posts: 119
Re: Sunshine Auto's - by rulk
« Reply #8, on September 11th, 2015, 09:43 AM »
Quote from Thijn on September 11th, 2015, 06:40 AM
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?

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 September 11th, 2015, 06:49 AM
Another 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.
Re: Sunshine Auto's - by rulk
« Reply #9, on September 11th, 2015, 09:49 AM »
Quote from KAKAN on September 11th, 2015, 07:08 AM
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
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

  • VC:MP Beta Tester
  • Posts: 288

KAKAN

  • Wiki Contributor
  • Posts: 3,343
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

rulk

  • Full Member
  • Shine Jesus Shine
  • Posts: 119
Re: Sunshine Auto's - by rulk
« Reply #12, on September 11th, 2015, 02:21 PM »Last edited on September 11th, 2015, 02:30 PM
Quote from KAKAN on September 11th, 2015, 02:18 PM
I 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

  • Wiki Contributor
  • Posts: 3,343
Re: Sunshine Auto's - by rulk
« Reply #13, on September 11th, 2015, 02:48 PM »
I have vehicles using function.nut, how can i use it, I don't have any vehicles using server.conf file.
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

rulk

  • Full Member
  • Shine Jesus Shine
  • Posts: 119
Re: Sunshine Auto's - by rulk
« Reply #14, on September 11th, 2015, 04:40 PM »
Quote from KAKAN on September 11th, 2015, 02:48 PM
I 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.
Code: [Select]

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

« [ GameMode ] ADM Script v1.0
[ #D~ Tools ] Textdraw & Sprite Editor! »