├── client ├── compat │ ├── init.lua │ └── resources │ │ ├── interact.lua │ │ ├── ox_target.lua │ │ ├── qtarget.lua │ │ └── qb_target.lua ├── framework │ ├── qbx.lua │ ├── ox.lua │ ├── nd.lua │ ├── qb.lua │ └── esx.lua ├── modules │ ├── store.lua │ ├── config.lua │ ├── dui.lua │ ├── animation.lua │ └── utils.lua ├── defaults.lua ├── main.lua └── api.lua ├── web ├── js │ ├── fetchNui.js │ ├── createOptions.js │ ├── main.js │ └── controls.js ├── style.css └── index.html ├── .github ├── actions │ └── bump-manifest-version.js ├── ISSUE_TEMPLATE │ ├── feature_request.yml │ └── bug_report.yml └── workflows │ └── release.yml ├── fxmanifest.lua ├── init.lua ├── README.md ├── _types.lua └── LICENSE /client/compat/init.lua: -------------------------------------------------------------------------------- 1 | require 'client.compat.resources.qtarget' 2 | require 'client.compat.resources.ox_target' 3 | require 'client.compat.resources.interact' 4 | require 'client.compat.resources.qb_target' -------------------------------------------------------------------------------- /client/framework/qbx.lua: -------------------------------------------------------------------------------- 1 | if not lib.checkDependency('qbx_core', '1.18.0', true) then return end 2 | 3 | local QBX = exports.qbx_core 4 | local utils = require 'client.modules.utils' 5 | 6 | ---@diagnostic disable-next-line: duplicate-set-field 7 | function utils.hasPlayerGotGroup(filter) 8 | return QBX:HasGroup(filter) 9 | end 10 | -------------------------------------------------------------------------------- /web/js/fetchNui.js: -------------------------------------------------------------------------------- 1 | export async function fetchNui(eventName, data) { 2 | const resp = await fetch(`https://sleepless_interact/${eventName}`, { 3 | method: 'post', 4 | headers: { 5 | 'Content-Type': 'application/json; charset=UTF-8', 6 | }, 7 | body: JSON.stringify(data), 8 | }); 9 | 10 | return await resp.json(); 11 | } 12 | -------------------------------------------------------------------------------- /client/framework/ox.lua: -------------------------------------------------------------------------------- 1 | if not lib.checkDependency('ox_core', '0.21.3', true) then return end 2 | 3 | local Ox = require '@ox_core.lib.init' --[[@as OxClient]] 4 | local utils = require 'client.modules.utils' 5 | local player = Ox.GetPlayer() 6 | 7 | ---@diagnostic disable-next-line: duplicate-set-field 8 | function utils.hasPlayerGotGroup(filter) 9 | return player.getGroup(filter) 10 | end 11 | -------------------------------------------------------------------------------- /.github/actions/bump-manifest-version.js: -------------------------------------------------------------------------------- 1 | // Based off of https://github.com/overextended/ox_lib/blob/master/.github/actions/bump-manifest-version.js 2 | const fs = require('fs') 3 | 4 | const version = process.env.TGT_RELEASE_VERSION 5 | const newVersion = version.replace('v', '') 6 | 7 | const manifestFile = fs.readFileSync('fxmanifest.lua', {encoding: 'utf8'}) 8 | 9 | const newFileContent = manifestFile.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`) 10 | 11 | fs.writeFileSync('fxmanifest.lua', newFileContent) 12 | -------------------------------------------------------------------------------- /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | -- FX Information 2 | fx_version 'cerulean' 3 | use_experimental_fxv2_oal 'yes' 4 | lua54 'yes' 5 | game 'gta5' 6 | 7 | version '2.1.1' 8 | 9 | shared_scripts { 10 | '@ox_lib/init.lua', 11 | } 12 | 13 | client_scripts { 14 | 'client/compat/init.lua', 15 | 'init.lua', 16 | 'client/*.lua', 17 | } 18 | 19 | files { 20 | 'web/**', 21 | 'client/modules/*.lua', 22 | 'client/framework/*.lua', 23 | 'client/compat/resources/*.lua' 24 | } 25 | 26 | provides { 27 | 'ox_target', 28 | 'qtarget' 29 | } 30 | 31 | dependency 'ox_lib' 32 | -------------------------------------------------------------------------------- /init.lua: -------------------------------------------------------------------------------- 1 | local export = exports.sleepless_interact 2 | 3 | local function call(self, index, ...) 4 | local function method(...) 5 | return export[index](nil, ...) 6 | end 7 | 8 | if not ... then 9 | self[index] = method 10 | end 11 | 12 | return method 13 | end 14 | 15 | local interact = setmetatable({ 16 | name = 'sleepless_interact', 17 | }, { 18 | __index = call, 19 | __newindex = function(self, key, fn) 20 | rawset(self, key, fn) 21 | 22 | if debug.getinfo(2, 'S').short_src:find('@sleepless_interact/client/api.lua') then 23 | exports(key, fn) 24 | end 25 | end 26 | }) 27 | 28 | _ENV.interact = interact -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /client/modules/store.lua: -------------------------------------------------------------------------------- 1 | local store = {} 2 | store.cooldownEndTime = 0 3 | 4 | store.nearby = {} 5 | 6 | store.coords = {} 7 | store.coordIds = {} 8 | 9 | store.localEntities = {} 10 | store.entities = {} 11 | 12 | store.offsets = { 13 | localEntities = {}, 14 | entities = {}, 15 | models = {}, 16 | peds = {}, 17 | objects = {}, 18 | vehicles = {}, 19 | players = {}, 20 | } 21 | 22 | store.bones = { 23 | localEntities = {}, 24 | entities = {}, 25 | models = {}, 26 | peds = {}, 27 | objects = {}, 28 | vehicles = {}, 29 | players = {}, 30 | } 31 | 32 | store.peds = {} 33 | store.objects = {} 34 | store.vehicles = {} 35 | store.players = {} 36 | store.models = {} 37 | 38 | store.current = {} 39 | 40 | return store 41 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Framework** 14 | The framework your server uses for players (e.g. Ox, ESX, QB). 15 | 16 | **Resource version** 17 | The version number listed in fxmanifest.lua, or optionally a commit hash. 18 | 19 | **To Reproduce** 20 | Steps to reproduce the behavior: 21 | 1. Go to '...' 22 | 2. Click on '....' 23 | 3. Scroll down to '....' 24 | 4. See error 25 | 26 | **Expected behavior** 27 | A clear and concise description of what you expected to happen. 28 | 29 | **Screenshots** 30 | If applicable, add screenshots to help explain your problem. 31 | 32 | **Additional context** 33 | Add any other context about the problem here. -------------------------------------------------------------------------------- /client/modules/config.lua: -------------------------------------------------------------------------------- 1 | local config = {} 2 | 3 | -- this is the maximum distance that interacts will render the indicator sprite (little cirlce) 4 | -- recommend keeping this pretty low for optimization 5 | config.maxInteractDistance = 5.0 6 | 7 | -- {0-255, 0-255, 0-255, 0-255} 8 | config.themeColor = { 28, 100, 184, 200 } --- r, g, b, a 9 | 10 | --- texture dictionary and texture name for the sprite used to show non active interactions. 11 | config.IndicatorSprite = { dict = 'shared', txt = 'emptydot_32' } 12 | 13 | -- boolean true/false use a keybind to show and hide the interactions 14 | config.useShowKeyBind = false 15 | 16 | -- string default key mapping for the show interactions keybind 17 | config.defaultShowKeyBind = 'LMENU' 18 | 19 | -- "hold" | "toggle" sets the behavior of the show interactions key bind 20 | config.showKeyBindBehavior = 'toggle' 21 | 22 | return config -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sleepless_interact 2 | 3 | A FiveM library for creating 3D DUI world interactions 4 | 5 | ![](https://img.shields.io/github/downloads/Sleepless-Development/sleepless_interact/total?logo=github) 6 | ![](https://img.shields.io/github/downloads/Sleepless-Development/sleepless_interact/latest/total?logo=github) 7 | ![](https://img.shields.io/github/contributors/Sleepless-Development/sleepless_interact?logo=github) 8 | ![](https://img.shields.io/github/v/release/Sleepless-Development/sleepless_interact?logo=github) 9 | 10 | 11 | ## thanks 12 | v2 uses a lot of code from ox_target to help ensure feature parity. so a big thanks to linden for that. [ox_target](https://github.com/overextended/ox_target) 13 | 14 | ## 📃 Documentation 15 | 16 | - [V1](https://sleeplessdevelopment.dev/interactv1) 17 | - [V2](https://sleeplessdevelopment.dev/interactv2) 18 | 19 | ## 💾 Download 20 | 21 | [seleepless_interact.zip](https://github.com/Sleepless-Development/sleepless_interact/releases/latest/download/sleepless_interact.zip) 22 | -------------------------------------------------------------------------------- /web/js/createOptions.js: -------------------------------------------------------------------------------- 1 | import { updateHighlight, setCurrentIndex } from "./controls.js"; 2 | 3 | const optionsWrapper = document.getElementById("options-wrapper"); 4 | 5 | export function createOptions(type, data, id) { 6 | if (data.hide) return; 7 | 8 | const option = document.createElement("div"); 9 | 10 | let iconClasses = "fa-fw"; 11 | 12 | if (data.icon) { 13 | if (data.icon.includes("fa-")) { 14 | iconClasses += ` ${data.icon}`; 15 | } else { 16 | iconClasses += ` fa-solid fa-${data.icon}`; 17 | } 18 | } 19 | 20 | 21 | const iconElement = ``; 24 | 25 | option.innerHTML = ` 26 |
27 | ${iconElement} 28 |

${data.label + (data.holdTime ? " (hold)" : "")}

