From ccc4af79d60f6e274c39255720e23a64eb821342 Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Thu, 25 Jul 2024 17:52:02 -0400 Subject: [PATCH 01/10] docs(PHYSICS/AddRope): Fixed incorrect ropeType description and added more details regarding different rope types --- PHYSICS/AddRope.md | 96 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 5bfe6a9ee..bc7f7136d 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -15,6 +15,56 @@ Rope does NOT interact with anything you attach it to, in some cases it make int Rope will sometimes contract and fall to the ground like you'd expect it to, but since it doesn't interact with the world the effect is just jaring. ``` +## Rope Types +There are 8 different rope types in the base game. Full rope data can be found in `ropedata.xml`. +- Type: `rage__ropeThin` + - Rope Type Value: `0` + - Vertices: `1` + - Radius: `0.03` + - Texture Names: `rope` & `rope_n` + +- Type: `rage__ropeWire6` + - Rope Type Value: `1` + - Vertices: `4` + - Radius: `0.015` + - Texture Names: `steel_cable` & `steel_cable_n` + +- Type: `rage__ropeWire32` + - Rope Type Value: `2` + - Vertices: `32` + - Radius: `0.025` + - Texture Names: `steel_cable` & `steel_cable_n` + +- Type: `rage__ropeMesh` + - Rope Type Value: `3` + - Vertices: `6` + - Radius: `0.03` + - Texture Names: `rope` & `rope_n` + +- Type: `rage__ropeThinWire32` + - Rope Type Value: `4` + - Vertices: `32` + - Radius: `0.01` + - Texture Names: `rope` & `rope_n` + +- Type: `rage__ropeReins` + - Rope Type Value: `5` + - Vertices: `32` + - Radius: `0.005` + - Texture Names: `rope` & `rope_n` + +- Type: `rage__ropeThin4` + - Rope Type Value: `6` + - Vertices: `4` + - Radius: `0.03` + - Texture Names: `rope` & `rope_n` + +- Type: `rage__ropeWire64` + - Rope Type Value: `7` + - Vertices: `64` + - Radius: `0.025` + - Texture Names: `steel_cable` & `steel_cable_n` + ## Parameters * **x**: Spawn coordinate X component. * **y**: Spawn coordinate Y component. @@ -23,7 +73,7 @@ Rope will sometimes contract and fall to the ground like you'd expect it to, but * **rotY**: Rotation Y component. * **rotZ**: Rotation Z component. * **maxLength**: The maximum length the rope can droop. -* **ropeType**: 1 to 4 are thick ropes. 5 and up are thin ropes. Ropes types defined in ropedata.xml. An invalid rope type such as 0 will crash the game. +* **ropeType**: The zero-based index of the entry in the `ropedata.xml` file. *NOTE: An invalid rope type, such as `8`, will crash the game.* * **initLength**: The initial length of the rope. * **minLength**: The minimum length the rope can be. * **lengthChangeRate**: The speed in which the rope will wind if winding is started. @@ -35,4 +85,46 @@ Rope will sometimes contract and fall to the ground like you'd expect it to, but * **unkPtr**: Unknown pointer, always 0 in original scrips. ## Return value -A script handle for the rope \ No newline at end of file +A script handle for the rope + +## Examples +```lua +RegisterCommand("new_rope", function(soruce, args) + + -- Get the handle for the player's ped + local pedHandle = PlayerPedId() + + -- Ensure that the rope textures are loaded + local timer = 0 + while not RopeAreTexturesLoaded() and timer < 1000 do + RopeLoadTextures() + timer = timer + 1 + Citizen.Wait(0) + end + + -- Get the coordinates for where the rope will be + local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) + + -- Create the rope + local newRopeHandle = AddRope( + ropePos.x, -- x + ropePos.y, -- y + ropePos.z, -- z + 0.0, -- rotX + 0.0, -- rotY + 0.0, -- rotZ + 10.0, -- maxLength + 1, -- ropeType + 10.0, -- initLength + 0.0, -- minLength + 1.0, -- lengthChangeRate + false, -- onlyPPU + false, -- collisionOn + false, -- lockFromFront + 1.0, -- timeMultiplier + false, -- breakable + 0 -- unkPtr + ) + +end) +``` \ No newline at end of file From 711c418c31e94105029fa0a9af45cc56b723bc4f Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Fri, 26 Jul 2024 15:11:18 -0400 Subject: [PATCH 02/10] chore(PHYSICS/AddRope): Updates and corrections based on review comments --- PHYSICS/AddRope.md | 87 +++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index bc7f7136d..0d1b0ab5b 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -15,7 +15,7 @@ Rope does NOT interact with anything you attach it to, in some cases it make int Rope will sometimes contract and fall to the ground like you'd expect it to, but since it doesn't interact with the world the effect is just jaring. ``` -## Rope Types +### Rope Types There are 8 different rope types in the base game. Full rope data can be found in `ropedata.xml`. - Type: `rage__ropeThin` - Rope Type Value: `0` @@ -73,7 +73,7 @@ There are 8 different rope types in the base game. Full rope data can be found i * **rotY**: Rotation Y component. * **rotZ**: Rotation Z component. * **maxLength**: The maximum length the rope can droop. -* **ropeType**: The zero-based index of the entry in the `ropedata.xml` file. *NOTE: An invalid rope type, such as `8`, will crash the game.* +* **ropeType**: The zero-based index of the entry in the `ropedata.xml` file. *NOTE: Using an index which does not exist will crash the game. As of right now, valid values are from `0` to `7` inclusive.* * **initLength**: The initial length of the rope. * **minLength**: The minimum length the rope can be. * **lengthChangeRate**: The speed in which the rope will wind if winding is started. @@ -89,42 +89,49 @@ A script handle for the rope ## Examples ```lua -RegisterCommand("new_rope", function(soruce, args) - - -- Get the handle for the player's ped - local pedHandle = PlayerPedId() - - -- Ensure that the rope textures are loaded - local timer = 0 - while not RopeAreTexturesLoaded() and timer < 1000 do - RopeLoadTextures() - timer = timer + 1 - Citizen.Wait(0) - end - - -- Get the coordinates for where the rope will be - local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) - - -- Create the rope - local newRopeHandle = AddRope( - ropePos.x, -- x - ropePos.y, -- y - ropePos.z, -- z - 0.0, -- rotX - 0.0, -- rotY - 0.0, -- rotZ - 10.0, -- maxLength - 1, -- ropeType - 10.0, -- initLength - 0.0, -- minLength - 1.0, -- lengthChangeRate - false, -- onlyPPU - false, -- collisionOn - false, -- lockFromFront - 1.0, -- timeMultiplier - false, -- breakable - 0 -- unkPtr - ) - -end) +RegisterCommand("new_rope", function(source, args, rawCommand) + + Citizen.CreateThread(function() + -- Get the handle for the player's ped + local pedHandle = PlayerPedId() + + -- Ensure that the rope textures are loaded + local timer = 0 + while not RopeAreTexturesLoaded() and timer < 1000 do + RopeLoadTextures() + timer = timer + 1 + Citizen.Wait(0) + end + + if not RopeAreTexturesLoaded() then + -- Error handling for the edge case where rope textures are not able to be loaded + print("Wasn't able to load rope textures!") + else + -- Get the coordinates for where the rope will be + local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) + + -- Create the rope + local newRopeHandle = AddRope( + ropePos.x, -- x + ropePos.y, -- y + ropePos.z, -- z + 0.0, -- rotX + 0.0, -- rotY + 0.0, -- rotZ + 10.0, -- maxLength + 1, -- ropeType + 10.0, -- initLength + 0.0, -- minLength + 1.0, -- lengthChangeRate + false, -- onlyPPU + false, -- collisionOn + false, -- lockFromFront + 1.0, -- timeMultiplier + false, -- breakable + 0 -- unkPtr + ) + end + end) + +end, false) ``` \ No newline at end of file From 8ec7240a0d29857f042ea1ac4a365493b48e4df8 Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Fri, 26 Jul 2024 16:32:58 -0400 Subject: [PATCH 03/10] chore(PHYSICS/AddRope): Updated example based on review comments --- PHYSICS/AddRope.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 0d1b0ab5b..1f807a916 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -96,10 +96,8 @@ RegisterCommand("new_rope", function(source, args, rawCommand) local pedHandle = PlayerPedId() -- Ensure that the rope textures are loaded - local timer = 0 - while not RopeAreTexturesLoaded() and timer < 1000 do + while not RopeAreTexturesLoaded() do RopeLoadTextures() - timer = timer + 1 Citizen.Wait(0) end From 48b4466d4948608af6517de8878fda0a96cbfa29 Mon Sep 17 00:00:00 2001 From: Jacob Paulin <56453471+JayPaulinCodes@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:34:01 -0400 Subject: [PATCH 04/10] docs(PHYSICS/AddRope): Updated code example based on review comments Co-authored-by: Dillon Skaggs --- PHYSICS/AddRope.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 1f807a916..7ac9b4ccc 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -96,8 +96,8 @@ RegisterCommand("new_rope", function(source, args, rawCommand) local pedHandle = PlayerPedId() -- Ensure that the rope textures are loaded + RopeLoadTextures() while not RopeAreTexturesLoaded() do - RopeLoadTextures() Citizen.Wait(0) end From 54220daee63e2c1d0ef56ce34ed0c6f51e61a404 Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Thu, 1 Aug 2024 07:37:21 -0400 Subject: [PATCH 05/10] docs(PHYSICS/AddRope): Updated code example based on review comments --- PHYSICS/AddRope.md | 51 +++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 7ac9b4ccc..2d9c2f19c 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -101,34 +101,29 @@ RegisterCommand("new_rope", function(source, args, rawCommand) Citizen.Wait(0) end - if not RopeAreTexturesLoaded() then - -- Error handling for the edge case where rope textures are not able to be loaded - print("Wasn't able to load rope textures!") - else - -- Get the coordinates for where the rope will be - local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) - - -- Create the rope - local newRopeHandle = AddRope( - ropePos.x, -- x - ropePos.y, -- y - ropePos.z, -- z - 0.0, -- rotX - 0.0, -- rotY - 0.0, -- rotZ - 10.0, -- maxLength - 1, -- ropeType - 10.0, -- initLength - 0.0, -- minLength - 1.0, -- lengthChangeRate - false, -- onlyPPU - false, -- collisionOn - false, -- lockFromFront - 1.0, -- timeMultiplier - false, -- breakable - 0 -- unkPtr - ) - end + -- Get the coordinates for where the rope will be + local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) + + -- Create the rope + local newRopeHandle = AddRope( + ropePos.x, -- x + ropePos.y, -- y + ropePos.z, -- z + 0.0, -- rotX + 0.0, -- rotY + 0.0, -- rotZ + 10.0, -- maxLength + 1, -- ropeType + 10.0, -- initLength + 0.0, -- minLength + 1.0, -- lengthChangeRate + false, -- onlyPPU + false, -- collisionOn + false, -- lockFromFront + 1.0, -- timeMultiplier + false, -- breakable + 0 -- unkPtr + ) end) end, false) From fd2fc607fb600b1c370acbd11097be55b83002a3 Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Sat, 3 Aug 2024 08:09:28 -0400 Subject: [PATCH 06/10] docs(PHYSICS/AddRope): Updated code example and type info Based on review comments the code example was updated to remove the command portion, and the previous list of rope types was swapped to a enum with comments for extra details. --- PHYSICS/AddRope.md | 130 ++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 83 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 2d9c2f19c..aa2cba9d7 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -17,53 +17,21 @@ Rope will sometimes contract and fall to the ground like you'd expect it to, but ### Rope Types There are 8 different rope types in the base game. Full rope data can be found in `ropedata.xml`. -- Type: `rage__ropeThin` - - Rope Type Value: `0` - - Vertices: `1` - - Radius: `0.03` - - Texture Names: `rope` & `rope_n` -- Type: `rage__ropeWire6` - - Rope Type Value: `1` - - Vertices: `4` - - Radius: `0.015` - - Texture Names: `steel_cable` & `steel_cable_n` +Rope types: -- Type: `rage__ropeWire32` - - Rope Type Value: `2` - - Vertices: `32` - - Radius: `0.025` - - Texture Names: `steel_cable` & `steel_cable_n` - -- Type: `rage__ropeMesh` - - Rope Type Value: `3` - - Vertices: `6` - - Radius: `0.03` - - Texture Names: `rope` & `rope_n` - -- Type: `rage__ropeThinWire32` - - Rope Type Value: `4` - - Vertices: `32` - - Radius: `0.01` - - Texture Names: `rope` & `rope_n` - -- Type: `rage__ropeReins` - - Rope Type Value: `5` - - Vertices: `32` - - Radius: `0.005` - - Texture Names: `rope` & `rope_n` - -- Type: `rage__ropeThin4` - - Rope Type Value: `6` - - Vertices: `4` - - Radius: `0.03` - - Texture Names: `rope` & `rope_n` - -- Type: `rage__ropeWire64` - - Rope Type Value: `7` - - Vertices: `64` - - Radius: `0.025` - - Texture Names: `steel_cable` & `steel_cable_n` +```c +enum ePhysicsRopeType { + RopeThin = 0, // Verticies: 1, Radius: 0.03, Textures: rope & rope_n + RopeWire6 = 1, // Verticies: 4, Radius: 0.015, Textures: steel_cable & steel_cable_n + RopeWire32 = 2, // Verticies: 32, Radius: 0.025, Textures: steel_cable & steel_cable_n + RopeMesh = 3, // Verticies: 6, Radius: 0.03, Textures: rope & rope_n + RopeThinWire32 = 4, // Verticies: 32, Radius: 0.01, Textures: rope & rope_n + RopeReins = 5, // Verticies: 32, Radius: 0.005, Textures: rope & rope_n + RopeThin4 = 6, // Verticies: 4, Radius: 0.03, Textures: rope & rope_n + RopeWire64 = 7 // Verticies: 64, Radius: 0.025, Textures: steel_cable & steel_cable_n +} +``` ## Parameters * **x**: Spawn coordinate X component. @@ -89,42 +57,38 @@ A script handle for the rope ## Examples ```lua -RegisterCommand("new_rope", function(source, args, rawCommand) - - Citizen.CreateThread(function() - -- Get the handle for the player's ped - local pedHandle = PlayerPedId() - - -- Ensure that the rope textures are loaded - RopeLoadTextures() - while not RopeAreTexturesLoaded() do - Citizen.Wait(0) - end - - -- Get the coordinates for where the rope will be - local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) - - -- Create the rope - local newRopeHandle = AddRope( - ropePos.x, -- x - ropePos.y, -- y - ropePos.z, -- z - 0.0, -- rotX - 0.0, -- rotY - 0.0, -- rotZ - 10.0, -- maxLength - 1, -- ropeType - 10.0, -- initLength - 0.0, -- minLength - 1.0, -- lengthChangeRate - false, -- onlyPPU - false, -- collisionOn - false, -- lockFromFront - 1.0, -- timeMultiplier - false, -- breakable - 0 -- unkPtr - ) - end) - -end, false) +Citizen.CreateThread(function() + -- Get the handle for the player's ped + local pedHandle = PlayerPedId() + + -- Ensure that the rope textures are loaded + RopeLoadTextures() + while not RopeAreTexturesLoaded() do + Citizen.Wait(0) + end + + -- Get the coordinates for where the rope will be + local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) + + -- Create the rope + local newRopeHandle = AddRope( + ropePos.x, -- x + ropePos.y, -- y + ropePos.z, -- z + 0.0, -- rotX + 0.0, -- rotY + 0.0, -- rotZ + 10.0, -- maxLength + 1, -- ropeType + 10.0, -- initLength + 0.0, -- minLength + 1.0, -- lengthChangeRate + false, -- onlyPPU + false, -- collisionOn + false, -- lockFromFront + 1.0, -- timeMultiplier + false, -- breakable + 0 -- unkPtr + ) +end) ``` \ No newline at end of file From 1e965b30020af44e8a2cc5b190b70f978e9422bf Mon Sep 17 00:00:00 2001 From: Jacob Paulin <56453471+JayPaulinCodes@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:36:55 -0400 Subject: [PATCH 07/10] chore(PHYSICS/AddRope): Updated based on review Co-authored-by: Dillon Skaggs --- PHYSICS/AddRope.md | 1 - 1 file changed, 1 deletion(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index aa2cba9d7..33dd5b681 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -15,7 +15,6 @@ Rope does NOT interact with anything you attach it to, in some cases it make int Rope will sometimes contract and fall to the ground like you'd expect it to, but since it doesn't interact with the world the effect is just jaring. ``` -### Rope Types There are 8 different rope types in the base game. Full rope data can be found in `ropedata.xml`. Rope types: From 531f415b8bdc115e97e3002eb9cf762eb4ceecc4 Mon Sep 17 00:00:00 2001 From: Jacob Paulin <56453471+JayPaulinCodes@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:37:04 -0400 Subject: [PATCH 08/10] chore(PHYSICS/AddRope): Updated based on review Co-authored-by: Dillon Skaggs --- PHYSICS/AddRope.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 33dd5b681..13eed508d 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -17,8 +17,6 @@ Rope will sometimes contract and fall to the ground like you'd expect it to, but There are 8 different rope types in the base game. Full rope data can be found in `ropedata.xml`. -Rope types: - ```c enum ePhysicsRopeType { RopeThin = 0, // Verticies: 1, Radius: 0.03, Textures: rope & rope_n From eca89fdce479645bf7f4502a33265a464a27b284 Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Tue, 6 Aug 2024 17:43:38 -0400 Subject: [PATCH 09/10] chore(PHYSICS/AddRope): Updated wording based on review --- PHYSICS/AddRope.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index 13eed508d..eb848fab9 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -38,7 +38,7 @@ enum ePhysicsRopeType { * **rotY**: Rotation Y component. * **rotZ**: Rotation Z component. * **maxLength**: The maximum length the rope can droop. -* **ropeType**: The zero-based index of the entry in the `ropedata.xml` file. *NOTE: Using an index which does not exist will crash the game. As of right now, valid values are from `0` to `7` inclusive.* +* **ropeType**: The zero-based index of the entry in the `ropedata.xml` file. *NOTE: Using an index which does not exist will crash the game. As of game build 3258, valid values are from `0` to `7` inclusive.* * **initLength**: The initial length of the rope. * **minLength**: The minimum length the rope can be. * **lengthChangeRate**: The speed in which the rope will wind if winding is started. From 836fc2bc7b2f17ee6512e07b68833b5a4b7f6da9 Mon Sep 17 00:00:00 2001 From: Dillon Skaggs Date: Thu, 8 Aug 2024 18:41:54 -0500 Subject: [PATCH 10/10] tweak: update example to include load/delete/exists checks --- PHYSICS/AddRope.md | 154 +++++++++++++++++++++++++++++++++------------ 1 file changed, 115 insertions(+), 39 deletions(-) diff --git a/PHYSICS/AddRope.md b/PHYSICS/AddRope.md index eb848fab9..a62376c38 100644 --- a/PHYSICS/AddRope.md +++ b/PHYSICS/AddRope.md @@ -9,10 +9,10 @@ int ADD_ROPE(float x, float y, float z, float rotX, float rotY, float rotZ, floa ``` ``` -Creates a rope at the specific position, that extends in the specified direction when not attached to any entities. -__ -Rope does NOT interact with anything you attach it to, in some cases it make interact with the world AFTER it breaks (seems to occur if you set the type to -1). -Rope will sometimes contract and fall to the ground like you'd expect it to, but since it doesn't interact with the world the effect is just jaring. +Creates a rope at the specific position, that extends in the specified direction when not attached to any entities. +__ +Rope does NOT interact with anything you attach it to, in some cases it make interact with the world AFTER it breaks (seems to occur if you set the type to -1). +Rope will sometimes contract and fall to the ground like you'd expect it to, but since it doesn't interact with the world the effect is just jaring. ``` There are 8 different rope types in the base game. Full rope data can be found in `ropedata.xml`. @@ -42,7 +42,7 @@ enum ePhysicsRopeType { * **initLength**: The initial length of the rope. * **minLength**: The minimum length the rope can be. * **lengthChangeRate**: The speed in which the rope will wind if winding is started. -* **onlyPPU**: +* **onlyPPU**: * **collisionOn**: Whether the rope should have collision. In original scripts this is followed by a LoadRopeData call when set. * **lockFromFront**: If max length is zero, and this is set to false the rope will become rigid (it will force a specific distance, what ever length is, between the objects). * **timeMultiplier**: The speed as which physics should run at. 1.0f is normal, 2.0f is twice as fast, -1.0f is time going backwards. This can affect gravity, etc. @@ -54,38 +54,114 @@ A script handle for the rope ## Examples ```lua -Citizen.CreateThread(function() - -- Get the handle for the player's ped - local pedHandle = PlayerPedId() - - -- Ensure that the rope textures are loaded - RopeLoadTextures() - while not RopeAreTexturesLoaded() do - Citizen.Wait(0) - end - - -- Get the coordinates for where the rope will be - local ropePos = GetOffsetFromEntityInWorldCoords(pedHandle, 0.0, 2.0, 0.5) - - -- Create the rope - local newRopeHandle = AddRope( - ropePos.x, -- x - ropePos.y, -- y - ropePos.z, -- z - 0.0, -- rotX - 0.0, -- rotY - 0.0, -- rotZ - 10.0, -- maxLength - 1, -- ropeType - 10.0, -- initLength - 0.0, -- minLength - 1.0, -- lengthChangeRate - false, -- onlyPPU - false, -- collisionOn - false, -- lockFromFront - 1.0, -- timeMultiplier - false, -- breakable - 0 -- unkPtr - ) +local function cleanup_rope_textures() + -- we only want to cleanup if there are no other ropes still left on the map + -- otherwise we'll make them go invisible. + if #GetAllRopes() == 0 then + -- there are no ropes on the map, we're safe to unload the textures. + RopeUnloadTextures() + end +end + +CreateThread(function() + -- if textures aren't loaded then we need to load them + if not RopeAreTexturesLoaded() then + -- load the textures so we can see the rope + RopeLoadTextures() + while not RopeAreTexturesLoaded() do + Wait(0) + end + end + + -- Create a rope and store the handle + local rope = AddRope(-2096.096, -311.906, 14.51, 0.0, 0.0, 0.0, 10.0, 1, 10.0, 0.0, 1.0, false, false, false, 1.0, false, 0) + -- Check if the rope exists. + if not DoesRopeExist(rope) then + cleanup_rope_textures() + -- If the rope does not exist, end the execution of the code here. + return + end + -- Let the rope exist for 3 seconds + Wait(3000) + -- Delete the rope! + DeleteRope(rope) + cleanup_rope_textures() end) -``` \ No newline at end of file +``` + +```cs +using static CitizenFX.Core.Native.API; + +async Task CreateRope() +{ + // wait for the textures to be loaded before we create the rope, + // otherwise it will be invisible. + bool isLoadedByAnotherScript = RopeAreTexturesLoaded(); + if (!isLoadedByAnotherScript) + { + RopeLoadTextures(); + while (!RopeAreTexturesLoaded()) + { + await BaseScript.Delay(0); + } + } + + /// + /// Unloads the rope texture if we were the script that requested it. + /// NOTE: This is bug prone, if possible you should do your own reference + /// counting via global state bags. + /// + void CleanupRopeTextures(bool alreadyLoadedByOtherScript) + { + // if we were the script to load the textures then we want to cleanup + // the textures, + if (!alreadyLoadedByOtherScript) + { + RopeUnloadTextures(); + } + } + + // not used by anything + int _unusedStringPtr = 0; + + Vector3 ropePosition = new Vector3(-2096.09f, -311.90f, 14.51f); + Vector3 ropeRotation = Vector3.Zero; + + // Create a rope and store the handle + int ropehandle = AddRope( + ropePosition.X, + ropePosition.Y, + ropePosition.Z, + ropeRotation.X, + ropeRotation.Y, + ropeRotation.Z, + 10f /* max length */, + 1 /* rope type */, + 10f /* init length */, + 0.5f /* min length */, + 0.5f /* length change rate */, + false /* ppu only */, + false /* collision on */, + false /* lock from front */, + 1f /* time multiplier */, + false /* breakable */, + ref _unusedStringPtr /* unused */ + ); + + // Check if the rope exists. + if (!DoesRopeExist(ref ropehandle)) + { + CleanupRopeTextures(isLoadedByAnotherScript); + // whoops, the rope doesn't exist, we don't want to do + // anything with an invalid reference + return; + } + + // We want to see the rope for 3 seconds + await BaseScript.Delay(3000); + + // begone rope! + DeleteRope(ref ropehandle); + CleanupRopeTextures(isLoadedByAnotherScript); +} +```