Sunshine Auto's - by rulk

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

Previous topic - Next topic

rulk

#15
OK chaps, I decided to create a complete installation guide for you all - all methods have been fully tested.

Thank you for making me aware of these issues.

Hope this helps,

rulk.


----------------------
Creating the database.
----------------------


Method One - Using the old server.conf

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.


Method Two - You created your vehicles using CreateVehicle()

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

2. Open up your main script and under OnScriptLoad() add the following;

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

// Or maybe you did.....
CreateVehicle( 145, 0, Vector( 0, 0, 0 ), 0, 0, 0 );

// Next, Load the sql_create.nut
dofile( sql_create.nut );

// Finally, call the main function from sql_create to iterate your server vehicles.
sql_create();

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.



------------------------
Using the example Script
------------------------

Method One - Adding it to your own script

This example assumes your main script is in the same directory as your server.exe


1. Check the file paths...

2. Under onScriptLoad( ), add the following;

// Load the class
dofile("sunshine/sunshine.nut");

// Load into array 'MyVehicles'
SunshineAutos.LoadDatabase("sunshine/sunshine.db");

// Remember to give me credits :-)
print( "=== Loaded Sunshine Auto's v1.1 - By rulk ===" );

3. Copy and paste all of the code under onPlayerCommand() into your own script.

4. Run the server and jump in-game.



Method Two - Using it independently

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.

Finally....

REMEMBER TO SAVE REGULARY!!
SunshineAutos.SaveDatabase("sunshine/sunshine.db");   
We are all god's children.

Thijn

Mirror updated.

Your script is very well described rulk, it will definitely help new scripters.

KAKAN

2nd thing,,,
// First Create your vehicles
dofile( "CreateVehicles.nut" );
Now there's a function name LoadVehs();
Which have the CreateVehicle thing, now tell me what shall i do? or the script will do itself
oh no

rulk

#18
Quote from: KAKAN on Sep 11, 2015, 05:50 PM2nd thing,,,
// First Create your vehicles
dofile( "CreateVehicles.nut" );
Now there's a function name LoadVehs();
Which have the CreateVehicle thing, now tell me what shall i do? or the script will do itself

// Load your vehicles first
LoadVehs();

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

// Call the main function
sql_create();

@Thijn thank you chap
We are all god's children.

KAKAN

Oh, Actually I was creating the cars after sql_create, so it wasn't working, THANKS, it working NOW!
oh no

rulk

Quote from: KAKAN on Sep 11, 2015, 06:02 PMOh, Actually I was creating the cars after sql_create, so it wasn't working, THANKS, it working NOW!

yay! I'm online for the next hour, so if you need anymore help, just let me know.

rulk
We are all god's children.

KAKAN

Oye!
1 bug:-
on the buycar system, you do not check the money of the player, so i made it, just don't know if it'll work or not
Here it is:-
else if ( cmd == "buycar" )
{
// Lets first establish if your in a vehicle
if ( player.Vehicle == null ) MessagePlayer( ">> Error: you are not in a vehicle.", player );
else
{
// OK, we're in a vehicle, lets get it's instance into a variable.
local vehicle = player.Vehicle;

// Put the IsPurchased property into a variable, so we can access squirrel's VM built in manipulation functions for that data type.
local val = MyVehicles[ vehicle.ID ].IsPurchased;

// First, check its an empty value ( it's available to buy )
if ( ( val == null ) || ( val.len() == 0 ) )
{
if( stats[ player.ID ].Cash >= MyVehicles[ vehicle.ID ].VehiclePrice )
{
// Then Set the value in our array.
MyVehicles[ vehicle.ID ].IsPurchased = player.Name;

// Display whats going on.
MessagePlayer( ">> You have now purchased this vehicle.", player );

//Reduce his money
stats[ player.ID ].Cash -= MyVehicles[ vehicle.ID ].VehiclePrice;
}
else MessagePlayer("You don't have enough money to buy this car.",player);
}

// It's got a value, and is purchased, therefore, not avilable to buy
else MessagePlayer( ">> Error: Vehicle not avilable to purchase.", player );
}
}

Can u check it and tell me the errors?
oh no

Thijn

That would work if your cash is stored in that variable, yes.

KAKAN

Thanks, rulk should add this as player.Cash, so it would work with everyone
oh no

KAKAN

BUMP*
I want that each user can buy only 2 vehicles, how can i do it?
Any examples pl0x
oh no

MacTavish

Quote from: KAKAN on Sep 21, 2015, 06:14 PMBUMP*
I want that each user can buy only 2 vehicles, how can i do it?
Any examples pl0x

Just check player vehiles through mycars function that if player already bought the 2 vehicles then throw a message

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KAKAN

How? I got no idea of doing it.
oh no

rulk

Quote from: Kusanagi on Sep 21, 2015, 06:26 PM
Quote from: KAKAN on Sep 21, 2015, 06:14 PMBUMP*
I want that each user can buy only 2 vehicles, how can i do it?
Any examples pl0x

Just check player vehiles through mycars function that if player already bought the 2 vehicles then throw a message

@kusanagi is right, just alter the MyCars algorithm, like this....

function HowManyCars(player)
{
// Empty string for our output.
local output = "";

// Var to count how many vehicles the player ownes.
local count = 0;
 
// Iterate the array, using a foreach loop.
foreach ( obj in this[ MyArray ] )
{
if ( obj != null )
{
            // Add the object properties to a tmp variable, so we can access squirrel's VM built in manipulation functions for that data type.
              local tmp = obj.IsPurchased;

// Check the value is not null or empty
if ( ( tmp != null ) && ( tmp.len() > 0 ) )
{
// Perform a string comparison, if we get a match, increase our counter.
if ( tmp.find( player ) != null ) count++;
}
}
}

// return count as integer.
return count;
}
We are all god's children.

SAzEe21


FinchDon

@KAKaN First Make A table VC in Which playername and count
on register iñsert into vc values nàme 0
then make GetVC and SetVC functions and add this on Buycar

else if ( GetVC( player ) >= 2  ) PrivMessage( player, "You already have two cars " );
else
{
SetVC( player, GetVC( player ) + 1 );
}

and same in. sell car -1
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )