Seatbelt question
#1

Hey.. I made myself a seatbelt command, and I'm trying to do that if the player exit the vehicle and the seatbelt still on him he wont be able to leave, it means he'll stay in the vehicle till he take it off...
any help how can I do it?
btw.. here's my seatbelt command..

pawn Код:
new seatbelt[MAX_PLAYERS];

if(!strcmp(cmd, "/seatbelt", true))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(seatbelt[playerid] == 0)
            {
                seatbelt[playerid] = 1;
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(string, sizeof(string), "* %s Puts on him the seat belt, and a seat belt buckle.", sendername);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            }
            else if(seatbelt[playerid] == 1)
            {
                seatbelt[playerid] = 0;
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(string, sizeof(string), "* %s Unbuckle the seat belt.", sendername);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            }
        }
        return 1;
    }
Reply
#2

Put this above OnPlayerCommandText:

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(seatbelt[playerid])
    {
        PutPlayerInVehicle(playerid, vehicleid, GetPlayerVehicleSeat(playerid));
        SendClientMessage(playerid, 0xAFAFAFAA, "    You must take your seatbelt off first! (/seatbelt)");
    }
    return 1;
}
Reply
#3

I've put it at OnPlayerExitVehicle..
but right now when the player is exit the car with the seatbelt on him it saying that line "you must take your seatbelt .......... " but he's not in the vehicle.. he can go out..
Reply
#4

PHP код:
public OnPlayerExitVehicle(playeridvehicleid)
{
    if(
seatbelt[playerid] == 0)
    {
        
PutPlayerInVehicle(playeridvehicleidGetPlayerVehicleSeat(playerid));
        
SendClientMessage(playerid0xAFAFAFAA"    You must unbuckle your seatbelt off first! (/seatbelt)");
    }
    return 
1;

( Not sure but i guess Emmet's mistake is he placed if(seatbelt[playerid]) instead of if(seatbelt[playerid] == 0)
Reply
#5

put under SCM return 0;
Reply
#6

Quote:
Originally Posted by Qur
Посмотреть сообщение
I've put it at OnPlayerExitVehicle..
but right now when the player is exit the car with the seatbelt on him it saying that line "you must take your seatbelt .......... " but he's not in the vehicle.. he can go out..
Sorry about that, try this:

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(seatbelt[playerid])
    {
        new Float:x, Float:y, Float:z;
        SetPVarInt(playerid, "VehicleExited", vehicleid);
        SetPVarInt(playerid, "VehicleSeat", GetPlayerVehicleSeat(playerid));
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(playerid, x, y, z);
        SetTimerEx("EnterBack", 600, false, "i", playerid);
        SendClientMessage(playerid, 0xAFAFAFAA, "    You must take your seatbelt off first! (/seatbelt)");
    }
    return 1;
}

forward EnterBack(playerid);
public EnterBack(playerid)
{
    PutPlayerInVehicle(playerid, GetPVarInt(playerid, "VehicleExited"), GetPVarInt(playerid, "VehicleSeat"));
    DeletePVar(playerid, "VehicleExited");
    return DeletePVar(playerid, "VehicleSeat");
}
Reply
#7

Thanks now it works fine, but would you just explain to me what you just did? so I can learn..
your first post was easier to understand, but this one a little complicated :P
Reply
#8

Quote:
Originally Posted by Qur
Посмотреть сообщение
Thanks now it works fine, but would you just explain to me what you just did? so I can learn..
your first post was easier to understand, but this one a little complicated :P
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(seatbelt[playerid])
    {
        new Float:x, Float:y, Float:z;
        SetPVarInt(playerid, "VehicleExited", vehicleid);
        SetPVarInt(playerid, "VehicleSeat", GetPlayerVehicleSeat(playerid));
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(playerid, x, y, z);
        SetTimerEx("EnterBack", 600, false, "i", playerid);
        SendClientMessage(playerid, 0xAFAFAFAA, "    You must take your seatbelt off first! (/seatbelt)");
    }
    return 1;
}

forward EnterBack(playerid);
public EnterBack(playerid)
{
    PutPlayerInVehicle(playerid, GetPVarInt(playerid, "VehicleExited"), GetPVarInt(playerid, "VehicleSeat"));
    DeletePVar(playerid, "VehicleExited");
    return DeletePVar(playerid, "VehicleSeat");
}
As you can see, when OnPlayerExitVehicle is called, and when the player has a seatbelt on ( if(seatbelt[playerid]) ) then it will:

- Create three new variables: x, y, z. These are all floats, as we're storing the player's position.
- The PVar "VehicleExited" is set to the vehicleid the player is currently trying to exit.
- The PVar "VehicleSeat" is set to where the player is sitting (seatid) in vehicleid.
- Then, it will get the player's position (GetPlayerPos) and store their values in x, y, z.
- It will set the player's position on top of the vehicle (SetPlayerPos).
- It will set a timer to call the function "EnterBack" in 600 milliseconds (which is 0.6 seconds, 1000 milliseconds is 1 second, etc).
- It will send them a message, saying they have to take their seatbelt off first.

The EnterBack function:

- Puts the player back into the vehicle as soon as it's called.
- Deletes the 2 PVars we used: VehicleSeat and VehicleExited.

Here's more information on the functions we've used in that code (they are links, click them!).

SetPVarInt
GetPVarInt
SetPlayerPos
GetPlayerPos
SetTimerEx
OnPlayerExitVehicle
Reply
#9

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(seatbelt[playerid])
    {
        new Float:x, Float:y, Float:z;
        SetPVarInt(playerid, "VehicleExited", vehicleid);
        SetPVarInt(playerid, "VehicleSeat", GetPlayerVehicleSeat(playerid));
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(playerid, x, y, z);
        SetTimerEx("EnterBack", 600, false, "i", playerid);
        SendClientMessage(playerid, 0xAFAFAFAA, "    You must take your seatbelt off first! (/seatbelt)");
    }
    return 1;
}

forward EnterBack(playerid);
public EnterBack(playerid)
{
    PutPlayerInVehicle(playerid, GetPVarInt(playerid, "VehicleExited"), GetPVarInt(playerid, "VehicleSeat"));
    DeletePVar(playerid, "VehicleExited");
    return DeletePVar(playerid, "VehicleSeat");
}
As you can see, when OnPlayerExitVehicle is called, and when the player has a seatbelt on ( if(seatbelt[playerid]) ) then it will:

- Create three new variables: x, y, z. These are all floats, as we're storing the player's position.
- The PVar "VehicleExited" is set to the vehicleid the player is currently trying to exit.
- The PVar "VehicleSeat" is set to where the player is sitting (seatid) in vehicleid.
- Then, it will get the player's position (GetPlayerPos) and store their values in x, y, z.
- It will set the player's position on top of the vehicle (SetPlayerPos).
- It will set a timer to call the function "EnterBack" in 600 milliseconds (which is 0.6 seconds, 1000 milliseconds is 1 second, etc).
- It will send them a message, saying they have to take their seatbelt off first.

The EnterBack function:

- Puts the player back into the vehicle as soon as it's called.
- Deletes the 2 PVars we used: VehicleSeat and VehicleExited.

Here's more information on the functions we've used in that code (they are links, click them!).

SetPVarInt
GetPVarInt
SetPlayerPos
GetPlayerPos
SetTimerEx
OnPlayerExitVehicle
Great skills you've
Reply
#10

Thanks a lot Emmet I'm sure it will help other people too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)