Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHYSICS - DeleteRope]: Added Native Documentation #1148

Merged

Conversation

JayPaulinCodes
Copy link
Contributor

Summary

Added documentation to the DeleteRope native with inspiration from the DeleteEntity native due to their similar function.

Validating Example(s)

local rope1 = nil
local rope2 = nil

local function spawnRopeOfType(ropeType)
    -- 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, ropePos.y, ropePos.z, 0.0, 0.0, 0.0, 10.0, ropeType, 10.0, 0.0, 1.0, false, false, false, 1.0, false, 0)

    return newRopeHandle
end

RegisterCommand("deleterope_dev_spawn_1", function(soruce, args)
    rope1 = spawnRopeOfType(0)
    print("deleterope_dev_spawn_1 - post", rope1)
end)

RegisterCommand("deleterope_dev_delete_1", function(soruce, args)
    print("deleterope_dev_delete_1 - pre", rope1)
    local delResult = DeleteRope(rope1)
    print("deleterope_dev_delete_1 - post", rope1, delResult)
    rope1 = nil
end)

RegisterCommand("deleterope_dev_spawn_2", function(soruce, args)
    rope2 = spawnRopeOfType(3)
    print("deleterope_dev_spawn_2 - post", rope2)
end)

RegisterCommand("deleterope_dev_delete_2", function(soruce, args)
    print("deleterope_dev_delete_2 - pre", rope2)
    local delResult = DeleteRope(rope2)
    print("deleterope_dev_delete_2 - post", rope2, delResult)
    rope2 = nil
end)

RegisterCommand("deleterope_example", function()
    
    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, ropePos.y, ropePos.z, 0.0, 0.0, 0.0, 10.0, ropeType, 10.0, 0.0, 1.0, false, false, false, 1.0, false, 0)

        -- Delay so we can see the rope for a bit
        Citizen.Wait(1000)

        -- Check if the rope exists.
        if not DoesRopeExist(newRopeHandle) then 
            -- If the rope does not exist, end the execution of the code here.
            return 
        end
    
        -- If the rope does exist, delete the rope.
        DeleteRope(newRopeHandle)

    end)

end)

Contribution Guidelines Acknowledgement

Before you submit this PR, please make sure:

  • You have read the contribution guidelines
  • You include an example that validates your change
  • Your English is grammatically correct

Renamed parameter, added description, and added code examples for Lua and C#
PHYSICS/DeleteRope.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@AvarianKnight AvarianKnight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things to get the examples to work out of the box

PHYSICS/DeleteRope.md Outdated Show resolved Hide resolved
PHYSICS/DeleteRope.md Outdated Show resolved Hide resolved
@AvarianKnight AvarianKnight added the needs validation This looks good, but needs additional confirmation of suggested change. label Aug 6, 2024
- also switches the paramater name back to `ropeId` from `ropeHandle` to maintain consistency with other natives.
@AvarianKnight AvarianKnight added ready-to-merge and removed needs validation This looks good, but needs additional confirmation of suggested change. labels Aug 8, 2024
PHYSICS/DeleteRope.md Outdated Show resolved Hide resolved
@AvarianKnight AvarianKnight merged commit 5b9708d into citizenfx:master Aug 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants