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;
}
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;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
if(seatbelt[playerid] == 0)
{
PutPlayerInVehicle(playerid, vehicleid, GetPlayerVehicleSeat(playerid));
SendClientMessage(playerid, 0xAFAFAFAA, " You must unbuckle your seatbelt off first! (/seatbelt)");
}
return 1;
}
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.. |
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");
}
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 |
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");
}
pawn Код:
- 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 |