Making it so players can't exit vehicles?
#1

How to make it so players can't leave a car, I'm making a minigame / event system for my server and don't want players to be able to exit the cars when playing, Can't figure it out.
Reply
#2

I think the only way to do this is using the function PutPlayerInVehicle under OnPlayerExitVehicle. Using TogglePlayerControllable freezes the player entirely
Reply
#3

Quote:
Originally Posted by TheLeech
Посмотреть сообщение
How to make it so players can't leave a car, I'm making a minigame / event system for my server and don't want players to be able to exit the cars when playing, Can't figure it out.
I used this in my server, just figure it out. ( I dont know if it will work to you)

Код:
#define REMOVETYPE_EXIT_VEHICLE 	1

stock RemoveFromDerby(playerid, removetype = REMOVETYPE_QUIT_SERVER)
{
	new
	    string[ 96 ],
	    timeplayed
	;
	SetVehicleVirtualWorld(pInfo[ playerid ][ VehicleID ], 1);

	dInfo[ VehicleOccupied ][ pInfo[ playerid ][ VehicleID ] ] = false;
	dInfo[ ActivePlayers ]--;
	pInfo[ playerid ][ InDerby ] = false;

	SetPlayerPos(playerid, 0, 0, 0);

	switch(removetype)
	{
	    case REMOVETYPE_QUIT_SERVER:
	    {
	        format(string, sizeof(string), ">> %s(ID: %d) left (%d/%d players)", pInfo[ playerid ][ Name ], playerid, dInfo[ ActivePlayers ]+1, dInfo[ TotalPlayers ]);
			SendClientMessageToAll(0xf3ec13AA, string);

			if(dInfo[ ActivePlayers ] == 1)
			{
			    foreach(Player, i)
			    {
			        if(pInfo[ i ][ InDerby ] == false) continue;
			        GameTextForPlayer(i, "~g~WINNER", 2500, 3);
			        format(string, sizeof(string), ">> %s(ID: %d) wins (position: %d/%d)", pInfo[ i ][ Name ], i, dInfo[ ActivePlayers ], dInfo[ TotalPlayers ]);
					GivePlayerScore(i, 5);
			        break;
				}
				dInfo[ DerbyEnded ] = true;
				SendClientMessageToAll(0xf3ec13AA, string);
				//SetTimer("ResetDerby", 3000, false);
			}
		}
		case REMOVETYPE_EXIT_VEHICLE:
		{
		    timeplayed = gettime() - pInfo[ playerid ][ StartTime ];

			GameTextForPlayer(playerid, "~r~LOST", 2500, 3);
		    format(string, sizeof(string), ">> %s(ID: %d) lost (exit vehicle, position: %d/%d, time: %d seconds)", pInfo[ playerid ][ Name ], playerid, dInfo[ ActivePlayers ]+1, dInfo[ TotalPlayers ], timeplayed);
			SendClientMessageToAll(0xf3ec13AA, string);

			if(dInfo[ ActivePlayers ] == 1)
			{
			    foreach(Player, i)
			    {
			        if(pInfo[ i ][ InDerby ] == false) continue;
			        GameTextForPlayer(i, "~g~WINNER", 2500, 3);
			        format(string, sizeof(string), ">> %s(ID: %d) wins (position: %d/%d)", pInfo[ i ][ Name ], i, dInfo[ ActivePlayers ], dInfo[ TotalPlayers ]);
			        GivePlayerScore(i, 5);
			        break;
				}
				dInfo[ DerbyEnded ] = true;
				SendClientMessageToAll(0xf3ec13AA, string);
				//SetTimer("ResetDerby", 3000, false);
			}
		}
		case REMOVETYPE_IDLE:
		{
      		timeplayed = gettime() - pInfo[ playerid ][ StartTime ];

		    GameTextForPlayer(playerid, "~r~LOST", 2500, 3);
		    format(string, sizeof(string), ">> %s(ID: %d) lost (idle, position: %d/%d, time: %d seconds)", pInfo[ playerid ][ Name ], playerid, dInfo[ ActivePlayers ]+1, dInfo[ TotalPlayers ], timeplayed);
			SendClientMessageToAll(0xf3ec13AA, string);

			if(dInfo[ ActivePlayers ] == 1)
			{
			    foreach(Player, i)
			    {
			        if(pInfo[ i ][ InDerby ] == false) continue;
			        GameTextForPlayer(i, "~g~WINNER", 2500, 3);
			        format(string, sizeof(string), ">> %s(ID: %d) wins (position: %d/%d)", pInfo[ i ][ Name ], i, dInfo[ ActivePlayers ], dInfo[ TotalPlayers ]);
			        GivePlayerScore(i, 5);
			        break;
				}
				dInfo[ DerbyEnded ] = true;
				SendClientMessageToAll(0xf3ec13AA, string);
				//SetTimer("ResetDerby", 3000, false);
			}
		}
		case REMOVETYPE_FELL:
		{
      		timeplayed = gettime() - pInfo[ playerid ][ StartTime ];

		    GameTextForPlayer(playerid, "~r~LOST", 2500, 3);
		    format(string, sizeof(string), ">> %s(ID: %d) lost (fell, position: %d/%d, time: %d seconds)", pInfo[ playerid ][ Name ], playerid, dInfo[ ActivePlayers ]+1, dInfo[ TotalPlayers ], timeplayed);
			SendClientMessageToAll(0xf3ec13AA, string);

			if(dInfo[ ActivePlayers ] == 1)
			{
			    foreach(Player, i)
			    {
			        if(pInfo[ i ][ InDerby ] == false) continue;
			        GameTextForPlayer(i, "~g~WINNER", 2500, 3);
			        format(string, sizeof(string), ">> %s(ID: %d) wins (position: %d/%d)", pInfo[ i ][ Name ], i, dInfo[ ActivePlayers ], dInfo[ TotalPlayers ]);
			        GivePlayerScore(i, 5);
			        break;
				}
				dInfo[ DerbyEnded ] = true;
				SendClientMessageToAll(0xf3ec13AA, string);
				//SetTimer("ResetDerby", 3000, false);
			}
		}
	}
	if(dInfo[ ActivePlayers ] <= 1 || dInfo[ TotalPlayers ] <= 1)
	{
	    dInfo[ DerbyEnded ] = true;
	    foreach(Player, i)
	    {
			if(GetPlayerState( i ) == PLAYER_STATE_SPECTATING) TogglePlayerSpectating(i, false);
			else SetPlayerPos(i, 0, 0, 0);
		}
		SetTimer("ResetDerby", 5000, false);
	}
	else if(dInfo[ ActivePlayers ] > 1)
	{
	    pInfo[ playerid ][ SpectateID ] = INVALID_PLAYER_ID;
		foreach(Player, i)
	 	{
			if(pInfo[ i ][ InDerby ] == false) continue;
	  		else pInfo[ playerid ][ SpectateID ] = i;
		}
		if(pInfo[ playerid ][ SpectateID ] != INVALID_PLAYER_ID)
		{
            TogglePlayerSpectating(playerid, true), PlayerSpectateVehicle(playerid, GetPlayerVehicleID( pInfo[ playerid ][ SpectateID ] ));
			TextDrawShowForPlayer(playerid, gSpecInfo[0]), TextDrawShowForPlayer(playerid, gSpecInfo[1]), TextDrawShowForPlayer(playerid, gSpecInfo[2]);
			UpdateSpecInfo(playerid);
		}
	}
	format(string, sizeof( string ), "Players in derby: ~y~%d/%d", dInfo[ ActivePlayers ], dInfo[ TotalPlayers ]);
	TextDrawSetString(gCounterInfo, string);
	TextDrawShowForAll(gCounterInfo);
}
Reply
#4

