Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
93 changes: 50 additions & 43 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,37 @@ end
---@return table|nil Entity information or nil if entity doesn't exist
local function GetEntityInfo(entity)
if not DoesEntityExist(entity) then return nil end

local coords = GetEntityCoords(entity)
local rotation = GetEntityRotation(entity, 2)
local heading = GetEntityHeading(entity)
local hash = GetEntityModel(entity)
local hashStr = tostring(hash)
local entityType = GetEntityType(entity)

local distance = #(coords - GetEntityCoords(PlayerPedId()))

local entityTypeStr = "Unknown"
if entityType == 1 then entityTypeStr = "Ped"
elseif entityType == 2 then entityTypeStr = "Vehicle"
elseif entityType == 3 then entityTypeStr = "Object" end

if entityType == 1 then
entityTypeStr = "Ped"
elseif entityType == 2 then
entityTypeStr = "Vehicle"
elseif entityType == 3 then
entityTypeStr = "Object"
end

local networkId = 'N/A'
if NetworkGetEntityIsNetworked(entity) then
networkId = NetworkGetNetworkIdFromEntity(entity)
end

return {
entity = entity,
hash = hash,
hashStr = hashStr,
coords = coords,
rotation = rotation,
heading = heading,
distance = distance,
type = entityTypeStr,
networkId = networkId
}
Expand All @@ -47,9 +53,9 @@ end
---@param entity number The entity handle
local function UpdateEntityInfo(entity)
if not entity or not DoesEntityExist(entity) then return end

lastEntityInfo = GetEntityInfo(entity)

SendNUIMessage({
type = 'updateInfo',
info = lastEntityInfo
Expand All @@ -58,11 +64,11 @@ end

---@param format string Format to copy ('model', 'coords', 'rotation', 'heading', 'all')
local function CopyInfo(format)
if not lastEntityInfo then
if not lastEntityInfo then
Notify("No entity information available", "error", 3000)
return
return
end

SendNUIMessage({
type = 'copyFormat',
format = format,
Expand Down Expand Up @@ -101,13 +107,13 @@ local function RotationToDirection(rotation)
y = (math.pi / 180) * rotation.y,
z = (math.pi / 180) * rotation.z
}

local direction = {
x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
z = math.sin(adjustedRotation.x)
}

return vector3(direction.x, direction.y, direction.z)
end

Expand All @@ -122,15 +128,15 @@ local function RaycastCamera(distance)
y = cameraCoord.y + direction.y * distance,
z = cameraCoord.z + direction.z * distance
}

local _, hit, endCoords, _, entityHit = GetShapeTestResult(
StartShapeTestRay(
cameraCoord.x, cameraCoord.y, cameraCoord.z,
destination.x, destination.y, destination.z,
-1, PlayerPedId(), 0
)
)

return hit, endCoords, entityHit
end

Expand All @@ -139,81 +145,81 @@ local function StopPropInfoMode()
isActive = false
displayInfo = false
targetEntity = nil

SendNUIMessage({
type = 'showUI',
show = false
})

SendNUIMessage({
type = 'showNoEntity',
show = false
})

SendNUIMessage({
type = 'updateInfo',
info = nil
})

Notify("Entity Info Mode deactivated", "error", Config.Notifications.duration.standard)
end

---@class PropInfoMode Starts the prop info mode
local function StartPropInfoMode()
isActive = true
displayInfo = true

SendNUIMessage({
type = 'showUI',
show = true
})

Notify("Entity Info Mode activated", "success", Config.Notifications.duration.standard)

CreateThread(function()
while isActive do
Wait(0)

local playerPed = PlayerPedId()

local hit, endCoords, entityHit = RaycastCamera(Config.Raycast.maxDistance)

if hit == 1 and DoesEntityExist(entityHit) then
targetEntity = entityHit

local playerPos = GetEntityCoords(playerPed)

if Config.Raycast.drawLine then
DrawLine(
playerPos.x, playerPos.y, playerPos.z,
endCoords.x, endCoords.y, endCoords.z,
Config.Raycast.lineColor[1], Config.Raycast.lineColor[2],
Config.Raycast.lineColor[1], Config.Raycast.lineColor[2],
Config.Raycast.lineColor[3], Config.Raycast.lineColor[4]
)
end

if Config.Raycast.drawMarker then
DrawMarker(0x50638AB9, endCoords.x, endCoords.y, endCoords.z,
0.0, 0.0, 0.0, 0.0, 180.0, 0.0,
Config.Raycast.markerSize, Config.Raycast.markerSize, Config.Raycast.markerSize,
Config.Raycast.markerColor[1], Config.Raycast.markerColor[2],
Config.Raycast.markerColor[3], Config.Raycast.markerColor[4],
false, false, 2, false, nil, nil, false)
DrawMarker(0x50638AB9, endCoords.x, endCoords.y, endCoords.z,
0.0, 0.0, 0.0, 0.0, 180.0, 0.0,
Config.Raycast.markerSize, Config.Raycast.markerSize, Config.Raycast.markerSize,
Config.Raycast.markerColor[1], Config.Raycast.markerColor[2],
Config.Raycast.markerColor[3], Config.Raycast.markerColor[4],
false, false, 2, false, nil, nil, false)
end

if displayInfo then
UpdateEntityInfo(entityHit)
SendNUIMessage({
type = 'showUI',
show = true
})
end

SendNUIMessage({
type = 'showNoEntity',
show = false
})

if IsControlJustReleased(0, Config.Keys.copyModel) then
CopyInfo('model')
elseif IsControlJustReleased(0, Config.Keys.copyCoords) then
Expand All @@ -230,14 +236,15 @@ local function StartPropInfoMode()
type = 'showUI',
show = displayInfo
})
Notify("Info display: " .. (displayInfo and "ON" or "OFF"), "primary", Config.Notifications.duration.short)
Notify("Info display: " .. (displayInfo and "ON" or "OFF"), "primary",
Config.Notifications.duration.short)
end
else
SendNUIMessage({
type = 'showNoEntity',
show = true
})

if targetEntity then
targetEntity = nil
SendNUIMessage({
Expand All @@ -256,5 +263,5 @@ RegisterCommand(Config.Commands.main, function()
else
StartPropInfoMode()
end
end, true)
TriggerEvent("chat:addSuggestion", "/"..Config.Commands.main, "Toggle display of entity information", {})
end, false)
TriggerEvent("chat:addSuggestion", "/" .. Config.Commands.main, "Toggle display of entity information", {})
20 changes: 10 additions & 10 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ Config.Commands = {

-- Key bindings
Config.Keys = {
toggle = 0xD9D0E1C0, -- Space key
copyModel = 0x760A9C6F, -- G key
copyCoords = 0xCEFD9220, -- E key
toggle = 0xD9D0E1C0, -- Space key
copyModel = 0x760A9C6F, -- G key
copyCoords = 0xCEFD9220, -- E key
copyRotation = 0xE30CD707, -- R key
copyHeading = 0xF3830D8E, -- J key
copyAll = 0x26E9DC00, -- Z key
copyHeading = 0xF3830D8E, -- J key
copyAll = 0x26E9DC00, -- Z key
}

-- Raycast settings
Config.Raycast = {
maxDistance = 25.0,
maxDistance = 50,
drawLine = true,
lineColor = {255, 0, 0, 180}, -- RGBA
lineColor = { 255, 0, 0, 180 }, -- RGBA
drawMarker = true,
markerColor = {255, 0, 0, 255}, -- RGBA
markerColor = { 255, 0, 0, 255 }, -- RGBA
markerSize = 0.03
}

Expand Down Expand Up @@ -50,7 +50,7 @@ function Notify(message, type, duration)
})
return
end

-- VORP
if GetResourceState('vorp_core') ~= 'missing' then
TriggerEvent('vorp:TipBottom', message, duration)
Expand All @@ -59,4 +59,4 @@ function Notify(message, type, duration)

-- Fallback F8 Console
print("^3[ENTITY INFO]^0 " .. message)
end
end
4 changes: 4 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ <h2>Entity Information</h2>
<div class="label">HEADING</div>
<div class="value">{{ formatHeading(entityInfo.heading) }}</div>
</div>
<div class="info-row">
<div class="label">DISTANCE</div>
<div class="value">{{ formatDistance(entityInfo.distance) }}</div>
</div>

<div class="controls">
<div><span class="key">G</span> Copy model hash</div>
Expand Down
Loading