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

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Re: Sunshine Auto's - by rulk
« Reply #30, on September 22nd, 2015, 05:49 AM »
Quote from FinchDon on September 22nd, 2015, 02: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

  • Wiki Contributor
  • Posts: 3,343
Re: Sunshine Auto's - by rulk
« Reply #31, on September 22nd, 2015, 06:26 AM »
Quote from rulk on September 21st, 2015, 08:07 PM
Quote from Kusanagi on September 21st, 2015, 07:26 PM
Quote from KAKAN on September 21st, 2015, 07:14 PM
BUMP*
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....

Code: [Select]
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?
Code: [Select]
if( HowManyCars(player) >= 2 ) MessagePlayer("You have enough vehicles",player);
??
Re: Sunshine Auto's - by rulk
« Reply #32, on September 22nd, 2015, 06:51 AM »Last edited on September 22nd, 2015, 07:02 AM
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?
Code: [Select]
MyVehicle[ vehicle.ID ].IsPurchased = null;

EDIT:-
I used this, but it isn't working :(
Code: [Select]
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
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 #33, on September 22nd, 2015, 10:04 AM »
try
Code: [Select]
MyVehicles[ vehicle.ID ].IsPurchased = "";

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

We are all god's children.

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 #36, on September 22nd, 2015, 01:51 PM »
you do realise that you've put double "==" in the example you posted ??

It should be,

Code: [Select]
MyVehicles[ vehicle.ID ].IsPurchased = "";

We are all god's children.

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 #38, on October 27th, 2015, 04:04 PM »
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

  • 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

Eva

  • Full Member
  • Posts: 142
Re: Sunshine Auto's - by rulk
« Reply #40, on May 1st, 2016, 11:17 AM »
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

  • Full Member
  • Shine Jesus Shine
  • Posts: 119
Re: Sunshine Auto's - by rulk
« Reply #41, on May 1st, 2016, 12:44 PM »
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

  • Full Member
  • Posts: 142
Re: Sunshine Auto's - by rulk
« Reply #42, on May 1st, 2016, 03:09 PM »
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

  • Full Member
  • Shine Jesus Shine
  • Posts: 119
Re: Sunshine Auto's - by rulk
« Reply #43, on May 1st, 2016, 03:57 PM »Last edited on May 1st, 2016, 04:04 PM
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

  • Sr. Member
  • Making American Great Again
  • Posts: 334
Re: Sunshine Auto's - by rulk
« Reply #44, on May 1st, 2016, 06:44 PM »
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.

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