Sunshine max car ?

KrooB

  • Jr. Member
  • WE ARE BEST
  • Posts: 75
Sunshine max car ?
«  »

I am using the SunShine Autos system, but there is no purchase limit and I could only find
Quote
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++;
   }
  }
 }
if( HowManyCars(player) >= 2 )
{
MessagePlayer("You have enough vehicles",player);
}
 // return count as integer.
 return count;
}
we are new because we are watching the old ???

[KM]Helathien

  • Newbie
  • Posts: 22
Re: Sunshine max car ?
« Reply #1,  »Last edited
Bro, What you actually do is just make a playerclass.
Code: [Select]
class PlayerStats
{
Cars = 0;
}

After That you should also update your database for example;
Code: [Select]
function onScriptload()
{
//just add this into your stats database or make a seperate for this
db <- ConnectSQL( "DataBase.db" );
stats <- array( GetMaxPlayers(), null )
QuerySQL(db, "CREATE TABLE IF NOT EXISTS Stats( Name TEXT, KILLS NUMERIC, DEATHS NUMERIC, CASH NUMERIC, CARS NUMERIC )
}

After That just edit your loadstats function example.
Code: [Select]
function LoadStats(player)
{
local q = QuerySQL( "SELECT * FROM Stats WHERE Name = '"+player.Name+"'" )
if ( q )
{
stats[player.ID].Cars = GetSQLColumnData( q, 4)
// just add this into your loadstats functions.
}
}

After That just make it like this
Code: [Select]
if ( stats[player.ID].Cars >= 3  ) MessagePlayer( "[#ff1111]Error: [#ffffff]You can not buy more then 3 cars"  ,player )

This code is untested. But you get the point
Feel free to PM me for any help.
If I am not available on the forum come to VKs Official Server I am usually there.