How to teleport player to train as passenger, and he wont be able to exit? - 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: How to teleport player to train as passenger, and he wont be able to exit? (
/showthread.php?tid=475629)
How to teleport player to train as passenger, and he wont be able to exit? -
Riwerry - 14.11.2013
How I can make that? NPC train driver come to station, player will get teleported to train as passenger and he wont be able to exit this train? Thx
Re: How to teleport player to train as passenger, and he wont be able to exit? -
Sascha - 14.11.2013
Say we have a variable called "new npctrain" which = the vehicle ID of the train, the NPC is using...
When the train comes in to the station now, you can teleport the player into like that:
Код:
PutPlayerInVehicle(playerid, npctrain, 1);
To prevent him from leaving the train, you can freeze the player
Код:
TogglePlayerControllable(playerid, 0);
To get sure, that there aren't players in the same seat (not sure if that would cause errors, you can use something like that) [NOT TESTET!!]
at the top of your script:
Код:
#define MAX_TRAIN_SEATS 20 //CHANGE THAT TO YOUR CUSTOM WISHES - THE MAX AMOUNTS OF SEATS THAT YOU TRAIN SHOULD HAVE
and then at the function or callback that says you whether the train entered the station:
Код:
new blocked = 0;
for(new n=1; n<=MAX_TRAIN_SEATS; n++)
{
blocked = 0;
for(new i=0; i<GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i) && GetPlayerVehicleID(i) == npctrain)
{
if(GetVehicleSeat(i) == n)
{
blocked = 1;
}
}
}
if(blocked == 0)
{
PutPlayerInVehicle(playerid, npctrain, n);
TogglePlayerControllable(playerid, 0);
}
}