#include <a_samp>
#include <zcmd>
#define colorYellow 0xFFFFFFAA
#define colorYelloww 0xC2A2DAAA
#define colorYellowww 0xBFF600FF
#define colorYellowwww 0xFFD9D991
forward StartEngine(playerid);
forward DamagedEngine(playerid);
new vehEngine[MAX_VEHICLES];
// new model = GetVehicleModel(vehicleid);
// && !(model == 481 || model == 510)
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vehicleid = GetPlayerVehicleID(playerid);
new model = GetVehicleModel(vehicleid);
if(newstate == PLAYER_STATE_DRIVER)
{
if(vehEngine[vehicleid] == 0 && !(model == 481 || model == 510||model == 509 || model == 509))
{
TogglePlayerControllable(playerid, 0);
SendClientMessage(playerid, colorYellow, "Вы вставляете ключ и заводите двигатель");
SendClientMessage(playerid, colorYellow, "Чтобы завести двигатель нажмите \"Shift\" чтобы заглушить \"/engine\"");
}
else if(vehEngine[vehicleid] == 1 )
{
TogglePlayerControllable(playerid, 1);
SendClientMessage(playerid, colorYellowww, "Двигатель автомобиля заведен");
}
}
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new vehicleid = GetPlayerVehicleID(playerid);
new model = GetVehicleModel(vehicleid);
if(IsPlayerInAnyVehicle(playerid))
{
if(vehEngine[vehicleid] == 0 && !(model == 481 || model == 510||model == 509 || model == 509))
{
if(newkeys == KEY_JUMP)
{
vehEngine[vehicleid] = 2;
SetTimerEx("StartEngine", 700, 0, "i", playerid);
SendClientMessage(playerid, colorYelloww, "Вы вставляете ключ и пытаетесь завести двигатель");
}
}
if(newkeys == KEY_SECONDARY_ATTACK)
{
RemovePlayerFromVehicle(playerid);
TogglePlayerControllable(playerid, 1);
}
}
return 1;
}
public StartEngine(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
new model = GetVehicleModel(vehicleid);
new Float:health;
new rand = random(2);
GetVehicleHealth(vehicleid, health);
if(IsPlayerInAnyVehicle(playerid))
{
if(vehEngine[vehicleid] == 2 && !(model == 481 || model == 510||model == 509 || model == 509))
{
if(health > 555)
{
if(rand == 0)
{
vehEngine[vehicleid] = 1;
TogglePlayerControllable(playerid, 1);
SetTimerEx("DamagedEngine", 700, 1, "i", playerid);
SendClientMessage(playerid, colorYellowww, "Вы завели двигатель");
}
if(rand == 1)
{
vehEngine[vehicleid] = 0;
TogglePlayerControllable(playerid, 0);
SendClientMessage(playerid, colorYellowwww, "Двигатель автомобиля не удалось завести");
}
}
else
{
vehEngine[vehicleid] = 0;
TogglePlayerControllable(playerid, 0);
SendClientMessage(playerid, colorYellowwww, "Двигатель автомобиля не удалось завести из-за повреждения");
}
}
}
return 1;
}
public DamagedEngine(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
new Float:health;
GetVehicleHealth(vehicleid, health);
if(IsPlayerInAnyVehicle(playerid))
{
if(vehEngine[vehicleid] == 1)
{
if(health < 300)
{
vehEngine[vehicleid] = 0;
TogglePlayerControllable(playerid, 0);
SendClientMessage(playerid, colorYellowwww, "Двигатель автомобиля захлох из-за повреждения");
}
}
}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
TogglePlayerControllable(playerid, 1);
return 1;
}
CMD:engine(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, colorYellowwww, "Вы должны быть в автомобиле и использовать эту команду");
if(vehEngine[vehicleid] == 0)
{
vehEngine[vehicleid] = 2;
SetTimerEx("StartEngine", 700, 0, "i", playerid);
SendClientMessage(playerid, colorYelloww, "Вы вставляете ключ и пытаетесь завести двигатель");
}
else if(vehEngine[vehicleid] == 1)
{
vehEngine[vehicleid] = 0;
TogglePlayerControllable(playerid, 0);
SendClientMessage(playerid, colorYellow, "Вы заглушили двигатель");
SendClientMessage(playerid, colorYellow, "Чтобы завести двигатель нажмите \"Shift\" чтобы заглушить \"/engine\"");
}
return 1;
}