From ace9badf788efcdb88830253ac5bf2a57834334b Mon Sep 17 00:00:00 2001 From: Space V <40030799+ahcenezdh@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:56:16 +0200 Subject: [PATCH 1/2] feat(natives/object): add documentation for DELETE_OBJECT * Add documentation for DELETE_OBJECT * Add examples (Lua, JS, C#) * A note about some entites who can't be deleted Co-Authored-By: Dillon Skaggs --- OBJECT/DeleteObject.md | 88 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/OBJECT/DeleteObject.md b/OBJECT/DeleteObject.md index 725632f58..48a6091c0 100644 --- a/OBJECT/DeleteObject.md +++ b/OBJECT/DeleteObject.md @@ -1,17 +1,71 @@ ---- -ns: OBJECT ---- -## DELETE_OBJECT - -```c -// 0x539E0AE3E6634B9F 0xD6EF9DA7 -void DELETE_OBJECT(Object* object); -``` - -``` -Deletes the specified object, then sets the handle pointed to by the pointer to NULL. -``` - -## Parameters -* **object**: - +--- +ns: OBJECT +--- +## DELETE_OBJECT + +```c +// 0x539E0AE3E6634B9F 0xD6EF9DA7 +void DELETE_OBJECT(Object* object); +``` + +Deletes the specified object. + +**Note**: If for some reason the entity won't delete, you might want to check if the object is a mission entity. + +``` +NativeDB Introduced: v323 +``` + +## Parameters +* **object**: The object you want to delete. + +## Examples +```lua +local playerPed = PlayerPedId() +local playerCoords = GetEntityCoords(playerPed) +local objectHash = GetHashKey("v_ret_gc_chair03") + +local object = GetClosestObjectOfType(playerCoords, 10.0, objectHash, true, false, false) +if object == 0 then return end + +-- If the object is a mission entity, we have to set it to false. Otherwise, it won't be possible to delete the object. +if IsEntityAMissionEntity(object) then + SetEntityAsMissionEntity(object, false, true) +end + +DeleteObject(object) +``` + +```js +const playerPed = PlayerPedId(); +const playerCoords = GetEntityCoords(playerPed, false); +const objectHash = GetHashKey("v_ret_gc_chair03"); + +const object = GetClosestObjectOfType(playerCoords[0], playerCoords[1], playerCoords[2], 10.0, objectHash, true, false, false); +if object === 0 return; + +// If the object is a mission entity, we have to set it to false. Otherwise, it won't be possible to delete the object. +if (IsEntityAMissionEntity(object)) { + SetEntityAsMissionEntity(object, false, true); +} + +DeleteObject(object); +``` + +```csharp +using static CitizenFX.Core.Native.API; + +int playerPed = PlayerPedId(); +Vector3 playerCoords = GetEntityCoords(playerPed, false); +uint objectHash = GetHashKey("v_ret_gc_chair03"); + +int prop = GetClosestObjectOfType(playerCoords.X, playerCoords.Y, playerCoords.Z, 10.0f, objectHash, true, false, false); + +// If the object is a mission entity, we have to set it to false. Otherwise, it won't be possible to delete the object. +if (IsEntityAMissionEntity(prop)) +{ + SetEntityAsMissionEntity(prop, false, true); +} + +DeleteObject(ref object); +``` \ No newline at end of file From 3ca54674560293bc128cf5f18c0de06d672ffc16 Mon Sep 17 00:00:00 2001 From: Dillon Skaggs Date: Fri, 23 Aug 2024 18:36:37 -0500 Subject: [PATCH 2/2] Fix code examples --- OBJECT/DeleteObject.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OBJECT/DeleteObject.md b/OBJECT/DeleteObject.md index 48a6091c0..f9a59a3ac 100644 --- a/OBJECT/DeleteObject.md +++ b/OBJECT/DeleteObject.md @@ -42,7 +42,7 @@ const playerCoords = GetEntityCoords(playerPed, false); const objectHash = GetHashKey("v_ret_gc_chair03"); const object = GetClosestObjectOfType(playerCoords[0], playerCoords[1], playerCoords[2], 10.0, objectHash, true, false, false); -if object === 0 return; +if (object === 0) return; // If the object is a mission entity, we have to set it to false. Otherwise, it won't be possible to delete the object. if (IsEntityAMissionEntity(object)) { @@ -57,15 +57,15 @@ using static CitizenFX.Core.Native.API; int playerPed = PlayerPedId(); Vector3 playerCoords = GetEntityCoords(playerPed, false); -uint objectHash = GetHashKey("v_ret_gc_chair03"); +uint objectHash = Game.GenerateHashASCII("v_ret_gc_chair03"); int prop = GetClosestObjectOfType(playerCoords.X, playerCoords.Y, playerCoords.Z, 10.0f, objectHash, true, false, false); - +if (prop == 0) return; // If the object is a mission entity, we have to set it to false. Otherwise, it won't be possible to delete the object. if (IsEntityAMissionEntity(prop)) { SetEntityAsMissionEntity(prop, false, true); } -DeleteObject(ref object); +DeleteObject(ref prop); ``` \ No newline at end of file