Add files via upload
This commit is contained in:
22 files changed
+2196
No files matched your search
@@ -0,0 +1,41 @@
|
||||
if GetConvar('interact_disabledefault', 'false') == 'true' then
|
||||
return
|
||||
end
|
||||
|
||||
local api = require 'client.interactions'
|
||||
|
||||
|
||||
|
||||
api.addGlobalVehicleInteraction({
|
||||
distance = 5.0,
|
||||
interactDst = 1.5,
|
||||
offset = vec3(0.0, 1.0, 0.0),
|
||||
bone = 'boot',
|
||||
id = 'interact:defaultTrunk',
|
||||
options = {
|
||||
name = 'interact:trunk',
|
||||
label = 'Trunk',
|
||||
action = function(entity)
|
||||
if GetVehicleDoorLockStatus(entity) ~= 1 then
|
||||
return lib.notify({ type = 'error', title = 'The trunk is locked.' })
|
||||
end
|
||||
|
||||
if GetVehicleDoorAngleRatio(entity, 5) <= 0.0 then
|
||||
return lib.notify({ type = 'error', title = 'the trunk is not open' })
|
||||
end
|
||||
|
||||
local plate = GetVehicleNumberPlateText(entity)
|
||||
local invId = 'trunk'..plate
|
||||
local coords = GetEntityCoords(entity)
|
||||
|
||||
TaskTurnPedToFaceCoord(cache.ped, coords.x, coords.y, coords.z, 0)
|
||||
|
||||
if not ps-inventory:openInventory('trunk', { id = invId, netid = NetworkGetNetworkIdFromEntity(entity), entityid = entity, door = 5 }) then return end
|
||||
end,
|
||||
},
|
||||
options = {
|
||||
label = 'hehehe',
|
||||
action = function(entity)
|
||||
end,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,114 @@
|
||||
local entities = {}
|
||||
local netIds = {}
|
||||
local models = {}
|
||||
local localEnties = {}
|
||||
|
||||
-- Sub caches are used for caching shit that is run every 250ms in the main loop
|
||||
local subCache = {}
|
||||
|
||||
function entities.isNetIdNearby(netID)
|
||||
local entity = netIds[netID]
|
||||
return entity and entity.entity
|
||||
end
|
||||
|
||||
function entities.getModelEntities(model)
|
||||
return models[model]
|
||||
end
|
||||
|
||||
function entities.isEntityNearby(entity)
|
||||
return localEnties[entity]
|
||||
end
|
||||
|
||||
function entities.getEntitiesByType(type)
|
||||
local amount = 0
|
||||
local entityTable = {}
|
||||
|
||||
if subCache[type] then
|
||||
return #subCache[type], subCache[type]
|
||||
end
|
||||
|
||||
for k, v in pairs(localEnties) do
|
||||
if v.type == type then
|
||||
amount = amount + 1
|
||||
entityTable[amount] = k
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(netIds) do
|
||||
if v.type == type then
|
||||
amount = amount + 1
|
||||
entityTable[amount] = v.entity
|
||||
end
|
||||
end
|
||||
|
||||
subCache[type] = entityTable
|
||||
|
||||
return amount, entityTable
|
||||
end
|
||||
|
||||
local function clearTables()
|
||||
table.wipe(netIds)
|
||||
table.wipe(models)
|
||||
table.wipe(localEnties)
|
||||
table.wipe(subCache)
|
||||
end
|
||||
|
||||
local NetworkGetNetworkIdFromEntity = NetworkGetNetworkIdFromEntity
|
||||
local NetworkGetEntityIsNetworked = NetworkGetEntityIsNetworked
|
||||
local GetEntityModel = GetEntityModel
|
||||
|
||||
local function buildEntities(eType, playerCoords)
|
||||
local entityPool = GetGamePool(eType)
|
||||
|
||||
local type = eType:sub(2):lower()
|
||||
|
||||
for i = 1, #entityPool do
|
||||
local entity = entityPool[i]
|
||||
|
||||
if #(playerCoords - GetEntityCoords(entity)) < 100.0 then
|
||||
local isNetworked = NetworkGetEntityIsNetworked(entity)
|
||||
local model = GetEntityModel(entity)
|
||||
|
||||
if isNetworked then
|
||||
local netId = NetworkGetNetworkIdFromEntity(entity)
|
||||
|
||||
if not netIds[netId] then
|
||||
netIds[netId] = {
|
||||
entity = entity,
|
||||
type = type,
|
||||
}
|
||||
end
|
||||
else
|
||||
localEnties[entity] = {
|
||||
entity = entity,
|
||||
type = type,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
if not models[model] then
|
||||
models[model] = {}
|
||||
end
|
||||
|
||||
models[model][#models[model] + 1] = {
|
||||
entity = entity,
|
||||
type = type,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
local playerCoords = GetEntityCoords(cache.ped)
|
||||
clearTables()
|
||||
|
||||
buildEntities('CVehicle', playerCoords)
|
||||
buildEntities('CPed', playerCoords)
|
||||
buildEntities('CObject', playerCoords)
|
||||
|
||||
Wait(2500)
|
||||
end
|
||||
end)
|
||||
|
||||
return entities
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
-- Generated glyph metrics for assets/prompt/font.png (Barlow Condensed SemiBold Italic, OFL).
|
||||
return {
|
||||
width = 512,
|
||||
height = 512,
|
||||
lineHeight = 53,
|
||||
ascent = 44,
|
||||
capHeight = 31,
|
||||
glyphs = {
|
||||
[' '] = { x = 4, y = 4, w = 0, xoff = -1, adv = 9.00 },
|
||||
['!'] = { x = 8, y = 4, w = 14, xoff = -1, adv = 11.00 },
|
||||
['"'] = { x = 26, y = 4, w = 18, xoff = -1, adv = 13.00 },
|
||||
['#'] = { x = 48, y = 4, w = 28, xoff = -1, adv = 26.00 },
|
||||
['$'] = { x = 80, y = 4, w = 22, xoff = -1, adv = 19.00 },
|
||||
['%'] = { x = 106, y = 4, w = 35, xoff = -1, adv = 33.00 },
|
||||
['&'] = { x = 145, y = 4, w = 27, xoff = -1, adv = 25.00 },
|
||||
['('] = { x = 191, y = 4, w = 15, xoff = -1, adv = 12.00 },
|
||||
[')'] = { x = 210, y = 4, w = 16, xoff = -1, adv = 12.00 },
|
||||
['*'] = { x = 230, y = 4, w = 20, xoff = -1, adv = 15.00 },
|
||||
['+'] = { x = 254, y = 4, w = 21, xoff = -1, adv = 19.00 },
|
||||
[','] = { x = 279, y = 4, w = 10, xoff = -1, adv = 8.00 },
|
||||
['-'] = { x = 293, y = 4, w = 16, xoff = -1, adv = 14.00 },
|
||||
['.'] = { x = 313, y = 4, w = 11, xoff = -1, adv = 9.00 },
|
||||
['/'] = { x = 328, y = 4, w = 20, xoff = -1, adv = 17.00 },
|
||||
['0'] = { x = 352, y = 4, w = 22, xoff = -1, adv = 19.00 },
|
||||
['1'] = { x = 378, y = 4, w = 15, xoff = -1, adv = 12.00 },
|
||||
['2'] = { x = 397, y = 4, w = 21, xoff = -1, adv = 18.00 },
|
||||
['3'] = { x = 422, y = 4, w = 22, xoff = -1, adv = 18.00 },
|
||||
['4'] = { x = 448, y = 4, w = 22, xoff = -1, adv = 20.00 },
|
||||
['5'] = { x = 474, y = 4, w = 22, xoff = -1, adv = 18.00 },
|
||||
['6'] = { x = 4, y = 61, w = 21, xoff = -1, adv = 18.00 },
|
||||
['7'] = { x = 29, y = 61, w = 22, xoff = -1, adv = 17.00 },
|
||||
['8'] = { x = 55, y = 61, w = 21, xoff = -1, adv = 19.00 },
|
||||
['9'] = { x = 80, y = 61, w = 21, xoff = -1, adv = 18.00 },
|
||||
[':'] = { x = 105, y = 61, w = 13, xoff = -1, adv = 11.00 },
|
||||
[';'] = { x = 122, y = 61, w = 12, xoff = -1, adv = 9.00 },
|
||||
['<'] = { x = 138, y = 61, w = 22, xoff = -1, adv = 19.00 },
|
||||
['='] = { x = 164, y = 61, w = 22, xoff = -1, adv = 19.00 },
|
||||
['>'] = { x = 190, y = 61, w = 21, xoff = -1, adv = 19.00 },
|
||||
['?'] = { x = 215, y = 61, w = 21, xoff = -1, adv = 18.00 },
|
||||
['@'] = { x = 240, y = 61, w = 34, xoff = -1, adv = 32.00 },
|
||||
['A'] = { x = 278, y = 61, w = 22, xoff = -2, adv = 19.00 },
|
||||
['B'] = { x = 304, y = 61, w = 23, xoff = -1, adv = 20.00 },
|
||||
['C'] = { x = 331, y = 61, w = 22, xoff = -1, adv = 20.00 },
|
||||
['D'] = { x = 357, y = 61, w = 23, xoff = -1, adv = 20.00 },
|
||||
['E'] = { x = 384, y = 61, w = 23, xoff = -1, adv = 19.00 },
|
||||
['F'] = { x = 411, y = 61, w = 23, xoff = -1, adv = 18.00 },
|
||||
['G'] = { x = 438, y = 61, w = 23, xoff = -1, adv = 20.00 },
|
||||
['H'] = { x = 465, y = 61, w = 23, xoff = -1, adv = 20.00 },
|
||||
['I'] = { x = 492, y = 61, w = 13, xoff = -1, adv = 10.00 },
|
||||
['J'] = { x = 4, y = 118, w = 22, xoff = -1, adv = 19.00 },
|
||||
['K'] = { x = 30, y = 118, w = 25, xoff = -1, adv = 20.00 },
|
||||
['L'] = { x = 59, y = 118, w = 20, xoff = -1, adv = 18.00 },
|
||||
['M'] = { x = 83, y = 118, w = 26, xoff = -1, adv = 23.00 },
|
||||
['N'] = { x = 113, y = 118, w = 25, xoff = -1, adv = 22.00 },
|
||||
['O'] = { x = 142, y = 118, w = 23, xoff = -1, adv = 20.00 },
|
||||
['P'] = { x = 169, y = 118, w = 23, xoff = -1, adv = 19.00 },
|
||||
['Q'] = { x = 196, y = 118, w = 22, xoff = -1, adv = 19.00 },
|
||||
['R'] = { x = 222, y = 118, w = 23, xoff = -1, adv = 20.00 },
|
||||
['S'] = { x = 249, y = 118, w = 22, xoff = -1, adv = 19.00 },
|
||||
['T'] = { x = 275, y = 118, w = 24, xoff = -1, adv = 19.00 },
|
||||
['U'] = { x = 303, y = 118, w = 24, xoff = -1, adv = 20.00 },
|
||||
['V'] = { x = 331, y = 118, w = 24, xoff = -1, adv = 20.00 },
|
||||
['W'] = { x = 359, y = 118, w = 33, xoff = -1, adv = 28.00 },
|
||||
['X'] = { x = 396, y = 118, w = 24, xoff = -1, adv = 20.00 },
|
||||
['Y'] = { x = 424, y = 118, w = 24, xoff = -1, adv = 19.00 },
|
||||
['Z'] = { x = 452, y = 118, w = 22, xoff = -1, adv = 17.00 },
|
||||
['['] = { x = 478, y = 118, w = 17, xoff = -2, adv = 14.00 },
|
||||
[']'] = { x = 27, y = 175, w = 19, xoff = -1, adv = 14.00 },
|
||||
['^'] = { x = 50, y = 175, w = 20, xoff = -1, adv = 18.00 },
|
||||
['_'] = { x = 74, y = 175, w = 20, xoff = -2, adv = 17.00 },
|
||||
['`'] = { x = 98, y = 175, w = 13, xoff = -1, adv = 9.00 },
|
||||
['a'] = { x = 115, y = 175, w = 21, xoff = -1, adv = 19.00 },
|
||||
['b'] = { x = 140, y = 175, w = 21, xoff = -1, adv = 19.00 },
|
||||
['c'] = { x = 165, y = 175, w = 20, xoff = -1, adv = 18.00 },
|
||||
['d'] = { x = 189, y = 175, w = 22, xoff = -1, adv = 19.00 },
|
||||
['e'] = { x = 215, y = 175, w = 20, xoff = -1, adv = 18.00 },
|
||||
['f'] = { x = 239, y = 175, w = 17, xoff = -1, adv = 12.00 },
|
||||
['g'] = { x = 260, y = 175, w = 21, xoff = -1, adv = 18.00 },
|
||||
['h'] = { x = 285, y = 175, w = 21, xoff = -1, adv = 19.00 },
|
||||
['i'] = { x = 310, y = 175, w = 13, xoff = -1, adv = 9.00 },
|
||||
['j'] = { x = 327, y = 175, w = 17, xoff = -5, adv = 9.00 },
|
||||
['k'] = { x = 348, y = 175, w = 21, xoff = -1, adv = 18.00 },
|
||||
['l'] = { x = 373, y = 175, w = 12, xoff = -1, adv = 8.00 },
|
||||
['m'] = { x = 389, y = 175, w = 30, xoff = -1, adv = 28.00 },
|
||||
['n'] = { x = 423, y = 175, w = 21, xoff = -1, adv = 19.00 },
|
||||
['o'] = { x = 448, y = 175, w = 20, xoff = -1, adv = 18.00 },
|
||||
['p'] = { x = 472, y = 175, w = 21, xoff = -1, adv = 19.00 },
|
||||
['q'] = { x = 4, y = 232, w = 21, xoff = -1, adv = 19.00 },
|
||||
['r'] = { x = 29, y = 232, w = 17, xoff = -1, adv = 13.00 },
|
||||
['s'] = { x = 50, y = 232, w = 19, xoff = -1, adv = 17.00 },
|
||||
['t'] = { x = 73, y = 232, w = 15, xoff = -1, adv = 12.00 },
|
||||
['u'] = { x = 92, y = 232, w = 21, xoff = -1, adv = 19.00 },
|
||||
['v'] = { x = 117, y = 232, w = 21, xoff = -1, adv = 18.00 },
|
||||
['w'] = { x = 142, y = 232, w = 29, xoff = -1, adv = 25.00 },
|
||||
['x'] = { x = 175, y = 232, w = 22, xoff = -2, adv = 18.00 },
|
||||
['y'] = { x = 201, y = 232, w = 22, xoff = -2, adv = 17.00 },
|
||||
['z'] = { x = 227, y = 232, w = 19, xoff = -1, adv = 16.00 },
|
||||
['{'] = { x = 250, y = 232, w = 18, xoff = -1, adv = 14.00 },
|
||||
['|'] = { x = 272, y = 232, w = 13, xoff = -2, adv = 7.00 },
|
||||
['}'] = { x = 289, y = 232, w = 17, xoff = -2, adv = 14.00 },
|
||||
['~'] = { x = 310, y = 232, w = 23, xoff = -1, adv = 20.00 },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,588 @@
|
||||
local log = require 'shared.log'
|
||||
local utils = require 'client.utils'
|
||||
local settings = require 'shared.settings'
|
||||
local interactions, filteredInteractions = {}, {}
|
||||
local table_sort = table.sort
|
||||
|
||||
-- CACHE.
|
||||
local MODELS = {}
|
||||
local ENTITIES = {}
|
||||
local ENTITY_BONES = {}
|
||||
local NETWORKED_ENTITIES = {}
|
||||
|
||||
local api = {}
|
||||
|
||||
AddEventHandler('interactions:groupsChanged', function(newgroups)
|
||||
-- Use this event handler to loop through all current interactions and remove any that are not in the new groups that way we limit the amount of iterations needed
|
||||
end)
|
||||
|
||||
local function checkParams(entity, options)
|
||||
if not entity then
|
||||
log:error('Entity is required to add an interaction')
|
||||
return
|
||||
else
|
||||
if type(entity) ~= 'number' then
|
||||
log:error('Entity must be a number')
|
||||
return
|
||||
end
|
||||
|
||||
if not DoesEntityExist(entity) then
|
||||
log:error('Entity %s does not exist', entity)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if not options then
|
||||
log:error('Options are required to add an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--#TODO: Add a way to filter interactions based on the players group
|
||||
local function filterInteractions()
|
||||
local myGroups = 'police'
|
||||
|
||||
local newInteractions = {}
|
||||
local amount = 0
|
||||
for k ,v in pairs(interactions) do
|
||||
amount += 1
|
||||
newInteractions[amount] = v
|
||||
end
|
||||
|
||||
filteredInteractions = newInteractions
|
||||
end
|
||||
|
||||
---@param model number|string : The model to add the interaction to
|
||||
---@param options table : { label, canInteract, action, event, serverEvent, args }
|
||||
---@param data table : { distance, interactDst, resource }
|
||||
local function addModel(model, options, data)
|
||||
if type(model) ~= "number" then
|
||||
model = joaat(model)
|
||||
end
|
||||
|
||||
if not IsModelValid(model) then
|
||||
log:error('Model %s is not valid', model)
|
||||
return
|
||||
end
|
||||
|
||||
if not MODELS[model] then
|
||||
log:debug('Adding model %s to interactions', model)
|
||||
MODELS[model] = {
|
||||
model = model,
|
||||
offset = data.offset,
|
||||
options = options,
|
||||
distance = data.distance,
|
||||
interactDst = data.interactDst,
|
||||
resource = data.resource,
|
||||
}
|
||||
else
|
||||
log:debug('Updating model %s in interactions', model)
|
||||
for _, option in pairs(options) do
|
||||
MODELS[model].options[#MODELS[model].options + 1] = option
|
||||
end
|
||||
|
||||
-- Update the distance and interactDst if the new data is greater
|
||||
if data.distance > MODELS[model].distance then
|
||||
MODELS[model].distance = data.distance
|
||||
end
|
||||
|
||||
if data.interactDst > MODELS[model].interactDst then
|
||||
MODELS[model].interactDst = data.interactDst
|
||||
end
|
||||
|
||||
-- Update the offset if there is new data
|
||||
if data.offset then
|
||||
MODELS[model].offset = data.offset
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param data table : { name, coords, options, distance, interactDst, groups }
|
||||
---@return number : The id of the interaction
|
||||
-- Add an interaction point at a set of coords
|
||||
function api.addInteraction(data)
|
||||
if not data.coords then
|
||||
log:error('Coords are required to add an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
if not data.options then
|
||||
log:error('Options are required to add an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
local id = #interactions + 1
|
||||
interactions[id] = {
|
||||
id = id,
|
||||
name = data.name or 'interaction:'..id,
|
||||
coords = data.coords,
|
||||
options = data.options or {},
|
||||
distance = data.distance or 8.0,
|
||||
interactDst = data.interactDst or 1.0,
|
||||
groups = data.groups or nil,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
|
||||
filterInteractions()
|
||||
|
||||
return id
|
||||
end exports('AddInteraction', api.addInteraction)
|
||||
|
||||
---@param data table : { name, entity, options, distance, interactDst, groups }
|
||||
---@return number : The id of the interaction
|
||||
-- Add an interaction point on a local (client side) entity
|
||||
function api.addLocalEntityInteraction(data)
|
||||
local entity = data.entity
|
||||
if not checkParams(entity, data.options) then
|
||||
if ENTITIES[entity] then
|
||||
ENTITIES[entity] = nil
|
||||
end
|
||||
return
|
||||
end
|
||||
local id = #interactions + 1
|
||||
-- If then entity not registered yet, add it
|
||||
if not ENTITIES[entity] then
|
||||
log:debug('Adding entity %s to interactions', entity)
|
||||
|
||||
interactions[id] = {
|
||||
id = id,
|
||||
name = data.name or 'interaction:'..id,
|
||||
entity = entity,
|
||||
options = data.options or {},
|
||||
distance = data.distance or 8.0,
|
||||
interactDst = data.interactDst or 1.0,
|
||||
offset = data.offset or vec(0.0, 0.0, 0.0),
|
||||
groups = data.groups or nil,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
|
||||
ENTITIES[entity] = interactions[id]
|
||||
|
||||
filterInteractions()
|
||||
return id
|
||||
end
|
||||
|
||||
-- If the entity is already registered, update it
|
||||
log:debug('Updating entity %s in interactions', entity)
|
||||
for index, option in pairs(data.options) do
|
||||
if option.name and ENTITIES[entity].options[index]?.name == option.name then
|
||||
log:debug('Option with name: ( %s ) already exists, updating', option.name)
|
||||
ENTITIES[entity].options[index] = option
|
||||
else
|
||||
ENTITIES[entity].options[#ENTITIES[entity].options + 1] = option
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the distance and interactDst if the new data is greater
|
||||
if data.distance > ENTITIES[entity].distance then
|
||||
ENTITIES[entity].distance = data.distance
|
||||
end
|
||||
|
||||
if data.interactDst > ENTITIES[entity].interactDst then
|
||||
ENTITIES[entity].interactDst = data.interactDst
|
||||
end
|
||||
|
||||
-- Update the offset if there is new data
|
||||
if data.offset then
|
||||
ENTITIES[entity].offset = data.offset
|
||||
end
|
||||
|
||||
interactions[id] = {
|
||||
id = id,
|
||||
entity = entity,
|
||||
options = ENTITIES[entity].options,
|
||||
distance = ENTITIES[entity].distance,
|
||||
interactDst = ENTITIES[entity].interactDst,
|
||||
offset = ENTITIES[entity].offset,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
|
||||
filterInteractions()
|
||||
|
||||
return id
|
||||
end exports('AddLocalEntityInteraction', api.addLocalEntityInteraction)
|
||||
|
||||
---@param data table : { name, netId, options, distance, interactDst, groups }
|
||||
---@return number : The id of the interaction
|
||||
-- Add an interaction point on a networked entity
|
||||
function api.addEntityInteraction(data)
|
||||
local netId = data.netId
|
||||
-- If the netId does not exist, we assume it is an entity
|
||||
local entity
|
||||
if type(netId) == 'number' and NetworkDoesNetworkIdExist(netId) then
|
||||
entity = utils.getEntity(netId)
|
||||
elseif type(netId) == 'number' then
|
||||
entity = netId
|
||||
end
|
||||
|
||||
if not checkParams(entity, data.options) then
|
||||
if NETWORKED_ENTITIES[netId] then
|
||||
NETWORKED_ENTITIES[netId] = nil
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- If the entity is not networked, add it as a local entity
|
||||
if not NetworkGetEntityIsNetworked(entity) then
|
||||
log:debug('Entity %s is not networked, adding as a local entity', entity)
|
||||
data.entity = entity
|
||||
return api.addLocalEntityInteraction(data)
|
||||
end
|
||||
netId = utils.getNet(entity)
|
||||
local id = #interactions + 1
|
||||
-- If then netId not registered yet, add it
|
||||
if not NETWORKED_ENTITIES[netId] then
|
||||
log:debug('Adding networkID %s to interactions', netId)
|
||||
|
||||
|
||||
interactions[id] = {
|
||||
id = id,
|
||||
name = data.name or 'interaction:'..id,
|
||||
entity = entity,
|
||||
options = data.options or {},
|
||||
distance = data.distance or 10.0,
|
||||
interactDst = data.interactDst or 1.0,
|
||||
offset = data.offset or vec(0.0, 0.0, 0.0),
|
||||
groups = data.groups or nil,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
|
||||
NETWORKED_ENTITIES[netId] = interactions[id]
|
||||
|
||||
filterInteractions()
|
||||
return id
|
||||
end
|
||||
|
||||
-- If the networkID is already registered, update it
|
||||
log:debug('Updating networkID %s in interactions', netId)
|
||||
for index, option in pairs(data.options) do
|
||||
if option.name and NETWORKED_ENTITIES[netId].options[index]?.name == option.name then
|
||||
log:debug('Option with name: ( %s ) already exists, updating', option.name)
|
||||
NETWORKED_ENTITIES[netId].options[index] = option
|
||||
else
|
||||
NETWORKED_ENTITIES[netId].options[#NETWORKED_ENTITIES[netId].options + 1] = option
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the distance and interactDst if the new data is greater
|
||||
if data.distance > NETWORKED_ENTITIES[netId].distance then
|
||||
NETWORKED_ENTITIES[netId].distance = data.distance
|
||||
end
|
||||
|
||||
if data.interactDst > NETWORKED_ENTITIES[netId].interactDst then
|
||||
NETWORKED_ENTITIES[netId].interactDst = data.interactDst
|
||||
end
|
||||
|
||||
-- Update the offset if there is new data
|
||||
if data.offset then
|
||||
NETWORKED_ENTITIES[netId].offset = data.offset
|
||||
end
|
||||
|
||||
interactions[id] = {
|
||||
id = id,
|
||||
entity = entity,
|
||||
options = NETWORKED_ENTITIES[netId].options,
|
||||
distance = NETWORKED_ENTITIES[netId].distance,
|
||||
interactDst = NETWORKED_ENTITIES[netId].interactDst,
|
||||
offset = NETWORKED_ENTITIES[netId].offset,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
|
||||
filterInteractions()
|
||||
|
||||
return id
|
||||
end exports('AddEntityInteraction', api.addEntityInteraction)
|
||||
|
||||
---@param data table : { name, entity[number|string], bone[string], options, distance, interactDst, groups }
|
||||
---@return number : The id of the interaction
|
||||
-- Add an interaction point on a networked entity's bone
|
||||
function api.addEntityBoneInteraction(data)
|
||||
|
||||
if not data.entity then
|
||||
log:error('Entity is required to add an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
if not data.bone then
|
||||
log:error('Bone is required to add an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
if not data.options then
|
||||
log:error('Options are required to add an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
-- temp workaround until table refactoring.
|
||||
local key = string.format('%s:%s', data.entity, data.bone)
|
||||
if not ENTITY_BONES[key] then
|
||||
log:debug('Added new entity bone interaction: %s', key)
|
||||
ENTITY_BONES[key] = {
|
||||
entity = data.entity,
|
||||
bone = data.bone,
|
||||
distance = data.distance or 10.0,
|
||||
interactDst = data.interactDst or 1.0,
|
||||
offset = data.offset or vec(0.0, 0.0, 0.0),
|
||||
options = data.options,
|
||||
groups = data.groups or nil,
|
||||
}
|
||||
else
|
||||
log:debug('Updating %s in bone interactions', key)
|
||||
|
||||
for index, option in pairs(data.options) do
|
||||
if option.name and ENTITY_BONES[key].options[index]?.name == option.name then
|
||||
log:debug('Option with name: ( %s ) already exists, updating', option.name)
|
||||
ENTITY_BONES[key].options[index] = option
|
||||
else
|
||||
ENTITY_BONES[key].options[#ENTITY_BONES[key].options + 1] = option
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the distance and interactDst if the new data is greater
|
||||
if data.distance > ENTITY_BONES[key].distance then
|
||||
ENTITY_BONES[key].distance = data.distance
|
||||
end
|
||||
|
||||
if data.interactDst > ENTITY_BONES[key].interactDst then
|
||||
ENTITY_BONES[key].interactDst = data.interactDst
|
||||
end
|
||||
|
||||
-- Update the offset if there is new data
|
||||
if data.offset then
|
||||
ENTITY_BONES[key].offset = data.offset
|
||||
end
|
||||
|
||||
log:debug('Updated entity bone interaction: %s', key)
|
||||
ENTITY_BONES[key] = {
|
||||
entity = data.entity,
|
||||
bone = data.bone,
|
||||
options = ENTITY_BONES[key].options,
|
||||
distance = ENTITY_BONES[key].distance,
|
||||
interactDst = ENTITY_BONES[key].interactDst,
|
||||
offset = ENTITY_BONES[key].offset,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
end
|
||||
|
||||
filterInteractions()
|
||||
|
||||
return id
|
||||
end exports('AddEntityBoneInteraction', api.addEntityBoneInteraction)
|
||||
|
||||
---@param data table : { name, modelData table : { model[string], offset[vec3] }, options, distance, interactDst, groups }
|
||||
-- Add interaction(s) to a list of models
|
||||
function api.addModelInteraction(data)
|
||||
data.distance = data.distance or 8.0
|
||||
data.interactDst = data.interactDst or 1.0
|
||||
for i = 1, #data.modelData do
|
||||
local modelData = data.modelData[i]
|
||||
if IsModelValid(modelData.model) then
|
||||
local min, max = GetModelDimensions(modelData.model)
|
||||
local size = (max - min)
|
||||
data.interactDst += (size.x / 8)
|
||||
data.distance += (size.x / 4)
|
||||
data.resource = GetInvokingResource()
|
||||
addModel(modelData.model, data.options, { offset = modelData.offset, distance = data.distance, interactDst = data.interactDst, resource = data.resource })
|
||||
end
|
||||
end
|
||||
end exports('AddModelInteraction', api.addModelInteraction)
|
||||
|
||||
---@param id number : The id of the interaction to remove
|
||||
-- Remove an interaction point by id.
|
||||
function api.removeInteraction(id)
|
||||
interactions[id] = nil
|
||||
log:debug('Removed interaction %s', id)
|
||||
filterInteractions()
|
||||
end
|
||||
exports('RemoveInteraction', api.removeInteraction)
|
||||
|
||||
---@param entity number : The entity to remove the interaction from
|
||||
-- Remove an interaction point by entity.
|
||||
function api.removeInteractionByEntity(entity)
|
||||
for i = #interactions, 1, -1 do
|
||||
local interaction = interactions[i]
|
||||
|
||||
if interaction.entity == entity then
|
||||
api.removeInteraction(i)
|
||||
end
|
||||
end
|
||||
end exports('RemoveInteractionByEntity', api.removeInteractionByEntity)
|
||||
|
||||
---@param id number : The id of the interaction to remove the option from
|
||||
---@param name? string : The name of the option to remove
|
||||
-- Remove an option from an interaction point by id.
|
||||
function api.removeInteractionOption(id, name)
|
||||
if not interactions[id] then
|
||||
log:error('Interaction with id: ( %s ) does not exist', id)
|
||||
return
|
||||
end
|
||||
|
||||
if not name then
|
||||
api.removeInteraction(id)
|
||||
return
|
||||
end
|
||||
|
||||
local options = interactions[id].options
|
||||
|
||||
if not options then
|
||||
log:error('Interaction with id: ( %s ) does not have any options', id)
|
||||
api.removeInteraction(id)
|
||||
return
|
||||
end
|
||||
|
||||
for i = #options, 1, -1 do
|
||||
local option = options[i]
|
||||
|
||||
if option.name == name then
|
||||
options[i] = nil
|
||||
log:debug('Removed option %s from interaction %s', name, id)
|
||||
end
|
||||
end
|
||||
end exports('RemoveInteractionOption', api.removeInteractionOption)
|
||||
|
||||
---@param id number : The id of the interaction to update
|
||||
---@param options table : The new options to update the interaction with
|
||||
-- Update an interaction point by id.
|
||||
function api.updateInteraction(id, options)
|
||||
if not options then
|
||||
log:error('Options are required to update an interaction')
|
||||
return
|
||||
end
|
||||
|
||||
if not interactions[id] then
|
||||
log:error('Interaction with id: ( %s ) does not exist', id)
|
||||
return
|
||||
end
|
||||
|
||||
if interactions[id] then
|
||||
interactions[id].options = options
|
||||
filterInteractions()
|
||||
end
|
||||
end exports('UpdateInteraction', api.updateInteraction)
|
||||
|
||||
function api.getNearbyInteractions()
|
||||
local options = {}
|
||||
local amount = 0
|
||||
|
||||
local playercoords = GetEntityCoords(cache.ped)
|
||||
|
||||
-- Temp loop : these checks need to be broken out into their own threads.
|
||||
local nearbyVehicles = lib.getNearbyVehicles(playercoords, settings.nearbyVehicleDistance, false)
|
||||
for i = 1, #nearbyVehicles do
|
||||
local vehicle = nearbyVehicles[i].vehicle
|
||||
local vehicleCoords = nearbyVehicles[i].coords
|
||||
|
||||
if settings.vehicleBoneDefaults.enabled then
|
||||
for bone, data in pairs(settings.vehicleBoneDefaults.bones) do
|
||||
local key = string.format('%s:%s', vehicle, bone)
|
||||
if not ENTITY_BONES[key] then
|
||||
api.addEntityBoneInteraction({
|
||||
entity = vehicle,
|
||||
bone = bone,
|
||||
options = data.options,
|
||||
distance = data.distance,
|
||||
interactDst = data.interactDst,
|
||||
offset = data.offset,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, interaction in pairs(ENTITY_BONES) do
|
||||
local distance = #(utils.getCoordsFromInteract(interaction) - playercoords)
|
||||
if distance <= interaction.distance then
|
||||
amount += 1
|
||||
interaction.curDist = distance
|
||||
options[amount] = interaction
|
||||
end
|
||||
end
|
||||
|
||||
local nearbyObjects = lib.getNearbyObjects(playercoords, settings.nearbyObjectDistance)
|
||||
for i = 1, #nearbyObjects do
|
||||
local nearby = nearbyObjects[i]
|
||||
local hash = GetEntityModel(nearby.object)
|
||||
|
||||
if MODELS[hash] then
|
||||
local interaction = lib.table.deepclone(MODELS[hash])
|
||||
-- put the functions to original references
|
||||
for k, v in pairs(interaction) do
|
||||
if type(v) == "table" then
|
||||
for id, item in pairs(v) do
|
||||
if item.action then
|
||||
item.action = MODELS[hash].options[id].action
|
||||
end
|
||||
if MODELS[hash].options[id].canInteract then
|
||||
item.canInteract = MODELS[hash].options[id].canInteract
|
||||
end
|
||||
if item.canInteract then
|
||||
local canInteract = false
|
||||
pcall(function()
|
||||
canInteract = item.canInteract(nearby.object, nearby.coords, item.args)
|
||||
end)
|
||||
v[id] = canInteract and item or nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local distance = #(nearby.coords - playercoords)
|
||||
interaction.entity = nearby.object
|
||||
|
||||
if distance <= interaction.distance then
|
||||
amount += 1
|
||||
interaction.curDist = distance
|
||||
options[amount] = interaction
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local amountOfInteractions = #filteredInteractions
|
||||
if amountOfInteractions > 0 then
|
||||
for i = 1, amountOfInteractions do
|
||||
local interaction = filteredInteractions[i]
|
||||
|
||||
local coords = interaction.coords or utils.getCoordsFromInteract(interaction)
|
||||
|
||||
local distance = #(coords - playercoords)
|
||||
|
||||
if distance <= interaction.distance then
|
||||
amount += 1
|
||||
interaction.curDist = distance
|
||||
options[amount] = interaction
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(options) do
|
||||
for i = 1, #v.options, 1 do
|
||||
if not v.options[i] then
|
||||
table.remove(v.options, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
if amount > 1 then
|
||||
table_sort(options, function(a, b)
|
||||
return a.curDist < b.curDist
|
||||
end)
|
||||
end
|
||||
|
||||
return options
|
||||
end
|
||||
|
||||
function api.disable(state)
|
||||
LocalPlayer.state:set('interactionsDisabled', state, true)
|
||||
end exports('Disable', api.disable)
|
||||
|
||||
AddEventHandler('onClientResourceStop', function(resource)
|
||||
for i = #interactions, 1, -1 do
|
||||
local interaction = interactions[i]
|
||||
|
||||
if interaction.resource == resource then
|
||||
api.removeInteraction(interaction.id)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return api
|
||||
@@ -0,0 +1,174 @@
|
||||
local interactions = require 'client.interactions'
|
||||
local utils = require 'client.utils'
|
||||
local settings = require 'shared.settings'
|
||||
local CURRENT_SELECTION = 1
|
||||
local CURRENT_OPTION = 0
|
||||
|
||||
-- CACHE
|
||||
local Wait = Wait
|
||||
local IsControlJustPressed = IsControlJustPressed
|
||||
local IsNuiFocused = IsNuiFocused
|
||||
local IsPedDeadOrDying = IsPedDeadOrDying
|
||||
local IsPedCuffed = IsPedCuffed
|
||||
|
||||
local visibleOptions = {}
|
||||
|
||||
-- Collects the options whose canInteract passes into visibleOptions and returns how many there are.
|
||||
local function getVisibleOptions(interaction)
|
||||
table.wipe(visibleOptions)
|
||||
local amount = 0
|
||||
local options = interaction.options
|
||||
for i = 1, #options do
|
||||
local option = options[i]
|
||||
local ok = true
|
||||
if option.canInteract then
|
||||
ok = false
|
||||
pcall(function() ok = option.canInteract(interaction.entity, interaction.coords, option.args) end)
|
||||
end
|
||||
if ok then
|
||||
amount += 1
|
||||
visibleOptions[amount] = option
|
||||
end
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
local function triggerOption(interaction, option)
|
||||
if option.action then
|
||||
pcall(function() option.action(interaction.entity, interaction.coords, option.args) end)
|
||||
elseif option.serverEvent then
|
||||
TriggerServerEvent(option.serverEvent, option.args)
|
||||
elseif option.event then
|
||||
TriggerEvent(option.event, option)
|
||||
end
|
||||
end
|
||||
|
||||
local nearby = {}
|
||||
local screenCoords, screenCount = {}, 0
|
||||
local hoverRadius = settings.Prompt.hoverRadius
|
||||
local GetAspectRatio = GetAspectRatio
|
||||
local math_sqrt = math.sqrt
|
||||
|
||||
local function CreateInteractions()
|
||||
local aspect = GetAspectRatio(false)
|
||||
local active, activeCoords, activeAmount, activeIndex
|
||||
local bestDist = hoverRadius
|
||||
screenCount = 0
|
||||
|
||||
-- Pass 1: find every on-screen point and pick the in-range one closest to the crosshair.
|
||||
for i = 1, #nearby do
|
||||
local interaction = nearby[i]
|
||||
local coords = interaction.coords or utils.getCoordsFromInteract(interaction)
|
||||
local onScreen, sx, sy = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z)
|
||||
|
||||
if onScreen then
|
||||
local amount = getVisibleOptions(interaction)
|
||||
|
||||
if amount > 0 then
|
||||
screenCount += 1
|
||||
screenCoords[screenCount] = coords
|
||||
|
||||
if interaction.curDist <= interaction.interactDst then
|
||||
local dx, dy = (sx - 0.5) * aspect, sy - 0.5
|
||||
local dist = math_sqrt(dx * dx + dy * dy)
|
||||
if dist < bestDist then
|
||||
bestDist = dist
|
||||
active, activeCoords, activeAmount, activeIndex = interaction, coords, amount, screenCount
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if screenCount == 0 then
|
||||
CURRENT_OPTION = 0
|
||||
return
|
||||
end
|
||||
|
||||
-- Pass 2: dots for everything except the hovered point, which gets the prompt instead.
|
||||
for i = 1, screenCount do
|
||||
if i ~= activeIndex then
|
||||
utils.drawDot(screenCoords[i])
|
||||
end
|
||||
end
|
||||
|
||||
if settings.Prompt.crosshair then
|
||||
utils.drawCrosshair()
|
||||
end
|
||||
|
||||
if not active then
|
||||
CURRENT_OPTION = 0
|
||||
return
|
||||
end
|
||||
|
||||
-- Rebuild the option list for the hovered point (pass 1 overwrote it while scanning).
|
||||
getVisibleOptions(active)
|
||||
|
||||
-- Bone and model interactions have no id, so fall back to the entity.
|
||||
local key = active.id or active.entity
|
||||
if key ~= CURRENT_OPTION then
|
||||
CURRENT_OPTION = key
|
||||
CURRENT_SELECTION = 1
|
||||
end
|
||||
|
||||
if CURRENT_SELECTION > activeAmount then
|
||||
CURRENT_SELECTION = activeAmount
|
||||
end
|
||||
|
||||
if CURRENT_SELECTION > 1 and (IsControlJustPressed(0, 172) or IsControlJustPressed(0, 15)) then
|
||||
CURRENT_SELECTION -= 1
|
||||
elseif CURRENT_SELECTION < activeAmount and (IsControlJustPressed(0, 173) or IsControlJustPressed(0, 14)) then
|
||||
CURRENT_SELECTION += 1
|
||||
end
|
||||
|
||||
utils.drawPrompt(activeCoords, visibleOptions, CURRENT_SELECTION)
|
||||
|
||||
if IsControlJustPressed(0, 38) then
|
||||
triggerOption(active, visibleOptions[CURRENT_SELECTION])
|
||||
end
|
||||
end
|
||||
|
||||
local function isDisabled()
|
||||
if LocalPlayer.state.interactionsDisabled then
|
||||
return true
|
||||
end
|
||||
|
||||
if settings.Disable.onDeath and (IsPedDeadOrDying(cache.ped) or LocalPlayer.state.isDead) then
|
||||
return true
|
||||
end
|
||||
|
||||
if settings.Disable.onNuiFocus and IsNuiFocused() then
|
||||
return true
|
||||
end
|
||||
|
||||
if settings.Disable.onVehicle and cache.vehicle then
|
||||
return true
|
||||
end
|
||||
|
||||
if settings.Disable.onHandCuff and IsPedCuffed(cache.ped) then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- Fast thread
|
||||
CreateThread(function ()
|
||||
lib.requestStreamedTextureDict('interactions_txd')
|
||||
while true do
|
||||
local wait = 500
|
||||
if next(nearby) and not isDisabled() then
|
||||
wait = 0
|
||||
CreateInteractions()
|
||||
end
|
||||
Wait(wait)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Slow checker thread
|
||||
CreateThread(function()
|
||||
while true do
|
||||
nearby = interactions.getNearbyInteractions()
|
||||
Wait(500)
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,50 @@
|
||||
CurrentTarget = nil
|
||||
|
||||
local StartShapeTestSweptSphere = StartShapeTestSweptSphere
|
||||
local GetShapeTestResult = GetShapeTestResult
|
||||
local GetPedBoneCoords = GetPedBoneCoords
|
||||
local GetGameplayCamRot = GetGameplayCamRot
|
||||
local GetEntityType = GetEntityType
|
||||
|
||||
local function getForwardVector(rotation)
|
||||
local rot = (math.pi / 180.0) * rotation
|
||||
return vector3(-math.sin(rot.z) * math.abs(math.cos(rot.x)), math.cos(rot.z) * math.abs(math.cos(rot.x)), math.sin(rot.x))
|
||||
end
|
||||
|
||||
local function rayCast(origin, target, options, ignoreEntity, radius)
|
||||
local handle = StartShapeTestSweptSphere(origin.x, origin.y, origin.z, target.x, target.y, target.z, radius, options, ignoreEntity, 0)
|
||||
return GetShapeTestResult(handle)
|
||||
end
|
||||
|
||||
local function entityInFrontOfPlayer(distance, radius, _, ignoreEntity)
|
||||
distance = distance or 3.0
|
||||
local originCoords = GetPedBoneCoords(cache.ped, 31086, 0, 0, 0)
|
||||
local forwardVectors = getForwardVector(GetGameplayCamRot(2))
|
||||
local forwardCoords = originCoords + (forwardVectors * distance)
|
||||
|
||||
if not forwardVectors then return end
|
||||
|
||||
local _, hit, _, _, targetEntity = rayCast(originCoords, forwardCoords, -1, ignoreEntity, radius or 0.2)
|
||||
|
||||
if not hit and targetEntity == 0 then return end
|
||||
|
||||
local entityType = GetEntityType(targetEntity)
|
||||
|
||||
return targetEntity, entityType
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(250)
|
||||
local entity, entityType
|
||||
pcall(function() entity, entityType, _ = entityInFrontOfPlayer(3.0, 0.2, 286, cache.ped) end)
|
||||
if entity and entityType ~= 0 then
|
||||
if entity ~= CurrentTarget then
|
||||
CurrentTarget = entity
|
||||
end
|
||||
elseif CurrentTarget then
|
||||
CurrentTarget = nil
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,6 @@
|
||||
local settings = require 'shared.settings'
|
||||
local txd = CreateRuntimeTxd('interactions_txd')
|
||||
|
||||
for _, v in pairs(settings.Textures) do
|
||||
CreateRuntimeTextureFromImage(txd, tostring(v), "assets/prompt/"..v..".png")
|
||||
end
|
||||
@@ -0,0 +1,147 @@
|
||||
local settings = require 'shared.settings'
|
||||
local textures = settings.Textures
|
||||
|
||||
local SetDrawOrigin = SetDrawOrigin
|
||||
local DrawSprite = DrawSprite
|
||||
local ClearDrawOrigin = ClearDrawOrigin
|
||||
local DoesEntityExist = DoesEntityExist
|
||||
local GetEntityBonePosition_2 = GetEntityBonePosition_2
|
||||
local GetEntityBoneIndexByName = GetEntityBoneIndexByName
|
||||
local GetOffsetFromEntityInWorldCoords = GetOffsetFromEntityInWorldCoords
|
||||
local IsEntityAPed = IsEntityAPed
|
||||
local GetEntityCoords = GetEntityCoords
|
||||
|
||||
local utils = {}
|
||||
|
||||
function utils.getNet(entity)
|
||||
return NetworkGetNetworkIdFromEntity(entity)
|
||||
end
|
||||
|
||||
function utils.getEntity(netID)
|
||||
return NetworkGetEntityFromNetworkId(netID)
|
||||
end
|
||||
|
||||
function utils.getTrunkOffset(entity)
|
||||
local min, _ = GetModelDimensions(GetEntityModel(entity))
|
||||
return GetOffsetFromEntityInWorldCoords(entity, 0.0, min.y - 0.5, 0.0)
|
||||
end
|
||||
|
||||
function utils.getCoordsFromInteract(interaction)
|
||||
if interaction.entity then
|
||||
if DoesEntityExist(interaction.entity) then
|
||||
if interaction.bone then
|
||||
return GetEntityBonePosition_2(interaction.entity, GetEntityBoneIndexByName(interaction.entity, interaction.bone))
|
||||
elseif interaction.model then
|
||||
return GetOffsetFromEntityInWorldCoords(interaction.entity, 0.0 + interaction.offset.x, 0.0 + interaction.offset.y, 0.0 + interaction.offset.z)
|
||||
else
|
||||
if IsEntityAPed(interaction.entity) then
|
||||
if interaction.offset and interaction.offset ~= vec3(0.0, 0.0, 0.0) then
|
||||
return GetOffsetFromEntityInWorldCoords(interaction.entity, 0.0 + interaction.offset.x, 0.0 + interaction.offset.y, 0.0 + interaction.offset.z)
|
||||
end
|
||||
return GetEntityBonePosition_2(interaction.entity, 0) -- SKEL_ROOT
|
||||
else
|
||||
if interaction.offset and interaction.offset ~= vec3(0.0, 0.0, 0.0) then
|
||||
return GetOffsetFromEntityInWorldCoords(interaction.entity, 0.0 + interaction.offset.x, 0.0 + interaction.offset.y, 0.0 + interaction.offset.z)
|
||||
end
|
||||
return GetEntityCoords(interaction.entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return vec3(0.0, 0.0, 0.0)
|
||||
end
|
||||
|
||||
local TXD = 'interactions_txd'
|
||||
local prompt = settings.Prompt
|
||||
local font = require 'client.font'
|
||||
local glyphs = font.glyphs
|
||||
local GetAspectRatio = GetAspectRatio
|
||||
local DrawSpriteUv = DrawSpriteUv
|
||||
local string_upper = string.upper
|
||||
local string_sub = string.sub
|
||||
|
||||
-- Draws text from the font atlas. x is the left edge, centerY the vertical centre of the capitals.
|
||||
-- Returns the drawn width. Must be called with a draw origin set if x/y are relative.
|
||||
local function drawGlyphs(text, x, centerY, capHeight, aspect, r, g, b, a)
|
||||
local k = capHeight / font.capHeight
|
||||
local h = font.lineHeight * k
|
||||
local cy = centerY + capHeight * 0.5 - font.ascent * k + h * 0.5
|
||||
local kx = k / aspect
|
||||
local vh = font.lineHeight / font.height
|
||||
local pen = x
|
||||
|
||||
for i = 1, #text do
|
||||
local glyph = glyphs[string_sub(text, i, i)] or glyphs['?']
|
||||
if glyph.w > 0 then
|
||||
local u, v = glyph.x / font.width, glyph.y / font.height
|
||||
DrawSpriteUv(TXD, textures.font, pen + (glyph.xoff + glyph.w * 0.5) * kx, cy, glyph.w * kx, h,
|
||||
u, v, u + glyph.w / font.width, v + vh, 0.0, r, g, b, a)
|
||||
end
|
||||
pen += glyph.adv * kx
|
||||
end
|
||||
|
||||
return pen - x
|
||||
end
|
||||
|
||||
local function measureText(text, capHeight, aspect)
|
||||
local kx = capHeight / font.capHeight / aspect
|
||||
local width = 0
|
||||
for i = 1, #text do
|
||||
width += (glyphs[string_sub(text, i, i)] or glyphs['?']).adv * kx
|
||||
end
|
||||
return width
|
||||
end
|
||||
|
||||
local function drawText(text, x, centerY, capHeight, aspect, color, alpha)
|
||||
if prompt.shadowAlpha > 0 then
|
||||
local offset = capHeight * 0.08
|
||||
drawGlyphs(text, x + offset / aspect, centerY + offset, capHeight, aspect, 0, 0, 0, math.floor(prompt.shadowAlpha * alpha / 255))
|
||||
end
|
||||
drawGlyphs(text, x, centerY, capHeight, aspect, color[1], color[2], color[3], alpha)
|
||||
end
|
||||
|
||||
-- Ring dot marking an interaction point.
|
||||
function utils.drawDot(coords)
|
||||
local size = prompt.dotSize
|
||||
SetDrawOrigin(coords.x, coords.y, coords.z, 0)
|
||||
DrawSprite(TXD, textures.dot, 0.0, 0.0, size / GetAspectRatio(false), size, 0.0, 255, 255, 255, 255)
|
||||
ClearDrawOrigin()
|
||||
end
|
||||
|
||||
-- Small dot in the middle of the screen used to hover between points.
|
||||
function utils.drawCrosshair()
|
||||
local size = prompt.crosshairSize
|
||||
DrawSprite(TXD, textures.crosshair, 0.5, 0.5, size / GetAspectRatio(false), size, 0.0, 255, 255, 255, 255)
|
||||
end
|
||||
|
||||
-- "[E] LABEL" drawn in place of the dot. The key badge sits on the point, the label to its right.
|
||||
-- With several options the selected row stays on the point, the others are dimmed above/below it.
|
||||
function utils.drawPrompt(coords, options, selection)
|
||||
local aspect = GetAspectRatio(false)
|
||||
local keyH = prompt.keySize
|
||||
local keyW = keyH / aspect
|
||||
local labelX = keyW * 0.5 + prompt.keyGap / aspect
|
||||
local keyTextX = -measureText(prompt.key, prompt.keyTextHeight, aspect) * 0.5
|
||||
local key, textColor, keyColor, keyTextColor = prompt.key, prompt.textColor, prompt.keyColor, prompt.keyTextColor
|
||||
|
||||
SetDrawOrigin(coords.x, coords.y, coords.z, 0)
|
||||
|
||||
for i = 1, #options do
|
||||
local y = (i - selection) * prompt.rowSpacing
|
||||
local label = options[i].label or ''
|
||||
if prompt.uppercase then label = string_upper(label) end
|
||||
|
||||
if i == selection then
|
||||
DrawSprite(TXD, textures.key, 0.0, y, keyW, keyH, 0.0, keyColor[1], keyColor[2], keyColor[3], keyColor[4])
|
||||
drawGlyphs(key, keyTextX, y, prompt.keyTextHeight, aspect, keyTextColor[1], keyTextColor[2], keyTextColor[3], keyTextColor[4])
|
||||
drawText(label, labelX, y, prompt.textHeight, aspect, textColor, textColor[4])
|
||||
else
|
||||
drawText(label, labelX, y, prompt.textHeight, aspect, textColor, prompt.dimmedAlpha)
|
||||
end
|
||||
end
|
||||
|
||||
ClearDrawOrigin()
|
||||
end
|
||||
|
||||
return utils
|
||||
Reference in new issue
Block a user