Sunshine max car ?

Started by KrOoB_, Jun 20, 2018, 10:42 PM

Previous topic - Next topic

KrOoB_


I am using the SunShine Autos system, but there is no purchase limit and I could only find


Quotefunction 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;
}

[KM]Helathien

#1
Bro, What you actually do is just make a playerclass.
class PlayerStats
{
Cars = 0;
}

After That you should also update your database for example;
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.
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
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.