Stopping player fom exiting car
#1

pawn Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    PutPlayerInVehicle(playerid,vehicleid,GetPlayerVehicleSeat(playerid));
    Mesaj(playerid,-1,"HEY, don't leave the car.");
    return 1;
}
But this only puts him back after he opens the door and steps out, i need something to stop him from opening the door in the first place.
Reply
#2

Use the callback OnPlayerKeyStateChange and check for the key KEY_SECONDARY_ATTACK.
Reply
#3

Isn't secondary attack right click ?
Reply
#4

No. It's actually 'F' or 'Enter'
Reply
#5

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_SECONDARY_ATTACK)
    {
   
    }
}
But what should i use to stop him from opening the door ?
Reply
#6

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if ( (newkeys & KEY_SECONDARY_ATTACK) && IsPlayerInAnyVehicle(playerid) )
    {
        PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), GetPlayerSeat(playerid));
    }
}
Try that. I don't think it'll work but you can try it
Reply
#7

thanks, will test now.
Reply
#8

NO, it dosen't work.I think its because you're getting the ID of the vehicle when the player already left the vehicle.
Reply
#9

Try getting the nearest vehicle ID, I'll find you the stock...

pawn Code:
stock GetNearestVehicle(playerid, Float:dis)
{
    new Float:X, Float:Y, Float:Z;
    if(GetPlayerPos(playerid, X, Y, Z))
    {
        new vehicleid = INVALID_VEHICLE_ID;
        for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
        {
            if(GetVehiclePos(v, VX, VY, VZ))
            {
                VX -= X, VY -= Y, VZ -= Z;
                temp = VX * VX + VY * VY + VZ * VZ;
                if(temp < dis) dis = temp, vehicleid = v;
            }
        }
        dis = floatpower(dis, 0.5);
        return vehicleid;
    }
    return INVALID_VEHICLE_ID;
}
Paste that on the bottom of your code... Then change the code to
pawn Code:
if ( (newkeys & KEY_SECONDARY_ATTACK) && IsPlayerInAnyVehicle(playerid) )
    {
        new nearest = GetNearestVehicle(playerid, 5.0);
        PutPlayerInVehicle(playerid, nearest, GetPlayerSeat(playerid));
    }
The seat however, I don't know how to get out of it...
Reply
#10

pawn Code:
// Top of your script
new
    g_PlayerVehicle[MAX_PLAYERS],
    g_SeatID[MAX_PLAYERS]
;


// OnPlayerStateChange
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    // Store vehicle's ID
    if ((newstate == PLAYER_STATE_DRIVER) || (newstate == PLAYER_STATE_PASSENGER))
    {
        g_PlayerVehicle[playerid] = GetPlayerVehicleID(playerid);
        g_SeatID[playerid] = GetPlayerVehicleSeat(playerid);
    }

    // Making not possible to get out of the car
    if ((newstate == PLAYER_STATE_ONFOOT) && ((oldstate == PLAYER_STATE_DRIVER) || (oldstate == PLAYER_STATE_PASSENGER)))
        PutPlayerInVehicle(playerid, g_PlayerVehicle[playerid], g_SeatID[playerid]);

    // Return
    return 1;
}
This should work



EDIT: Sorry, I thought you want to put player back in vehicle after he get outs.
This code should work:

pawn Code:
// Top of your script
new
    g_PlayerVehicle[MAX_PLAYERS],
    g_SeatID[MAX_PLAYERS]
;

forward PutPlayerBackInVehicle(playerid);
public  PutPlayerBackInVehicle(playerid)
{
    PutPlayerInVehicle(playerid, g_PlayerVehicle[playerid], g_SeatID[playerid]);

    return 1;
}


// OnPlayerStateChange
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    // Store vehicle's ID
    if ((newstate == PLAYER_STATE_DRIVER) || (newstate == PLAYER_STATE_PASSENGER))
    {
        g_PlayerVehicle[playerid] = GetPlayerVehicleID(playerid);
        g_SeatID[playerid] = GetPlayerVehicleSeat(playerid);
    }

    // Return
    return 1;
}


// OnPlayerKeyStateChange
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    // Making not possible to get out of the car
    if (IsPlayerInAnyVehicle(playerid))
    {
        if (newkeys & KEY_SECONDARY_ATTACK)
        {
            SetTimerEx("PutPlayerBackInVehicle", 100, false, "i", playerid);
        }
    }

    // Return
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)