Skip to content

Commit

Permalink
feat(natives): update natives/examples (#1031)
Browse files Browse the repository at this point in the history
* feat(natives): update natives/examples

* Update FREEZE_ENTITY_POSITION
* Update SET_ENTITY_COORDS_NO_OFFSET
* Update SET_ENTITY_ROTATION
* Update SET_WEATHER_TYPE_NOW
* Update SET_WEATHER_TYPE_PERSIST
* Update NETWORK_OVERRIDE_CLOCK_TIME
* Update SET_PED_HAIR_TINT

* Update SetWeatherTypePersist.md

Note regarding native support in networked sessions.

* Update SetWeatherTypeNow.md

Note regarding native support in networked sessions.

* Update SetEntityRotation.md

Reference rotation orders.

* Update SetEntityRotation.md

Correct condition's statement logical operators so the example actually prints when not in a vehicle.

---------

Co-authored-by: ammonia-cfx <38232208+4mmonium@users.noreply.github.com>
  • Loading branch information
ahcenezdh and 4mmonium committed Mar 2, 2024
1 parent 023de75 commit e6f4735
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 69 deletions.
28 changes: 22 additions & 6 deletions ENTITY/FreezeEntityPosition.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ns: ENTITY
void FREEZE_ENTITY_POSITION(Entity entity, BOOL toggle);
```
Freezes or unfreezes an entity preventing its coordinates to change by the player if set to `true`. You can still change the entity position using SET_ENTITY_COORDS.
Freezes or unfreezes an entity preventing its coordinates to change by the player if set to `true`. You can still change the entity position using [`SET_ENTITY_COORDS`](#_0x06843DA7060A026B).
## Parameters
* **entity**: The entity to freeze/unfreeze.
Expand All @@ -17,19 +17,35 @@ Freezes or unfreezes an entity preventing its coordinates to change by the playe
## Examples
```lua
FreezeEntityPosition(PlayerPedId(), true)
-- Freeze the local player.
-- Retrieve the player ped
local playerPed = PlayerPedId()
-- Freeze the ped
FreezeEntityPosition(playerPed, true)
```

```js
FreezeEntityPosition(PlayerPedId(), true);
// Freeze the local player.

// Retrieve the player ped
const playerPed = PlayerPedId();

// Freeze the ped
FreezeEntityPosition(playerPed, true);
```

```cs
using static CitizenFX.Core.Native.API;
// ...
// Freeze the local player.
// Retrieve the player ped
Ped playerPed = PlayerPedId();

FreezeEntityPosition(PlayerPedId(), true);
// Freeze the ped
FreezeEntityPosition(playerPed, true);

// or the preferred use of C# wrapper
Game.PlayerPed.IsPositionFrozen = true;
```
```
24 changes: 14 additions & 10 deletions ENTITY/SetEntityCoordsNoOffset.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ ns: ENTITY

```c
// 0x239A3351AC1DA385 0x4C83DE8D
void SET_ENTITY_COORDS_NO_OFFSET(Entity entity, float xPos, float yPos, float zPos, BOOL alive, BOOL deadFlag, BOOL ragdollFlag);
void SET_ENTITY_COORDS_NO_OFFSET(Entity entity, float x, float y, float z, BOOL keepTasks, BOOL keepIK, BOOL doWarp);
```
Sets the coordinates (world position) for a specified entity.
Teleports an entity to specified coordinates directly, with options to maintain certain behaviors post-teleportation.
## Parameters
* **entity**: The entity to change coordinates for.
* **xPos**: The X coordinate.
* **yPos**: The Y coordinate.
* **zPos**: The Z coordinate, origin level.
* **alive**: Unused by the game, potentially used by debug builds of GTA in order to assert whether or not an entity was alive.
* **deadFlag**: Whether to disable physics for dead peds, too, and not just living peds.
* **ragdollFlag**: A special flag used for ragdolling peds.
**Note**:
- This native allows precise placement of entities without the usual adjustments for collision or interaction with the environment that may occur with other teleportation natives.
- The `keepTasks` and `keepIK` parameters are specifically useful for maintaining the current state of a ped, ensuring actions or animations are not abruptly stopped due to the teleportation.
- Setting `doWarp` to `false` is useful when simulating continuous movement or when the entity should interact with its immediate surroundings upon arrival.
## Parameters
* **entity**: The entity to reposition.
* **x**: X coordinate for the new position.
* **y**: Y coordinate for the new position.
* **z**: Z coordinate for the new position.
* **keepTasks**: If `true`, the tasks currently assigned to the ped are not removed upon teleportation. Applies only to peds.
* **keepIK**: If `true`, the Inverse Kinematics (IK) on the ped are not reset upon teleportation. Applies only to peds.
* **doWarp**: If `false`, the entity will maintain continuous motion and will not clear contacts nor create space for itself upon teleportation.
56 changes: 49 additions & 7 deletions ENTITY/SetEntityRotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,56 @@ ns: ENTITY

```c
// 0x8524A8B0171D5E07 0x0A345EFE
void SET_ENTITY_ROTATION(Entity entity, float pitch, float roll, float yaw, int rotationOrder, BOOL p5);
void SET_ENTITY_ROTATION(Entity entity, float pitch, float roll, float yaw, int rotationOrder, BOOL bDeadCheck);
```
Sets the rotation of a specified entity in the game world.
```
NativeDB Introduced: v323
```
## Parameters
* **entity**:
* **pitch**:
* **roll**:
* **yaw**:
* **rotationOrder**: The order yaw pitch roll are applied, see [`GET_ENTITY_ROTATION`](#_0xAFBD61CC738D9EB9).
* **p5**:
* **entity**: The entity to rotate.
* **pitch**: The pitch (X-axis) rotation in degrees.
* **roll**: The roll (Y-axis) rotation in degrees.
* **yaw**: The yaw (Z-axis) rotation in degrees.
* **rotationOrder**: Specifies the order in which yaw, pitch, and roll are applied, see [`GET_ENTITY_ROTATION`](#_0xAFBD61CC738D9EB9) for the available rotation orders.
* **bDeadCheck**: Usually set to `true`. Determines whether to check if the entity is dead before applying the rotation.
## Examples
```lua
-- Example of rotating a vehicle 360 degrees
RegisterCommand('360', function()
local playerPed = PlayerPedId() -- Get the player's Ped
local vehicle = GetVehiclePedIsIn(playerPed, false) -- Get the vehicle the player is currently in.
if not vehicle or not DoesEntityExist(vehicle) then
print("You are not in a vehicle")
return
end
local rot = GetEntityRotation(vehicle, 2)
local roll, pitch, yaw = rot.x, rot.y, rot.z
local finalYaw = yaw + 360
local steps = 20 -- Reduced the number of steps so each rotation is larger
-- Function to perform the rotation gradually
local function doRotation()
local currentYaw = yaw
-- Loop to adjust the rotation in steps
for i = 1, steps do
Citizen.Wait(20) -- Increases the delay between each adjustment to make the animation slower
currentYaw = currentYaw + (360 / steps) -- Increments the rotation
if currentYaw >= finalYaw then
currentYaw = finalYaw
end
-- Apply the current rotation
SetEntityRotation(vehicle, roll, pitch, currentYaw % 360, 2, true)
if currentYaw == finalYaw then
break -- Stops the loop once the rotation is complete
end
end
end
-- Execute the rotation in a coroutine to not block the main thread
Citizen.CreateThread(doRotation)
end, false)
```
41 changes: 23 additions & 18 deletions MISC/SetWeatherTypeNow.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@ ns: MISC
void SET_WEATHER_TYPE_NOW(char* weatherType);
```
Immediately changes the game's weather to the specified type, which will then persist for one cycle before the game resumes its natural weather progression.
**Note:** This native is not supported in networked sessions. Please refer to [`SET_OVERRIDE_WEATHER`](#_0xA43D5C6FE51ADBEF) or [`SET_WEATHER_TYPE_NOW_PERSIST`](#_0xED712CA327900C8A) if you want to override weather in networked sessions.
```
// timecycle_keyframe_data
BLIZZARD = 0x27EA2814
CLEAR = 0x36A83D84
CLEARING = 0x6DB1A50D
CLOUDS = 0x30FDAF5C
EXTRASUNNY = 0x97AA0A79
FOGGY = 0xAE737644
HALLOWEEN = 0xC91A3202
NEUTRAL = 0xA4CA1326
OVERCAST = 0xBB898D2D
RAIN = 0x54A69840
SMOG = 0x10DCF4B5
SNOW = 0xEFB6EFF6
SNOWLIGHT = 0x23FB812B
THUNDER = 0xB677829F
XMAS = 0xAAC9C895
NativeDB Introduced: v323
```
## Parameters
* **weatherType**:
**Weather Types:**
- CLEAR
- EXTRASUNNY
- CLOUDS
- OVERCAST
- RAIN
- CLEARING
- THUNDER
- SMOG
- FOGGY
- XMAS
- SNOW
- SNOWLIGHT
- BLIZZARD
- HALLOWEEN
- NEUTRAL
## Parameters
* **weatherType**: The weather type to set. This should be one of the predefined weather type strings.
11 changes: 8 additions & 3 deletions MISC/SetWeatherTypePersist.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ ns: MISC
void SET_WEATHER_TYPE_PERSIST(char* weatherType);
```
Refer to [`SET_WEATHER_TYPE_NOW_PERSIST`](#_0xED712CA327900C8A) for weather types.
Sets the current weather type to persist indefinitely until changed.
## Parameters
* **weatherType**:
**Note:** This native is not supported in networked sessions. Please refer to [`SET_OVERRIDE_WEATHER`](#_0xA43D5C6FE51ADBEF) or [`SET_WEATHER_TYPE_NOW_PERSIST`](#_0xED712CA327900C8A) if you want to override weather in networked sessions.
```
NativeDB Introduced: v323
```
## Parameters
* **weatherType**: The weather type to be set as persistent. Refer to [`SET_WEATHER_TYPE_NOW_PERSIST`](#_0xED712CA327900C8A) for a list of weather type strings.
12 changes: 6 additions & 6 deletions NETWORK/NetworkOverrideClockTime.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ ns: NETWORK
void NETWORK_OVERRIDE_CLOCK_TIME(int hours, int minutes, int seconds);
```
Works in Singleplayer too.
Passing wrong data (e.g. hours above 23) will cause the game to crash.
Overrides the game clock time for the local player, allowing for manipulation of the in-game time. This native is effective in both multiplayer and singleplayer modes.
## Parameters
* **hours**:
* **minutes**:
* **seconds**:
**Note:** Passing wrong data (e.g. hours above 23) will cause the game to crash.
## Parameters
* **hours**: The hour to set (0-23).
* **minutes**: The minute to set (0-59).
* **seconds**: The second to set (0-59).
19 changes: 0 additions & 19 deletions PED/SetPedHairColor.md

This file was deleted.

22 changes: 22 additions & 0 deletions PED/SetPedHairTint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
ns: PED
aliases: ["_SET_PED_HAIR_COLOR"]
---
## SET_PED_HAIR_TINT

```c
// 0x4CFFC65454C93A49
void SET_PED_HAIR_TINT(Ped ped, int colorID, int highlightColorID);
```
Sets the tint index for the hair on the specified ped.
```
NativeDB Introduced: v323
```
## Parameters
* **ped**: The Ped whose hair tint is to be set.
* **colorID**: The tint index for the primary hair color.
* **highlightColorID**: The tint index for the hair highlight color.

0 comments on commit e6f4735

Please sign in to comment.