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 (https://www.scribd.com/doc/311209876/Sunshine-Autos-Method1)
Method Two - You created your vehicles using CreateVehicle() (https://www.scribd.com/doc/311210090/Sunshine-Autos-Method2)
Using the example Script (https://www.scribd.com/doc/311210125/SUNSHINE-AUTOS-Example-Script)
DOWNLOAD (http://files.thijn.ovh/download/582ed36e512d9f2923bbf88b2b41cf22/sunshine.zip)
Good Work
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
NICE Work!!
Thanks for the MIRROR, the site he gave was not working
Another quick question about your sql_create script. You use "100,000" as price, which isn't an integer.
Hmm, The database is not working
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
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.
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
Hey
@rulk ,
go through your private messages please.
I have tried rulk , still then not working
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
I have vehicles using function.nut, how can i use it, I don't have any vehicles using server.conf file.
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();
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");
Mirror updated.
Your script is very well described rulk, it will definitely help new scripters.
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
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
Oh, Actually I was creating the cars after sql_create, so it wasn't working, THANKS, it working NOW!
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
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?
That would work if your cash is stored in that variable, yes.
Thanks, rulk should add this as player.Cash, so it would work with everyone
BUMP*
I want that each user can buy only 2 vehicles, how can i do it?
Any examples pl0x
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
How? I got no idea of doing it.
Quote from: Kusanagi on Sep 21, 2015, 06:26 PMQuote 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;
}
Awesome broo..
@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
Quote from: FinchDon on Sep 22, 2015, 01:46 AM@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
@FinchDon you know
@rulk made this system on arrays so why you want someone to use and SQLite query again
Quote from: rulk on Sep 21, 2015, 07:07 PMQuote from: Kusanagi on Sep 21, 2015, 06:26 PMQuote 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;
}
So i need to use somthing like this?
if( HowManyCars(player) >= 2 ) MessagePlayer("You have enough vehicles",player);
??
and yes, In the sell car system, I want the IsPurchased variable be null(just like in start)
So is this the correct way to use this?
MyVehicle[ vehicle.ID ].IsPurchased = null;
EDIT:-
I used this, but it isn't working :(
else if ( cmd == "sellcar" )
{
// A paremeter checks before we can transfer the 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 they own that vehicle.
if ( val == player.Name )
{
// OK, now Set the value in our array.
MyVehicles[ vehicle.ID ].IsPurchased == null;
//Return him the money
player.Cash += MyVehicles[ vehicle.ID ].VehiclePrice/2
// Display whats going on.
MessagePlayer( ">> You have now sold this vehicle", player );
}
// They do not own that vehicle.
else MessagePlayer( ">> Error: you do not own this vehicle.", player );
}
}
The problem is:- When i type /sellcar, it shows you have sold this vehicle, my money also increases, but the car is not sold
try
MyVehicles[ vehicle.ID ].IsPurchased = "";
because VC-MP's null returns nullx0000000 or something similar.
Hmm, I'll
Doesn't work, same problem as before
you do realise that you've put double "==" in the example you posted ??
It should be,
MyVehicles[ vehicle.ID ].IsPurchased = "";
Thanks, working now!
Updated to v1.1 -
Now only saves the vehicles you have purchased/Sold/Shared etc from the array to the database.
Thanks to
@Thijn for the suggestion and
@KAKAN for pointing it out.
Download link is in the first post. ( Example script included. )
Hope you enjoy.
rulk
Updated again
Sorry for any inconvenience
No problem.
Nice work.
I dont know what i do wrong but i have tried Method One - Using the old server.conf and followed the steps.
My vehicles are in server config like this: <Vehicle model="191" x="-542.1738" y="792.2469" z="97.0344" angle="336.3952" col1="0" col2="0" world="1"/>
on scriptload i have added: // Load the class
dofile("scripts/sunshine.nut");
// Load into array 'MyVehicles'
SunshineAutos.LoadDatabase("scripts/sunshine.db");
print( "=== Loaded Sunshine Auto's v1.1 - By rulk ===" );
and the Cmd's are in my main.nut
Everything is working exept after import the Sql.blah the Vehicles are not written to the db. it stays empty.
Did i miss something else?
hya
@Ron Have you run sql_create.nut to create blah.sql which contains a list of all the vehicles in your server?
yes i followed the steps of Method 1 and it created this sql.blah. then i imported it into sunshine.db but its emty with no vehicles here a pic.
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.23.210%2Fimages%2Fdatabase.png&hash=6d4a57fd447bd2921512147518a83daf067c34ac)
Hya
@Ron Before you start the following, just check blah.sql has all the necessary 'INSERT INTO' sql statements in it.
assuming it does, try...
1. Delete your existing table, and write changes to the database.
2. Select: file -> import -> database from sql file
3. select blah.sql
4. Answer 'NO' to "Do you want to create a new database file to hold the imported data?"
5. Import complete message box will appear
Sorry rulk, but I recommend one thing, better make a video tutorial which explains the entire process because there are not many who understand you.
hya
@kennedyarzHe wanted to know how to import the file into his database. There are hundreds of database viewers out there, i cant make a video for every one.
just do it your method. so all will have an idea of how to do it, because as explains this very confusing.
To be completely honest, if that's confusing you shouldn't be making a server and just stick to playing.
then you come here to say that it is not confusing? is perfect you? because they think that this topic has both comments and so many questions? of course it is confusing. and by not knowing this I cannot have the knowledge to make a server? There are many experts in the script that are still asking about this method.
:( again empty, i did exactly as you said the message box appeared import succes but still its emty no vehicles there.
all vehicles are written in server.config and load when the server starts. i have the sql_create.nut in the folder were my server.exe is and the server.config. my other scripts are in the folder scripts.
Quote from: Ron on May 01, 2016, 07:16 PM:( again empty, i did exactly as you said the message box appeared import succes but still its emty no vehicles there.
all vehicles are written in server.config and load when the server starts. i have the sql_create.nut in the folder were my server.exe is and the server.config. my other scripts are in the folder scripts.
Read his post again. What does the sql file actually contain?
Also, do you actually load the sql_create.nut file, and are there any vehicles in your server at the time you're loading it?
Yes Thijn i have read :) the sql file when its created contains the following:
CREATE TABLE `MyVehicles` ( `VehicleID` INTEGER, `VehicleModel` TEXT, `VehicleCat` TEXT, `VehiclePrice` INTEGER, `IsPurchased` TEXT, `IsShared` TEXT );
and yes i load the sql_create.nut, ofcourse otherwize i wouldnt have the sql.blah... and yes when i start the server vehycles are there also in console msg vehicles loaded.
as well as thjin said "not if complicated is can not do this without server of the Nations United do surface" my opinion with respect is the truth I don't like the way you expressed.
Quote from: Ron on May 01, 2016, 09:55 PMYes Thijn i have read :) the sql file when its created contains the following:
CREATE TABLE `MyVehicles` ( `VehicleID` INTEGER, `VehicleModel` TEXT, `VehicleCat` TEXT, `VehiclePrice` INTEGER, `IsPurchased` TEXT, `IsShared` TEXT );
and yes i load the sql_create.nut, ofcourse otherwize i wouldnt have the sql.blah... and yes when i start the server vehycles are there also in console msg vehicles loaded.
Load it after 5 seconds. Maybe the vehicles were not created yet.
Hya
@RonA complete blah.sql should look like this
http://pastebin.com/raw/nVGTybrW
if it does, the script has worked. the rest is down to you to import it into your database.
Thank you
@rulk, i will try again. if it doesnt work,, i guess i can do it manualy instead with this blag.sql example then.
you can, but is that what your blah.sql looks like ?
@Ronalso, in
server.cfg Make the
xmlconf plugin first in the list.
Quote from: rulk on May 02, 2016, 08:13 AMyou can, but is that what your blah.sql looks like ?
No rulk, only the top part is there, not the vehicleslist like in your example.
And the xmlconf plugin allready was first in list.
but i will give it another shot today :) otherwize ill do it manualy, thanks a lot for you patiencce!
I have added step-by-step installation guides with screenshots. Hopefully it helps.
-------------------------
STEP-BY-STEP INSTALL GUIDES
-------------------------
Method One - Using the old server.conf (https://www.scribd.com/doc/311209876/Sunshine-Autos-Method1)
Method Two - You created your vehicles using CreateVehicle() (https://www.scribd.com/doc/311210090/Sunshine-Autos-Method2)
Using the example Script (https://www.scribd.com/doc/311210125/SUNSHINE-AUTOS-Example-Script)
Did it manualy now and it works :) thnx
And rulk i looked at your screenshots manual and i do it exactly the same as you show, but it doesnt load the vehicles in sql.blah
and my vehicles are in server.config (old way).
anyway thanks again it works now :)
fucking mother cows do everything as this in the script but when I try to open the database of sunshine with this browser opens it me blank, not is that it happens, but I think it is the browser but other databases if you open them. before this example if it opened. What happened to the old sunshine? This is empty...
@kennedyarz I haven't changed the database, It's meant to be empty. You need to populate it yourself using
sql_create.nut.See the documentation...
-------------------------
STEP-BY-STEP INSTALL GUIDES-------------------------
Method One - Using the old server.conf (https://www.scribd.com/doc/311209876/Sunshine-Autos-Method1)
Method Two - You created your vehicles using CreateVehicle() (https://www.scribd.com/doc/311210090/Sunshine-Autos-Method2)
Using the example Script (https://www.scribd.com/doc/311210125/SUNSHINE-AUTOS-Example-Script)
Error. When I open the browser I choose Import. then it displays a message and I option of duress in 'NO' then says "BROWSER. EXE STOPPED WORKING"
What does your blah.sql contain?
CREATE TABLE `MyVehicles` (
`VehicleID` INTEGER,
`VehicleModel` TEXT,
`VehicleCat` TEXT,
`VehiclePrice` INTEGER,
`IsPurchased` TEXT,
`IsShared` TEXT
);
In that case read the install guide.
help me in line for team views
This does not know that answer. but as he says "it is easy"
@rulk I haven't used your script but I have taken the time to read threw and I find it very interesting.
As well as your scripting methods,. This is an interesting release.
This is not a support forum,.
@kennedyarzPlease respect author's post when needing help. A kind thing to do is create a support forum and message the content owner in PM that you could use there assistance,. and if the PM does not work just add a link to this post instead.
Also kennedyarz this is not something a rookie plays with or someone like myself technically, Yet I have been scripting for quite some time now. I suggest for you to take the time to read the scripts and study them understand how they work. Learn from rulk. This is not something you just add to a server due to either the server you own sucks and you want to be a boss server owner, This is more of a script you add when your server is successful and you want to treat your player base. Technically this script is pointless without a really decent player base.
@rulk I am glad you have taken the time to create this release for other scriptwriters to be capable to read and understand(if they actually will instead of just attempting to add it to a random server work^^^).
Honestly I do not see myself using this at all instead just reading and understanding.
~*Thank You
i have a problem with this goddamn script
i have created the sql file thing it has 30 kb
whenever when i enter a car, and type /car nothing happens, and prints a error in to console
i entered a stinger, and typed /car
error:
AN ERROR HAS OCCURED [the index '113' does not exist]
line 33
its: local output = @"Model: " + MyVehicles[ vehicle.ID ].VehicleModel + " - " +
i cant get it to working :( i already readed your installation guide, but i cant make it work
Well, dump the .sql file to a database file and load that database. Usually, any SQLite viewer/editor can do this work.
Click on the import option, then select .sql as the option and locate the sql file.
still the same error
i mean, how to import and then load to that database file?
nvm, i fixed myself
THX!!!
Found a exploit in your script in the /buycar command
Players can buy car, but without money.
if ( cmd == "buycar" )
{
// Lets first establish if your in a vehicle
if ( player.Vehicle == null ) MessagePlayer( "[#ff0000]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 ) )
{
// Then Set the value in our array.
MyVehicles[ vehicle.ID ].IsPurchased = player.Name;
// The array has been updated, so set our value to 'true' so we can save it to the database.
MyVehicles[ vehicle.ID ].Update = true;
// Display whats going on.
MessagePlayer( "[#ff0000]You have now purchased this vehicle.", player );
}
// It's got a value, and is purchased, therefore, not avilable to buy
else MessagePlayer( "[#ff0000]Error: Vehicle not avilable to purchase.", player );
}
}
there isnt any money checks , so a player can buy any car with 0$ in their pocket
fixed
if ( cmd == "buycar" )
{
// Lets first establish if your in a vehicle
if ( player.Vehicle == null ) MessagePlayer( "[#ff0000]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 ( player.Cash < MyVehicles[vehicle.ID].VehiclePrice ) {
PM("[#ff0000]Not enought cash",player)
return false;
}
if ( ( val == null ) || ( val.len() == 0 ) )
{
// Then Set the value in our array.
MyVehicles[ vehicle.ID ].IsPurchased = player.Name;
// The array has been updated, so set our value to 'true' so we can save it to the database.
MyVehicles[ vehicle.ID ].Update = true;
player.Cash -= MyVehicles[vehicle.ID].VehiclePrice;
// Display whats going on.
MessagePlayer( "[#ff0000]You have now purchased this vehicle.", player );
}
// It's got a value, and is purchased, therefore, not avilable to buy
else MessagePlayer( "[#ff0000]Error: Vehicle not avilable to purchase.", player );
}
}
Quote from: Kewun on Aug 21, 2016, 05:48 PMfixed
if ( cmd == "buycar" )
{
// Lets first establish if your in a vehicle
if ( player.Vehicle == null ) MessagePlayer( "[#ff0000]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 ( player.Cash < MyVehicles[vehicle.ID].VehiclePrice ) {
PM("[#ff0000]Not enought cash",player)
return false;
}
if ( ( val == null ) || ( val.len() == 0 ) )
{
// Then Set the value in our array.
MyVehicles[ vehicle.ID ].IsPurchased = player.Name;
// The array has been updated, so set our value to 'true' so we can save it to the database.
MyVehicles[ vehicle.ID ].Update = true;
player.Cash -= MyVehicles[vehicle.ID].VehiclePrice;
// Display whats going on.
MessagePlayer( "[#ff0000]You have now purchased this vehicle.", player );
}
// It's got a value, and is purchased, therefore, not avilable to buy
else MessagePlayer( "[#ff0000]Error: Vehicle not avilable to purchase.", player );
}
}
i forgot a little thing, use MessagePlayer instead of PM because in my script i use PM created function.
also, when i saved custom vehicles, in sql browser, their names are null(0x0000000000) ;c
Quote from: Kewun on Aug 30, 2016, 05:01 AMalso, when i saved custom vehicles, in sql browser, their names are null(0x0000000000) ;c
That's because GetVehicleModel doesn't return custom vehicle's name. You need to create your own function and modify the script.
dont we need the functionOnplayerEnterVehicle ??
anyone knows how to add a vehicle to sunshine database when the vehicle is new and not in database?
i would need a command for this, because im adding new vehicles to server. so that i dont have to remove the sunshine.db and readingg and players losing cars
if( cmd == "newveh" ){
//Your work...
MyVehicles.push( SunshineAutos(
VehicleID = vehicle.ID,
VehicleModel = vehicle.Model,
VehicleCat = GetVehicleType( vehicle.Model ),
VehiclePrice = 1,
IsPurchased = false,
IsShared = null,
Update = true
);
//Update the database using SunshineAutos.SaveDatabase("sunshine/sunshine.db"); to save the changes.
}
Be sure to check his script before using this. I made this just to give an example. This won't work unless you make the necessary changes.
yeah i ve tested this and im getting VehicleID index does not exist
ill try repair this
if ( cmd == "add" )
{
if (!ReadIniBool("stats.ini","admin",player.UID2))
{
PM("nope",player)
return false;
}
if(!player.Vehicle)
{
PM("[#ff0000]You must be in car without stats in /car to add it",player)
return false;
}
SunshineAutos.LoadDatabase("sunshine/sunshine.db"); // getting error here!!!!!!!!!!
MyVehicles.push( SunshineAutos(
VehicleID = player.Vehicle.ID,
VehicleModel = player.Vehicle.Model,
VehicleCat = GetVehicleType( player.Vehicle.Model ),
VehiclePrice = rand()%100000,
IsPurchased = false,
IsShared = null,
Update = true
));
SunshineAutos.SaveDatabase("sunshine/sunshine.db");
PM("[#00ff00]Vehicle ID: "+player.Vehicle.ID+" pushed to database",player)
}
after this im getting
AN ERROR HAS OCCURED [trying to modify a class that has already been instantiated]
on line sunshineautos.loaddatabase
i commented it on code
and car doesnt get added to databse
note im noob in sqlite things
Quote from: Kewun on Oct 28, 2016, 08:32 PM...
after this im getting
AN ERROR HAS OCCURED [trying to modify a class that has already been instantiated]
on line sunshineautos.loaddatabase
i commented it on code
and car doesnt get added to databse
note im noob in sqlite things
class Test
{
var0 = 24
}
// Ok. No instance of Test exists so far
test.rawnewmember("var1", 82);
// Make an instance of Test
local t = Test()
// Error. I've already created instances of Test. I can't modify it now
test.rawnewmember("var2", 127);
You're probably modifying a class in LoadDatabase() function based on the information from the database. Such behavior is not allowed.
From your command:-
SunshineAutos.LoadDatabase("sunshine/sunshine.db"); // getting error here!!!!!!!!!!
The database is already loaded. You can't do it again. Remove that line, its no longer needed. you can use SaveDatabase instead( you must do it after creating the vehicle, not before. )
@. , he probably won't understand you( I guess so. )
yea but when i add vehicle ussing this
https://forum.vc-mp.org/?topic=1177.0
It gets in the sunshine db some how oor bugged and the database messes up, car names are messed, pcj is sanchez etc and random prices
i dont know how to fix it
Quote from: Kewun on Oct 29, 2016, 07:12 AMyea but when i add vehicle ussing this
https://forum.vc-mp.org/?topic=1177.0
It gets in the sunshine db some how oor bugged and the database messes up, car names are messed, pcj is sanchez etc and random prices
i dont know how to fix it
You are saving the vehicle with different structure between the two databases. The database used in "Sunshine's Auto" is different from that used in another script.
so how can I fix this? Putting
SaveDatabase("sunshine/sunshine.db")
Before
MyVehicles.push( SunshineAutos(
VehicleID = player.Vehicle.ID,
VehicleModel = player.Vehicle.Model,
VehicleCat = GetVehicleType( player.Vehicle.Model ),
VehiclePrice = rand()%100000,
IsPurchased = false,
IsShared = null,
Update = true
));
Put it after that. Atleast think of it before posting. Why are you saving the database before you've edited it?
Its like, opening your script, saving it( with no edits done yet. ) and then editing and closing. See? You saved nothing? That thing is the same.
fuck, i cant fix it, too hard for me, im getting the index VehicleID doesnt exist error
can you fix this for me and give me the full command please?
simply u didnt defined VehicleID
fixed
but another problem popped up
i add a car using /addcar carmodel colr1 colr2
works fine
but when ido /savecar, it saves in sunshine database
server restart - bam
vehicle names messed up, police vehicle is esperanto, some other police vehicle is sanchez, stallion is banshee
how i can fix this?
Try This In It Too
function onPlayerEnterVehicle( player, veh, isPassenger )
{
local vehicle = player.Vehicle;
local output = @"Model: " + MyVehicles[ vehicle.ID ].VehicleModel + " - " +
"ID: " + MyVehicles[ vehicle.ID ].VehicleID + " - " +
"Type: " + MyVehicles[ vehicle.ID ].VehicleCat + " - " +
"Price: " + MyVehicles[ vehicle.ID ].VehiclePrice;
local
IsPurchased = MyVehicles[ vehicle.ID ].IsPurchased.len() > 0 ? MyVehicles[ vehicle.ID ].IsPurchased : "For Sale",
IsShared = MyVehicles[ vehicle.ID ].IsShared.len() > 0 ? MyVehicles[ vehicle.ID ].IsShared : "Not Shared";
output = output + " - " + "Owner: " + IsPurchased + " - " + "Sharer: " + IsShared;
MessagePlayer( output, player );
}