29 | `; 30 | option.className = "option-container"; 31 | option.targetType = type; 32 | option.color = data.color; 33 | option.targetId = id; 34 | option.holdTime = data.holdTime || 0; // Default to 0 if no holdtime 35 | option.hideButton = data.hideButton || false; 36 | 37 | optionsWrapper.appendChild(option); 38 | 39 | if (optionsWrapper.children.length === 1) { 40 | setCurrentIndex(0); 41 | updateHighlight(); 42 | } 43 | } -------------------------------------------------------------------------------- /client/framework/nd.lua: -------------------------------------------------------------------------------- 1 | local NDCore = exports["ND_Core"] 2 | 3 | local playerGroups = NDCore:getPlayer()?.groups or {} 4 | 5 | RegisterNetEvent("ND:characterLoaded", function(data) 6 | playerGroups = data.groups 7 | end) 8 | 9 | RegisterNetEvent("ND:updateCharacter", function(data) 10 | if source == '' then return end 11 | playerGroups = data.groups or {} 12 | end) 13 | 14 | local utils = require 'client.modules.utils' 15 | 16 | ---@diagnostic disable-next-line: duplicate-set-field 17 | function utils.hasPlayerGotGroup(filter) 18 | local _type = type(filter) 19 | 20 | if _type == 'string' then 21 | local group = playerGroups[filter] 22 | 23 | if group then 24 | return true 25 | end 26 | elseif _type == 'table' then 27 | local tabletype = table.type(filter) 28 | 29 | if tabletype == 'hash' then 30 | for name, grade in pairs(filter) do 31 | local playerGrade = playerGroups[name]?.rank 32 | 33 | if playerGrade and grade <= playerGrade then 34 | return true 35 | end 36 | end 37 | elseif tabletype == 'array' then 38 | for i = 1, #filter do 39 | local name = filter[i] 40 | local group = playerGroups[name] 41 | 42 | if group then 43 | return true 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /web/js/main.js: -------------------------------------------------------------------------------- 1 | import { createOptions } from "./createOptions.js"; 2 | import { fetchNui } from "./fetchNui.js"; 3 | import { onSelect } from "./controls.js"; 4 | import { setCurrentIndex, resetHold, setDefaultColor } from "./controls.js"; 5 | 6 | const optionsWrapper = document.getElementById("options-wrapper"); 7 | const body = document.body; 8 | 9 | window.addEventListener("message", (event) => { 10 | switch (event.data.action) { 11 | case "visible": { 12 | body.style.visibility = event.data.value ? "visible" : "hidden"; 13 | break 14 | } 15 | 16 | case "setOptions": { 17 | optionsWrapper.innerHTML = ""; 18 | 19 | if (event.data.value.options) { 20 | for (const type in event.data.value.options) { 21 | event.data.value.options[type].forEach((data, id) => { 22 | createOptions(type, data, id + 1); 23 | }); 24 | } 25 | if (event.data.value.resetIndex) { 26 | setCurrentIndex(0); 27 | } 28 | } 29 | break 30 | } 31 | 32 | case "interact": { 33 | onSelect(); 34 | break 35 | } 36 | 37 | case "release": { 38 | resetHold(); 39 | break 40 | } 41 | 42 | case "setColor": { 43 | const c = event.data.value 44 | const color = `rgb(${c[0]}, ${c[1]}, ${c[2]}, ${c[3] / 255})` 45 | setDefaultColor(color) 46 | body.style.setProperty('--theme-color', color) 47 | break 48 | } 49 | 50 | case "setCooldown": { 51 | body.style.opacity = event.data.value ? '0.3' : '1' 52 | const interactKey = document.getElementById("interact-key"); 53 | 54 | interactKey.innerHTML = event.data.value ? `` : 'E' 55 | 56 | break 57 | } 58 | } 59 | }); 60 | 61 | window.addEventListener("load", async (event) => { 62 | await fetchNui("load"); 63 | }); -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*.*.*" 7 | 8 | jobs: 9 | create-release: 10 | name: Build and Create Tagged release 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Install archive tools 15 | run: sudo apt install zip 16 | 17 | - name: Checkout source code 18 | uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | ref: ${{ github.event.repository.default_branch }} 22 | 23 | - name: Get variables 24 | id: get_vars 25 | run: | 26 | echo '::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)' 27 | echo '::set-output name=DATE::$(date +'%D')' 28 | 29 | - name: Bump manifest version 30 | run: node .github/actions/bump-manifest-version.js 31 | env: 32 | TGT_RELEASE_VERSION: ${{ github.ref_name }} 33 | 34 | - name: Push manifest change 35 | uses: EndBug/add-and-commit@v8 36 | with: 37 | add: fxmanifest.lua 38 | push: true 39 | author_name: Manifest Bumper 40 | author_email: 41898282+github-actions[bot]@users.noreply.github.com 41 | message: "chore: bump manifest version to ${{ github.ref_name }}" 42 | 43 | - name: Update tag ref 44 | uses: EndBug/latest-tag@latest 45 | with: 46 | tag-name: ${{ github.ref_name }} 47 | 48 | - name: Bundle files 49 | run: | 50 | mkdir -p ./temp/sleepless_interact 51 | mkdir -p ./temp/sleepless_interact/web 52 | cp ./{README.md,LICENSE,fxmanifest.lua,init.lua,_types.lua} ./temp/sleepless_interact 53 | cp -r ./{client,web} ./temp/sleepless_interact 54 | cd ./temp && zip -r ../sleepless_interact.zip ./sleepless_interact 55 | 56 | - name: Create Release 57 | uses: "marvinpinto/action-automatic-releases@v1.2.1" 58 | id: auto_release 59 | with: 60 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 61 | title: "${{ env.RELEASE_VERSION }}" 62 | prerelease: false 63 | files: sleepless_interact.zip 64 | 65 | env: 66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /client/modules/dui.lua: -------------------------------------------------------------------------------- 1 | local store = require 'client.modules.store' 2 | local config = require 'client.modules.config' 3 | 4 | local dui = {} 5 | local screenW, screenH = GetActualScreenResolution() 6 | local controlsRunning = false 7 | 8 | function dui.register() 9 | if dui.instance then 10 | dui.instance:remove() 11 | end 12 | 13 | dui.instance = lib.dui:new( 14 | { 15 | url = ("nui://%s/web/index.html"):format(cache.resource), 16 | width = screenW, 17 | height = screenH, 18 | } 19 | ) 20 | 21 | while not dui.loaded do Wait(100) end 22 | 23 | dui.sendMessage('visible', true) 24 | dui.sendMessage('setColor', config.themeColor) 25 | end 26 | 27 | RegisterNuiCallback('load', function(_, cb) 28 | dui.loaded = true 29 | Wait(1000) 30 | cb(1) 31 | end) 32 | 33 | RegisterNuiCallback('currentOption', function(data, cb) 34 | store.current.index = data[1] 35 | cb(1) 36 | end) 37 | 38 | function dui.sendMessage(action, value) 39 | dui.instance:sendMessage({ 40 | action = action, 41 | value = value 42 | }) 43 | 44 | if action == 'setOptions' and not controlsRunning then 45 | if controlsRunning then return end 46 | controlsRunning = true 47 | CreateThread(function() 48 | while next(store.current) do 49 | dui.handleDuiControls() 50 | Wait(0) 51 | end 52 | controlsRunning = false 53 | end) 54 | end 55 | end 56 | 57 | local IsControlJustPressed = IsControlJustPressed 58 | local SendDuiMouseWheel = SendDuiMouseWheel 59 | 60 | dui.handleDuiControls = function() 61 | if not dui.instance?.duiObject then return end 62 | 63 | local input = false 64 | 65 | if (IsControlJustPressed(3, 180)) then -- SCROLL DOWN 66 | SendDuiMouseWheel(dui.instance.duiObject, -50, 0.0) 67 | input = true 68 | end 69 | 70 | if (IsControlJustPressed(3, 181)) then -- SCROLL UP 71 | SendDuiMouseWheel(dui.instance.duiObject, 50, 0.0) 72 | input = true 73 | end 74 | 75 | if (IsControlJustPressed(3, 173)) then -- ARROW DOWN 76 | SendDuiMouseWheel(dui.instance.duiObject, -50, 0.0) 77 | input = true 78 | end 79 | 80 | if (IsControlJustPressed(3, 172)) then -- ARROW UP 81 | SendDuiMouseWheel(dui.instance.duiObject, 50, 0.0) 82 | input = true 83 | end 84 | 85 | if input then 86 | Wait(200) 87 | end 88 | end 89 | 90 | dui.register() --- on load and on resource start? 91 | 92 | return dui 93 | -------------------------------------------------------------------------------- /client/framework/qb.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | 3 | local success, result = pcall(function() 4 | return QBCore.Functions.GetPlayerData() 5 | end) 6 | 7 | local playerData = success and result or {} 8 | local utils = require 'client.modules.utils' 9 | local playerItems = utils.getItems() 10 | 11 | local function setPlayerItems() 12 | if not playerData or not playerData.items then return end 13 | 14 | table.wipe(playerItems) 15 | 16 | for _, item in pairs(playerData.items) do 17 | playerItems[item.name] = (playerItems[item.name] or 0) + (item.amount or 0) 18 | end 19 | end 20 | 21 | local usingOxInventory = utils.hasExport('ox_inventory.Items') 22 | 23 | if not usingOxInventory then 24 | setPlayerItems() 25 | end 26 | 27 | AddEventHandler('QBCore:Client:OnPlayerLoaded', function() 28 | playerData = QBCore.Functions.GetPlayerData() 29 | if not usingOxInventory then setPlayerItems() end 30 | end) 31 | 32 | RegisterNetEvent('QBCore:Player:SetPlayerData', function(val) 33 | if source == '' then return end 34 | 35 | playerData = val 36 | 37 | if not usingOxInventory then setPlayerItems() end 38 | end) 39 | 40 | ---@diagnostic disable-next-line: duplicate-set-field 41 | function utils.hasPlayerGotGroup(filter) 42 | local _type = type(filter) 43 | 44 | if _type == 'string' then 45 | local job = playerData.job.name == filter 46 | local gang = playerData.gang.name == filter 47 | local citizenId = playerData.citizenid == filter 48 | 49 | if job or gang or citizenId then 50 | return true 51 | end 52 | elseif _type == 'table' then 53 | local tabletype = table.type(filter) 54 | 55 | if tabletype == 'hash' then 56 | for name, grade in pairs(filter) do 57 | local job = playerData.job.name == name 58 | local gang = playerData.gang.name == name 59 | local citizenId = playerData.citizenid == name 60 | 61 | if job and grade <= playerData.job.grade.level or gang and grade <= playerData.gang.grade.level or citizenId then 62 | return true 63 | end 64 | end 65 | elseif tabletype == 'array' then 66 | for i = 1, #filter do 67 | local name = filter[i] 68 | local job = playerData.job.name == name 69 | local gang = playerData.gang.name == name 70 | local citizenId = playerData.citizenid == name 71 | 72 | if job or gang or citizenId then 73 | return true 74 | end 75 | end 76 | end 77 | end 78 | end -------------------------------------------------------------------------------- /client/framework/esx.lua: -------------------------------------------------------------------------------- 1 | local ESX = exports.es_extended:getSharedObject() 2 | local utils = require 'client.modules.utils' 3 | local groups = { 'job', 'job2' } 4 | local playerGroups = {} 5 | local playerItems = utils.getItems() 6 | local usingOxInventory = GetResourceState('ox_inventory'):find('start') 7 | 8 | local function setPlayerData(playerData) 9 | table.wipe(playerGroups) 10 | table.wipe(playerItems) 11 | 12 | for i = 1, #groups do 13 | local group = groups[i] 14 | local data = playerData[group] 15 | 16 | if data then 17 | playerGroups[group] = data 18 | end 19 | end 20 | 21 | if usingOxInventory or not playerData.inventory then return end 22 | 23 | for _, v in pairs(playerData.inventory) do 24 | if v.count > 0 then 25 | playerItems[v.name] = v.count 26 | end 27 | end 28 | end 29 | 30 | if ESX.PlayerLoaded then 31 | setPlayerData(ESX.PlayerData) 32 | end 33 | 34 | RegisterNetEvent('esx:playerLoaded', function(data) 35 | if source == '' then return end 36 | setPlayerData(data) 37 | end) 38 | 39 | RegisterNetEvent('esx:setJob', function(job) 40 | if source == '' then return end 41 | playerGroups.job = job 42 | end) 43 | 44 | RegisterNetEvent('esx:setJob2', function(job) 45 | if source == '' then return end 46 | playerGroups.job2 = job 47 | end) 48 | 49 | RegisterNetEvent('esx:addInventoryItem', function(name, count) 50 | playerItems[name] = count 51 | end) 52 | 53 | RegisterNetEvent('esx:removeInventoryItem', function(name, count) 54 | playerItems[name] = count 55 | end) 56 | 57 | ---@diagnostic disable-next-line: duplicate-set-field 58 | function utils.hasPlayerGotGroup(filter) 59 | local _type = type(filter) 60 | for i = 1, #groups do 61 | local group = groups[i] 62 | 63 | if _type == 'string' then 64 | local data = playerGroups[group] 65 | 66 | if filter == data?.name then 67 | return true 68 | end 69 | elseif _type == 'table' then 70 | local tabletype = table.type(filter) 71 | 72 | if tabletype == 'hash' then 73 | for name, grade in pairs(filter) do 74 | local data = playerGroups[group] 75 | 76 | if data?.name == name and grade <= data.grade then 77 | return true 78 | end 79 | end 80 | elseif tabletype == 'array' then 81 | for j = 1, #filter do 82 | local name = filter[j] 83 | local data = playerGroups[group] 84 | 85 | if data?.name == name then 86 | return true 87 | end 88 | end 89 | end 90 | end 91 | end 92 | end 93 | -------------------------------------------------------------------------------- /client/modules/animation.lua: -------------------------------------------------------------------------------- 1 | local animation = {} 2 | 3 | local createdProps = {} 4 | 5 | local currentAnim = nil 6 | 7 | local function createProp(ped, prop) 8 | lib.requestModel(prop.model) 9 | local coords = GetEntityCoords(ped) 10 | local object = CreateObject(prop.model, coords.x, coords.y, coords.z, false, false, false) 11 | 12 | AttachEntityToEntity(object, ped, GetPedBoneIndex(ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, prop.rotOrder or 0, true) 13 | SetModelAsNoLongerNeeded(prop.model) 14 | return object 15 | end 16 | 17 | local function deleteProgressProps(serverId) 18 | local playerProps = createdProps[serverId] 19 | if not playerProps then return end 20 | for i = 1, #playerProps do 21 | local prop = playerProps[i] 22 | if DoesEntityExist(prop) then 23 | DeleteEntity(prop) 24 | end 25 | end 26 | createdProps[serverId] = nil 27 | end 28 | 29 | function animation.playAnim(anim, prop) 30 | if anim.dict then 31 | currentAnim = anim 32 | 33 | lib.requestAnimDict(anim.dict) 34 | 35 | TaskPlayAnim(cache.ped, anim.dict, anim.clip, anim.blendIn or 3.0, anim.blendOut or 1.0, anim.duration or -1, anim.flag or 49, anim.playbackRate or 0, 36 | anim.lockX, anim.lockY, anim.lockZ) 37 | RemoveAnimDict(anim.dict) 38 | elseif anim.scenario then 39 | TaskStartScenarioInPlace(cache.ped, anim.scenario, 0, anim.playEnter == nil or anim.playEnter --[[@as boolean]]) 40 | end 41 | 42 | if prop then 43 | TriggerServerEvent('Interact:SetHoldProps', prop) 44 | end 45 | end 46 | 47 | function animation.stopAnim() 48 | if currentAnim then 49 | if currentAnim.dict then 50 | StopAnimTask(cache.ped, currentAnim.dict, currentAnim.clip, 1.0) 51 | Wait(0) 52 | else 53 | ClearPedTasks(cache.ped) 54 | end 55 | currentAnim = nil 56 | end 57 | 58 | TriggerServerEvent('Interact:SetHoldProps', nil) 59 | end 60 | 61 | AddStateBagChangeHandler('interact:holdProps', nil, function(bagName, key, value, reserved, replicated) 62 | if replicated then return end 63 | 64 | local ply = GetPlayerFromStateBagName(bagName) 65 | if ply == 0 then return end 66 | 67 | local ped = GetPlayerPed(ply) 68 | local serverId = GetPlayerServerId(ply) 69 | 70 | if not value then 71 | return deleteProgressProps(serverId) 72 | end 73 | 74 | createdProps[serverId] = {} 75 | local playerProps = createdProps[serverId] 76 | 77 | if value.model then 78 | playerProps[#playerProps + 1] = createProp(ped, value) 79 | else 80 | for i = 1, #value do 81 | local prop = value[i] 82 | 83 | if prop then 84 | playerProps[#playerProps + 1] = createProp(ped, prop) 85 | end 86 | end 87 | end 88 | end) 89 | 90 | return animation 91 | -------------------------------------------------------------------------------- /web/style.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"); 2 | 3 | :root { 4 | font-size: 1vh; 5 | } 6 | 7 | body { 8 | user-select: none; 9 | white-space: nowrap; 10 | margin: 0; 11 | overflow: hidden; 12 | color: whitesmoke; 13 | 14 | --bg-color: rgb(25, 25, 25, 0.85); 15 | --theme-color: rgb(28, 100, 184, 0.8); 16 | 17 | transition: opacity 200ms linear; 18 | } 19 | 20 | p { 21 | margin: 0; 22 | } 23 | 24 | #container { 25 | position: absolute; 26 | top: 50%; 27 | left: 50%; 28 | transform: translate(-50%, -50%); 29 | display: flex; 30 | align-items: center; 31 | justify-content: center; 32 | } 33 | 34 | #options-wrapper { 35 | position: absolute; 36 | top: 50%; 37 | left: 50%; 38 | translate: 20% -50%; 39 | } 40 | 41 | .option-container { 42 | color: var(--color-default); 43 | display: flex; 44 | flex-direction: row; 45 | justify-content: flex-start; 46 | align-items: center; 47 | font-family: "Roboto"; 48 | background: var(--bg-color); 49 | font-size: 1rem; 50 | vertical-align: middle; 51 | margin: 0.2rem; 52 | transition: 300ms; 53 | transform-origin: left top; 54 | scale: 1; 55 | height: 2rem; 56 | padding-right: 1rem; 57 | top: 0; 58 | min-width: 10rem; 59 | } 60 | 61 | .animated-background { 62 | position: absolute; 63 | height: 100%; 64 | width: 1%; /* Default state: collapsed */ 65 | background-color: var(--theme-color); 66 | z-index: 1; 67 | transition: width 250ms ease-in-out; /* Smooth transition for both directions */ 68 | } 69 | 70 | .option-container.highlighted .animated-background { 71 | width: 100%; /* Expand when highlighted */ 72 | } 73 | 74 | .option-icon { 75 | font-size: 1.2rem; 76 | line-height: 0; 77 | width: 1.3rem; 78 | margin: 0.45rem; 79 | color: var(--color-default); 80 | z-index: 2; 81 | } 82 | 83 | .option-label { 84 | font-weight: 500; 85 | z-index: 2; 86 | } 87 | 88 | #interact-container { 89 | width: 2.5rem; 90 | height: 2.5rem; 91 | display: flex; 92 | align-items: center; 93 | justify-content: center; 94 | border-radius: 0.1rem; 95 | overflow: hidden; 96 | background: var(--bg-color); 97 | } 98 | 99 | #interact-progress { 100 | position: absolute; 101 | width: 100%; 102 | height: 0%; 103 | top: 50%; 104 | left: 50%; 105 | transform: translate(-50%, -50%); 106 | background: var(--theme-color); 107 | transition: height 0ms; 108 | /* animation: progress 1000ms linear infinite; */ 109 | } 110 | 111 | #interact-key { 112 | font-size: 1.5rem; 113 | position: absolute; 114 | color: whitesmoke; 115 | width: 100%; 116 | height: 100%; 117 | font-family: "Roboto"; 118 | border: 0.1rem solid whitesmoke; 119 | aspect-ratio: 1; 120 | display: flex; 121 | align-items: center; 122 | justify-content: center; 123 | border-radius: 0.2rem; 124 | overflow: hidden; 125 | } 126 | 127 | @keyframes progress { 128 | from { 129 | height: 0%; 130 | } 131 | to { 132 | height: 100%; 133 | } 134 | } -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |
10 |
E
11 |
12 | 13 |
14 |
15 |
16 | 17 |

Option 1

18 |
19 | 20 |
21 |
22 | 23 |

Option 2

24 |
25 | 26 |
27 |
28 | 29 |

Option 3 (hold)

30 |
31 | 32 |
33 |
34 | 35 |

Option 4

36 |
37 | 38 |
39 |
40 | 41 |

Option 5

42 |
43 |
44 |
45 | 46 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /client/compat/resources/interact.lua: -------------------------------------------------------------------------------- 1 | local function generateUUID() 2 | return ('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'):gsub('[xy]', function(c) 3 | local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb) 4 | return ('%x'):format(v) 5 | end) 6 | end 7 | 8 | local function exportHandler(exportName, func) 9 | AddEventHandler(('__cfx_export_interact_%s'):format(exportName), function(setCB) 10 | setCB(func) 11 | end) 12 | end 13 | 14 | local function convert(data, resource) 15 | local converted = {} 16 | local id = data.id or generateUUID() 17 | for i = 1, #data.options do 18 | local option = data.options[i] 19 | local newOption = { 20 | label = option.label or "Unnamed Option", 21 | icon = option.icon, 22 | iconColor = option.iconColor, 23 | distance = data.interactDst or 1.0, 24 | canInteract = option.canInteract, 25 | groups = data.groups, 26 | name = id, 27 | resource = resource, 28 | offset = data.offset, 29 | bones = (data.bone and { data.bone }) or nil, 30 | onSelect = option.action, 31 | cooldown = 1000, 32 | event = option.event, 33 | serverEvent = option.serverEvent, 34 | } 35 | converted[#converted + 1] = newOption 36 | end 37 | return converted, id 38 | end 39 | 40 | exportHandler('AddInteraction', function(data) 41 | local coords = data.coords 42 | local options = convert(data, GetInvokingResource()) 43 | local id = interact.addCoords(coords, options) 44 | return id 45 | end) 46 | 47 | exportHandler('AddLocalEntityInteraction', function(data) 48 | local entity = data.entity 49 | local options, id = convert(data, GetInvokingResource()) 50 | interact.addLocalEntity(entity, options) 51 | return id 52 | end) 53 | 54 | exportHandler('AddEntityInteraction', function(data) 55 | local netId = data.netId 56 | local options, id = convert(data, GetInvokingResource()) 57 | interact.addEntity(netId, options) 58 | return id 59 | end) 60 | 61 | exportHandler('AddGlobalVehicleInteraction', function(data) 62 | local options, id = convert(data, GetInvokingResource()) 63 | interact.addGlobalVehicle(options) 64 | return id 65 | end) 66 | 67 | exportHandler('addGlobalPlayerInteraction', function(data) 68 | local options, id = convert(data, GetInvokingResource()) 69 | interact.addGlobalPlayer(options) 70 | return id 71 | end) 72 | 73 | exportHandler('AddModelInteraction', function(data) 74 | local model = data.model 75 | local options, id = convert(data, GetInvokingResource()) 76 | interact.addModel(model, options) 77 | return id 78 | end) 79 | 80 | exportHandler('RemoveInteraction', function(id) 81 | interact.removeCoords(id, nil, true) 82 | end) 83 | 84 | exportHandler('RemoveLocalEntityInteraction', function(entity, id) 85 | interact.removeLocalEntity(entity, id) 86 | end) 87 | 88 | exportHandler('RemoveEntityInteraction', function(netId, id) 89 | interact.removeEntity(netId, id) 90 | end) 91 | 92 | exportHandler('RemoveModelInteraction', function(model, id) 93 | interact.removeModel(model, id) 94 | end) 95 | 96 | exportHandler('RemoveGlobalVehicleInteraction', function(id) 97 | interact.removeGlobalVehicle(id) 98 | end) 99 | 100 | exportHandler('RemoveGlobalPlayerInteraction', function(id) 101 | interact.removeGlobalPlayer(id) 102 | end) 103 | -------------------------------------------------------------------------------- /web/js/controls.js: -------------------------------------------------------------------------------- 1 | import { fetchNui } from "./fetchNui.js"; 2 | const optionsWrapper = document.getElementById("options-wrapper"); 3 | const progressElement = document.getElementById("interact-progress"); 4 | const interactButton = document.getElementById("interact-container"); 5 | 6 | let currentIndex = 0; 7 | let isHolding = false; 8 | let holdStartTime = null; 9 | let holdTimeout = null; 10 | let defaultColor = null; 11 | 12 | export function checkHideButton() { 13 | const options = optionsWrapper.querySelectorAll(".option-container"); 14 | const option = options[currentIndex]; 15 | 16 | interactButton.style.visibility = option && option.hideButton ? "hidden" : "visible"; 17 | } 18 | 19 | export function setDefaultColor(color) { 20 | defaultColor = color; 21 | return defaultColor; 22 | } 23 | 24 | export function setCurrentIndex(newIndex) { 25 | currentIndex = newIndex; 26 | checkHideButton(); 27 | return currentIndex; 28 | } 29 | 30 | export function onSelect() { 31 | const options = optionsWrapper.querySelectorAll(".option-container"); 32 | const option = options[currentIndex]; 33 | 34 | if (!option) return; 35 | 36 | if (option.holdTime) { 37 | startHold(option); 38 | fetchNui("startHoldAnim", [option.targetType, option.targetId]); 39 | } else { 40 | fetchNui("select", [option.targetType, option.targetId]); 41 | } 42 | } 43 | 44 | function completeHold(option) { 45 | if (!isHolding) return; 46 | 47 | const options = optionsWrapper.querySelectorAll(".option-container"); 48 | const currentOption = options[currentIndex]; 49 | 50 | if (!currentOption) return; 51 | 52 | // Verify it's still the same option 53 | if (currentOption === option) { 54 | fetchNui("select", [option.targetType, option.targetId]); 55 | } 56 | } 57 | 58 | export function resetHold() { 59 | if (!isHolding) return; 60 | 61 | isHolding = false; 62 | holdStartTime = null; 63 | clearTimeout(holdTimeout); 64 | progressElement.style.transition = "none"; 65 | progressElement.style.height = "0"; 66 | 67 | fetchNui("endHoldAnim"); 68 | } 69 | 70 | function startHold(option) { 71 | if (isHolding) return; 72 | 73 | isHolding = true; 74 | holdStartTime = Date.now(); 75 | progressElement.style.transition = `height ${option.holdTime}ms linear`; 76 | progressElement.style.height = "100%"; 77 | 78 | holdTimeout = setTimeout(() => { 79 | completeHold(option); 80 | }, option.holdTime); 81 | } 82 | 83 | export function updateHighlight() { 84 | const options = optionsWrapper.querySelectorAll(".option-container"); 85 | if (options.length > 0) { 86 | options.forEach((option) => option.classList.remove("highlighted")); 87 | options[currentIndex].classList.add("highlighted"); 88 | 89 | if (options[currentIndex].color) { 90 | const c = options[currentIndex].color; 91 | const color = `rgb(${c[0]}, ${c[1]}, ${c[2]}, ${c[3] / 255})`; 92 | document.body.style.setProperty("--theme-color", color); 93 | } else { 94 | document.body.style.setProperty("--theme-color", defaultColor); 95 | } 96 | } 97 | } 98 | 99 | window.addEventListener("wheel", (event) => { 100 | if (isHolding) return; 101 | 102 | const options = optionsWrapper.querySelectorAll(".option-container"); 103 | if (options.length === 0) return; 104 | 105 | if (event.deltaY > 0) { 106 | currentIndex = setCurrentIndex((currentIndex + 1) % options.length); 107 | } else { 108 | currentIndex = setCurrentIndex((currentIndex - 1 + options.length) % options.length); 109 | } 110 | 111 | updateHighlight(); 112 | 113 | fetchNui("currentOption", [currentIndex + 1]); 114 | }); 115 | 116 | updateHighlight(); 117 | -------------------------------------------------------------------------------- /client/defaults.lua: -------------------------------------------------------------------------------- 1 | local GetEntityBoneIndexByName = GetEntityBoneIndexByName 2 | local GetEntityBonePosition_2 = GetEntityBonePosition_2 3 | local GetVehicleDoorLockStatus = GetVehicleDoorLockStatus 4 | 5 | local bones = { 6 | [0] = 'dside_f', 7 | [1] = 'pside_f', 8 | [2] = 'dside_r', 9 | [3] = 'pside_r' 10 | } 11 | 12 | ---@param vehicle number 13 | ---@param door number 14 | local function toggleDoor(vehicle, door) 15 | if GetVehicleDoorLockStatus(vehicle) ~= 2 then 16 | if GetVehicleDoorAngleRatio(vehicle, door) > 0.0 then 17 | SetVehicleDoorShut(vehicle, door, false) 18 | else 19 | SetVehicleDoorOpen(vehicle, door, false, false) 20 | end 21 | end 22 | end 23 | 24 | ---@param entity number 25 | ---@param coords vector3 26 | ---@param door number 27 | ---@param useOffset boolean? 28 | ---@return boolean? 29 | local function canInteractWithDoor(entity, coords, door, useOffset) 30 | if not GetIsDoorValid(entity, door) or GetVehicleDoorLockStatus(entity) > 1 or IsVehicleDoorDamaged(entity, door) or cache.vehicle then return end 31 | 32 | if useOffset then return true end 33 | 34 | local boneName = bones[door] 35 | 36 | if not boneName then return false end 37 | 38 | local boneId = GetEntityBoneIndexByName(entity, 'door_' .. boneName) 39 | 40 | if boneId ~= -1 then 41 | return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.5 or #(coords - GetEntityBonePosition_2(entity, GetEntityBoneIndexByName(entity, 'seat_' .. boneName))) < 0.72 42 | end 43 | end 44 | 45 | local function onSelectDoor(data, door) 46 | local entity = data.entity 47 | 48 | if NetworkGetEntityOwner(entity) == cache.playerId then 49 | return toggleDoor(entity, door) 50 | end 51 | 52 | TriggerServerEvent('ox_target:toggleEntityDoor', VehToNet(entity), door) 53 | end 54 | 55 | RegisterNetEvent('ox_target:toggleEntityDoor', function(netId, door) 56 | local entity = NetToVeh(netId) 57 | toggleDoor(entity, door) 58 | end) 59 | 60 | interact.addGlobalVehicle({ 61 | { 62 | name = 'ox_target:driverF', 63 | icon = 'fa-solid fa-car-side', 64 | label = "Toggle front driver door", 65 | bones = 'door_dside_f', 66 | distance = 2, 67 | canInteract = function(entity, distance, coords, name) 68 | return canInteractWithDoor(entity, coords, 0) 69 | end, 70 | onSelect = function(data) 71 | onSelectDoor(data, 0) 72 | end 73 | }, 74 | { 75 | name = 'ox_target:passengerF', 76 | icon = 'fa-solid fa-car-side', 77 | label = "Toggle front passenger door", 78 | bones = 'door_pside_f', 79 | distance = 2, 80 | canInteract = function(entity, distance, coords, name) 81 | return canInteractWithDoor(entity, coords, 1) 82 | end, 83 | onSelect = function(data) 84 | onSelectDoor(data, 1) 85 | end 86 | }, 87 | { 88 | name = 'ox_target:driverR', 89 | icon = 'fa-solid fa-car-side', 90 | label = "Toggle rear driver door", 91 | bones = 'door_dside_r', 92 | distance = 2, 93 | canInteract = function(entity, distance, coords) 94 | return canInteractWithDoor(entity, coords, 2) 95 | end, 96 | onSelect = function(data) 97 | onSelectDoor(data, 2) 98 | end 99 | }, 100 | { 101 | name = 'ox_target:passengerR', 102 | icon = 'fa-solid fa-car-side', 103 | label = "Toggle rear passenger door", 104 | bones = 'door_pside_r', 105 | distance = 2, 106 | canInteract = function(entity, distance, coords) 107 | return canInteractWithDoor(entity, coords, 3) 108 | end, 109 | onSelect = function(data) 110 | onSelectDoor(data, 3) 111 | end 112 | }, 113 | { 114 | name = 'ox_target:bonnet', 115 | icon = 'fa-solid fa-car', 116 | label = "Toggle hood", 117 | offset = vec3(0.5, 1, 0.5), 118 | distance = 2, 119 | canInteract = function(entity, distance, coords) 120 | return canInteractWithDoor(entity, coords, 4, true) 121 | end, 122 | onSelect = function(data) 123 | onSelectDoor(data, 4) 124 | end 125 | }, 126 | { 127 | name = 'ox_target:trunk', 128 | icon = 'fa-solid fa-car-rear', 129 | label = "Toggle trunk", 130 | offset = vec3(0.5, 0, 0.5), 131 | distance = 2, 132 | canInteract = function(entity, distance, coords, name) 133 | return canInteractWithDoor(entity, coords, 5, true) 134 | end, 135 | onSelect = function(data) 136 | onSelectDoor(data, 5) 137 | end 138 | } 139 | }) -------------------------------------------------------------------------------- /client/compat/resources/ox_target.lua: -------------------------------------------------------------------------------- 1 | local glm = require 'glm' 2 | 3 | local zoneToCoord = {} 4 | 5 | local function exportHandler(exportName, func) 6 | AddEventHandler(('__cfx_export_ox_target_%s'):format(exportName), function(setCB) 7 | setCB(func) 8 | end) 9 | end 10 | 11 | local function disableTargeting(state) 12 | interact.disableInteract(state) 13 | end 14 | 15 | local function addGlobalObject(options) 16 | interact.addGlobalObject(options) 17 | end 18 | 19 | local function removeGlobalObject(optionNames) 20 | interact.removeGlobalObject(optionNames) 21 | end 22 | 23 | local function addGlobalPed(options) 24 | interact.addGlobalPed(options) 25 | end 26 | 27 | local function removeGlobalPed(optionNames) 28 | interact.removeGlobalPed(optionNames) 29 | end 30 | 31 | local function addGlobalPlayer(options) 32 | interact.addGlobalPlayer(options) 33 | end 34 | 35 | local function removeGlobalPlayer(optionNames) 36 | interact.removeGlobalPlayer(optionNames) 37 | end 38 | 39 | local function addGlobalVehicle(options) 40 | interact.addGlobalVehicle(options) 41 | end 42 | 43 | local function removeGlobalVehicle(optionNames) 44 | interact.removeGlobalVehicle(optionNames) 45 | end 46 | 47 | local function addModel(models, options) 48 | interact.addModel(models, options) 49 | end 50 | 51 | local function removeModel(models, optionNames) 52 | interact.removeModel(models, optionNames) 53 | end 54 | 55 | local function addEntity(netIds, options) 56 | interact.addEntity(netIds, options) 57 | end 58 | 59 | local function removeEntity(netIds, optionNames) 60 | interact.removeEntity(netIds, optionNames) 61 | end 62 | 63 | local function addLocalEntity(entities, options) 64 | interact.addLocalEntity(entities, options) 65 | end 66 | 67 | local function removeLocalEntity(entities, optionNames) 68 | interact.removeLocalEntity(entities, optionNames) 69 | end 70 | 71 | local function addSphereZone(data) 72 | local coordsId = interact.addCoords(data.coords, data.options) 73 | 74 | if data.name then 75 | zoneToCoord[data.name] = coordsId 76 | end 77 | 78 | return coordsId 79 | end 80 | 81 | local function addBoxZone(data) 82 | local coordsId = interact.addCoords(data.coords, data.options) 83 | 84 | if data.name then 85 | zoneToCoord[data.name] = coordsId 86 | end 87 | 88 | return coordsId 89 | end 90 | 91 | local function addPolyZone(data) 92 | 93 | local points = {} 94 | for i = 1, #data.points do 95 | points[i] = glm.vec3(data.points[i].x, data.points[i].y, data.z or 0) 96 | end 97 | 98 | local polygon = glm.polygon.new(points) 99 | local coords = polygon:centroid() 100 | 101 | if not polygon:isPlanar() then 102 | local zCoords = {} 103 | for i = 1, #points do 104 | local z = points[i].z 105 | zCoords[z] = (zCoords[z] or 0) + 1 106 | end 107 | 108 | local coordsArray = {} 109 | for z, count in pairs(zCoords) do 110 | coordsArray[#coordsArray + 1] = { coord = z, count = count } 111 | end 112 | 113 | table.sort(coordsArray, function(a, b) return a.count > b.count end) 114 | 115 | local zCoord = coordsArray[1].coord 116 | local averageTo = 1 117 | for i = 2, #coordsArray do 118 | if coordsArray[i].count < coordsArray[1].count then 119 | averageTo = i - 1 120 | break 121 | end 122 | end 123 | 124 | if averageTo > 1 then 125 | zCoord = 0 126 | for i = 1, averageTo do 127 | zCoord = zCoord + coordsArray[i].coord 128 | end 129 | zCoord = zCoord / averageTo 130 | end 131 | 132 | for i = 1, #points do 133 | points[i] = glm.vec3(data.points[i].x, data.points[i].y, zCoord) 134 | end 135 | 136 | polygon = glm.polygon.new(points) 137 | coords = polygon:centroid() 138 | end 139 | 140 | if not data.z then 141 | coords.z = GetHeightmapBottomZForPosition(coords.x, coords.y) 142 | end 143 | 144 | local finalCoords = vec3(coords.x, coords.y, coords.z) 145 | 146 | local coordsId = interact.addCoords(finalCoords, data.options) 147 | 148 | if data.name then 149 | zoneToCoord[data.name] = coordsId 150 | end 151 | 152 | return coordsId 153 | end 154 | 155 | local function removeZone(id) 156 | if zoneToCoord[id] then 157 | id = zoneToCoord[id] 158 | end 159 | 160 | interact.removeCoords(id) 161 | 162 | zoneToCoord[id] = nil 163 | end 164 | 165 | exportHandler('disableTargeting', disableTargeting) 166 | exportHandler('addGlobalObject', addGlobalObject) 167 | exportHandler('removeGlobalObject', removeGlobalObject) 168 | exportHandler('addGlobalPed', addGlobalPed) 169 | exportHandler('removeGlobalPed', removeGlobalPed) 170 | exportHandler('addGlobalPlayer', addGlobalPlayer) 171 | exportHandler('removeGlobalPlayer', removeGlobalPlayer) 172 | exportHandler('addGlobalVehicle', addGlobalVehicle) 173 | exportHandler('removeGlobalVehicle', removeGlobalVehicle) 174 | exportHandler('addModel', addModel) 175 | exportHandler('removeModel', removeModel) 176 | exportHandler('addEntity', addEntity) 177 | exportHandler('removeEntity', removeEntity) 178 | exportHandler('addLocalEntity', addLocalEntity) 179 | exportHandler('removeLocalEntity', removeLocalEntity) 180 | exportHandler('addSphereZone', addSphereZone) 181 | exportHandler('addBoxZone', addBoxZone) 182 | exportHandler('addPolyZone', addPolyZone) 183 | exportHandler('removeZone', removeZone) -------------------------------------------------------------------------------- /_types.lua: -------------------------------------------------------------------------------- 1 | --- Represents an interaction option with various properties. 2 | ---@class InteractOption 3 | ---@field label string The display label for the option. 4 | ---@field icon? string The icon associated with the option. 5 | ---@field iconColor? string The css color for the icon 6 | ---@field distance? number The maximum distance at which the option is available. 7 | ---@field holdTime? number Makes the option a press and hold and sets how long it should be held for. (miliseconds) 8 | ---@field canInteract? fun(entity: number, distance: number, coords: vector3, name: string): boolean? A function to determine if the option can be interacted with. 9 | ---@field name? string A unique identifier for the option. 10 | ---@field resource? string The resource that registered the option. 11 | ---@field offset? vector3 A relative offset from the entity's position. 12 | ---@field offsetAbsolute? vector3 An absolute offset in world coordinates. 13 | ---@field color? number[] 4 numbers in an array that will be used for rgba and will overwrite the theme color for that option. 14 | ---@field bones? string | string[] An array of bone IDs associated with the option. 15 | ---@field allowInVehicle? boolean marks the option as being able to be used inside a vehicle. 16 | ---@field onSelect? fun(data: InteractResponse) A function to execute when the option is selected. 17 | ---@field cooldown? number number of miliseconds the interact system should cooldown for after this option is selected. prevents spam. 18 | ---@field export? string Optional export function name 19 | ---@field event? string Client-side event to trigger 20 | ---@field serverEvent? string Server-side event to trigger 21 | ---@field command? string Command to execute 22 | ---@field onActive? fun(data: InteractResponse) A function to execute when the option is active. 23 | ---@field onInactive? fun(data: InteractResponse) A function to execute when the option was active and is now inactive. 24 | ---@field whileActive? fun(data: InteractResponse) A function to execute while the option is active on a loop. 25 | 26 | ---@class NearbyItem 27 | ---@field options InteractOption[] 28 | ---@field currentDistance number 29 | ---@field entity? number 30 | ---@field bone? string 31 | ---@field coords vector3 32 | ---@field offset? string 33 | ---@field coordId? string 34 | 35 | -- Represents the response structure sent to onSelect and other callable methods. 36 | ---@class InteractResponse 37 | ---@field entity? number Entity ID or 0 if not applicable. 38 | ---@field coordsId? string ID of the coordinate zone, if applicable. 39 | ---@field coords vector3 Coordinates of the interaction point. 40 | ---@field distance number Distance from the player to the interaction point. 41 | ---@field label string Label of the option. 42 | ---@field name? string Name of the option, if provided. 43 | ---@field resource string Resource that registered the option. 44 | ---@field offset? vector3 Offset from the entity's position, if applicable. 45 | ---@field offsetAbsolute? vector3 Absolute offset in world coordinates, if applicable. 46 | ---@field bones? string|string[] Bones associated with the option, if applicable. 47 | 48 | -- Represents the current interaction state in the store. 49 | ---@class CurrentInteraction 50 | ---@field entity? number Entity ID 51 | ---@field coordsId? string ID of the coordinate, if applicable. 52 | ---@field coords? vector3 Coordinates of the interaction point. 53 | ---@field distance number Distance from the player to the interaction point. 54 | ---@field options table Options grouped by category (e.g., "global", "model") 55 | 56 | --- A table mapping string keys (e.g., bone IDs or offset IDs) to arrays of options. 57 | ---@class OptionsMap 58 | ---@field [string] InteractOption[] 59 | 60 | --- A table mapping model hashes (numbers) to arrays of options. 61 | ---@class ModelOptions 62 | ---@field [number] InteractOption[] 63 | 64 | --- A table mapping network IDs (numbers) to arrays of options. 65 | ---@class EntityOptions 66 | ---@field [number] InteractOption[] 67 | 68 | --- A table mapping local entity IDs (numbers) to arrays of options. 69 | ---@class LocalEntityOptions 70 | ---@field [number] InteractOption[]nsArray 71 | 72 | --- A table mapping coordinate IDs (strings) to arrays of options. 73 | ---@class CoordOptions 74 | ---@field [string] InteractOption[] 75 | 76 | --- A table mapping coordinate IDs (strings) to their vector3 positions. 77 | ---@class CoordIds 78 | ---@field [string] vector3 79 | 80 | --- A structure for storing bone-specific options across different categories. 81 | ---@class BonesStore 82 | ---@field peds OptionsMap Bone options for peds. 83 | ---@field vehicles OptionsMap Bone options for vehicles. 84 | ---@field objects OptionsMap Bone options for objects. 85 | ---@field players OptionsMap Bone options for players. 86 | ---@field models table Bone options for models, keyed by model hash. 87 | ---@field entities table Bone options for networked entities, keyed by netId. 88 | ---@field localEntities table Bone options for local entities, keyed by entityId. 89 | 90 | --- A structure for storing offset-specific options across different categories. 91 | ---@class OffsetsStore 92 | ---@field peds OptionsMap Offset options for peds. 93 | ---@field vehicles OptionsMap Offset options for vehicles. 94 | ---@field objects OptionsMap Offset options for objects. 95 | ---@field players OptionsMap Offset options for players. 96 | ---@field models table Offset options for models, keyed by model hash. 97 | ---@field entities table Offset options for networked entities, keyed by netId. 98 | ---@field localEntities table Offset options for local entities, keyed by entityId. 99 | 100 | --- The main store module structure for organizing interaction options. 101 | ---@class Store 102 | ---@field peds InteractOption[] Options for all peds globally. 103 | ---@field vehicles InteractOption[] Options for all vehicles globally. 104 | ---@field objects InteractOption[] Options for all objects globally. 105 | ---@field players InteractOption[] Options for all players globally. 106 | ---@field models ModelOptions Options for specific models, keyed by model hash. 107 | ---@field entities EntityOptions Options for networked entities, keyed by netId. 108 | ---@field localEntities LocalEntityOptions Options for local entities, keyed by entityId. 109 | ---@field coords CoordOptions Options for specific coordinates, keyed by coordId. 110 | ---@field coordIds CoordIds Coordinate positions, keyed by coordId. 111 | ---@field bones BonesStore Bone-specific options for various categories. 112 | ---@field offsets OffsetsStore Offset-specific options for various categories. 113 | -------------------------------------------------------------------------------- /client/compat/resources/qtarget.lua: -------------------------------------------------------------------------------- 1 | local glm = require 'glm' 2 | 3 | local function exportHandler(exportName, func) 4 | AddEventHandler(('__cfx_export_qtarget_%s'):format(exportName), function(setCB) 5 | setCB(func) 6 | end) 7 | end 8 | 9 | local zoneToCoord = {} 10 | 11 | ---@param options table 12 | ---@return table 13 | local function convert(options) 14 | local distance = options.distance 15 | options = options.options 16 | 17 | -- People may pass options as a hashmap (or mixed, even) 18 | for k, v in pairs(options) do 19 | if type(k) ~= 'number' then 20 | table.insert(options, v) 21 | end 22 | end 23 | 24 | for id, v in pairs(options) do 25 | if type(id) ~= 'number' then 26 | options[id] = nil 27 | goto continue 28 | end 29 | 30 | v.onSelect = v.action 31 | v.distance = v.distance or distance 32 | v.name = v.name or v.label 33 | v.groups = v.job 34 | v.items = v.item or v.required_item 35 | 36 | if v.event and v.type and v.type ~= 'client' then 37 | if v.type == 'server' then 38 | v.serverEvent = v.event 39 | elseif v.type == 'command' then 40 | v.command = v.event 41 | end 42 | 43 | v.event = nil 44 | v.type = nil 45 | end 46 | 47 | v.action = nil 48 | v.job = nil 49 | v.item = nil 50 | v.required_item = nil 51 | v.qtarget = true 52 | 53 | ::continue:: 54 | end 55 | 56 | return options 57 | end 58 | 59 | exportHandler('AddBoxZone', function(name, center, length, width, options, targetoptions) 60 | local coordsId = interact.addCoords(center, convert(targetoptions)) 61 | 62 | if name then 63 | zoneToCoord[name] = coordsId 64 | end 65 | 66 | return coordsId 67 | end) 68 | 69 | exportHandler('AddPolyZone', function(name, points, options, targetoptions) 70 | 71 | local newPoints = {} 72 | for i = 1, #points do 73 | newPoints[i] = glm.vec3(points[i].x, points[i].y, 0) 74 | end 75 | 76 | local polygon = glm.polygon.new(newPoints) 77 | local coords = polygon:centroid() 78 | 79 | if not polygon:isPlanar() then 80 | local zCoords = {} 81 | for i = 1, #newPoints do 82 | local z = newPoints[i].z 83 | zCoords[z] = (zCoords[z] or 0) + 1 84 | end 85 | 86 | local coordsArray = {} 87 | for z, count in pairs(zCoords) do 88 | coordsArray[#coordsArray + 1] = { coord = z, count = count } 89 | end 90 | 91 | table.sort(coordsArray, function(a, b) return a.count > b.count end) 92 | 93 | local zCoord = coordsArray[1].coord 94 | local averageTo = 1 95 | for i = 2, #coordsArray do 96 | if coordsArray[i].count < coordsArray[1].count then 97 | averageTo = i - 1 98 | break 99 | end 100 | end 101 | 102 | if averageTo > 1 then 103 | zCoord = 0 104 | for i = 1, averageTo do 105 | zCoord = zCoord + coordsArray[i].coord 106 | end 107 | zCoord = zCoord / averageTo 108 | end 109 | 110 | -- Update points with averaged z coordinate 111 | for i = 1, #newPoints do 112 | newPoints[i] = glm.vec3(points[i].x, points[i].y, zCoord) 113 | end 114 | 115 | polygon = glm.polygon.new(newPoints) 116 | coords = polygon:centroid() 117 | end 118 | 119 | if not options.z then 120 | coords.z = GetHeightmapBottomZForPosition(coords.x, coords.y) 121 | end 122 | 123 | local finalCoords = vec3(coords.x, coords.y, coords.z) 124 | 125 | local coordsId = interact.addCoords(finalCoords, convert(targetoptions)) 126 | 127 | if name then 128 | zoneToCoord[name] = coordsId 129 | end 130 | 131 | return coordsId 132 | end) 133 | 134 | exportHandler('AddCircleZone', function(name, center, radius, options, targetoptions) 135 | local coordsId = interact.addCoords(center, convert(targetoptions)) 136 | 137 | if name then 138 | zoneToCoord[name] = coordsId 139 | end 140 | 141 | return coordsId 142 | end) 143 | 144 | exportHandler('RemoveZone', function(id) 145 | if zoneToCoord[id] then 146 | id = zoneToCoord[id] 147 | end 148 | 149 | interact.removeCoords(id) 150 | 151 | zoneToCoord[id] = nil 152 | end) 153 | 154 | exportHandler('AddTargetBone', function(bones, options) 155 | if type(bones) ~= 'table' then bones = { bones } end 156 | options = convert(options) 157 | 158 | for _, v in pairs(options) do 159 | v.bones = bones 160 | end 161 | 162 | interact.addGlobalVehicle(options) 163 | end) 164 | 165 | exportHandler('AddTargetEntity', function(entities, options) 166 | if type(entities) ~= 'table' then entities = { entities } end 167 | options = convert(options) 168 | 169 | for i = 1, #entities do 170 | local entity = entities[i] 171 | 172 | if NetworkGetEntityIsNetworked(entity) then 173 | interact.addEntity(NetworkGetNetworkIdFromEntity(entity), options) 174 | else 175 | interact.addLocalEntity(entity, options) 176 | end 177 | end 178 | end) 179 | 180 | exportHandler('RemoveTargetEntity', function(entities, labels) 181 | if type(entities) ~= 'table' then entities = { entities } end 182 | 183 | for i = 1, #entities do 184 | local entity = entities[i] 185 | 186 | if NetworkGetEntityIsNetworked(entity) then 187 | interact.removeEntity(NetworkGetNetworkIdFromEntity(entity), labels) 188 | else 189 | interact.removeLocalEntity(entity, labels) 190 | end 191 | end 192 | end) 193 | 194 | exportHandler('AddTargetModel', function(models, options) 195 | interact.addModel(models, convert(options)) 196 | end) 197 | 198 | exportHandler('RemoveTargetModel', function(models, labels) 199 | interact.removeModel(models, labels) 200 | end) 201 | 202 | exportHandler('Ped', function(options) 203 | interact.addGlobalPed(convert(options)) 204 | end) 205 | 206 | exportHandler('RemovePed', function(labels) 207 | interact.removeGlobalPed(labels) 208 | end) 209 | 210 | exportHandler('Vehicle', function(options) 211 | interact.addGlobalVehicle(convert(options)) 212 | end) 213 | 214 | exportHandler('RemoveVehicle', function(labels) 215 | interact.removeGlobalVehicle(labels) 216 | end) 217 | 218 | exportHandler('Object', function(options) 219 | interact.addGlobalObject(convert(options)) 220 | end) 221 | 222 | exportHandler('RemoveObject', function(labels) 223 | interact.removeGlobalObject(labels) 224 | end) 225 | 226 | exportHandler('Player', function(options) 227 | interact.addGlobalPlayer(convert(options)) 228 | end) 229 | 230 | exportHandler('RemovePlayer', function(labels) 231 | interact.removeGlobalPlayer(labels) 232 | end) 233 | -------------------------------------------------------------------------------- /client/modules/utils.lua: -------------------------------------------------------------------------------- 1 | ---@diagnostic disable: inject-field 2 | local store = require 'client.modules.store' 3 | local utils = {} 4 | 5 | ---@param coords vector3 The coordinates to convert. 6 | ---@return string id A string ID in the format "x_y_z". 7 | function utils.makeIdFromCoords(coords) 8 | local x = math.floor(coords.x * 1000) 9 | local y = math.floor(coords.y * 1000) 10 | local z = math.floor(coords.z * 1000) 11 | return string.format('%s_%s_%s', x, y, z) 12 | end 13 | 14 | ---@param offset vector3 The offset vector. 15 | ---@param offsetType string The type of offset ("offset" or "offsetAbsolute"). 16 | ---@return string id A string ID in the format "x_y_z_type". 17 | function utils.makeOffsetIdFromCoords(offset, offsetType) 18 | local x = math.floor(offset.x * 1000) 19 | local y = math.floor(offset.y * 1000) 20 | local z = math.floor(offset.z * 1000) 21 | return string.format("%d_%d_%d_%s", x, y, z, offsetType) 22 | end 23 | 24 | ---@param id string The offset ID to parse. 25 | ---@return number x The x-coordinate. 26 | ---@return number y The y-coordinate. 27 | ---@return number z The z-coordinate. 28 | ---@return string offsetType The type of offset. 29 | function utils.getCoordsAndTypeFromOffsetId(id) 30 | local x, y, z, offsetType = id:match("(%-?%d+)_(%-?%d+)_(%-?%d+)_(%w+)") 31 | return x / 1000, y / 1000, z / 1000, offsetType 32 | end 33 | 34 | ---@param coords table|vector3|vector4 The input coordinates. 35 | ---@return vector3 The converted or validated vector3. 36 | function utils.convertToVector(coords) 37 | local _type = type(coords) 38 | 39 | if _type ~= 'vector3' then 40 | if _type == 'table' or _type == 'vector4' then 41 | return vec3(coords[1] or coords.x, coords[2] or coords.y, coords[3] or coords.z) 42 | end 43 | 44 | error(("expected type 'vector3' or 'table' (received %s)"):format(_type)) 45 | end 46 | 47 | return coords 48 | end 49 | 50 | ---@param option InteractOption The interaction option. 51 | ---@param server boolean|nil Whether to prepare the response for server-side use. 52 | ---@return InteractResponse response The response table with context from the current interaction. 53 | function utils.getResponse(option, server) 54 | local response = table.clone(option) --[[@as InteractResponse]] 55 | response.entity = store.current.entity 56 | response.coordsId = store.current.coordsId 57 | response.coords = store.current.coords 58 | response.distance = store.current.distance 59 | 60 | if server then 61 | response.entity = response.entity ~= 0 and NetworkGetEntityIsNetworked(response.entity) and 62 | NetworkGetNetworkIdFromEntity(response.entity) or 0 63 | end 64 | 65 | response.icon = nil 66 | response.groups = nil 67 | response.items = nil 68 | response.canInteract = nil 69 | response.onSelect = nil 70 | response.export = nil 71 | response.event = nil 72 | response.serverEvent = nil 73 | response.command = nil 74 | 75 | return response 76 | end 77 | 78 | local GetOffsetFromEntityInWorldCoords = GetOffsetFromEntityInWorldCoords 79 | local GetEntityBoneIndexByName = GetEntityBoneIndexByName 80 | local GetModelDimensions = GetModelDimensions 81 | local GetEntityBonePosition_2 = GetEntityBonePosition_2 82 | local GetEntityCoords = GetEntityCoords 83 | local GetEntityModel = GetEntityModel 84 | 85 | ---@param item NearbyItem 86 | function utils.getDrawCoordsForInteract(item) 87 | if not item then return vec3(0, 0, 0) end 88 | 89 | if item.coordId then 90 | return item.coords 91 | end 92 | 93 | if item.offset then 94 | local x, y, z, offsetType = utils.getCoordsAndTypeFromOffsetId(item.offset) 95 | local entityModel = GetEntityModel(item.entity) 96 | 97 | ---@diagnostic disable-next-line: param-type-mismatch 98 | local offset = vec3(tonumber(x), tonumber(y), tonumber(z)) 99 | 100 | if offsetType == "offset" then 101 | local min, max = GetModelDimensions(entityModel) 102 | offset = (max - min) * offset + min 103 | end 104 | 105 | return GetOffsetFromEntityInWorldCoords(item.entity, offset.x, offset.y, offset.z) 106 | end 107 | 108 | if item.bone then 109 | local boneIndex = GetEntityBoneIndexByName(item.entity, item.bone) 110 | return boneIndex and GetEntityBonePosition_2(item.entity, boneIndex) or item.coords 111 | end 112 | 113 | if item.entity then 114 | return GetEntityCoords(item.entity) 115 | end 116 | 117 | return item.coords 118 | end 119 | 120 | local playerItems = {} 121 | 122 | function utils.getItems() 123 | return playerItems 124 | end 125 | 126 | ---@param filter string | string[] | table 127 | ---@param hasAny boolean? 128 | ---@return boolean 129 | function utils.hasPlayerGotItems(filter, hasAny) 130 | if not playerItems then return true end 131 | 132 | local _type = type(filter) 133 | 134 | if _type == 'string' then 135 | return (playerItems[filter] or 0) > 0 136 | elseif _type == 'table' then 137 | local tabletype = table.type(filter) 138 | 139 | if tabletype == 'hash' then 140 | for name, amount in pairs(filter) do 141 | local hasItem = (playerItems[name] or 0) >= amount 142 | 143 | if hasAny then 144 | if hasItem then return true end 145 | elseif not hasItem then 146 | return false 147 | end 148 | end 149 | elseif tabletype == 'array' then 150 | for i = 1, #filter do 151 | local hasItem = (playerItems[filter[i]] or 0) > 0 152 | 153 | if hasAny then 154 | if hasItem then return true end 155 | elseif not hasItem then 156 | return false 157 | end 158 | end 159 | end 160 | end 161 | 162 | return not hasAny 163 | end 164 | 165 | ---@param coords vector3 166 | ---@return number 167 | function utils.getScreenDistanceSquared(coords) 168 | local success, screenX, screenY = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z) 169 | if not success then return math.huge end 170 | 171 | local dx = screenX - 0.5 172 | local dy = screenY - 0.5 173 | return dx * dx + dy * dy 174 | end 175 | 176 | ---@param export string 177 | ---@return boolean 178 | function utils.hasExport(export) 179 | local resource, exportName = string.strsplit('.', export) 180 | 181 | return pcall(function() 182 | return exports[resource][exportName] 183 | end) 184 | end 185 | 186 | 187 | SetTimeout(0, function() 188 | if GetResourceState('ox_inventory'):find('start') then 189 | setmetatable(playerItems, { 190 | __index = function(self, index) 191 | self[index] = exports.ox_inventory:Search('count', index) or 0 192 | return self[index] 193 | end 194 | }) 195 | 196 | AddEventHandler('ox_inventory:itemCount', function(name, count) 197 | playerItems[name] = count 198 | end) 199 | end 200 | 201 | 202 | if GetResourceState('ox_core'):find('start') then 203 | require 'client.framework.ox' 204 | elseif GetResourceState('es_extended'):find('start') then 205 | require 'client.framework.esx' 206 | elseif GetResourceState('qbx_core'):find('start') then 207 | require 'client.framework.qbx' 208 | elseif GetResourceState('ND_Core'):find('start') then 209 | require 'client.framework.nd' 210 | elseif GetResourceState('qb-core'):find('start') then 211 | require 'client.framework.qb' 212 | end 213 | end) 214 | 215 | return utils 216 | -------------------------------------------------------------------------------- /client/compat/resources/qb_target.lua: -------------------------------------------------------------------------------- 1 | local glm = require 'glm' 2 | 3 | local function exportHandler(exportName, func) 4 | AddEventHandler(('__cfx_export_qb-target_%s'):format(exportName), function(setCB) 5 | setCB(func) 6 | end) 7 | end 8 | 9 | local zoneToCoord = {} 10 | 11 | ---@param options table 12 | ---@return table 13 | local function convert(options) 14 | local distance = options.distance 15 | options = options.options 16 | 17 | -- People may pass options as a hashmap (or mixed, even) 18 | for k, v in pairs(options) do 19 | if type(k) ~= 'number' then 20 | table.insert(options, v) 21 | end 22 | end 23 | 24 | for id, v in pairs(options) do 25 | if type(id) ~= 'number' then 26 | options[id] = nil 27 | goto continue 28 | end 29 | 30 | v.onSelect = v.action 31 | v.distance = v.distance or distance 32 | v.name = v.name or v.label 33 | v.items = v.item 34 | v.icon = v.icon 35 | v.groups = v.job 36 | 37 | local groupType = type(v.groups) 38 | if groupType == 'nil' then 39 | v.groups = {} 40 | groupType = 'table' 41 | end 42 | if groupType == 'string' then 43 | local val = v.gang 44 | if type(v.gang) == 'table' then 45 | if table.type(v.gang) ~= 'array' then 46 | val = {} 47 | for k in pairs(v.gang) do 48 | val[#val + 1] = k 49 | end 50 | end 51 | end 52 | 53 | if val then 54 | v.groups = {v.groups, type(val) == 'table' and table.unpack(val) or val} 55 | end 56 | 57 | val = v.citizenid 58 | if type(v.citizenid) == 'table' then 59 | if table.type(v.citizenid) ~= 'array' then 60 | val = {} 61 | for k in pairs(v.citizenid) do 62 | val[#val+1] = k 63 | end 64 | end 65 | end 66 | 67 | if val then 68 | v.groups = {v.groups, type(val) == 'table' and table.unpack(val) or val} 69 | end 70 | elseif groupType == 'table' then 71 | local val = {} 72 | if table.type(v.groups) ~= 'array' then 73 | for k in pairs(v.groups) do 74 | val[#val + 1] = k 75 | end 76 | v.groups = val 77 | val = nil 78 | end 79 | 80 | val = v.gang 81 | if type(v.gang) == 'table' then 82 | if table.type(v.gang) ~= 'array' then 83 | val = {} 84 | for k in pairs(v.gang) do 85 | val[#val + 1] = k 86 | end 87 | end 88 | end 89 | 90 | if val then 91 | v.groups = {table.unpack(v.groups), type(val) == 'table' and table.unpack(val) or val} 92 | end 93 | 94 | val = v.citizenid 95 | if type(v.citizenid) == 'table' then 96 | if table.type(v.citizenid) ~= 'array' then 97 | val = {} 98 | for k in pairs(v.citizenid) do 99 | val[#val+1] = k 100 | end 101 | end 102 | end 103 | 104 | if val then 105 | v.groups = {table.unpack(v.groups), type(val) == 'table' and table.unpack(val) or val} 106 | end 107 | end 108 | 109 | if type(v.groups) == 'table' and table.type(v.groups) == 'empty' then 110 | v.groups = nil 111 | end 112 | 113 | if v.event and v.type and v.type ~= 'client' then 114 | if v.type == 'server' then 115 | v.serverEvent = v.event 116 | elseif v.type == 'command' then 117 | v.command = v.event 118 | end 119 | 120 | v.event = nil 121 | v.type = nil 122 | end 123 | 124 | v.action = nil 125 | v.job = nil 126 | v.gang = nil 127 | v.citizenid = nil 128 | v.item = nil 129 | v.qtarget = true 130 | 131 | ::continue:: 132 | end 133 | 134 | return options 135 | end 136 | 137 | exportHandler('AddBoxZone', function(name, center, length, width, options, targetoptions) 138 | local coordsId = interact.addCoords(center, convert(targetoptions)) 139 | 140 | if name then 141 | zoneToCoord[name] = coordsId 142 | end 143 | 144 | return coordsId 145 | end) 146 | 147 | exportHandler('AddPolyZone', function(name, points, options, targetoptions) 148 | local newPoints = {} 149 | for i = 1, #points do 150 | newPoints[i] = glm.vec3(points[i].x, points[i].y, 0) 151 | end 152 | 153 | local polygon = glm.polygon.new(newPoints) 154 | local coords = polygon:centroid() 155 | 156 | if not polygon:isPlanar() then 157 | local zCoords = {} 158 | for i = 1, #newPoints do 159 | local z = newPoints[i].z 160 | zCoords[z] = (zCoords[z] or 0) + 1 161 | end 162 | 163 | local coordsArray = {} 164 | for z, count in pairs(zCoords) do 165 | coordsArray[#coordsArray + 1] = { coord = z, count = count } 166 | end 167 | 168 | table.sort(coordsArray, function(a, b) return a.count > b.count end) 169 | 170 | local zCoord = coordsArray[1].coord 171 | local averageTo = 1 172 | for i = 2, #coordsArray do 173 | if coordsArray[i].count < coordsArray[1].count then 174 | averageTo = i - 1 175 | break 176 | end 177 | end 178 | 179 | if averageTo > 1 then 180 | zCoord = 0 181 | for i = 1, averageTo do 182 | zCoord = zCoord + coordsArray[i].coord 183 | end 184 | zCoord = zCoord / averageTo 185 | end 186 | 187 | -- Update points with averaged z coordinate 188 | for i = 1, #newPoints do 189 | newPoints[i] = glm.vec3(points[i].x, points[i].y, zCoord) 190 | end 191 | 192 | polygon = glm.polygon.new(newPoints) 193 | coords = polygon:centroid() 194 | end 195 | 196 | if not options.z then 197 | coords.z = GetHeightmapBottomZForPosition(coords.x, coords.y) 198 | end 199 | 200 | local finalCoords = vec3(coords.x, coords.y, coords.z) 201 | 202 | local coordsId = interact.addCoords(finalCoords, convert(targetoptions)) 203 | 204 | if name then 205 | zoneToCoord[name] = coordsId 206 | end 207 | 208 | return coordsId 209 | end) 210 | 211 | exportHandler('AddCircleZone', function(name, center, radius, options, targetoptions) 212 | local coordsId = interact.addCoords(center, convert(targetoptions)) 213 | 214 | if name then 215 | zoneToCoord[name] = coordsId 216 | end 217 | 218 | return coordsId 219 | end) 220 | 221 | exportHandler('RemoveZone', function(id) 222 | if zoneToCoord[id] then 223 | id = zoneToCoord[id] 224 | end 225 | 226 | interact.removeCoords(id) 227 | 228 | zoneToCoord[id] = nil 229 | end) 230 | 231 | exportHandler('AddTargetBone', function(bones, options) 232 | if type(bones) ~= 'table' then bones = { bones } end 233 | options = convert(options) 234 | 235 | for _, v in pairs(options) do 236 | v.bones = bones 237 | end 238 | 239 | interact.addGlobalVehicle(options) 240 | end) 241 | 242 | exportHandler('AddTargetEntity', function(entities, options) 243 | if type(entities) ~= 'table' then entities = { entities } end 244 | options = convert(options) 245 | 246 | for i = 1, #entities do 247 | local entity = entities[i] 248 | 249 | if NetworkGetEntityIsNetworked(entity) then 250 | interact.addEntity(NetworkGetNetworkIdFromEntity(entity), options) 251 | else 252 | interact.addLocalEntity(entity, options) 253 | end 254 | end 255 | end) 256 | 257 | exportHandler('RemoveTargetEntity', function(entities, labels) 258 | if type(entities) ~= 'table' then entities = { entities } end 259 | 260 | for i = 1, #entities do 261 | local entity = entities[i] 262 | 263 | if NetworkGetEntityIsNetworked(entity) then 264 | interact.removeEntity(NetworkGetNetworkIdFromEntity(entity), labels) 265 | else 266 | interact.removeLocalEntity(entity, labels) 267 | end 268 | end 269 | end) 270 | 271 | exportHandler('AddTargetModel', function(models, options) 272 | interact.addModel(models, convert(options)) 273 | end) 274 | 275 | exportHandler('RemoveTargetModel', function(models, labels) 276 | interact.removeModel(models, labels) 277 | end) 278 | 279 | exportHandler('AddGlobalPed', function(options) 280 | interact.addGlobalPed(convert(options)) 281 | end) 282 | 283 | exportHandler('RemoveGlobalPed', function(labels) 284 | interact.removeGlobalPed(labels) 285 | end) 286 | 287 | exportHandler('AddGlobalVehicle', function(options) 288 | interact.addGlobalVehicle(convert(options)) 289 | end) 290 | 291 | exportHandler('RemoveGlobalVehicle', function(labels) 292 | interact.removeGlobalVehicle(labels) 293 | end) 294 | 295 | exportHandler('AddGlobalObject', function(options) 296 | interact.addGlobalObject(convert(options)) 297 | end) 298 | 299 | exportHandler('RemoveGlobalObject', function(labels) 300 | interact.removeGlobalObject(labels) 301 | end) 302 | 303 | exportHandler('AddGlobalPlayer', function(options) 304 | interact.addGlobalPlayer(convert(options)) 305 | end) 306 | 307 | exportHandler('RemoveGlobalPlayer', function(labels) 308 | interact.removeGlobalPlayer(labels) 309 | end) 310 | 311 | exportHandler('AddEntityZone', function() 312 | lib.print.warn('AddEntityZone is not supported by sleepless_interact - try using addEntity/addLocalEntity.') 313 | end) 314 | 315 | exportHandler('RemoveTargetBone', function() 316 | lib.print.warn('RemoveTargetBone is not supported by sleepless_interact.') 317 | end) -------------------------------------------------------------------------------- /client/main.lua: -------------------------------------------------------------------------------- 1 | local dui = require 'client.modules.dui' 2 | local store = require 'client.modules.store' 3 | local config = require 'client.modules.config' 4 | local utils = require 'client.modules.utils' 5 | local animation = require 'client.modules.animation' 6 | 7 | ---@type boolean 8 | local drawLoopRunning = false 9 | 10 | local GetEntityCoords = GetEntityCoords 11 | local DrawSprite = DrawSprite 12 | local SetDrawOrigin = SetDrawOrigin 13 | local getNearbyObjects = lib.getNearbyObjects 14 | local getNearbyPlayers = lib.getNearbyPlayers 15 | local getNearbyVehicles = lib.getNearbyVehicles 16 | local getNearbyPeds = lib.getNearbyPeds 17 | local GetOffsetFromEntityInWorldCoords = GetOffsetFromEntityInWorldCoords 18 | local GetEntityBoneIndexByName = GetEntityBoneIndexByName 19 | local GetEntityBonePosition_2 = GetEntityBonePosition_2 20 | local GetModelDimensions = GetModelDimensions 21 | local NetworkGetEntityIsNetworked = NetworkGetEntityIsNetworked 22 | local NetworkGetNetworkIdFromEntity = NetworkGetNetworkIdFromEntity 23 | local GetEntityModel = GetEntityModel 24 | 25 | local r, g, b, a = table.unpack(config.themeColor) 26 | 27 | 28 | RegisterNUICallback('startHoldAnim', function(data, cb) 29 | local option = store.current.options?[data[1]]?[data[2]] 30 | 31 | cb('ok') 32 | 33 | if not option or not option.anim then 34 | return 35 | end 36 | 37 | animation.playAnim(option.anim, option.prop) 38 | end) 39 | 40 | RegisterNUICallback('endHoldAnim', function(data, cb) 41 | animation.stopAnim() 42 | cb('ok') 43 | end) 44 | 45 | local pressed = false 46 | lib.addKeybind({ 47 | name = 'interact_action', 48 | description = 'Interact', 49 | defaultKey = 'E', 50 | onPressed = function(self) 51 | if GetGameTimer() > store.cooldownEndTime then 52 | if not next(store.current) then return end 53 | pressed = true 54 | dui.sendMessage("interact") 55 | end 56 | end, 57 | onReleased = function(self) 58 | if not pressed then return end 59 | pressed = false 60 | dui.sendMessage("release") 61 | end, 62 | }) 63 | 64 | 65 | local hidePerKeybind = config.showKeyBindBehavior == "hold" 66 | if config.useShowKeyBind then 67 | lib.addKeybind({ 68 | name = 'sleepless_interact:toggle', 69 | description = 'show interactions', 70 | defaultKey = config.defaultShowKeyBind, 71 | onPressed = function(self) 72 | if config.showKeyBindBehavior == "toggle" then 73 | hidePerKeybind = not hidePerKeybind 74 | 75 | if hidePerKeybind then 76 | table.wipe(store.nearby) 77 | lib.notify({ 78 | title = 'Interact', 79 | description = 'Disabled', 80 | type = 'warning' 81 | }) 82 | else 83 | lib.notify({ 84 | title = 'Interact', 85 | description = 'Enabled', 86 | type = 'success' 87 | }) 88 | end 89 | else 90 | hidePerKeybind = false 91 | end 92 | end, 93 | onReleased = function(self) 94 | if config.showKeyBindBehavior == "toggle" then return end 95 | hidePerKeybind = true 96 | end 97 | }) 98 | end 99 | 100 | local modelCache, netIdCache = {}, {} 101 | 102 | local function cachedEntityInfo(entity) 103 | if modelCache[entity] then 104 | return modelCache[entity], netIdCache[entity] 105 | end 106 | 107 | local model = GetEntityModel(entity) 108 | local netId = NetworkGetEntityIsNetworked(entity) and NetworkGetNetworkIdFromEntity(entity) or nil 109 | modelCache[entity] = model 110 | netIdCache[entity] = netId 111 | return model, netId 112 | end 113 | 114 | ---@param options InteractOption[] 115 | ---@param entity number 116 | ---@param distance number 117 | ---@param coords vector3 118 | ---@return nil | table, number | nil, boolean | nil 119 | local function filterValidOptions(options, entity, distance, coords) 120 | if not options then return nil end 121 | local validOptions = {} 122 | local totalValid = 0 123 | local hasGlobal = options['global'] ~= nil 124 | local hasNonGlobal = false 125 | 126 | for category, _options in pairs(options) do 127 | if category ~= 'global' then 128 | hasNonGlobal = true 129 | end 130 | 131 | local validCategoryOptions = {} 132 | 133 | for i = 1, #_options do 134 | local option = _options[i] 135 | local hide = false 136 | 137 | if not hide and not option.allowInVehicle and cache.vehicle then 138 | hide = true 139 | end 140 | 141 | 142 | if not hide then hide = distance > (option.distance or 2.0) end 143 | 144 | if not hide and option.groups then hide = not utils.hasPlayerGotGroup(option.groups) end 145 | 146 | if not hide and option.items then hide = not utils.hasPlayerGotItems(option.items, option.anyItem) end 147 | 148 | if not hide and option.canInteract then 149 | local success, resp = pcall(option.canInteract, entity, distance, coords, option.name) 150 | hide = not success or not resp 151 | end 152 | 153 | if not hide then 154 | validCategoryOptions[#validCategoryOptions + 1] = option 155 | totalValid = totalValid + 1 156 | end 157 | 158 | option.hideButton = not option.onSelect and not option.event and not option.export and not option.serverEvent and not option.command 159 | end 160 | 161 | if #validCategoryOptions > 0 then 162 | validOptions[category] = validCategoryOptions 163 | end 164 | end 165 | 166 | local hideCompletely = hasGlobal and not hasNonGlobal and totalValid == 0 167 | 168 | if totalValid == 0 then 169 | return nil, nil, hideCompletely 170 | end 171 | 172 | return validOptions, totalValid, hideCompletely 173 | end 174 | 175 | ---@param entity number 176 | ---@param globalType string 177 | ---@return InteractOption[] | nil 178 | local function getOptionsForEntity(entity, globalType) 179 | if not entity then return nil end 180 | 181 | if IsPedAPlayer(entity) then 182 | return { 183 | global = store.players, 184 | } 185 | end 186 | 187 | local model, netId = cachedEntityInfo(entity) 188 | 189 | local options = { 190 | global = (store[globalType] ~= nil and #store[globalType] > 0 and store[globalType]) or nil, 191 | model = (store.models[model] ~= nil and #store.models[model] > 0 and store.models[model]) or nil, 192 | entity = (netId and store.entities[netId] ~= nil and #store.entities[netId] > 0 and store.entities[netId]) or nil, 193 | localEntity = (store.localEntities[entity] ~= nil and #store.localEntities[entity] > 0 and store.localEntities[entity]) or nil, 194 | } 195 | 196 | return next(options) and options or nil 197 | end 198 | 199 | ---@param entity number 200 | ---@param globalType string 201 | ---@return table | nil 202 | local function getBoneOptionsForEntity(entity, globalType) 203 | if not entity then return nil end 204 | local model, netId = cachedEntityInfo(entity) 205 | local boneOptions = {} 206 | local hasOptions = false 207 | 208 | if store.bones[globalType] then 209 | for boneId, options in pairs(store.bones[globalType]) do 210 | if #options > 0 then 211 | boneOptions[boneId] = boneOptions[boneId] or {} 212 | boneOptions[boneId].global = options 213 | hasOptions = true 214 | end 215 | end 216 | end 217 | 218 | if store.bones.models and store.bones.models[model] then 219 | for boneId, options in pairs(store.bones.models[model]) do 220 | if #options > 0 then 221 | boneOptions[boneId] = boneOptions[boneId] or {} 222 | boneOptions[boneId].model = options 223 | hasOptions = true 224 | end 225 | end 226 | end 227 | 228 | if netId and store.bones.entities and store.bones.entities[netId] then 229 | for boneId, options in pairs(store.bones.entities[netId]) do 230 | if #options > 0 then 231 | boneOptions[boneId] = boneOptions[boneId] or {} 232 | boneOptions[boneId].entity = options 233 | hasOptions = true 234 | end 235 | end 236 | end 237 | 238 | if not netId and store.bones.localEntities and store.bones.localEntities[entity] then 239 | for boneId, options in pairs(store.bones.localEntities[entity]) do 240 | if #options > 0 then 241 | boneOptions[boneId] = boneOptions[boneId] or {} 242 | boneOptions[boneId].localEntity = options 243 | hasOptions = true 244 | end 245 | end 246 | end 247 | 248 | return hasOptions and boneOptions or nil 249 | end 250 | 251 | ---@param entity number 252 | ---@param globalType string 253 | ---@return table | nil 254 | local function getOffsetOptionsForEntity(entity, globalType) 255 | if not entity then return nil end 256 | local model, netId = cachedEntityInfo(entity) 257 | local offsetOptions = {} 258 | local hasOptions = false 259 | 260 | if store.offsets[globalType] then 261 | for offsetStr, options in pairs(store.offsets[globalType]) do 262 | if #options > 0 then 263 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {} 264 | offsetOptions[offsetStr].global = options 265 | hasOptions = true 266 | end 267 | end 268 | end 269 | 270 | if store.offsets.models and store.offsets.models[model] then 271 | for offsetStr, options in pairs(store.offsets.models[model]) do 272 | if #options > 0 then 273 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {} 274 | offsetOptions[offsetStr].model = options 275 | hasOptions = true 276 | end 277 | end 278 | end 279 | 280 | if netId and store.offsets.entities and store.offsets.entities[netId] then 281 | for offsetStr, options in pairs(store.offsets.entities[netId]) do 282 | if #options > 0 then 283 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {} 284 | offsetOptions[offsetStr].entity = options 285 | hasOptions = true 286 | end 287 | end 288 | end 289 | 290 | if not netId and store.offsets.localEntities and store.offsets.localEntities[entity] then 291 | for offsetStr, options in pairs(store.offsets.localEntities[entity]) do 292 | if #options > 0 then 293 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {} 294 | offsetOptions[offsetStr].localEntity = options 295 | hasOptions = true 296 | end 297 | end 298 | end 299 | 300 | return hasOptions and offsetOptions or nil 301 | end 302 | 303 | ---@param coords vector3 304 | ---@return NearbyItem[] 305 | local function checkNearbyEntities(coords) 306 | local valid = {} 307 | local num = 0 308 | 309 | local function processEntities(entities, globalType) 310 | for i = 1, #entities do 311 | local ent = entities[i] 312 | local entity = ent.object or ent.vehicle or ent.ped 313 | local model = cachedEntityInfo(entity) 314 | local entCoords = GetEntityCoords(entity) 315 | local options = getOptionsForEntity(entity, globalType) 316 | local boneOptions = getBoneOptionsForEntity(entity, globalType) 317 | local offsetOptions = getOffsetOptionsForEntity(entity, globalType) 318 | 319 | 320 | if options then 321 | num = num + 1 322 | valid[num] = { 323 | entity = entity, 324 | coords = entCoords, 325 | currentDistance = #(coords - entCoords), 326 | currentScreenDistance = utils.getScreenDistanceSquared(entCoords), 327 | options = options 328 | } 329 | end 330 | 331 | if boneOptions then 332 | for boneId, _options in pairs(boneOptions) do 333 | local boneIndex = GetEntityBoneIndexByName(entity, boneId) 334 | if boneIndex ~= -1 then 335 | local boneCoords = GetEntityBonePosition_2(entity, boneIndex) 336 | num = num + 1 337 | valid[num] = { 338 | entity = entity, 339 | bone = boneId, 340 | coords = boneCoords, 341 | currentDistance = #(coords - boneCoords), 342 | currentScreenDistance = utils.getScreenDistanceSquared(boneCoords), 343 | options = _options 344 | } 345 | end 346 | end 347 | end 348 | 349 | if offsetOptions then 350 | for offsetStr, _options in pairs(offsetOptions) do 351 | local x, y, z, offsetType = utils.getCoordsAndTypeFromOffsetId(offsetStr) 352 | if x and y and z and offsetType then 353 | local offset = vec3(tonumber(x), tonumber(y), tonumber(z)) 354 | local worldPos 355 | if offsetType == "offset" then 356 | local min, max = GetModelDimensions(model) 357 | offset = (max - min) * offset + min 358 | end 359 | worldPos = GetOffsetFromEntityInWorldCoords(entity, offset.x, offset.y, offset.z) 360 | num = num + 1 361 | valid[num] = { 362 | entity = entity, 363 | offset = offsetStr, 364 | coords = worldPos, 365 | currentDistance = #(coords - worldPos), 366 | currentScreenDistance = utils.getScreenDistanceSquared(worldPos), 367 | options = _options 368 | } 369 | end 370 | end 371 | end 372 | end 373 | end 374 | 375 | processEntities(getNearbyObjects(coords, 10.0), 'objects') 376 | processEntities(getNearbyVehicles(coords, 10.0, true), 'vehicles') 377 | processEntities(getNearbyPlayers(coords, 10.0, false), 'players') 378 | processEntities(getNearbyPeds(coords, 10.0), 'peds') 379 | 380 | return valid 381 | end 382 | 383 | ---@param coords vector3 384 | ---@param update NearbyItem[] 385 | ---@return NearbyItem[] 386 | local function checkNearbyCoords(coords, update) 387 | for id, _coords in pairs(store.coordIds) do 388 | local dist = #(coords - _coords) 389 | if dist < config.maxInteractDistance then 390 | update[#update + 1] = { 391 | coords = _coords, 392 | currentDistance = dist, 393 | currentScreenDistance = utils.getScreenDistanceSquared(_coords), 394 | coordId = id, 395 | options = { coords = store.coords[id] } 396 | } 397 | end 398 | end 399 | return update 400 | end 401 | 402 | 403 | local function shouldHideInteract() 404 | if IsNuiFocused() or LocalPlayer.state.hideInteract or (lib and lib.progressActive()) or hidePerKeybind or LocalPlayer.state.invOpen then 405 | return true 406 | end 407 | return false 408 | end 409 | 410 | local activeOptions = {} 411 | 412 | local aspectRatio = GetAspectRatio(true) 413 | local function drawLoop() 414 | if drawLoopRunning then return end 415 | drawLoopRunning = true 416 | 417 | lib.requestStreamedTextureDict(config.IndicatorSprite.dict) 418 | 419 | local lastClosestItem, lastValidCount, lastValidOptions = nil, 0, nil 420 | local nearbyData = {} 421 | local playerCoords 422 | 423 | local entityStartCoords = {} 424 | local movingEntity = {} 425 | 426 | CreateThread(function() 427 | while drawLoopRunning do 428 | if shouldHideInteract() then 429 | table.wipe(store.nearby) 430 | break 431 | end 432 | 433 | playerCoords = GetEntityCoords(cache.ped) 434 | nearbyData = {} 435 | for i = 1, #store.nearby do 436 | local item = store.nearby[i] 437 | 438 | local coords = utils.getDrawCoordsForInteract(item) 439 | 440 | if coords then 441 | if item.entity then 442 | if not entityStartCoords[item.entity] then 443 | entityStartCoords[item.entity] = coords 444 | end 445 | 446 | if coords ~= entityStartCoords then 447 | movingEntity[item.entity] = true 448 | end 449 | end 450 | 451 | local distance = #(playerCoords - coords) 452 | local validOpts, validCount, hideCompletely = filterValidOptions(item.options, item.entity, distance, coords) 453 | local id = item.bone or item.offset or item.entity or item.coordId 454 | local shouldUpdate = false 455 | 456 | if id == lastClosestItem then 457 | if lastValidOptions then 458 | shouldUpdate = not lib.table.matches(validOpts, lastValidOptions) 459 | end 460 | end 461 | 462 | nearbyData[i] = { 463 | item = item, 464 | coords = coords, 465 | shouldUpdate = shouldUpdate, 466 | hideCompletely = hideCompletely, 467 | distance = distance, 468 | validOpts = validOpts, 469 | validCount = validCount 470 | } 471 | end 472 | end 473 | Wait(150) 474 | end 475 | end) 476 | 477 | while #store.nearby > 0 do 478 | Wait(0) 479 | local foundValid = false 480 | 481 | for i = 1, #store.nearby do 482 | local data = nearbyData[i] 483 | 484 | if data and data.coords and not data.hideCompletely then 485 | local item = data.item 486 | local coords = (item.entity and not movingEntity[item.entity] and data.coords) or utils.getDrawCoordsForInteract(item) 487 | 488 | SetDrawOrigin(coords.x, coords.y, coords.z) 489 | 490 | if not foundValid and data.validOpts and data.validCount > 0 then 491 | foundValid = true 492 | 493 | DrawSprite(dui.instance.dictName, dui.instance.txtName, 0.0, 0.0, 1.0, 1.0, 0.0, 255, 255, 255, 255) 494 | local newClosestId = item.bone or item.offset or item.entity or item.coordId 495 | if data.shouldUpdate or lastClosestItem ~= newClosestId or lastValidCount ~= data.validCount then 496 | local newOptions = {} 497 | 498 | if data.validOpts then 499 | for _, opts in pairs(data.validOpts) do 500 | for j = 1, #opts do 501 | local opt = opts[j] 502 | newOptions[opt] = true 503 | if not activeOptions[opt] then 504 | activeOptions[opt] = true 505 | local resp = (opt.onActive or opt.whileActive) and utils.getResponse(opt) 506 | 507 | if opt.onActive then 508 | pcall(opt.onActive, resp) 509 | end 510 | 511 | if opt.whileActive then 512 | CreateThread(function() 513 | while activeOptions[opt] do 514 | pcall(opt.whileActive, resp) 515 | Wait(0) 516 | end 517 | end) 518 | end 519 | end 520 | end 521 | end 522 | end 523 | 524 | if lastValidOptions then 525 | for _, opts in pairs(lastValidOptions) do 526 | for j = 1, #opts do 527 | local opt = opts[j] 528 | 529 | if opt.onInactive and not newOptions[opt] and activeOptions[opt] then 530 | pcall(opt.onInactive, utils.getResponse(opt)) 531 | activeOptions[opt] = nil 532 | end 533 | end 534 | end 535 | end 536 | 537 | local resetIndex = lastClosestItem ~= newClosestId 538 | lastClosestItem = newClosestId 539 | lastValidCount = data.validCount 540 | lastValidOptions = data.validOpts 541 | 542 | store.current = { 543 | options = data.validOpts, 544 | entity = item.entity, 545 | distance = data.distance, 546 | coords = coords, 547 | index = 1, 548 | } 549 | dui.sendMessage('setOptions', { options = data.validOpts, resetIndex = resetIndex }) 550 | end 551 | else 552 | local distance = #(playerCoords - coords) 553 | if distance < config.maxInteractDistance and item.currentScreenDistance < math.huge then 554 | local distanceRatio = math.max(1.0 - (distance / 10.0), 0.0) 555 | local scale = 0.025 * distanceRatio 556 | DrawSprite(config.IndicatorSprite.dict, config.IndicatorSprite.txt, 0.0, 0.0, scale, scale * aspectRatio, 45.0, r, g, b, 255) 557 | end 558 | end 559 | 560 | ClearDrawOrigin() 561 | end 562 | end 563 | 564 | if not foundValid and next(store.current) then 565 | for _, opts in pairs(store.current.options) do 566 | for j = 1, #opts do 567 | local opt = opts[j] 568 | 569 | if opt.onInactive and activeOptions[opt] then 570 | pcall(opt.onInactive, utils.getResponse(opt)) 571 | activeOptions[opt] = nil 572 | end 573 | end 574 | end 575 | store.current = {} 576 | lastClosestItem = nil 577 | end 578 | end 579 | 580 | SetStreamedTextureDictAsNoLongerNeeded(config.IndicatorSprite.dict) 581 | 582 | drawLoopRunning = false 583 | end 584 | 585 | local function BuilderLoop() 586 | while true do 587 | if shouldHideInteract() then 588 | table.wipe(store.nearby) 589 | else 590 | local coords = GetEntityCoords(cache.ped) 591 | local update = checkNearbyEntities(coords) 592 | update = checkNearbyCoords(coords, update) 593 | 594 | store.nearby = update 595 | 596 | table.sort(store.nearby, function(a, b) 597 | return a.currentScreenDistance < b.currentScreenDistance 598 | end) 599 | 600 | if #store.nearby > 0 and not drawLoopRunning then 601 | CreateThread(drawLoop) 602 | end 603 | end 604 | Wait(1000) 605 | end 606 | end 607 | 608 | RegisterNUICallback('select', function(data, cb) 609 | local currentTime = GetGameTimer() 610 | if store.current.options and currentTime > (store.cooldownEndTime or 0) then 611 | local option = store.current.options?[data[1]]?[data[2]] 612 | if option then 613 | if option.onSelect then 614 | option.onSelect(option.qtarget and store.current.entity or utils.getResponse(option)) 615 | elseif option.export then 616 | exports[option.resource][option.export](nil, utils.getResponse(option)) 617 | elseif option.event then 618 | TriggerEvent(option.event, utils.getResponse(option)) 619 | elseif option.serverEvent then 620 | TriggerServerEvent(option.serverEvent, utils.getResponse(option, true)) 621 | elseif option.command then 622 | ExecuteCommand(option.command) 623 | end 624 | local cooldown = option.cooldown or 1500 625 | store.cooldownEndTime = currentTime + cooldown 626 | if cooldown > 0 then 627 | dui.sendMessage('setCooldown', true) 628 | Wait(cooldown) 629 | dui.sendMessage('setCooldown', false) 630 | end 631 | end 632 | end 633 | cb(1) 634 | end) 635 | 636 | CreateThread(BuilderLoop) 637 | -------------------------------------------------------------------------------- /client/api.lua: -------------------------------------------------------------------------------- 1 | local utils = require 'client.modules.utils' 2 | local store = require 'client.modules.store' 3 | 4 | --- Throws a type error with a formatted message. 5 | ---@param variable string The name of the variable with the type issue. 6 | ---@param expected string The expected type. 7 | ---@param received string The actual type received. 8 | local function typeError(variable, expected, received) 9 | error(("expected %s to have type '%s' (received %s)"):format(variable, expected, received)) 10 | end 11 | 12 | --- Validates and normalizes an options table into an array. 13 | ---@param options InteractOption | InteractOption[] A single option table or an array of option tables. 14 | ---@return InteractOption[] options An array of options. 15 | local function checkOptions(options) 16 | local optionsType = type(options) 17 | if optionsType ~= 'table' then 18 | typeError('options', 'table', optionsType) 19 | end 20 | 21 | local tableType = table.type(options) 22 | if tableType == 'hash' and options.label then 23 | options = { options } 24 | elseif tableType ~= 'array' then 25 | typeError('options', 'array', ('%s table'):format(tableType)) 26 | end 27 | 28 | return options 29 | end 30 | 31 | --- Removes options from a target array based on names and resource. 32 | ---@param target InteractOption[] The array of options to modify. 33 | ---@param remove? string | string[] A single option name or array of names to remove. If nil, removes all options for the resource. 34 | ---@param resource string The resource owning the options. 35 | local function removeOptions(target, remove, resource) 36 | if remove then 37 | if type(remove) ~= 'table' then remove = { remove } end 38 | local removeSet = {} 39 | for i = 1, #remove do 40 | removeSet[remove[i]] = true 41 | end 42 | for i = #target, 1, -1 do 43 | local option = target[i] 44 | if option.resource == resource and removeSet[option.name] then 45 | table.remove(target, i) 46 | end 47 | end 48 | else 49 | -- Remove all options for the resource 50 | for i = #target, 1, -1 do 51 | if target[i].resource == resource then 52 | table.remove(target, i) 53 | end 54 | end 55 | end 56 | end 57 | 58 | --- Adds options to a target array, handling bones and offsets if present. 59 | ---@param target InteractOption[] The array to add options to. 60 | ---@param options InteractOption | InteractOption[] A single option or array of options to add. 61 | ---@param resource string The resource registering the options. 62 | ---@param bonesTarget OptionsMap|nil The bone options map to update, if applicable. 63 | ---@param offsetsTarget OptionsMap|nil The offset options map to update, if applicable. 64 | local function addOptions(target, options, resource, bonesTarget, offsetsTarget) 65 | options = checkOptions(options) 66 | local checkNames = {} 67 | 68 | resource = resource or 'sleepless_interact' 69 | 70 | for i = #options, 1, -1 do 71 | local option = options[i] 72 | option.resource = option.resource or resource 73 | 74 | if resource == 'sleepless_interact' then 75 | if option.canInteract then 76 | option.canInteract = msgpack.unpack(msgpack.pack(option.canInteract)) 77 | end 78 | if option.onSelect then 79 | option.onSelect = msgpack.unpack(msgpack.pack(option.onSelect)) 80 | end 81 | if option.onActive then 82 | option.onActive = msgpack.unpack(msgpack.pack(option.onActive)) 83 | end 84 | if option.onInactive then 85 | option.onInactive = msgpack.unpack(msgpack.pack(option.onInactive)) 86 | end 87 | if option.whileActive then 88 | option.whileActive = msgpack.unpack(msgpack.pack(option.whileActive)) 89 | end 90 | end 91 | 92 | if option.offset or option.offsetAbsolute then 93 | local offsetKey = option.offset and 'offset' or 'offsetAbsolute' 94 | local offset = option[offsetKey] 95 | local offsetType = type(offset) 96 | 97 | if offsetType == 'table' and offset.x and offset.y and offset.z then 98 | offset = vec3(offset.x, offset.y, offset.z) 99 | end 100 | 101 | if offsetType ~= 'table' and offsetType ~= 'vector3' then 102 | typeError('offset', 'vector3', offsetType) 103 | end 104 | 105 | local offsetStr = utils.makeOffsetIdFromCoords(offset, offsetKey) 106 | 107 | if offsetsTarget and offsetStr then 108 | offsetsTarget[offsetStr] = offsetsTarget[offsetStr] or {} 109 | if option.name then 110 | removeOptions(offsetsTarget[offsetStr], { option.name }, resource) 111 | end 112 | table.insert(offsetsTarget[offsetStr], 1, table.remove(options, i)) 113 | end 114 | elseif option.bones and bonesTarget then 115 | if type(option.bones) ~= "table" then 116 | option.bones = { option.bones --[[@as string]] } 117 | end 118 | 119 | local boneOptions = table.remove(options, i) 120 | 121 | for j = 1, #option.bones do 122 | local boneId = option.bones[j] 123 | bonesTarget[boneId] = bonesTarget[boneId] or {} 124 | if option.name then 125 | removeOptions(bonesTarget[boneId], { option.name }, resource) 126 | end 127 | table.insert(bonesTarget[boneId], 1, boneOptions) 128 | end 129 | elseif option.name then 130 | checkNames[#checkNames + 1] = option.name 131 | end 132 | end 133 | 134 | if checkNames[1] then 135 | removeOptions(target, checkNames, resource) 136 | end 137 | 138 | for i = 1, #options do 139 | table.insert(target, options[i]) 140 | end 141 | end 142 | 143 | --- Removes options from a target and its associated bones and offsets. 144 | ---@param target InteractOption[] The array to remove options from. 145 | ---@param remove? string | string[] A single option name or array of names to remove. If nil, removes all options for the resource. 146 | ---@param resource string The resource owning the options. 147 | ---@param bonesTarget OptionsMap|nil The bone options map to update, if applicable. 148 | ---@param offsetsTarget OptionsMap|nil The offset options map to update, if applicable. 149 | local function removeTarget(target, remove, resource, bonesTarget, offsetsTarget) 150 | if target then 151 | removeOptions(target, remove, resource) 152 | end 153 | 154 | if bonesTarget then 155 | for _, options in pairs(bonesTarget) do 156 | removeOptions(options, remove, resource) 157 | end 158 | end 159 | 160 | if offsetsTarget then 161 | for _, options in pairs(offsetsTarget) do 162 | removeOptions(options, remove, resource) 163 | end 164 | end 165 | end 166 | 167 | --- Disables or enables interaction and clears nearby/current options. 168 | ---@param state boolean True to disable interaction, false to enable. 169 | function interact.disableInteract(state) 170 | if type(state) == "boolean" then 171 | LocalPlayer.state.hideInteract = state 172 | end 173 | store.nearby = {} 174 | store.current = {} 175 | end 176 | 177 | --- Adds options to a specific coordinate location. 178 | ---@param coords vector3 | vector3[] The world coordinates for the options. 179 | ---@param options InteractOption | InteractOption[] A single option or array of options. 180 | ---@return string | string[] ids The ID of the added coordinate options. 181 | function interact.addCoords(coords, options) 182 | local coordsType = type(coords) 183 | if coordsType ~= 'table' and coordsType ~= 'vector3' and coordsType ~= 'vector4' then 184 | typeError('coords', 'vector3 or vector3[]', coordsType) 185 | end 186 | 187 | if coordsType == "table" and coords.x and coords.y and coords.z then 188 | coords = { vector3(coords.x, coords.y, coords.z) } 189 | end 190 | 191 | if coordsType ~= "table" then 192 | coords = { coords } 193 | end 194 | 195 | local resource = GetInvokingResource() 196 | options = checkOptions(options) 197 | local ids = {} 198 | 199 | for i = 1, #coords do 200 | local c = coords[i] 201 | local cType = type(c) 202 | 203 | if cType == 'vector4' then 204 | c = vec3(c.x, c.y, c.z) 205 | cType = type(c) 206 | end 207 | 208 | if cType ~= 'vector3' then 209 | typeError('coords', 'vector3', cType) 210 | end 211 | 212 | local id = utils.makeIdFromCoords(c) 213 | store.coords[id] = store.coords[id] or {} 214 | store.coordIds[id] = c 215 | addOptions(store.coords[id], table.clone(options), resource, nil, nil) 216 | ids[i] = id 217 | end 218 | 219 | return (#ids == 1 and ids[1]) or ids 220 | end 221 | 222 | --- Removes options from a coordinate location. 223 | ---@param id string The coordinate ID to modify. 224 | ---@param remove? string | string[] Specific option names to remove, or nil to remove all for the resource. 225 | function interact.removeCoords(id, remove) 226 | if not store.coords[id] then 227 | warn(('attempted to remove a coord that does not exist (id: %s)'):format(id)) 228 | return 229 | end 230 | 231 | local resource = GetInvokingResource() 232 | removeOptions(store.coords[id], remove, resource) 233 | 234 | if #store.coords[id] == 0 then 235 | store.coords[id] = nil 236 | store.coordIds[id] = nil 237 | end 238 | end 239 | 240 | --- Adds options globally for all peds. 241 | ---@param options InteractOption | InteractOption[] A single option or array of options. 242 | function interact.addGlobalPed(options) 243 | addOptions(store.peds, options, GetInvokingResource(), store.bones.peds, store.offsets.peds) 244 | end 245 | 246 | --- Removes options globally from all peds. 247 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 248 | function interact.removeGlobalPed(remove) 249 | if not remove then return end 250 | 251 | removeTarget(store.peds, remove, GetInvokingResource(), store.bones.peds, store.offsets.peds) 252 | 253 | if store.bones.peds then 254 | for boneId, boneOptions in pairs(store.bones.peds) do 255 | if #boneOptions == 0 then 256 | store.bones.peds[boneId] = nil 257 | end 258 | end 259 | end 260 | 261 | if store.offsets.peds then 262 | for offsetStr, offsetOptions in pairs(store.offsets.peds) do 263 | if #offsetOptions == 0 then 264 | store.offsets.peds[offsetStr] = nil 265 | end 266 | end 267 | end 268 | end 269 | 270 | --- Adds options globally for all vehicles. 271 | ---@param options InteractOption | InteractOption[] A single option or array of options. 272 | function interact.addGlobalVehicle(options) 273 | addOptions(store.vehicles, options, GetInvokingResource(), store.bones.vehicles, store.offsets.vehicles) 274 | end 275 | 276 | --- Removes options globally from all vehicles. 277 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 278 | function interact.removeGlobalVehicle(remove) 279 | if not remove then return end 280 | 281 | removeTarget(store.vehicles, remove, GetInvokingResource(), store.bones.vehicles, store.offsets.vehicles) 282 | 283 | if store.bones.vehicles then 284 | for boneId, boneOptions in pairs(store.bones.vehicles) do 285 | if #boneOptions == 0 then 286 | store.bones.vehicles[boneId] = nil 287 | end 288 | end 289 | end 290 | 291 | if store.offsets.vehicles then 292 | for offsetStr, offsetOptions in pairs(store.offsets.vehicles) do 293 | if #offsetOptions == 0 then 294 | store.offsets.vehicles[offsetStr] = nil 295 | end 296 | end 297 | end 298 | end 299 | 300 | --- Adds options globally for all objects. 301 | ---@param options InteractOption | InteractOption[] A single option or array of options. 302 | function interact.addGlobalObject(options) 303 | addOptions(store.objects, options, GetInvokingResource(), store.bones.objects, store.offsets.objects) 304 | end 305 | 306 | --- Removes options globally from all objects. 307 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 308 | function interact.removeGlobalObject(remove) 309 | if not remove then return end 310 | 311 | removeTarget(store.objects, remove, GetInvokingResource(), store.bones.objects, store.offsets.objects) 312 | 313 | if store.bones.objects then 314 | for boneId, boneOptions in pairs(store.bones.objects) do 315 | if #boneOptions == 0 then 316 | store.bones.objects[boneId] = nil 317 | end 318 | end 319 | end 320 | 321 | if store.offsets.objects then 322 | for offsetStr, offsetOptions in pairs(store.offsets.objects) do 323 | if #offsetOptions == 0 then 324 | store.offsets.objects[offsetStr] = nil 325 | end 326 | end 327 | end 328 | end 329 | 330 | --- Adds options globally for all players. 331 | ---@param options InteractOption | InteractOption[] A single option or array of options. 332 | function interact.addGlobalPlayer(options) 333 | addOptions(store.players, options, GetInvokingResource(), store.bones.players, store.offsets.players) 334 | end 335 | 336 | --- Removes options globally from all players. 337 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 338 | function interact.removeGlobalPlayer(remove) 339 | if not remove then return end 340 | 341 | removeTarget(store.players, remove, GetInvokingResource(), store.bones.players, store.offsets.players) 342 | 343 | if store.bones.players then 344 | for boneId, boneOptions in pairs(store.bones.players) do 345 | if #boneOptions == 0 then 346 | store.bones.players[boneId] = nil 347 | end 348 | end 349 | end 350 | 351 | if store.offsets.players then 352 | for offsetStr, offsetOptions in pairs(store.offsets.players) do 353 | if #offsetOptions == 0 then 354 | store.offsets.players[offsetStr] = nil 355 | end 356 | end 357 | end 358 | end 359 | 360 | --- Adds options for specific models. 361 | ---@param models number | string | (number | string)[] A single model (hash or name) or array of models. 362 | ---@param options InteractOption | InteractOption[] A single option or array of options. 363 | function interact.addModel(models, options) 364 | if type(models) ~= 'table' then models = { models } end 365 | local resource = GetInvokingResource() 366 | for i = 1, #models do 367 | local model = models[i] 368 | model = tonumber(model) or joaat(model) 369 | store.models[model] = store.models[model] or {} 370 | store.bones.models[model] = store.bones.models[model] or {} 371 | store.offsets.models[model] = store.offsets.models[model] or {} 372 | addOptions(store.models[model], table.clone(options), resource, store.bones.models[model], store.offsets.models[model]) 373 | end 374 | end 375 | 376 | --- Removes options from specific models. 377 | ---@param models number | string | (number | string)[] A single model (hash or name) or array of models. 378 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 379 | function interact.removeModel(models, remove) 380 | if type(models) ~= 'table' then models = { models } end 381 | local resource = GetInvokingResource() 382 | for i = 1, #models do 383 | local model = models[i] 384 | model = tonumber(model) or joaat(model) 385 | if store.models[model] then 386 | removeTarget(store.models[model], remove, resource, store.bones.models[model], store.offsets.models[model]) 387 | 388 | if store.models[model] and #store.models[model] == 0 then 389 | store.models[model] = nil 390 | end 391 | 392 | if store.bones.models[model] then 393 | for boneId, boneOptions in pairs(store.bones.models[model]) do 394 | if #boneOptions == 0 then 395 | store.bones.models[model][boneId] = nil 396 | end 397 | end 398 | if not next(store.bones.models[model]) then 399 | store.bones.models[model] = nil 400 | end 401 | end 402 | 403 | if store.offsets.models[model] then 404 | for offsetStr, offsetOptions in pairs(store.offsets.models[model]) do 405 | if #offsetOptions == 0 then 406 | store.offsets.models[model][offsetStr] = nil 407 | end 408 | end 409 | if not next(store.offsets.models[model]) then 410 | store.offsets.models[model] = nil 411 | end 412 | end 413 | end 414 | end 415 | end 416 | 417 | --- Adds options for specific networked entities. 418 | ---@param netIds number | number[] A single netId or array of netIds. 419 | ---@param options InteractOption | InteractOption[] A single option or array of options. 420 | function interact.addEntity(netIds, options) 421 | if type(netIds) ~= 'table' then netIds = { netIds } end 422 | local resource = GetInvokingResource() 423 | for i = 1, #netIds do 424 | local netId = netIds[i] 425 | if NetworkDoesNetworkIdExist(netId) then 426 | store.entities[netId] = store.entities[netId] or {} 427 | store.bones.entities[netId] = store.bones.entities[netId] or {} 428 | store.offsets.entities[netId] = store.offsets.entities[netId] or {} 429 | addOptions(store.entities[netId], table.clone(options), resource, store.bones.entities[netId], store.offsets.entities[netId]) 430 | end 431 | end 432 | end 433 | 434 | --- Removes options from specific networked entities. 435 | ---@param netIds number | number[] A single netId or array of netIds. 436 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 437 | function interact.removeEntity(netIds, remove) 438 | if type(netIds) ~= 'table' then netIds = { netIds } end 439 | local resource = GetInvokingResource() 440 | for i = 1, #netIds do 441 | local netId = netIds[i] 442 | removeTarget(store.entities[netId], remove, resource, store.bones.entities[netId], store.offsets.entities[netId]) 443 | 444 | if store.entities[netId] and #store.entities[netId] == 0 then 445 | store.entities[netId] = nil 446 | end 447 | 448 | if store.bones.entities[netId] then 449 | for boneId, boneOptions in pairs(store.bones.entities[netId]) do 450 | if #boneOptions == 0 then 451 | store.bones.entities[netId][boneId] = nil 452 | end 453 | end 454 | if not next(store.bones.entities[netId]) then 455 | store.bones.entities[netId] = nil 456 | end 457 | end 458 | 459 | if store.offsets.entities[netId] then 460 | for offsetStr, offsetOptions in pairs(store.offsets.entities[netId]) do 461 | if #offsetOptions == 0 then 462 | store.offsets.entities[netId][offsetStr] = nil 463 | end 464 | end 465 | if not next(store.offsets.entities[netId]) then 466 | store.offsets.entities[netId] = nil 467 | end 468 | end 469 | end 470 | end 471 | 472 | --- Adds options for specific local entities. 473 | ---@param entityIds number | number[] A single entityId or array of entityIds. 474 | ---@param options InteractOption | InteractOption[] A single option or array of options. 475 | function interact.addLocalEntity(entityIds, options) 476 | if type(entityIds) ~= 'table' then entityIds = { entityIds } end 477 | local resource = GetInvokingResource() 478 | for i = 1, #entityIds do 479 | local entityId = entityIds[i] 480 | if DoesEntityExist(entityId) then 481 | store.localEntities[entityId] = store.localEntities[entityId] or {} 482 | store.bones.localEntities[entityId] = store.bones.localEntities[entityId] or {} 483 | store.offsets.localEntities[entityId] = store.offsets.localEntities[entityId] or {} 484 | addOptions(store.localEntities[entityId], table.clone(options), resource, store.bones.localEntities[entityId], store.offsets.localEntities[entityId]) 485 | else 486 | lib.print.warn(('No entity with id "%s" exists.'):format(entityId)) 487 | end 488 | end 489 | end 490 | 491 | --- Removes options from specific local entities. 492 | ---@param entityIds number | number[] A single entityId or array of entityIds. 493 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource. 494 | function interact.removeLocalEntity(entityIds, remove) 495 | if type(entityIds) ~= 'table' then entityIds = { entityIds } end 496 | local resource = GetInvokingResource() 497 | for i = 1, #entityIds do 498 | local entityId = entityIds[i] 499 | removeTarget(store.localEntities[entityId], remove, resource, store.bones.localEntities[entityId], store.offsets.localEntities[entityId]) 500 | 501 | if store.localEntities[entityId] and #store.localEntities[entityId] == 0 then 502 | store.localEntities[entityId] = nil 503 | end 504 | 505 | if store.bones.localEntities[entityId] then 506 | for boneId, boneOptions in pairs(store.bones.localEntities[entityId]) do 507 | if #boneOptions == 0 then 508 | store.bones.localEntities[entityId][boneId] = nil 509 | end 510 | end 511 | if not next(store.bones.localEntities[entityId]) then 512 | store.bones.localEntities[entityId] = nil 513 | end 514 | end 515 | 516 | if store.offsets.localEntities[entityId] then 517 | for offsetStr, offsetOptions in pairs(store.offsets.localEntities[entityId]) do 518 | if #offsetOptions == 0 then 519 | store.offsets.localEntities[entityId][offsetStr] = nil 520 | end 521 | end 522 | if not next(store.offsets.localEntities[entityId]) then 523 | store.offsets.localEntities[entityId] = nil 524 | end 525 | end 526 | end 527 | end 528 | 529 | -- Thread to clean up local entities that no longer exist. 530 | CreateThread(function() 531 | while true do 532 | Wait(60000) 533 | for entityId in pairs(store.localEntities) do 534 | if not DoesEntityExist(entityId) then 535 | store.localEntities[entityId] = nil 536 | store.bones.localEntities[entityId] = nil 537 | store.offsets.localEntities[entityId] = nil 538 | end 539 | end 540 | end 541 | end) 542 | 543 | --- Removes all options associated with a specific resource from a target array. 544 | ---@param target InteractOption[] The array to clean up. 545 | ---@param resource string The resource whose options should be removed. 546 | local function removeResourceOptions(target, resource) 547 | if not target then return end 548 | for i = #target, 1, -1 do 549 | if target[i].resource == resource then 550 | table.remove(target, i) 551 | end 552 | end 553 | end 554 | 555 | AddEventHandler('onClientResourceStop', function(resource) 556 | removeResourceOptions(store.peds, resource) 557 | removeResourceOptions(store.vehicles, resource) 558 | removeResourceOptions(store.objects, resource) 559 | removeResourceOptions(store.players, resource) 560 | 561 | for boneId, options in pairs(store.bones.peds or {}) do 562 | removeResourceOptions(options, resource) 563 | if #options == 0 then 564 | store.bones.peds[boneId] = nil 565 | end 566 | end 567 | 568 | for boneId, options in pairs(store.bones.vehicles or {}) do 569 | removeResourceOptions(options, resource) 570 | if #options == 0 then 571 | store.bones.vehicles[boneId] = nil 572 | end 573 | end 574 | 575 | for boneId, options in pairs(store.bones.objects or {}) do 576 | removeResourceOptions(options, resource) 577 | if #options == 0 then 578 | store.bones.objects[boneId] = nil 579 | end 580 | end 581 | 582 | for boneId, options in pairs(store.bones.players or {}) do 583 | removeResourceOptions(options, resource) 584 | if #options == 0 then 585 | store.bones.players[boneId] = nil 586 | end 587 | end 588 | 589 | for offsetStr, options in pairs(store.offsets.peds or {}) do 590 | removeResourceOptions(options, resource) 591 | if #options == 0 then 592 | store.offsets.peds[offsetStr] = nil 593 | end 594 | end 595 | 596 | for offsetStr, options in pairs(store.offsets.vehicles or {}) do 597 | removeResourceOptions(options, resource) 598 | if #options == 0 then 599 | store.offsets.vehicles[offsetStr] = nil 600 | end 601 | end 602 | 603 | for offsetStr, options in pairs(store.offsets.objects or {}) do 604 | removeResourceOptions(options, resource) 605 | if #options == 0 then 606 | store.offsets.objects[offsetStr] = nil 607 | end 608 | end 609 | 610 | for offsetStr, options in pairs(store.offsets.players or {}) do 611 | removeResourceOptions(options, resource) 612 | if #options == 0 then 613 | store.offsets.players[offsetStr] = nil 614 | end 615 | end 616 | 617 | for model, options in pairs(store.models) do 618 | local stillHasOptions = false 619 | 620 | if store.bones.models[model] then 621 | for boneId, boneOptions in pairs(store.bones.models[model]) do 622 | removeResourceOptions(boneOptions, resource) 623 | if #boneOptions == 0 then 624 | store.bones.models[model][boneId] = nil 625 | end 626 | end 627 | if not next(store.bones.models[model]) then 628 | store.bones.models[model] = nil 629 | else 630 | stillHasOptions = true 631 | end 632 | end 633 | 634 | if store.offsets.models[model] then 635 | for offsetStr, offsetOptions in pairs(store.offsets.models[model]) do 636 | removeResourceOptions(offsetOptions, resource) 637 | if #offsetOptions == 0 then 638 | store.offsets.models[model][offsetStr] = nil 639 | end 640 | end 641 | if not next(store.offsets.models[model]) then 642 | store.offsets.models[model] = nil 643 | else 644 | stillHasOptions = true 645 | end 646 | end 647 | 648 | removeResourceOptions(options, resource) 649 | if #options == 0 and not stillHasOptions then 650 | store.models[model] = nil 651 | end 652 | end 653 | 654 | for netId, options in pairs(store.entities) do 655 | local stillHasOptions = false 656 | 657 | if store.bones.entities[netId] then 658 | for boneId, boneOptions in pairs(store.bones.entities[netId]) do 659 | removeResourceOptions(boneOptions, resource) 660 | if #boneOptions == 0 then 661 | store.bones.entities[netId][boneId] = nil 662 | end 663 | end 664 | if not next(store.bones.entities[netId]) then 665 | store.bones.entities[netId] = nil 666 | else 667 | stillHasOptions = true 668 | end 669 | end 670 | 671 | if store.offsets.entities[netId] then 672 | for offsetStr, offsetOptions in pairs(store.offsets.entities[netId]) do 673 | removeResourceOptions(offsetOptions, resource) 674 | if #offsetOptions == 0 then 675 | store.offsets.entities[netId][offsetStr] = nil 676 | end 677 | end 678 | if not next(store.offsets.entities[netId]) then 679 | store.offsets.entities[netId] = nil 680 | else 681 | stillHasOptions = true 682 | end 683 | end 684 | 685 | removeResourceOptions(options, resource) 686 | if #options == 0 and not stillHasOptions then 687 | store.entities[netId] = nil 688 | end 689 | end 690 | 691 | for entityId, options in pairs(store.localEntities) do 692 | local stillHasOptions = false 693 | 694 | if store.bones.localEntities[entityId] then 695 | for boneId, boneOptions in pairs(store.bones.localEntities[entityId]) do 696 | removeResourceOptions(boneOptions, resource) 697 | if #boneOptions == 0 then 698 | store.bones.localEntities[entityId][boneId] = nil 699 | end 700 | end 701 | if not next(store.bones.localEntities[entityId]) then 702 | store.bones.localEntities[entityId] = nil 703 | else 704 | stillHasOptions = true 705 | end 706 | end 707 | 708 | if store.offsets.localEntities[entityId] then 709 | for offsetStr, offsetOptions in pairs(store.offsets.localEntities[entityId]) do 710 | removeResourceOptions(offsetOptions, resource) 711 | if #offsetOptions == 0 then 712 | store.offsets.localEntities[entityId][offsetStr] = nil 713 | end 714 | end 715 | if not next(store.offsets.localEntities[entityId]) then 716 | store.offsets.localEntities[entityId] = nil 717 | else 718 | stillHasOptions = true 719 | end 720 | end 721 | 722 | removeResourceOptions(options, resource) 723 | if #options == 0 and not stillHasOptions then 724 | store.localEntities[entityId] = nil 725 | end 726 | end 727 | 728 | for id, options in pairs(store.coords) do 729 | removeResourceOptions(options, resource) 730 | if #options == 0 then 731 | store.coords[id] = nil 732 | store.coordIds[id] = nil 733 | end 734 | end 735 | end) 736 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------