Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
// Setup local variables
new vid, Name[24], Msg[128], engine, lights, alarm, doors, bonnet, boot, objective;
switch (newstate)
{
case PLAYER_STATE_DRIVER: // Player became the driver of a vehicle
{
// Get the ID of the player's vehicle
vid = GetPlayerVehicleID(playerid);
// Get the player's name (the one who is trying to enter the vehicle)
GetPlayerName(playerid, Name, sizeof(Name));
// Check if the vehicle is owned
if (AVehicleData[vid][Owned] == true)
{
// Check if the vehicle is owned by somebody else (strcmp will not be 0)
if (strcmp(AVehicleData[vid][Owner], Name, false) != 0)
{
// Force the player out of the vehicle
RemovePlayerFromVehicle(playerid);
// Turn off the lights and engine
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
// Let the player know he cannot use somebody else's vehicle
format(Msg, 128, TXT_SpeedometerCannotUseVehicle, AVehicleData[vid][Owner]);
SendClientMessage(playerid, 0xFFFFFFFF, Msg);
}
// Check if the vehicle is clamped
if (AVehicleData[vid][Clamped] == true)
{
// Force the player out of the vehicle
RemovePlayerFromVehicle(playerid);
// Turn off the lights and engine
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
// Let the player know he cannot use a clamped vehicle
format(Msg, 128, TXT_SpeedometerClampedVehicle);
SendClientMessage(playerid, 0xFFFFFFFF, Msg);
format(Msg, 128, TXT_SpeedometerClampedVehicle2);
SendClientMessage(playerid, 0xFFFFFFFF, Msg);
}
}
// Check if the player is not a cop
if (PInfo[playerid][PlayerClass] != ClassPolice)
{
// First check if the vehicle is a static vehicle (player can still use a bought cop-car that he bought in his house,
// as a bought vehicle isn't static)
if (AVehicleData[vid][StaticVehicle] == true)
{
// Check if the entered vehicle is a cop vehicle
switch (GetVehicleModel(vid))
{
case VehiclePoliceLSPD, VehiclePoliceSFPD, VehiclePoliceLVPD, VehicleHPV1000, VehiclePoliceRanger:
{
// Force the player out of the vehicle
RemovePlayerFromVehicle(playerid);
// Turn off the lights and engine
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
// Let the player know he cannot use a cop car
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use a police vehicle");
}
}
}
}
// Check if the player is not a pilot
if (PInfo[playerid][PlayerClass] != ClassPilot)
{
// First check if the vehicle is a static vehicle (player can still use a bought plane that he bought in his house,
// as a bought vehicle isn't static)
if (AVehicleData[vid][StaticVehicle] == true)
{
// Check if the entered vehicle is a plane or helicopter vehicle
switch (GetVehicleModel(vid))
{
case VehicleShamal, VehicleNevada, VehicleStuntPlane, VehicleDodo, VehicleMaverick, VehicleCargobob:
{
// Force the player out of the vehicle
RemovePlayerFromVehicle(playerid);
// Turn off the lights and engine
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
// Let the player know he cannot use a cop car
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use a pilot vehicle");
}
}
}
}
}
}
return 1;
}
// This callback gets called whenever a player presses a key
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Debug the keypresses
// DebugKeys(playerid, newkeys, oldkeys);
// ****************************************************************************************
// NOTE: the keys are messed up, so the code may look strange when testing for certain keys
// ****************************************************************************************
// Fining and jailing players when you're police and press the correct keys
// Check the class of the player
switch (PInfo[playerid][PlayerClass])
{
case ClassPolice:
{
// If the police-player pressed the RMB key (AIM key) when OUTSIDE his vehicle
if (((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE)) && (GetPlayerVehicleID(playerid) == 0))
Police_FineNearbyPlayers(playerid);
// If the police-player pressed the LCTRL (SECUNDAIRY key) key when INSIDE his vehicle
if (((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION)) && (GetPlayerVehicleID(playerid) != 0))
Police_WarnNearbyPlayers(playerid);
}
case ClassAssistance:
{
// If the assistance-player pressed the RMB key (AIM key) when OUTSIDE his vehicle
if (((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE)) && (GetPlayerVehicleID(playerid) == 0))
Assistance_FixVehicle(playerid);
// If the police-player pressed the LCTRL (SECUNDAIRY key) key when INSIDE his vehicle
if (((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION)) && (GetPlayerVehicleID(playerid) != 0))
Assistance_FixOwnVehicle(playerid);
}
}
// Trying to attach the closest vehicle to the towtruck when the player pressed FIRE when inside a towtruck
// Check if the player is inside a towtruck
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == VehicleTowTruck)
{
// Check if the player pushed the fire-key
if(newkeys & KEY_FIRE)
{
// Get the vehicle-id of the closest vehicle
new closest = GetClosestVehicle(playerid);
if(VehicleToPlayer(playerid, closest) < 10) // Check if the closest vehicle is within 10m from the player
AttachTrailerToVehicle(closest, GetPlayerVehicleID(playerid)); // Attach the vehicle to the towtruck
}
}
// Refuel a vehicle when driving a vehicle and pressing the HORN key
// Check if the player presses the HORN key
if ((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
{
// Check if the player is driving a vehicle
if (GetPlayerVehicleSeat(playerid) == 0)
{
// Loop through all ARefuelPickups
for (new i; i < sizeof(ARefuelPickups); i++)
{
// Check if the player is in range of a refuelpickup
if(IsPlayerInRangeOfPoint(playerid, 2.5, ARefuelPickups[i][pux], ARefuelPickups[i][puy], ARefuelPickups[i][puz]))
{
// Show a message that the player's vehicle is refuelling
GameTextForPlayer(playerid, TXT_Refuelling, 3000, 4);
// Don't allow the player to move again (the timer will allow it after refuelling)
TogglePlayerControllable(playerid, 0);
// Start a timer (let the player wait until the vehicle is refuelled)
SetTimerEx("RefuelVehicle", 5000, false, "i", playerid);
// Stop the search
break;
}
}
}
}
return 1;
}