Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion bt-target/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Models = {}
local Zones = {}
Local Bones = {}

Citizen.CreateThread(function()
RegisterKeyMapping("+playerTarget", "Player Targeting", "keyboard", "LMENU") --Removed Bind System and added standalone version
Expand Down Expand Up @@ -38,7 +39,8 @@ function playerTargetEnable()
while targetActive do
local plyCoords = GetEntityCoords(GetPlayerPed(-1))
local hit, coords, entity = RayCastGamePlayCamera(20.0)

local nearestVehicle = GetNearestVehicle()

if hit == 1 then
if GetEntityType(entity) ~= 0 then
for _, model in pairs(Models) do
Expand Down Expand Up @@ -76,8 +78,52 @@ 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 == PlayerJob.name then
if #(plyCoords - coords) <= Bones[_]["distance"] then
success = true
newOptions = {}
for i, op in ipairs(Bones[_]["options"]) do
table.insert(newOptions,Bones[_]["options"][i])
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
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 +191,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 +262,46 @@ 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",
},
{
event = "localEye.door.unlock",
icon = "fas fa-door-open",
label = "Unlock Door",
},
},
types = doors,
job = {"all"},
distance = 1.5
})
]]