[Tutorial] Vehicle System "Engine & Lights".
#1

Let's start with making a loop throuth all vehicles in

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().
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:
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;
}
Reply


Messages In This Thread
Vehicle System "Engine & Lights". - by Gogeta - 08.11.2014, 19:54
Re: Vehicle System "Engine & Lights". - by sammp - 08.11.2014, 19:58
Re: Vehicle System "Engine & Lights". - by Gogeta - 08.11.2014, 20:00
Re: Vehicle System "Engine & Lights". - by MrBlake - 07.12.2014, 08:06
Re: Vehicle System "Engine & Lights". - by LivingLikeYouDo - 07.12.2014, 11:57
Re: Vehicle System "Engine & Lights". - by n0minal - 07.12.2014, 14:04
Re: Vehicle System "Engine & Lights". - by MrBlake - 07.12.2014, 15:57
Re: Vehicle System "Engine & Lights". - by PowerPC603 - 07.12.2014, 16:27

Forum Jump:


Users browsing this thread: 1 Guest(s)