Stop player from entering vehicle
#1

How can I do that? I know there's a function OnPlayerEnterVehicle, but I need to stop player from entering that vehicle, any suggestions?
Reply
#2

Use RemovePlayerFromVehicle.
Reply
#3

Quote:
Originally Posted by maramizo
View Post
Use RemovePlayerFromVehicle.
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    RemovePlayerFromVehicle(playerid);
    return 1;
}
- not working

I can't use OnPlayerUpdate since I want to stop him from entering it, not removing him, simply, when player press F or RETURN it won't enter vehicle, instead he will be standing still
Reply
#4

Yep, adding RemovePlayerFromVehicle under OnPlayerEnterVehicle won't work at all.


I recommend using SetVehicleParamsForPlayer under OnVehicleStreamIn. Example:

pawn Code:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(vehicleid == YourVehicleIDHere) // if the vehicle that streams in is the vehicle you want to lock (Change YourVehicleIDHere)
    {
        if(forplayerid == ThePlayerIDHere) // if the player that the vehicle streams in for is the player you want to stop from entering the vehicle (Change ThePlayerIDHere)
        {
            SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1); // lock the doors for the player
        }
    }
    return 1;
}
Reply
#5

RemovePlayerFromVehicle would only work if he's already inside the vehicle.
I think he wants to know how to prevent anyone to even enter the vehicle, like it would be as if the doors are locked.

Everytime a player logs in, you can process all vehicles and set the doors locked/unlocked based on the ownership of the vehicle.

Pseudocode:
Code:
// Loop through all vehicles
for vid = 0 to 1999
	// Check if this vehicle exists
	if (VehicleData[vid][VehicleExists] == 1)
		// Loop through all players
		for playerid = 0 to MAX_PLAYERS
			// Check if this player is connected
			if IsPlayerConnected(playerid)
				// Check if this player is the owner
				if (GetPlayerName(playerid) == VehicleData[vid][Owner])
					// Unlock the doors for the owner
					SetVehicleParamsForPlayer(vid, playerid, 0, 0)
				else
					// Lock the doors for every other player
					SetVehicleParamsForPlayer(vid, playerid, 0, 1)
				endif
			endif
		next
	endif
next
Reply
#6

Quote:
Originally Posted by AmigaBlizzard
View Post
RemovePlayerFromVehicle would only work if he's already inside the vehicle.
I think he wants to know how to prevent anyone to even enter the vehicle, like it would be as if the doors are locked.

Everytime a player logs in, you can process all vehicles and set the doors locked/unlocked based on the ownership of the vehicle.

Pseudocode:
Code:
// Loop through all vehicles
for vid = 0 to 1999
	// Check if this vehicle exists
	if (VehicleData[vid][VehicleExists] == 1)
		// Loop through all players
		for playerid = 0 to MAX_PLAYERS
			// Check if this player is connected
			if IsPlayerConnected(playerid)
				// Check if this player is the owner
				if (GetPlayerName(playerid) == VehicleData[vid][Owner])
					// Unlock the doors for the owner
					SetVehicleParamsForPlayer(vid, playerid, 0, 0)
				else
					// Lock the doors for every other player
					SetVehicleParamsForPlayer(vid, playerid, 0, 1)
				endif
			endif
		next
	endif
next
exactly, I just didn't know that there's a function to lock doors so I wanted to do it on my own :P anyway, how can I show that little message box at the left of the screen, not dialog box, but some kind of message box, I hope you know what I mean

edit: + I have this code, but since I'm testing it on local machine without any players I hav eno idea if it is working, but it should lock/unlock doors when I use command /dvere, however I can enter vehicle even if I locked it, but I can't test it with other players since I'm testing it on local machine... soo what I think this is doing is that it will lock doors for everyone except me, am I right? I have same code but with engine and it is working for turning it off/on, + how does alarm works? I've never seen it before

pawn Code:
if(!strcmp("/dvere", cmdtext))
    {
        if(GetPlayerVehicleID(playerid) != 0)
        {
            new motor, svetla, alarm, dvere, kapota, kufor, obj;
            GetVehicleParamsEx(GetPlayerVehicleID(playerid), motor, svetla, alarm, dvere, kapota, kufor, obj);
            if(dvere == 0)
                dvere = 1;
            else
                dvere = 0;
            SetVehicleParamsEx(GetPlayerVehicleID(playerid), motor, svetla, alarm, dvere, kapota, kufor, obj);
        }
        return 1;
    }
Reply
#7

Quote:
Originally Posted by AmigaBlizzard
View Post
Everytime a player logs in, you can process all vehicles and set the doors locked/unlocked based on the ownership of the vehicle.
Actually, that wouldn't work because

Quote:
Originally Posted by Wiki
Note: From 0.3 you will have to re-apply this function when OnVehicleStreamIn is called!
while this refers to SetVehicleParamsForPlayer. Otherwise, a player will simply be able to enter any vehicle streams in for him/her after few seconds from logging in ('Spawning' I guess).

Hence the following code wouldn't work at all
pawn Code:
public OnPlayerSpawn(playerid) // or OnPlayerConnect
{
    for(new i = 0; i < MAX_VEHICLES; i ++)
    {
        print("executing");
        SetVehicleParamsForPlayer(i, playerid, 0, 1);
    }
    return 1;
}
But, this code would work perfectly
pawn Code:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
    return 1;
}
Quote:
Originally Posted by SEnergy
View Post
it should lock/unlock doors when I use command /dvere, however I can enter vehicle even if I locked it
Just use the method I posted above with SetVehicleParamsForPlayer and OnVehicleStreamIn.



Quote:
Originally Posted by SEnergy
View Post
how can I show that little message box at the left of the screen, not dialog box, but some kind of message box, I hope you know what I mean
You gotta create textdraws.
Reply
#8

Here, try this:
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
     if(newstate == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid) == VEHICLE_ID)
          RemovePlayerFromVehicle(playerid);

     return 1;
}
And dont forget to replace VEHICLE_ID with yours!
Reply
#9

Quote:
Originally Posted by Universal
View Post
Here, try this:
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
     if(newstate == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid) == VEHICLE_ID)
          RemovePlayerFromVehicle(playerid);

     return 1;
}
And dont forget to replace VEHICLE_ID with yours!
That would remove him from the vehicle, but:

Quote:
Originally Posted by SEnergy
View Post
I want to stop him from entering it, not removing him, simply, when player press F or RETURN it won't enter vehicle, instead he will be standing still
Reply
#10

pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
      if(vehicleid == VEHICLE_ID && ANY_OTHER_STATEMENT)
           TogglePlayerControllable(playerid, true);
      return 1;
}
You can also use SetVehicleParamsEx if you want, but then you should make another if statement, or maybe else which unlocks the vehicle.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)