-
Notifications
You must be signed in to change notification settings - Fork 10
Engines
- Engine or motor, as it's in real life, is a machine designed to convert one form of energy into mechanical energy. In SA:MP, they are used to have values between 0 (false) or 1 (true). Pretty self-explanatory, when value is equal to 0, engine is off, but when the value is equal to 1, the engine is running.
These values are modified via
SetVehicleParamsEx
function.
- There's a function in SA:MP which allows you to change engine states. It's as mentioned above,
SetVehicleParamsEx
. The function actually is used to modify all values of all vehicle parts, like bonnet, objective, alarms, boot etc... Therefore, you need to take into account you are going to need all those values gotten before you can modify. The values from all vehicle params. Let's take a look how it looks. We'll take a closer look into an example from SA:MP/open.mp wikipedia.
// If setting a single parameter, you should obtain the current parameters so they aren't ALL changed
new
engine, lights, alarm, doors, bonnet, boot, objective;
// Somewhere where you create the vehicle..
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective); // ONLY the engine param was changed to VEHICLE_PARAMS_ON (1)
With vehicle-framework, this becomes a lot easier, as framework finishes all this work for you.
- Like we've just learnt. Framework finishes all of the work for you. Also, it uses tags.
A tag is a prefix to a variable which tells the compiler to treat the variable specially under certain circumstances.
The tags are either E_ENGINE_STATE_ON
or E_ENGINE_STATE_OFF
, and that's used in only one function, thus, look below. The tags' names are pretty self-explanatory. You got the point just by reading them, one turns engine on, the other off. Enough, let's look at the code.
// So, you created a vehicle and it returned its id stored in variable `vehicleid` and later in script you use
Vehicle_SetEngineState(vehicleid, E_ENGINE_STATE_ON);
Easy, isn't it? But don't mix this with:
Vehicle_SetEngineState(vehicleid, 1); // WILL GIVE YOU WARNING
This will clearly give you a warning. The function Vehicle_SetEngineState
is very smart. It tags the first parameter with VEHICLE_FRAMEWORK_TAGS
, thus, it allows you to use different things, like vehicle groups, instead of just vehicleid. Therefore, it accepts either group ID or vehicle ID in first parameter.
new VehicleGroup: vehicleGroup;
Vehicle_SetEngineState(vehicleGroup, E_ENGINE_STATE_ON); // Correct
Vehicle_SetEngineState(vehicleGroup, 1); // WILL GIVE YOU WARNING
To obtain vehicle state, simply use Vehicle_GetEngineState
function. Simple. It return state directly, altough, you can't use groups, it just accepts vehicle IDs.
Vehicle_GetEngineState(vehicleid);
It returns tagged value, that means if you are going to store the value of function above has returned, you have to use tagged variable also.
new e_ENGINE_STATES: variableToGetEngineState;
variableToGetEngineState = Vehicle_GetEngineState(vehicleid); // correct
// --
new variableToGetEngineState;
variableToGetEngineState = Vehicle_GetEngineState(vehicleid); // WILL GIVE YOU A WARNING
This library has been made to ease use of vehicle functions provided by SA:MP. I've spent most of my free time to develop a library that everyone can use. This is also the biggest library I've ever made. Therefore, if you find any bugs, feel free to request a pull or report me.
-
Functions
- Engines
- Lights
- Alarms
-
Doors
- Vehicle_SetDoorState
- Vehicle_GetDoorState
- Vehicle_GetDoorsLockState
- Vehicle_SetDoorsLockState
- Tires
- Vehicle_SetTireState
- Vehicle_GetTireState
- Plates
- Vehicle_GetNumberPlate
- Vehicle_SetNumberPlate
- Windows
- Vehicle_SetWindows
- Vehicle_GetWindows
- Panels
- Vehicle_SetPanelStates
- Vehicle_GetPanelStates
- Vehicle_SetBumperStates
- Vehicle_GetBumperStates
- Vehicle_GetWindshieldState