OnPlayerStateChange problem
#1

On private cars scripts, One certain person ( example: me ) can get in a car, But if anyone else trys, The server kicks them out the car,
Well for my gamemode, I want to change it so instead of a player name, Its player skins ( I know how to do that ) But its this bit i dont,
OnPlayerStateChange bit, You have your vehicle name that the vehicle its going to work on,
But for 2 cars, You would have to repeat that code, And for 3 cars you would have to do it again,
I have about 100 cars and i dont want to do it that many times, Is there a way,
So i can have 1 OnPlayerStateChange bit, And i dont have to repeat it,
But it works for 100 cars, Incase you dont know what i mean by OnPlayerStateChange bit,
Heres the code

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate) // The OnPlayerStateChange function
{
  new PlayerName[24]; // We create a variable which will contain the players name.
  GetPlayerName(playerid, PlayerName, sizeof(PlayerName)); // We use GetPlayerName to store the name in 'PlayerName'.

  if(newstate == PLAYER_STATE_DRIVER) // Check the new state, since he's the driver in this case, we continue.
  {
   new Vehicle = GetPlayerVehicleID(playerid); // This saves the player's vehicle id into the variable 'vehicle'
   if(Vehicle == Matthias) // We check if the vehicle is the one we don't want everyone to enter
   { // It is, so we continue.
     if(strcmp(PlayerName,"Matthias",true)) // We use strcmp to check if the player who entered the car is the same as 'Matthias'
     {
      RemovePlayerFromVehicle(playerid); // It's not, so we remove the player from the car.
      SendClientMessage(playerid, 0x33AA33AA, "I'm sorry, but this car has been reserved for Matthias"); // And we inform him about why he got removed from the car.
     }
   }
  }
  return 1;
}
This was taken of Matthias tutorial on how to do this,
But anyway thats an example code,

If your still confused ask me and il try my hardest to explain more
Reply
#2

privatevehicle1 and privatevehicle2 and so on or just privatevehicle
Reply
#3

Ok, I know ive done this wrong, But i dont know how to fix it,
So could if you dont mind correct me,

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new PlayerName[24];
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

    if(newstate == PLAYER_STATE_DRIVER)
    {
    new Vehicle = GetPlayerVehicleID(playerid);
    if(Vehicle >= privatevehicle[0] && Vehicle <= privatevehicle[99])
    {
                new playerskin;
                playerskin = GetPlayerSkin(playerid);
                if(playerskin == 280)
                {
        RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid, 0x33AA33AA, "This car is property of San Fierro Police Department");
        }
    }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)