[Tutorial] Engine system with keys
#1

Engine and lights with a key!

We need to define pressing keys.
pawn Code:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) //Detecting keys
The code below will make the engine and lights be manual, not automatic. This goes under OnGameModeInit.
pawn Code:
ManualVehicleEngineAndLights();//Instead of vehicle engines and lights automatic, they are now manual.
Now, we'll make the code for detecting pressing the key. You can change the key to whatever you want.
pawn Code:
if(PRESSED(KEY_SUBMISSION))//If the player pressed KEY_SUBMISSION (2)
{
If the player pressed the submission key.
pawn Code:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)//Checks if the player is the driver
{
If the player is driving the vehicle. Stops passengers from abusing it.
pawn Code:
new vehicle = GetPlayerVehicleID(playerid);//Getting the players vehicle id.
We need to get the players vehicle id so we know what vehicle were controlling.
pawn Code:
new engine,lights,alarm,doors,bonnet,boot,objective;//The vehicle params
The variables for the vehicle params
pawn Code:
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);//Getting the vehicle params
We get the vehicle params to see if the engine and lights are on yet. if they are, we stop the engine. If not, we start the engine.
pawn Code:
if(engine == 0)//If the engine is off
{
If the engine is off, We used GetVehiceParamsEx to find out.
pawn Code:
SetVehicleParamsEx(vehicle,1,1,alarm,doors,bonnet,boot,objective);//We turn on the engine and lights
We start the engine and turn on the lights. We set the variable to 1.
pawn Code:
SendClientMessage(playerid,-1,"You started the engine!");
We send a message to the player telling them they started the engine.
pawn Code:
}
else//Else is the engine is on
{
If the engine is on (variable = 1) We will stop the engine.
pawn Code:
SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);//We turn off the engine and lights
This stops the engine and turns off the lights.
pawn Code:
SendClientMessage(playerid,-1,"You stopped the engine!");//Sends a message to the player telling him he stopped the engine.
}
Sends a message to the player telling them he stoped the engine.
pawn Code:
}
}
return 1;
}
Our closing brackets.

Compile, now you have your own engine system using keys!.

If theres any bugs,spelling mistakes or anything else.
Please post here.

Hope i helped.
Reply
#2

wow awesome Tut. It helps for sure ppl which don't want use any commands for this.

Just one word EPIC

btw first Post :3
Reply
#3

I just have the feeling that the engine will stay on only if you keep the key 2 pressed.AND that is because you used PRESSED,why didn't you just check the key using:
pawn Code:
newkeys & KEY_SUBMISSION
Reply
#4

Quote:
Originally Posted by Cjgogo
View Post
I just have the feeling that the engine will stay on only if you keep the key 2 pressed.AND that is because you used PRESSED,why didn't you just check the key using:
pawn Code:
newkeys & KEY_SUBMISSION
No, when you press it, it toggles the engine depending if its currently on or off. Ive tested this and it worked perfectly.
Reply
#5

Nice tutorial. Very helpful for beginners.
Reply
#6

that helped me , thanks
Reply
#7

Just the thing I needed,thanks.
Reply
#8

Cooll this is wat i was waiting for
Reply
#9

What if I want only the engine to be manual ?
Reply
#10

Nice tutorial, Maybe you could update it using the /engine command also?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)