I would do something like:

Код:
new inCar = 0;
new playingMiniGame= 0;
Then on method were mini game starts set:

Код:
playingMiniGame = 1;
And check if he's in car. Or if when event starts player is automatically in car set:

Код:
inCar = 1;
Finally OnPlayerExitVehicle check:

Код:
if(playingMiniGame == 1 && inCar == 1){
	SendClientMessage(playerid, 0x00FF00FF, "You can't exit vehicle while on event.");
        return 1;
}
Reply
#5

Just make it like this when the player exits the car the player gets automatically re-spawned much easier
Reply
#6

Quote:
Originally Posted by Xtra
Посмотреть сообщение
Just make it like this when the player exits the car the player gets automatically re-spawned much easier
Respawned?

Do you even think? Simply put the player back in when OnPlayerStateChange occurs, or watch for OnPlayerExitVehicle...
Reply
#7

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Respawned?

Do you even think? Simply put the player back in when OnPlayerStateChange occurs, or watch for OnPlayerExitVehicle...
im actually not talking about the script my above message is misleading lol, if a event is starting they would definitely be a admin so im saying that just respawn the player which exits the vehicle
Reply
#8

Quote:
Originally Posted by TonyII
Посмотреть сообщение
I think the only way to do this is using the function PutPlayerInVehicle under OnPlayerExitVehicle. Using TogglePlayerControllable freezes the player entirely
Well, He can use
PHP код:
Clearplayeranimation(playerid
to easily prevent the player from exiting the vehicle.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)