leet.features
A script can switch client features on and off, change their settings and run one-shot actions, the same ones you find in the menu. The set is fixed: scripts can use only the names in the tables below.
Whatever a script changes changes as it would in the menu and can end up in the player's saved config. So remember the
previous values and put them back in leet.events.onUnload.
Names
- A feature has a name such as
"player.godmode". It is either enabled (true) or disabled (false). - A setting belongs to a feature and is named
"<feature>.<setting>", for example"player.godmode.bullet". Its value is a boolean or a number, depending on the setting. - An action is a one-shot command such as
"vehicle.repair". It has no state; you run it withtrigger. - Names are case-insensitive:
"Player.GodMode"and"player.godmode"are the same feature. - Only the names listed below are available to scripts.
Changes behave like menu changes. Enabling a feature or changing a setting from a script is the same as doing it in the
menu: the menu shows the new state at once, and if the player later saves their config, the change is saved too. A script that
changes features should remember the previous values and restore them in leet.events.onUnload.
Available features
Toggles
Use get / set with a boolean.
| Feature | Description |
|---|---|
player.anti_afk | Anti-AFK. |
player.godmode | Player godmode. Its settings choose which damage types are blocked. |
player.no_ragdoll | The player does not ragdoll. |
player.restore_health | Keeps the player's health topped up to the target value. |
player.unlimited_stamina | Unlimited stamina. |
vehicle.godmode | Vehicle godmode. Its settings choose which kinds of damage are blocked. |
vehicle.autopilot | Autopilot: drives the current vehicle to the map waypoint, or to the point given to leet.vehicle.driveTo. |
remote_calls.event_log | The event logger: records the client's remote calls from the moment it is on (the menu's Development tab shows the log). Turn it off when you are done. |
Settings
| Setting | Type | Range | Description |
|---|---|---|---|
player.godmode.bullet | boolean | Block bullet damage. | |
player.godmode.fire | boolean | Block fire damage. | |
player.godmode.explosion | boolean | Block explosion damage. | |
player.godmode.collision | boolean | Block collision damage. | |
player.godmode.melee | boolean | Block melee damage. | |
player.godmode.steam | boolean | Block steam damage. | |
player.godmode.smoke | boolean | Block smoke damage. | |
player.godmode.drown | boolean | Block drowning. | |
player.godmode.electric | boolean | Block the stun gun reaction. | |
player.restore_health.value | number | 101 to 200 | Target health. A player's health runs from 100 (dead) to 200. |
vehicle.godmode.health | boolean | Protect vehicle health. | |
vehicle.godmode.body | boolean | Protect the body. | |
vehicle.godmode.engine | boolean | Protect the engine. | |
vehicle.godmode.tyres | boolean | Protect the tyres. | |
vehicle.godmode.wheels | boolean | Protect the wheels. | |
vehicle.godmode.lights | boolean | Protect the lights. | |
vehicle.godmode.doors | boolean | Protect the doors. | |
vehicle.godmode.glass | boolean | Protect the windows. | |
vehicle.autopilot.speed | number | 0.1 to 500 | Autopilot speed, in m/s. |
vehicle.autopilot.stop_range | number | 1 to 50 | Distance from the waypoint at which the autopilot stops, in meters. |
Actions
Use trigger.
| Action | Description |
|---|---|
player.clear_tasks | Clears the player's current tasks and animations (for example, to get unstuck). |
vehicle.repair | Repairs the current vehicle. |
vehicle.flip | Puts the current vehicle back on its wheels. |
leet.features.get
leet.features.get(name: string): boolean | number | undefinedReads a feature's state or a setting's value. For a feature it returns true (enabled) or false (disabled), for a setting
its value (a boolean or a number). Never throws.
const parts = ['bullet', 'fire', 'explosion', 'collision', 'melee', 'steam', 'smoke', 'drown', 'electric']
.filter((t) => leet.features.get(`player.godmode.${t}`));
mp.console.logInfo(
`godmode: ${leet.features.get('player.godmode') ? 'on' : 'off'}, blocks: ${parts.join(', ') || 'nothing'}`
);Parameters
name(string): a feature or setting name, case-insensitive.
Keep in mind
- For an action, an unknown name, a name not available to scripts, or a
namethat is not a string, you getundefined.
leet.features.set
leet.features.set(name: string, value: boolean | number): undefinedEnables or disables a feature, or changes a setting. Returns nothing. The change behaves like one made in the menu, see Changes behave like menu changes.
leet.features.set('player.godmode', true);
leet.features.set('player.restore_health.value', 180);Parameters
name(string): a feature or setting name, case-insensitive. Actions are not accepted.value(boolean | number): for a feature,trueenables it andfalsedisables it. For a setting, a boolean or a number, as the setting's type in Settings requires. Numbers must be within the listed range.
| Error | When |
|---|---|
leet: unknown feature | name is unknown, not available to scripts, an action, or not a string. |
leet: wrong value type | value has the wrong type: for example a number for a boolean feature or setting, a boolean for a number setting, a string, or undefined. |
leet: value out of range | value is a number outside the setting's range, or NaN / Infinity. |
leet.features.trigger
leet.features.trigger(name: string): undefinedRuns a one-shot action, the same as pressing its button in the menu. Returns nothing.
leet.features.trigger('vehicle.repair');Parameters
name(string): an action name from Actions, case-insensitive.
Errors: leet: unknown action (name is unknown, not an action, or not a string).
Recipes
Turn on protection while farming and restore everything on Stop
The script enables Anti-AFK, godmode and health restore while it runs, and puts every value back the way it was when the player presses Stop.
const wanted = {
'player.anti_afk': true,
'player.godmode': true,
'player.godmode.bullet': true,
'player.godmode.melee': true,
'player.restore_health': true,
'player.restore_health.value': 200,
};
// Remember the current values first.
const previous = {};
for (const name of Object.keys(wanted)) {
previous[name] = leet.features.get(name);
}
for (const [name, value] of Object.entries(wanted)) {
leet.features.set(name, value);
}
mp.console.logInfo('[farm] protections enabled');
leet.events.onUnload(() => {
for (const [name, value] of Object.entries(previous)) {
if (value !== undefined) leet.features.set(name, value);
}
mp.console.logInfo('[farm] previous settings restored');
});The previous values are read before the first set, or there would be nothing to restore. The undefined check is there
because get returns it for an unavailable name, and set with undefined throws leet: wrong value type.
Find out why set failed
function trySet(name, value) {
try {
leet.features.set(name, value);
mp.console.logInfo(`set ${name} = ${value}`);
} catch (e) {
mp.console.logError(`set ${name} = ${value} failed: ${e.message}`);
}
}
trySet('player.no_ragdoll', true); // ok
trySet('player.flying_cars', true); // leet: unknown feature
trySet('vehicle.repair', true); // leet: unknown feature (it is an action)
trySet('player.godmode.fire', 1); // leet: wrong value type
trySet('player.restore_health.value', '150'); // leet: wrong value type
trySet('player.restore_health.value', 500); // leet: value out of range
trySet('vehicle.autopilot.speed', NaN); // leet: value out of rangeEach line shows which error its case gives. The error text is in e.message.
Read and change the autopilot speed
const speed = leet.features.get('vehicle.autopilot.speed');
mp.console.logInfo(`autopilot speed: ${speed} m/s (${(speed * 3.6).toFixed(0)} km/h)`);
// 90 km/h, stop 10 m from the waypoint
leet.features.set('vehicle.autopilot.speed', 90 / 3.6);
leet.features.set('vehicle.autopilot.stop_range', 10);
leet.events.onUnload(() => {
if (speed !== undefined) leet.features.set('vehicle.autopilot.speed', speed);
});The speed is in m/s, so km/h is divided by 3.6. On Stop the script puts the previous speed back.
Repair the vehicle with a key
Pressing F6 in a vehicle repairs it.
const KEY_F6 = 0x75;
const onKey = () => {
if (mp.gui.cursor.visible) return; // chat or a menu is open
if (!mp.players.local.vehicle) {
leet.ui.notify('You are not in a vehicle', 'warning');
return;
}
leet.features.trigger('vehicle.repair');
leet.ui.notify('Vehicle repaired', 'success');
};
mp.keys.bind(KEY_F6, true, onKey);
leet.events.onUnload(() => {
mp.keys.unbind(KEY_F6, true, onKey);
});The cursor check keeps the repair from firing while the player types in chat. The key is unbound in onUnload with the same
function it was bound with.