Alright here you go. With this, you just have to press "2" and then it'll say "Starting vehicle..." and after three seconds the engine will either start or fail with a 50/50 chance rate.
Code:
// Put this at the top of your script
forward StartEngine(playerid);
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_SUBMISSION))
{
if(IsPlayerInAnyVehicle(playerid))
{
new vehid;
vehid = GetPlayerVehicleID(playerid);
new
iEngine, iLights, iAlarm,
iDoors, iBonnet, iBoot,
iObjective;
GetVehicleParamsEx(vehid, iEngine, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new string[200];
if(iEngine == 1) // Engine is on
{
SetTimerEx("StartEngine", 3000, 0, "i", playerid);
SendClientMessage(playerid, COLOR_GREEN, "** [Hint]: Vehicle engine starting");
format(string, sizeof(string), "* %s turns the key of the vehicle attempting to start it", name);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
else // Engine is off
{
SetVehicleParamsEx(vehid, 0, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
SendClientMessage(playerid, COLOR_GOLD, "** [Hint]: Vehicle engine stopped");
SendClientMessage(playerid, COLOR_GOLD, "** To re-start the vehicle's engine press '2'");
format(string, sizeof(string), "* %s turns the key of the vehicle shutting it {FF0000}[OFF]", name);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
}
}
return 1;
}
public StartEngine(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
new rand = random(2);
new
iEngine, iLights, iAlarm,
iDoors, iBonnet, iBoot,
iObjective;
GetVehicleParamsEx(vehicleid, iEngine, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
if(IsPlayerInAnyVehicle(playerid))
{
if(iEngine == 0) // Engine is off
{
new vmodel[128];
new string[240];
GetVehicleName(vehicleid,vmodel,sizeof(vmodel));
if(rand == 0)
{
SetVehicleParamsEx(vehicleid, 1, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
SetTimerEx("DamagedEngine", 1000, 1, "i", playerid);
format(string, sizeof(string), "* The engine of the %s succeeds and turns{37DB45} [ON]",vmodel);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
}
if(rand == 1)
{
SetVehicleParamsEx(vehicleid, 0, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
format(string, sizeof(string), "* The engine of the %s fails and remains{FF0000} [OFF]",vmodel);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
}
}
}
return 1;
}