|
| 1 | +--- |
| 2 | +ns: OBJECT |
| 3 | +aliases: ["0xF9C1681347C8BD15"] |
| 4 | +--- |
| 5 | +## FIX_OBJECT_FRAGMENT |
| 6 | + |
| 7 | +```c |
| 8 | +// 0xF9C1681347C8BD15 |
| 9 | +void FIX_OBJECT_FRAGMENT(Object object); |
| 10 | +``` |
| 11 | +
|
| 12 | +Resets and brings back all the children of a fragment based object. |
| 13 | +This should be used when attaching or detaching an object from another entity, especially when the object being detached consists of multiple fragments. |
| 14 | +
|
| 15 | +Attempting to teleport a fragment-based object using [`SET_ENTITY_COORDS`](#_0x06843DA7060A026B) such as a flag object, will result in it remaining in place and failing to teleport, given the condition mentioned in the preceding statement. |
| 16 | +
|
| 17 | +The native should be executed after detaching the object from its parent entity and before calling [`SET_ENTITY_COORDS`](#_0x06843DA7060A026B). |
| 18 | +
|
| 19 | +Example given down below. |
| 20 | +
|
| 21 | +
|
| 22 | +## Parameters |
| 23 | +* **object**: The object to fix fragments for (a handle should be passed). |
| 24 | +
|
| 25 | +## Examples |
| 26 | +```lua |
| 27 | +RegisterCommand("fixobject", function(source, args, rawCommand) |
| 28 | + -- prop_flag_ls does not get teleported after being attached to the player |
| 29 | + -- prop_beachflag_01 only the pole gets teleported after being attached to the player |
| 30 | + local modelHash = `prop_beachflag_01` |
| 31 | + if not HasModelLoaded(modelHash) then |
| 32 | + RequestModel(modelHash) |
| 33 | + while not HasModelLoaded(modelHash) do |
| 34 | + Citizen.Wait(1) |
| 35 | + end |
| 36 | + end |
| 37 | +
|
| 38 | + -- Set argument 1 to 0 if you wish to see what occurs when fragments aren't fixed. |
| 39 | + -- i.e. /fixobject 0 |
| 40 | + local shouldFixFragments = tonumber(args[1]) or true |
| 41 | + |
| 42 | + local entity = CreateObject(modelHash, GetEntityCoords(PlayerPedId()), true, false, false) |
| 43 | + AttachEntityToEntity( |
| 44 | + entity, |
| 45 | + PlayerPedId(), |
| 46 | + GetPedBoneIndex(PlayerPedId(), 0x796E), --0x796E |
| 47 | + 0.0, 0.0, 0.1, -- offset attachment for the first entity |
| 48 | + 0.0, 0.0, 0.0, |
| 49 | + false, |
| 50 | + false, |
| 51 | + false, |
| 52 | + false, |
| 53 | + 1, -- rotation order |
| 54 | + true, |
| 55 | + false |
| 56 | + ) |
| 57 | + |
| 58 | + Citizen.SetTimeout(5000, function() |
| 59 | + DetachEntity(entity, true, true) |
| 60 | + Citizen.Trace("Detaching entity...") |
| 61 | + end) |
| 62 | +
|
| 63 | + Citizen.SetTimeout(8000, function() |
| 64 | + local coords = GetEntityCoords(PlayerPedId()) |
| 65 | + Citizen.Trace( |
| 66 | + string.format("Setting coords to %f %f %f...", coords.x, coords.y, coords.z) |
| 67 | + ) |
| 68 | + if shouldFixFragments then |
| 69 | + Citizen.Trace("Fixing fragments for entity...") |
| 70 | + FixObjectFragment(entity) |
| 71 | + end |
| 72 | + SetEntityCoords(entity, coords, false, false, false, true) |
| 73 | + FreezeEntityPosition(entity, true) |
| 74 | + end) |
| 75 | +end, false) |
| 76 | +``` |
0 commit comments