Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
Added the ability to add vehicle bones
Browse files Browse the repository at this point in the history
Good for things like opening doors, repairing engines etc, added an example use case at the bottom as well.
  • Loading branch information
TheeDeer authored Mar 11, 2021
1 parent e65d64d commit cbb5140
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions bt-target/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,58 @@ function playerTargetEnable()
end
end
end

--Vehicle Bones
if nearestVehicle then
for _, bone in pairs(Bones) do
local boneIndex = GetEntityBoneIndexByName(nearestVehicle, _)
local bonePos = GetWorldPositionOfEntityBone(nearestVehicle, boneIndex)
local distanceToBone = GetDistanceBetweenCoords(bonePos, plyCoords, 1)
if #(bonePos - coords) <= Bones[_]["distance"] then
for k , v in ipairs(Bones[_]["job"]) do
if v == "all" or v == currentJob then
if #(plyCoords - coords) <= Bones[_]["distance"] then
success = true
newOptions = {}
for i, op in ipairs(Bones[_]["options"]) do
for z, n in ipairs(Bones[_]["options"][i]['job']) do
if n == 'all' or n == currentJob then
table.insert(newOptions,Bones[_]["options"][i])
end
end
end
SendNUIMessage({response = "validTarget", data = newOptions})

while success and targetActive do
local plyCoords = GetEntityCoords(GetPlayerPed(-1))
local hit, coords, entity = RayCastGamePlayCamera(7.0)
local boneI = GetEntityBoneIndexByName(nearestVehicle, _)

DisablePlayerFiring(PlayerPedId(), true)

if (IsControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 24)) then
SetNuiFocus(true, true)
SetCursorLocation(0.5, 0.5)
end

if #(plyCoords - coords) > Bones[_]["distance"] then
success = false
targetActive = false
SendNUIMessage({response = "closeTarget"})
end

Citizen.Wait(1)
end
SendNUIMessage({response = "leftTarget"})
end
end
end
end
end
end
end


for _, zone in pairs(Zones) do
if Zones[_]:isPointInside(coords) then
for k , v in ipairs(Zones[_]["targetoptions"]["job"]) do
Expand Down Expand Up @@ -145,6 +195,22 @@ RegisterNUICallback('closeTarget', function(data, cb)
targetActive = false
end)

--Added functions
function GetNearestVehicle()
local playerPed = GetPlayerPed(-1)
local playerCoords = GetEntityCoords(playerPed)
if not (playerCoords and playerPed) then
return
end

local pointB = GetEntityForwardVector(playerPed) * 0.001 + playerCoords

local shapeTest = StartShapeTestCapsule(playerCoords.x, playerCoords.y, playerCoords.z, pointB.x, pointB.y, pointB.z, 1.0, 10, playerPed, 7)
local _, hit, _, _, entity = GetShapeTestResult(shapeTest)

return (hit == 1 and IsEntityAVehicle(entity)) and entity or false
end

--Functions from https://forum.cfx.re/t/get-camera-coordinates/183555/14

function RotationToDirection(rotation)
Expand Down Expand Up @@ -200,10 +266,48 @@ function AddTargetModel(models, parameteres)
end
end

function AddTargetBone(bones, parameteres)
for _, bone in pairs(bones) do
Bones[bone] = parameteres
end
end

exports("AddCircleZone", AddCircleZone)

exports("AddBoxZone", AddBoxZone)

exports("AddPolyzone", AddPolyzone)

exports("AddTargetModel", AddTargetModel)

exports("AddTargetBone", AddTargetBone)

--EXAMPLE USAGE OF NEW EDITS
--[[
local doors = {
"door_dside_f",
"door_pside_f",
"door_dside_r",
"door_pside_r",
"boot"
}
exports["bt-target"]:AddTargetBone(doors, {
options = {
{
event = "localEye.door",
icon = "fas fa-door-open",
label = "Toggle Door",
job = {"all"}
},
{
event = "localEye.door.unlock",
icon = "fas fa-door-open",
label = "Unlock Door",
job = {"LEO","FD","DOT"}
},
},
types = doors,
job = {"all"},
distance = 1.5
})
]]

2 comments on commit cbb5140

@LiamDormon
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this not need the GetNearestVehicle function being called when you hold down ALT to work? I'm not seeing anywhere that the nearestVehicle variable is being defined

@LiamDormon
Copy link
Contributor

Choose a reason for hiding this comment

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

When you have more than one bones added and you look from one bone to another it will close the menu and you cannot open it again until you restart the script.

Please sign in to comment.