Skip to content

Commit

Permalink
feat(docs): document natives
Browse files Browse the repository at this point in the history
* Document natives
* Added some comments in the code and a TODO
  • Loading branch information
ahcenezdh committed Sep 8, 2024
1 parent bfb1ff3 commit 774ef24
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ static HookFunction initFunction([]()

if (fwEntity* vehicle = getAndCheckVehicle(context, "GET_VEHICLE_HAS_FLAG"))
{
// 0x020: VehicleModelInfoOffset
auto addr = *reinterpret_cast<uint64_t *>((unsigned char *)vehicle + 0x020);
auto target_block = *(uint32_t*)(addr + VehicleFlagsOffset + sizeof(uint32_t) * (flagIndex / 32));
context.SetResult<bool>((target_block & (1 << (flagIndex & 31))) != 0);
Expand All @@ -1404,10 +1405,12 @@ static HookFunction initFunction([]()
if (flagIndex < 0 || flagIndex >= (32 * 7))
{
return;
//TODO: Check if the flag is valid with CVehicleModelInfo::GetVehicleFlag()
}

if (fwEntity* vehicle = getAndCheckVehicle(context, "SET_VEHICLE_FLAG"))
{
// 0x020: VehicleModelInfoOffset
auto addr = *reinterpret_cast<uint64_t *>((unsigned char *)vehicle + 0x020);
auto flag_block_addr = addr + VehicleFlagsOffset + sizeof(uint32_t) * (flagIndex / 32);

Expand Down
36 changes: 33 additions & 3 deletions ext/native-decls/GetVehicleHasFlag.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,42 @@ bool GET_VEHICLE_HAS_FLAG(Vehicle vehicle, int flagIndex);
Get vehicle.meta flag by index. Useful examples include FLAG_LAW_ENFORCEMENT (31), FLAG_RICH_CAR (36), FLAG_IS_ELECTRIC (43), FLAG_IS_OFFROAD_VEHICLE (48).
Complete list of flags: https://gtamods.com/wiki/Vehicles.meta#flags
Compilation of all vehicles' metadata files (including their flags): https://forum.cfx.re/t/vehicle-meta-files-last-dlc/5142301
For a complete list of flags, you can refer to the [Vehicle Flags documentation](https://docs.fivem.net/docs/game-references/vehicle-references/vehicle-flags/).
## Parameters
* **vehicle**: The vehicle to obtain data for.
* **flagIndex**: Flag index (0-203)
## Return value
A boolean for whether the flag is set.
A boolean for whether the flag is set.
## Examples
```lua
local function getVehicleFlags(vehicle)
local vehicleFlags = {}
for i = 0, 203 do
if GetVehicleHasFlag(vehicle, i) then
vehicleFlags[#vehicleFlags+1] = i
end
end
return vehicleFlags
end
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
getVehicleFlags(vehicle)
```

```js
function getVehicleFlags(vehicle) {
const vehicleFlags = [];
for (let i = 0; i <= 203; i++) {
if (GetVehicleHasFlag(vehicle, i)) {
vehicleFlags.push(i);
}
}
return vehicleFlags;
}

const vehicle = GetVehiclePedIsIn(PlayerPedId(), false);
getVehicleFlags(vehicle);
```
25 changes: 21 additions & 4 deletions ext/native-decls/SetVehicleFlag.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@ apiset: client
void SET_VEHICLE_FLAG(Vehicle vehicle, int flagIndex, bool value);
```
Set vehicle.meta flag by index. This native is a setter for [GET_VEHICLE_HAS_FLAG](#_0x7A2F9BA7)
**Note**: Depending on the game build, some vehicle flags may not exist as they were introduced in later versions.
## Parameters
* **vehicle**:
* **flagIndex**:
* **value**:
* **vehicle**: The vehicle on which you want to set or unset a flag.
* **flagIndex**: The index of the flag to modify.
* **value**: A boolean to enable `true` or disable `false` the flag.
## Return value
## Examples
```lua
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
SetVehicleFlag(vehicle, 43, true) -- Set the vehicle as a electric vehicle
```

```js
const vehicle = GetVehiclePedIsIn(PlayerPedId(), false);

## Return value
SetVehicleFlag(vehicle, 43, true) // Set the vehicle as a electric vehicle
```

0 comments on commit 774ef24

Please sign in to comment.