Keep a player in a vehicle [rep++]
#1

I have a problem, I wan't to be able to detain a player in a vehicle, so that they can't get out. There are ways to do this that I know of, but they are not complete solutions, for example, I could use TogglePlayerControllable, but then they wouldn't be able to look around. I could use OnPlayerChangeState, or OnPlayerExitVehicle, but I have tried both of these, and in the game, the player will exit the vehicle, before being put back in it.

What I wan't to do is make it such that the player can't even open the door, when the press the exit key, nothing should happen.

If someone could show me a way to prevent the exitvehicle animations from being shown at all (ie nothing happens) it would be much appreciated, thanks in advance.
Reply
#2

Try to lock the doors ?
this is impossible
Reply
#3

I should have mentioned I had tried this, but locking the doors doesn't stop a player leaving the vehicle, only entering it.
Reply
#4

Now I didn't really test this but it should work if that doesn't you might need to keep track of the players arrested vehicle ID and put them into that vehicle+seat.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK &&
        PlayerIsArrested[playerid]) PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), GetPlayerVehicleSeat(playerid));
    return 1;
}
@Edit ok further testing indicates that there appears no direct way to actually check when a player gets out of a vehicle looks like your out of luck. (I mean when they initially get out by key press)
Reply
#5

Something like
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
        if (PRESSED(KEY_SECONDARY_ATTACK))
        {
                if (IsPlayerInAnyVehicle(playerid))
                {
                        PutPlayerInVehicle(playerid, vehicleid, 2);
                }
        }
        return 1;
}
Reply
#6

@Wizdo did you not read what I said?
Reply
#7

Thanks much for your replies, guys.

I have figured out a way to do this that is as close to what I want as possible. As Pottus stated, there is no clean, direct way to do this (correct me if I'm wrong, and I wish I was). However I found another technicality that allows me to stop the player getting out of their vehicle.

When the player gets out of the vehicle, as far as the game is concerned, it plays an animation. All I have to do is use the clear animations function, which stops the leave vehicle animation from playing, and then put the player back in the vehicle. This is not seamless, it will cause the player's camera position to be reset (to directly behind the vehicle), but the player will not appear to leave the vehicle, and in theory, the other clients that are streamed in shouldn't notice anything, but I haven't tested that yet.

The solution code:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK &&
        PlayerIsArrested[playerid]){
        ClearAnimations(playerid, 1);
        PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), GetPlayerVehicleSeat(playerid));
    return 1;
}
All this does is stops the animation from being played by the clients, and puts the player back in the vehicle when they try to get out. If there is an even better way to do this (which I doubt there would be), I will happily let you inform me, but for now, I think this will be good enough.

Again, I would give rep to Pottus, as his reply was the most helpful, however I already did that for something else, and the forum won't let me do it again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)