Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.
Open
Changes from 1 commit
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
43 changes: 21 additions & 22 deletions bt-target/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ end

function playerTargetEnable()
if success then return end
if IsPedArmed(PlayerPedId(), 6) then return end
local playerPed = GetPlayerPed(-1) -- Defining player ped id before running loop
Copy link
Contributor

Choose a reason for hiding this comment

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

PlayerPedId() is more performant than GetPlayerPed(-1), not sure why you've swapped them here.

if IsPedArmed(playerPed, 6) then return end

targetActive = true

SendNUIMessage({response = "openTarget"})

while targetActive do
local plyCoords = GetEntityCoords(GetPlayerPed(-1))
local plyCoords = GetEntityCoords(playerPed)
local hit, coords, entity = RayCastGamePlayCamera(20.0)

if hit == 1 then
Expand All @@ -45,32 +46,30 @@ function playerTargetEnable()
if _ == GetEntityModel(entity) then
for k , v in ipairs(Models[_]["job"]) do
if v == "all" or v == PlayerJob.name then
if _ == GetEntityModel(entity) then
if #(plyCoords - coords) <= Models[_]["distance"] then
if #(plyCoords - coords) <= Models[_]["distance"] then

success = true
success = true

SendNUIMessage({response = "validTarget", data = Models[_]["options"]})
SendNUIMessage({response = "validTarget", data = Models[_]["options"]})

while success and targetActive do
local plyCoords = GetEntityCoords(GetPlayerPed(-1))
local hit, coords, entity = RayCastGamePlayCamera(20.0)
while success and targetActive do
local plyCoords = GetEntityCoords(playerPed)
local hit, coords, entity = RayCastGamePlayCamera(20.0)

DisablePlayerFiring(PlayerPedId(), true)
DisablePlayerFiring(playerPed, true)

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

if GetEntityType(entity) == 0 or #(plyCoords - coords) > Models[_]["distance"] then
success = false
end
if (IsControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 24)) then
SetNuiFocus(true, true)
SetCursorLocation(0.5, 0.5)
end

Citizen.Wait(1)
if GetEntityType(entity) == 0 or #(plyCoords - coords) > Models[_]["distance"] then
success = false
end
SendNUIMessage({response = "leftTarget"})

Citizen.Wait(1)
end
SendNUIMessage({response = "leftTarget"})
end
end
end
Expand All @@ -88,10 +87,10 @@ function playerTargetEnable()

SendNUIMessage({response = "validTarget", data = Zones[_]["targetoptions"]["options"]})
while success and targetActive do
local plyCoords = GetEntityCoords(GetPlayerPed(-1))
local plyCoords = GetEntityCoords(playerPed)
local hit, coords, entity = RayCastGamePlayCamera(20.0)

DisablePlayerFiring(PlayerPedId(), true)
DisablePlayerFiring(playerPed, true)

if (IsControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 24)) then
SetNuiFocus(true, true)
Expand Down