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 - AddRope]: Updated Rope Type Info #1145

Merged

Conversation

JayPaulinCodes
Copy link
Contributor

Summary

Updated the AddRope native documentation to fix the incorrect information regarding the ropeType parameter and provided more details regarding the 8 possible rope types. Also included a simple example usage of the native in the form of a command.

Validating Example(s)

local currentRope = nil
local propHandle = nil
local propHash = `prop_cs_fuel_nozle`
local pumpHash = `prop_gas_pump_1d`
local timeout = 1000
local pumpCoords = vector3(-2096.096436, -311.906891, 14.510918)
print("propHash", propHash)
print("pumpHash", pumpHash)

function spawnRopeOfType(ropeType)
    print("============================================")
    local pedHandle = PlayerPedId()
    local position = GetEntityCoords(pedHandle)
    print("ped", pedHandle, position)

    -- Create the prop
    if not HasModelLoaded(propHash) then
        local timer = 0
        while not HasModelLoaded(propHash) and timer < timeout do
            RequestModel(propHash)
            timer = timer + 1
            Citizen.Wait(1)
        end
    end
    propHandle = CreateObjectNoOffset(propHash, position.x, position.y, position.z, true, true, false)
    SetModelAsNoLongerNeeded(propHash)
    print("propHandle", propHandle)

    -- Attach the prop to ped
    local boneIndex = GetPedBoneIndex(pedHandle, 18905) -- SKEL_L_Hand
    print("boneIndex", boneIndex)
    AttachEntityToEntity(propHandle, pedHandle, boneIndex, 0.11, 0.02, 0.02, -15.0, -90.0, -80.0, false, false, false, false, 2, true)

    -- Create the rope
    local timer2 = 0
    while not RopeAreTexturesLoaded() and timer2 < timeout do
        RopeLoadTextures()
        timer2 = timer2 + 1
        Citizen.Wait(1)
    end

    currentRope = AddRope(
        0.0, -- x
        0.0, -- y
        0.0, -- z
        0.0, -- rotX
        0.0, -- rotY
        0.0, -- rotZ
        3.0, -- maxLength
        ropeType, -- ropeType
        1000.0, -- initLength
        0.0, -- minLength
        0.5, -- lengthChangeRate
        false, -- onlyPPU
        true, -- collisionOn
        true, -- lockFromFront
        1.0, -- timeMultiplier
        true, -- breakable
        0 -- unkPtr
    )
    print("currentRope", currentRope)
    ActivatePhysics(currentRope)

    -- Attach the rope to the prop
    local propPos = GetOffsetFromEntityInWorldCoords(propHandle, 0.0, -0.033, -0.195)
    print("propPos", propPos)
    local pumpHandle = GetClosestObjectOfType(pumpCoords.x, pumpCoords.y, pumpCoords.z, 10.0, pumpHash, false, true, true)
    print("pumpHandle", pumpHandle)
    local pumpCoords = GetEntityCoords(pumpHandle)
    print("pumpCoords", pumpCoords)
    
    AttachEntitiesToRope(currentRope, pumpHandle, propHandle, 
        pumpCoords.x, pumpCoords.y, pumpCoords.z,
        propPos.x, propPos.y, propPos.z,
        5.0, false, false, nil, nil)
end

RegisterCommand("ropetypes_dev_del", function(soruce, args)
    DeleteRope(currentRope)
    DeleteObject(propHandle)
end)

RegisterCommand("ropetypes_dev_spawn_0", function(soruce, args)
    print("ropetypes_dev_spawn_0")
    spawnRopeOfType(0)
end)

RegisterCommand("ropetypes_dev_spawn_1", function(soruce, args)
    print("ropetypes_dev_spawn_1")
    spawnRopeOfType(1)
end)

RegisterCommand("ropetypes_dev_spawn_2", function(soruce, args)
    print("ropetypes_dev_spawn_2")
    spawnRopeOfType(2)
end)

RegisterCommand("ropetypes_dev_spawn_3", function(soruce, args)
    print("ropetypes_dev_spawn_3")
    spawnRopeOfType(3)
end)

RegisterCommand("ropetypes_dev_spawn_4", function(soruce, args)
    print("ropetypes_dev_spawn_4")
    spawnRopeOfType(4)
end)

RegisterCommand("ropetypes_dev_spawn_5", function(soruce, args)
    print("ropetypes_dev_spawn_5")
    spawnRopeOfType(5)
end)

RegisterCommand("ropetypes_dev_spawn_6", function(soruce, args)
    print("ropetypes_dev_spawn_6")
    spawnRopeOfType(6)
end)

RegisterCommand("ropetypes_dev_spawn_7", function(soruce, args)
    print("ropetypes_dev_spawn_7")
    spawnRopeOfType(7)
end)


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)

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

… more details regarding different rope types
Copy link
Contributor

@colistro123 colistro123 left a comment

Choose a reason for hiding this comment

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

Suggested some corrections and did some nitpicking, otherwise looks good to me for the most part.

PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
Copy link
Contributor

@colistro123 colistro123 left a comment

Choose a reason for hiding this comment

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

LGTM 😊

PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
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 Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
PHYSICS/AddRope.md Outdated Show resolved Hide resolved
@AvarianKnight AvarianKnight mentioned this pull request Aug 6, 2024
@AvarianKnight AvarianKnight added needs validation This looks good, but needs additional confirmation of suggested change. ready-to-merge and removed needs validation This looks good, but needs additional confirmation of suggested change. labels Aug 7, 2024
@AvarianKnight AvarianKnight merged commit b3cc701 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.

3 participants