Sunshine Auto's - by rulk

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

Previous topic - Next topic

MacTavish

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

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

Retired VC:MP Player/Scripter :P

KAKAN

Quote from: rulk on Sep 21, 2015, 07:07 PM
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;
}
So i need to use somthing like this?
if( HowManyCars(player) >= 2 ) MessagePlayer("You have enough vehicles",player);??
oh no

KAKAN

#32
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
oh no

rulk

try
MyVehicles[ vehicle.ID ].IsPurchased = "";

because VC-MP's null returns nullx0000000 or something similar.

We are all god's children.

KAKAN

oh no

KAKAN

Doesn't work, same problem as before
oh no

rulk

you do realise that you've put double "==" in the example you posted ??

It should be,

MyVehicles[ vehicle.ID ].IsPurchased = "";

We are all god's children.

KAKAN

oh no

rulk

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
We are all god's children.

KAKAN

oh no

Eva

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?


rulk

hya @Ron
Have you run sql_create.nut to create blah.sql which contains a list of all the vehicles in your server?
We are all god's children.

Eva

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.

rulk

#43
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
We are all god's children.

kennedyarz

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.