SA-MP Forums Archive
[Tutorial] [TUT] How to make a car enterable for a certain name only? - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] [TUT] How to make a car enterable for a certain name only? (/showthread.php?tid=91130)



[TUT] How to make a car enterable for a certain name only? - GTA_Rules - 12.08.2009

Hi,

Since I'm bored, I thought I'd make a little tutorial about how you can make a car enterable for one person only.

First off, we put a variable on top of your script:

pawn Код:
new Matthias; // The name is not really important, this can be anything you want.
Secondly, we place the car in the server, and use Matthias = AddStaticVehicle(...), so the server knows this is the car only I can enter.
If you don't know how to use AddStaticVehicle, check this. This needs to be put in OnGameModeInit or OnFilterScriptInit, depending on what you're using.

pawn Код:
Matthias = AddStaticVehicle(451,1890.1632,1989.1708,13.4920,179.9223,6,6); // This will spawn a turismo in the parking lot in LV
Now this is where the hard part begins, we use OnPlayerStateChange, to check if the player enters a car.

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;
}
It's simple as that! If you have done everything as described above, you will have a car in your server which only a player with the name 'Matthias' can enter. Of course you will have to edit this a bit so it fit's nice into your gamemode.
The entire code:

pawn Код:
// On top of your script:

new Matthias;

// In OnGameModeInit or OnFilterScriptInit

Matthias = AddStaticVehicle(451,1890.1632,1989.1708,13.4920,179.9223,6,6);

// Outside other functions

public OnPlayerStateChange(playerid, newstate, oldstate)
{
  new PlayerName[24];
  GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

  if(newstate == PLAYER_STATE_DRIVER)
  {
   new Vehicle = GetPlayerVehicleID(playerid);
   if(Vehicle == Matthias)
   {
     if(strcmp(PlayerName,"Matthias",true))
     {
      RemovePlayerFromVehicle(playerid);
      SendClientMessage(playerid, 0x33AA33AA, "I'm sorry, but this car has been reserved for Matthias");
     }
   }
  }
  return 1;
}
I hope this helped you,
Matthias


Re: [TUT] How to make a car enterable for a certain name only? - extra - 12.08.2009

Good job! This is really usefull


Re: [TUT] How to make a car enterable for a certain name only? - GTA_Rules - 12.08.2009

Thanks


Re: [TUT] How to make a car enterable for a certain name only? - James_Alex - 12.08.2009

nice


Re: [TUT] How to make a car enterable for a certain name only? - DauerDicht - 12.08.2009

Nice, and how can it make parkable and lockable?


Re: [TUT] How to make a car enterable for a certain name only? - GTA_Rules - 12.08.2009

Quote:
Originally Posted by DauerDicht
Nice, and how can it make parkable and lockable?
Parkable?
For lockable: https://sampwiki.blast.hk/wiki/Function:...aramsForPlayer


Re: [TUT] How to make a car enterable for a certain name only? - [MeTalgEaR] - 12.08.2009

excuse me but i do not under stand this part:
if the player name matthias is true why does it remove him from the vehicle should it remove if the name amtthias is false? thx for ur help it helped alot


Re: [TUT] How to make a car enterable for a certain name only? - dice7 - 12.08.2009

Because string compare is stupid and returns true if the strings don't match.
That's why you use on commands strcmp("/lol", cmdtext) == 0, so the cmd will execute if strcmp is false


Re: [TUT] How to make a car enterable for a certain name only? - [MeTalgEaR] - 12.08.2009

owwwwww thxxx mate


Re: [TUT] How to make a car enterable for a certain name only? - Vichuzz - 13.08.2009

Nice work Matt..this is useful for admins!