08.11.2014, 19:54
(
Last edited by Gogeta; 08/11/2014 at 08:28 PM.
)
Let's start with making a loop throuth all vehicles in
Now all we got to do is when we press 2 while we are inside a car so we turn the engine and lights on.
pawn Code:
for(new i; i < MAX_VEHICLES; i++) // This is the loop if i is greater then MAX VEHICLES it will continue.
{
new engine, lights, alarm, doors, bonnet, boot, objective; // Required variables.
engine = 0; // 0 means OFF, so when the server start's all car's are off.
lights = 0; // Same as engine.
SetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
}
return 1;
// Put the code above at end of InGameInit().
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) // This is when the player taps a button in keyboard.
{
if(newkeys & KEY_SUBMISSION) Number 2 or + in your keyboard.
{
if(IsPlayerInAnyVehicle(playerid)) // If the player is in any vehicle (I should have done this to state driver but anyways).
{
new engine, lights, alarm, doors, bonnet, boot, objective; // Variables to store the status.
new vid = GetPlayerVehicleID(playerid); // We need to get players vehicle to get the params.
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective); // We need to get vehicle params in order to change them.
if(engine == 0) // If engine is OFF the code below turns on the engine.
{
SetVehicleParamsEx(vid,1,1,alarm,doors,bonnet,boot,objective);
SendClientMessage(playerid,-1,"You turned ON your vehicle engine and lights.");
return 1;
}
else if(engine == 1) // If the engine is ON so we turn it off.
{
SetVehicleParamsEx(vid,0,0,alarm,doors,bonnet,boot,objective);
SendClientMessage(playerid,-1,"You turned OFF your vehicle engine and lights.");
return 1;
}
else if(engine == -1) // If the params are unset let's take a example when you spawn a car as admin.
{
SetVehicleParamsEx(vid,1,1,alarm,doors,bonnet,boot,objective);
}
}
}
return 1;
}