Vehicles variable
#1

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!
Reply
#2

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.
Reply
#3

Thanks, it works!!!
Reply
#4

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

Код:
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.
Reply
#6

Thanks, everything works!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)