Seatbelt question
#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


Messages In This Thread
Seatbelt question - by Qur - 28.11.2011, 07:57
Re: Seatbelt question - by Emmet_ - 28.11.2011, 08:00
Re: Seatbelt question - by Qur - 28.11.2011, 10:02
Re: Seatbelt question - by Aira - 28.11.2011, 10:15
Re: Seatbelt question - by System64 - 28.11.2011, 10:15
Re: Seatbelt question - by Emmet_ - 28.11.2011, 10:16
Re: Seatbelt question - by Qur - 28.11.2011, 10:26
Re: Seatbelt question - by Emmet_ - 28.11.2011, 10:38
Re: Seatbelt question - by Egyptian Trooper - 28.11.2011, 10:52
Re: Seatbelt question - by Qur - 28.11.2011, 11:03

Forum Jump:


Users browsing this thread: 1 Guest(s)