Skip to content

Commit

Permalink
tweak: update c# example for DeleteRope
Browse files Browse the repository at this point in the history
- also switches the paramater name back to `ropeId` from `ropeHandle` to maintain consistency with other natives.
  • Loading branch information
AvarianKnight committed Aug 8, 2024
1 parent 51a6cad commit becee43
Showing 1 changed file with 72 additions and 15 deletions.
87 changes: 72 additions & 15 deletions PHYSICS/DeleteRope.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ ns: PHYSICS

```c
// 0x52B4829281364649 0x748D72AF
void DELETE_ROPE(int* ropeHandle);
void DELETE_ROPE(int* ropeId);
```
Deletes the rope with the specified handle.
You might want to check if the rope exists before with [DOES_ROPE_EXIST](#_0xFD5448BE3111ED96).
## Parameters
* **ropeHandle**: The handle of the rope to delete
* **ropeId**: The handle of the rope to delete
## Examples
```lua
Expand Down Expand Up @@ -52,19 +52,76 @@ end)
```

```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);
}
}

// Create a rope and store the reference
int unkPtr = 0;
int ropehandle = AddRope(0f, 0f, 0f, 0f, 0f, 0f, 10f, 5, 10f, 0f, 1f, false, false, false, 1f, false, ref unkPtr);
/// <summary>
/// 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.
/// </summary>
void CleanupRopeTextures(bool alreadyLoadedByOtherScript)
{
// if we were the script to load the textures then we want to cleanup
// the textures,
if (!alreadyLoadedByOtherScript)
{
RopeUnloadTextures();
}
}

// Check if the rope exists.
if (!DoesRopeExist(ref ropehandle))
{
// If the rope does not exist, end the execution of the code here.
return;
}
// 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 */
);

// If the rope does exist, delete the rope.
DeleteRope(ref ropehandle);
```
// Check if the rope exists.
if (!DoesRopeExist(ref ropehandle))
{
CleanupRopeTextures(isLoadedByAnotherScript);
// whoops, the rope doesn't exist, we don't want 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);
}
```

0 comments on commit becee43

Please sign in to comment.