SA-MP Forums Archive
Vehicles variable - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Vehicles variable (/showthread.php?tid=399608)



Vehicles variable - Armands - 15.12.2012

Hello! I got a problem with variable, which I want to add to multiple cars.
Like this:
PHP код:
new Variable[MAX_VEHICLES];
public 
OnGameModeInIt()
{
      
Variable[1] = CreateVehicle(....................................);
      
Variable[2] = CreateVehicle(....................................);
      return 
1;
}
public 
OnPlayerStateChange(playeridoldstatenewstate)
{
      if(
newstate == PLAYER_STATE_DRIVER)
      {
             if(
GetPlayerVehicleID(playerid)==Variable[all the cars with Variable]) // I just want to not write this line with Variable[number, for example - 1] for multiple times, I want this in one line like I wrote under if(newstate == ....)
             
{
                    
// Function
             
}
      }

I hope you will help me, thanks!


Re: Vehicles variable - FTLOG - 15.12.2012

If i understand what you mean, check out this:

Код:
public OnPlayerStateChange(playerid, oldstate, newstate) 
{ 
      if(newstate == PLAYER_STATE_DRIVER) 
      { 
             for( new i = 0; i < sizeof( Variable ); ++i ) { // Loop for all the vehicles assigned to 'Variable' array
             
                     if( GetPlayerVehicleID( playerid ) == Variable[ i ] )
                     { 
                            // Function 
                     }
              } 
      } 
}
This is not the most efficient method though, you should experiment more for efficiency. Hope i helped.


Re: Vehicles variable - Armands - 15.12.2012

Thanks, it works!!!


Re: Vehicles variable - Armands - 15.12.2012

On more question. How can I get the ID of the vehicle, that just spawned by CreateVehicle in the script?


Re: Vehicles variable - FTLOG - 15.12.2012

Код:
new vehicle_id = CreateVehicle( 411, 0.0, 0.0, 0.0, 0.0, -1, -1, -1 );
printf( "%i", vehicle_id ); // Will print the vehicle id that we created above
This example shows how it's done with local variable, but you can also asign IDs to global variables.


Re: Vehicles variable - Armands - 15.12.2012

Thanks, everything works!