├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ └── feature_request.yml
├── actions
│ └── bump-manifest-version.js
└── workflows
│ └── release.yml
├── LICENSE
├── README.md
├── _types.lua
├── client
├── api.lua
├── compat
│ ├── init.lua
│ └── resources
│ │ ├── interact.lua
│ │ ├── ox_target.lua
│ │ ├── qb_target.lua
│ │ └── qtarget.lua
├── defaults.lua
├── framework
│ ├── esx.lua
│ ├── nd.lua
│ ├── ox.lua
│ ├── qb.lua
│ └── qbx.lua
├── main.lua
└── modules
│ ├── config.lua
│ ├── dui.lua
│ ├── store.lua
│ └── utils.lua
├── fxmanifest.lua
├── init.lua
└── web
├── index.html
├── js
├── controls.js
├── createOptions.js
├── fetchNui.js
└── main.js
└── style.css
/.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.
--------------------------------------------------------------------------------
/.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.
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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 }}
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # sleepless_interact
2 |
3 | A FiveM library for creating 3D DUI world interactions
4 |
5 | 
6 | 
7 | 
8 | 
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 |
--------------------------------------------------------------------------------
/_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/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], 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], 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 | if not next(store.bones.peds) then
260 | store.bones.peds = nil
261 | end
262 | end
263 |
264 | if store.offsets.peds then
265 | for offsetStr, offsetOptions in pairs(store.offsets.peds) do
266 | if #offsetOptions == 0 then
267 | store.offsets.peds[offsetStr] = nil
268 | end
269 | end
270 | if not next(store.offsets.peds) then
271 | store.offsets.peds = nil
272 | end
273 | end
274 | end
275 |
276 | --- Adds options globally for all vehicles.
277 | ---@param options InteractOption | InteractOption[] A single option or array of options.
278 | function interact.addGlobalVehicle(options)
279 | addOptions(store.vehicles, options, GetInvokingResource(), store.bones.vehicles, store.offsets.vehicles)
280 | end
281 |
282 | --- Removes options globally from all vehicles.
283 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource.
284 | function interact.removeGlobalVehicle(remove)
285 | if not remove then return end
286 |
287 | removeTarget(store.vehicles, remove, GetInvokingResource(), store.bones.vehicles, store.offsets.vehicles)
288 |
289 | if store.bones.vehicles then
290 | for boneId, boneOptions in pairs(store.bones.vehicles) do
291 | if #boneOptions == 0 then
292 | store.bones.vehicles[boneId] = nil
293 | end
294 | end
295 | if not next(store.bones.vehicles) then
296 | store.bones.vehicles = nil
297 | end
298 | end
299 |
300 | if store.offsets.vehicles then
301 | for offsetStr, offsetOptions in pairs(store.offsets.vehicles) do
302 | if #offsetOptions == 0 then
303 | store.offsets.vehicles[offsetStr] = nil
304 | end
305 | end
306 | if not next(store.offsets.vehicles) then
307 | store.offsets.vehicles = nil
308 | end
309 | end
310 | end
311 |
312 | --- Adds options globally for all objects.
313 | ---@param options InteractOption | InteractOption[] A single option or array of options.
314 | function interact.addGlobalObject(options)
315 | addOptions(store.objects, options, GetInvokingResource(), store.bones.objects, store.offsets.objects)
316 | end
317 |
318 | --- Removes options globally from all objects.
319 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource.
320 | function interact.removeGlobalObject(remove)
321 | if not remove then return end
322 |
323 | removeTarget(store.objects, remove, GetInvokingResource(), store.bones.objects, store.offsets.objects)
324 |
325 | if store.bones.objects then
326 | for boneId, boneOptions in pairs(store.bones.objects) do
327 | if #boneOptions == 0 then
328 | store.bones.objects[boneId] = nil
329 | end
330 | end
331 | if not next(store.bones.objects) then
332 | store.bones.objects = nil
333 | end
334 | end
335 |
336 | if store.offsets.objects then
337 | for offsetStr, offsetOptions in pairs(store.offsets.objects) do
338 | if #offsetOptions == 0 then
339 | store.offsets.objects[offsetStr] = nil
340 | end
341 | end
342 | if not next(store.offsets.objects) then
343 | store.offsets.objects = nil
344 | end
345 | end
346 | end
347 |
348 | --- Adds options globally for all players.
349 | ---@param options InteractOption | InteractOption[] A single option or array of options.
350 | function interact.addGlobalPlayer(options)
351 | addOptions(store.players, options, GetInvokingResource(), store.bones.players, store.offsets.players)
352 | end
353 |
354 | --- Removes options globally from all players.
355 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource.
356 | function interact.removeGlobalPlayer(remove)
357 | if not remove then return end
358 |
359 | removeTarget(store.players, remove, GetInvokingResource(), store.bones.players, store.offsets.players)
360 |
361 | if store.bones.players then
362 | for boneId, boneOptions in pairs(store.bones.players) do
363 | if #boneOptions == 0 then
364 | store.bones.players[boneId] = nil
365 | end
366 | end
367 | if not next(store.bones.players) then
368 | store.bones.players = nil
369 | end
370 | end
371 |
372 | if store.offsets.players then
373 | for offsetStr, offsetOptions in pairs(store.offsets.players) do
374 | if #offsetOptions == 0 then
375 | store.offsets.players[offsetStr] = nil
376 | end
377 | end
378 | if not next(store.offsets.players) then
379 | store.offsets.players = nil
380 | end
381 | end
382 | end
383 |
384 | --- Adds options for specific models.
385 | ---@param models number | string | (number | string)[] A single model (hash or name) or array of models.
386 | ---@param options InteractOption | InteractOption[] A single option or array of options.
387 | function interact.addModel(models, options)
388 | if type(models) ~= 'table' then models = { models } end
389 | local resource = GetInvokingResource()
390 | for i = 1, #models do
391 | local model = models[i]
392 | model = tonumber(model) or joaat(model)
393 | store.models[model] = store.models[model] or {}
394 | store.bones.models[model] = store.bones.models[model] or {}
395 | store.offsets.models[model] = store.offsets.models[model] or {}
396 | addOptions(store.models[model], table.clone(options), resource, store.bones.models[model], store.offsets.models[model])
397 | end
398 | end
399 |
400 | --- Removes options from specific models.
401 | ---@param models number | string | (number | string)[] A single model (hash or name) or array of models.
402 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource.
403 | function interact.removeModel(models, remove)
404 | if type(models) ~= 'table' then models = { models } end
405 | local resource = GetInvokingResource()
406 | for i = 1, #models do
407 | local model = models[i]
408 | model = tonumber(model) or joaat(model)
409 | if store.models[model] then
410 | removeTarget(store.models[model], remove, resource, store.bones.models[model], store.offsets.models[model])
411 |
412 | if store.models[model] and #store.models[model] == 0 then
413 | store.models[model] = nil
414 | end
415 |
416 | if store.bones.models[model] then
417 | for boneId, boneOptions in pairs(store.bones.models[model]) do
418 | if #boneOptions == 0 then
419 | store.bones.models[model][boneId] = nil
420 | end
421 | end
422 | if not next(store.bones.models[model]) then
423 | store.bones.models[model] = nil
424 | end
425 | end
426 |
427 | if store.offsets.models[model] then
428 | for offsetStr, offsetOptions in pairs(store.offsets.models[model]) do
429 | if #offsetOptions == 0 then
430 | store.offsets.models[model][offsetStr] = nil
431 | end
432 | end
433 | if not next(store.offsets.models[model]) then
434 | store.offsets.models[model] = nil
435 | end
436 | end
437 | end
438 | end
439 | end
440 |
441 | --- Adds options for specific networked entities.
442 | ---@param netIds number | number[] A single netId or array of netIds.
443 | ---@param options InteractOption | InteractOption[] A single option or array of options.
444 | function interact.addEntity(netIds, options)
445 | if type(netIds) ~= 'table' then netIds = { netIds } end
446 | local resource = GetInvokingResource()
447 | for i = 1, #netIds do
448 | local netId = netIds[i]
449 | if NetworkDoesNetworkIdExist(netId) then
450 | store.entities[netId] = store.entities[netId] or {}
451 | store.bones.entities[netId] = store.bones.entities[netId] or {}
452 | store.offsets.entities[netId] = store.offsets.entities[netId] or {}
453 | addOptions(store.entities[netId], table.clone(options), resource, store.bones.entities[netId], store.offsets.entities[netId])
454 | end
455 | end
456 | end
457 |
458 | --- Removes options from specific networked entities.
459 | ---@param netIds number | number[] A single netId or array of netIds.
460 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource.
461 | function interact.removeEntity(netIds, remove)
462 | if type(netIds) ~= 'table' then netIds = { netIds } end
463 | local resource = GetInvokingResource()
464 | for i = 1, #netIds do
465 | local netId = netIds[i]
466 | removeTarget(store.entities[netId], remove, resource, store.bones.entities[netId], store.offsets.entities[netId])
467 |
468 | if store.entities[netId] and #store.entities[netId] == 0 then
469 | store.entities[netId] = nil
470 | end
471 |
472 | if store.bones.entities[netId] then
473 | for boneId, boneOptions in pairs(store.bones.entities[netId]) do
474 | if #boneOptions == 0 then
475 | store.bones.entities[netId][boneId] = nil
476 | end
477 | end
478 | if not next(store.bones.entities[netId]) then
479 | store.bones.entities[netId] = nil
480 | end
481 | end
482 |
483 | if store.offsets.entities[netId] then
484 | for offsetStr, offsetOptions in pairs(store.offsets.entities[netId]) do
485 | if #offsetOptions == 0 then
486 | store.offsets.entities[netId][offsetStr] = nil
487 | end
488 | end
489 | if not next(store.offsets.entities[netId]) then
490 | store.offsets.entities[netId] = nil
491 | end
492 | end
493 | end
494 | end
495 |
496 | --- Adds options for specific local entities.
497 | ---@param entityIds number | number[] A single entityId or array of entityIds.
498 | ---@param options InteractOption | InteractOption[] A single option or array of options.
499 | function interact.addLocalEntity(entityIds, options)
500 | if type(entityIds) ~= 'table' then entityIds = { entityIds } end
501 | local resource = GetInvokingResource()
502 | for i = 1, #entityIds do
503 | local entityId = entityIds[i]
504 | if DoesEntityExist(entityId) then
505 | store.localEntities[entityId] = store.localEntities[entityId] or {}
506 | store.bones.localEntities[entityId] = store.bones.localEntities[entityId] or {}
507 | store.offsets.localEntities[entityId] = store.offsets.localEntities[entityId] or {}
508 | addOptions(store.localEntities[entityId], table.clone(options), resource, store.bones.localEntities[entityId], store.offsets.localEntities[entityId])
509 | else
510 | lib.print.warn(('No entity with id "%s" exists.'):format(entityId))
511 | end
512 | end
513 | end
514 |
515 | --- Removes options from specific local entities.
516 | ---@param entityIds number | number[] A single entityId or array of entityIds.
517 | ---@param remove? string | string[] A single option name or array of names to remove, or nil to remove all for the resource.
518 | function interact.removeLocalEntity(entityIds, remove)
519 | if type(entityIds) ~= 'table' then entityIds = { entityIds } end
520 | local resource = GetInvokingResource()
521 | for i = 1, #entityIds do
522 | local entityId = entityIds[i]
523 | removeTarget(store.localEntities[entityId], remove, resource, store.bones.localEntities[entityId], store.offsets.localEntities[entityId])
524 |
525 | if store.localEntities[entityId] and #store.localEntities[entityId] == 0 then
526 | store.localEntities[entityId] = nil
527 | end
528 |
529 | if store.bones.localEntities[entityId] then
530 | for boneId, boneOptions in pairs(store.bones.localEntities[entityId]) do
531 | if #boneOptions == 0 then
532 | store.bones.localEntities[entityId][boneId] = nil
533 | end
534 | end
535 | if not next(store.bones.localEntities[entityId]) then
536 | store.bones.localEntities[entityId] = nil
537 | end
538 | end
539 |
540 | if store.offsets.localEntities[entityId] then
541 | for offsetStr, offsetOptions in pairs(store.offsets.localEntities[entityId]) do
542 | if #offsetOptions == 0 then
543 | store.offsets.localEntities[entityId][offsetStr] = nil
544 | end
545 | end
546 | if not next(store.offsets.localEntities[entityId]) then
547 | store.offsets.localEntities[entityId] = nil
548 | end
549 | end
550 | end
551 | end
552 |
553 | -- Thread to clean up local entities that no longer exist.
554 | CreateThread(function()
555 | while true do
556 | Wait(60000)
557 | for entityId in pairs(store.localEntities) do
558 | if not DoesEntityExist(entityId) then
559 | store.localEntities[entityId] = nil
560 | store.bones.localEntities[entityId] = nil
561 | store.offsets.localEntities[entityId] = nil
562 | end
563 | end
564 | end
565 | end)
566 |
567 | --- Removes all options associated with a specific resource from a target array.
568 | ---@param target InteractOption[] The array to clean up.
569 | ---@param resource string The resource whose options should be removed.
570 | local function removeResourceOptions(target, resource)
571 | if not target then return end
572 | for i = #target, 1, -1 do
573 | if target[i].resource == resource then
574 | table.remove(target, i)
575 | end
576 | end
577 | end
578 |
579 | AddEventHandler('onClientResourceStop', function(resource)
580 | removeResourceOptions(store.peds, resource)
581 | removeResourceOptions(store.vehicles, resource)
582 | removeResourceOptions(store.objects, resource)
583 | removeResourceOptions(store.players, resource)
584 |
585 | for boneId, options in pairs(store.bones.peds or {}) do
586 | removeResourceOptions(options, resource)
587 | if #options == 0 then
588 | store.bones.peds[boneId] = nil
589 | end
590 | end
591 |
592 | for boneId, options in pairs(store.bones.vehicles or {}) do
593 | removeResourceOptions(options, resource)
594 | if #options == 0 then
595 | store.bones.vehicles[boneId] = nil
596 | end
597 | end
598 |
599 | for boneId, options in pairs(store.bones.objects or {}) do
600 | removeResourceOptions(options, resource)
601 | if #options == 0 then
602 | store.bones.objects[boneId] = nil
603 | end
604 | end
605 |
606 | for boneId, options in pairs(store.bones.players or {}) do
607 | removeResourceOptions(options, resource)
608 | if #options == 0 then
609 | store.bones.players[boneId] = nil
610 | end
611 | end
612 |
613 | for offsetStr, options in pairs(store.offsets.peds or {}) do
614 | removeResourceOptions(options, resource)
615 | if #options == 0 then
616 | store.offsets.peds[offsetStr] = nil
617 | end
618 | end
619 |
620 | for offsetStr, options in pairs(store.offsets.vehicles or {}) do
621 | removeResourceOptions(options, resource)
622 | if #options == 0 then
623 | store.offsets.vehicles[offsetStr] = nil
624 | end
625 | end
626 |
627 | for offsetStr, options in pairs(store.offsets.objects or {}) do
628 | removeResourceOptions(options, resource)
629 | if #options == 0 then
630 | store.offsets.objects[offsetStr] = nil
631 | end
632 | end
633 |
634 | for offsetStr, options in pairs(store.offsets.players or {}) do
635 | removeResourceOptions(options, resource)
636 | if #options == 0 then
637 | store.offsets.players[offsetStr] = nil
638 | end
639 | end
640 |
641 | for model, options in pairs(store.models) do
642 | removeResourceOptions(options, resource)
643 | if #options == 0 then
644 | store.models[model] = nil
645 | end
646 |
647 | if store.bones.models[model] then
648 | for boneId, boneOptions in pairs(store.bones.models[model]) do
649 | removeResourceOptions(boneOptions, resource)
650 | if #boneOptions == 0 then
651 | store.bones.models[model][boneId] = nil
652 | end
653 | end
654 | if not next(store.bones.models[model]) then
655 | store.bones.models[model] = nil
656 | end
657 | end
658 |
659 | if store.offsets.models[model] then
660 | for offsetStr, offsetOptions in pairs(store.offsets.models[model]) do
661 | removeResourceOptions(offsetOptions, resource)
662 | if #offsetOptions == 0 then
663 | store.offsets.models[model][offsetStr] = nil
664 | end
665 | end
666 | if not next(store.offsets.models[model]) then
667 | store.offsets.models[model] = nil
668 | end
669 | end
670 | end
671 |
672 | for netId, options in pairs(store.entities) do
673 | removeResourceOptions(options, resource)
674 | if #options == 0 then
675 | store.entities[netId] = nil
676 | end
677 |
678 | if store.bones.entities[netId] then
679 | for boneId, boneOptions in pairs(store.bones.entities[netId]) do
680 | removeResourceOptions(boneOptions, resource)
681 | if #boneOptions == 0 then
682 | store.bones.entities[netId][boneId] = nil
683 | end
684 | end
685 | if not next(store.bones.entities[netId]) then
686 | store.bones.entities[netId] = nil
687 | end
688 | end
689 |
690 | if store.offsets.entities[netId] then
691 | for offsetStr, offsetOptions in pairs(store.offsets.entities[netId]) do
692 | removeResourceOptions(offsetOptions, resource)
693 | if #offsetOptions == 0 then
694 | store.offsets.entities[netId][offsetStr] = nil
695 | end
696 | end
697 | if not next(store.offsets.entities[netId]) then
698 | store.offsets.entities[netId] = nil
699 | end
700 | end
701 | end
702 |
703 | for entityId, options in pairs(store.localEntities) do
704 | removeResourceOptions(options, resource)
705 | if #options == 0 then
706 | store.localEntities[entityId] = nil
707 | end
708 |
709 | if store.bones.localEntities[entityId] then
710 | for boneId, boneOptions in pairs(store.bones.localEntities[entityId]) do
711 | removeResourceOptions(boneOptions, resource)
712 | if #boneOptions == 0 then
713 | store.bones.localEntities[entityId][boneId] = nil
714 | end
715 | end
716 | if not next(store.bones.localEntities[entityId]) then
717 | store.bones.localEntities[entityId] = nil
718 | end
719 | end
720 |
721 | if store.offsets.localEntities[entityId] then
722 | for offsetStr, offsetOptions in pairs(store.offsets.localEntities[entityId]) do
723 | removeResourceOptions(offsetOptions, resource)
724 | if #offsetOptions == 0 then
725 | store.offsets.localEntities[entityId][offsetStr] = nil
726 | end
727 | end
728 | if not next(store.offsets.localEntities[entityId]) then
729 | store.offsets.localEntities[entityId] = nil
730 | end
731 | end
732 | end
733 |
734 | for id, options in pairs(store.coords) do
735 | removeResourceOptions(options, resource)
736 | if #options == 0 then
737 | store.coords[id] = nil
738 | store.coordIds[id] = nil
739 | end
740 | end
741 | end)
742 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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)
--------------------------------------------------------------------------------
/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/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/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/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
6 | ---@type boolean
7 | local drawLoopRunning = false
8 |
9 | local GetEntityCoords = GetEntityCoords
10 | local DrawSprite = DrawSprite
11 | local SetDrawOrigin = SetDrawOrigin
12 | local getNearbyObjects = lib.getNearbyObjects
13 | local getNearbyPlayers = lib.getNearbyPlayers
14 | local getNearbyVehicles = lib.getNearbyVehicles
15 | local getNearbyPeds = lib.getNearbyPeds
16 | local GetOffsetFromEntityInWorldCoords = GetOffsetFromEntityInWorldCoords
17 | local GetEntityBoneIndexByName = GetEntityBoneIndexByName
18 | local GetEntityBonePosition_2 = GetEntityBonePosition_2
19 | local GetModelDimensions = GetModelDimensions
20 | local NetworkGetEntityIsNetworked = NetworkGetEntityIsNetworked
21 | local NetworkGetNetworkIdFromEntity = NetworkGetNetworkIdFromEntity
22 | local GetEntityModel = GetEntityModel
23 |
24 | local r, g, b, a = table.unpack(config.themeColor)
25 |
26 | local pressed = false
27 | lib.addKeybind({
28 | name = 'interact_action',
29 | description = 'Interact',
30 | defaultKey = 'E',
31 | onPressed = function(self)
32 | if GetGameTimer() > store.cooldownEndTime then
33 | if not next(store.current) then return end
34 | pressed = true
35 | dui.sendMessage("interact")
36 | end
37 | end,
38 | onReleased = function(self)
39 | if not pressed then return end
40 | pressed = false
41 | dui.sendMessage("release")
42 | end,
43 | })
44 |
45 |
46 | local hidePerKeybind = config.showKeyBindBehavior == "hold"
47 | if config.useShowKeyBind then
48 | lib.addKeybind({
49 | name = 'sleepless_interact:toggle',
50 | description = 'show interactions',
51 | defaultKey = config.defaultShowKeyBind,
52 | onPressed = function(self)
53 | if config.showKeyBindBehavior == "toggle" then
54 | hidePerKeybind = not hidePerKeybind
55 |
56 | if hidePerKeybind then
57 | table.wipe(store.nearby)
58 | lib.notify({
59 | title = 'Interact',
60 | description = 'Disabled',
61 | type = 'warning'
62 | })
63 | else
64 | lib.notify({
65 | title = 'Interact',
66 | description = 'Enabled',
67 | type = 'success'
68 | })
69 | end
70 | else
71 | hidePerKeybind = false
72 | end
73 | end,
74 | onReleased = function(self)
75 | if config.showKeyBindBehavior == "toggle" then return end
76 | hidePerKeybind = true
77 | end
78 | })
79 | end
80 |
81 | local modelCache, netIdCache = {}, {}
82 |
83 | local function cachedEntityInfo(entity)
84 | if modelCache[entity] then
85 | return modelCache[entity], netIdCache[entity]
86 | end
87 |
88 | local model = GetEntityModel(entity)
89 | local netId = NetworkGetEntityIsNetworked(entity) and NetworkGetNetworkIdFromEntity(entity) or nil
90 | modelCache[entity] = model
91 | netIdCache[entity] = netId
92 | return model, netId
93 | end
94 |
95 | ---@param options InteractOption[]
96 | ---@param entity number
97 | ---@param distance number
98 | ---@param coords vector3
99 | ---@return nil | table, number | nil, boolean | nil
100 | local function filterValidOptions(options, entity, distance, coords)
101 | if not options then return nil end
102 | local validOptions = {}
103 | local totalValid = 0
104 | local hasGlobal = options['global'] ~= nil
105 | local hasNonGlobal = false
106 |
107 | for category, _options in pairs(options) do
108 | if category ~= 'global' then
109 | hasNonGlobal = true
110 | end
111 |
112 | local validCategoryOptions = {}
113 |
114 | for i = 1, #_options do
115 | local option = _options[i]
116 | local hide = false
117 |
118 | if not hide and not option.allowInVehicle and cache.vehicle then
119 | hide = true
120 | end
121 |
122 | if not hide then hide = distance > (option.distance or 2.0) end
123 |
124 | if not hide and option.groups then hide = not utils.hasPlayerGotGroup(option.groups) end
125 |
126 | if not hide and option.items then hide = not utils.hasPlayerGotItems(option.items, option.anyItem) end
127 |
128 | if not hide and option.canInteract then
129 | local success, resp = pcall(option.canInteract, entity, distance, coords, option.name)
130 | hide = not success or not resp
131 | end
132 |
133 | if not hide then
134 | validCategoryOptions[#validCategoryOptions + 1] = option
135 | totalValid = totalValid + 1
136 | end
137 | end
138 |
139 | if #validCategoryOptions > 0 then
140 | validOptions[category] = validCategoryOptions
141 | end
142 | end
143 |
144 | local hideCompletely = hasGlobal and not hasNonGlobal and totalValid == 0
145 |
146 | if totalValid == 0 then
147 | return nil, nil, hideCompletely
148 | end
149 |
150 | return validOptions, totalValid, hideCompletely
151 | end
152 |
153 | ---@param entity number
154 | ---@param globalType string
155 | ---@return InteractOption[] | nil
156 | local function getOptionsForEntity(entity, globalType)
157 | if not entity then return nil end
158 |
159 | if IsPedAPlayer(entity) then
160 | return {
161 | global = store.players,
162 | }
163 | end
164 |
165 | local model, netId = cachedEntityInfo(entity)
166 |
167 | local options = {
168 | global = (store[globalType] ~= nil and #store[globalType] > 0 and store[globalType]) or nil,
169 | model = (store.models[model] ~= nil and #store.models[model] > 0 and store.models[model]) or nil,
170 | entity = (netId and store.entities[netId] ~= nil and #store.entities[netId] > 0 and store.entities[netId]) or nil,
171 | localEntity = (store.localEntities[entity] ~= nil and #store.localEntities[entity] > 0 and store.localEntities[entity]) or nil,
172 | }
173 |
174 | return next(options) and options or nil
175 | end
176 |
177 | ---@param entity number
178 | ---@param globalType string
179 | ---@return table | nil
180 | local function getBoneOptionsForEntity(entity, globalType)
181 | if not entity then return nil end
182 | local model, netId = cachedEntityInfo(entity)
183 | local boneOptions = {}
184 | local hasOptions = false
185 |
186 | if store.bones[globalType] then
187 | for boneId, options in pairs(store.bones[globalType]) do
188 | if #options > 0 then
189 | boneOptions[boneId] = boneOptions[boneId] or {}
190 | boneOptions[boneId].global = options
191 | hasOptions = true
192 | end
193 | end
194 | end
195 |
196 | if store.bones.models and store.bones.models[model] then
197 | for boneId, options in pairs(store.bones.models[model]) do
198 | if #options > 0 then
199 | boneOptions[boneId] = boneOptions[boneId] or {}
200 | boneOptions[boneId].model = options
201 | hasOptions = true
202 | end
203 | end
204 | end
205 |
206 | if netId and store.bones.entities and store.bones.entities[netId] then
207 | for boneId, options in pairs(store.bones.entities[netId]) do
208 | if #options > 0 then
209 | boneOptions[boneId] = boneOptions[boneId] or {}
210 | boneOptions[boneId].entity = options
211 | hasOptions = true
212 | end
213 | end
214 | end
215 |
216 | if not netId and store.bones.localEntities and store.bones.localEntities[entity] then
217 | for boneId, options in pairs(store.bones.localEntities[entity]) do
218 | if #options > 0 then
219 | boneOptions[boneId] = boneOptions[boneId] or {}
220 | boneOptions[boneId].localEntity = options
221 | hasOptions = true
222 | end
223 | end
224 | end
225 |
226 | return hasOptions and boneOptions or nil
227 | end
228 |
229 | ---@param entity number
230 | ---@param globalType string
231 | ---@return table | nil
232 | local function getOffsetOptionsForEntity(entity, globalType)
233 | if not entity then return nil end
234 | local model, netId = cachedEntityInfo(entity)
235 | local offsetOptions = {}
236 | local hasOptions = false
237 |
238 | if store.offsets[globalType] then
239 | for offsetStr, options in pairs(store.offsets[globalType]) do
240 | if #options > 0 then
241 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {}
242 | offsetOptions[offsetStr].global = options
243 | hasOptions = true
244 | end
245 | end
246 | end
247 |
248 | if store.offsets.models and store.offsets.models[model] then
249 | for offsetStr, options in pairs(store.offsets.models[model]) do
250 | if #options > 0 then
251 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {}
252 | offsetOptions[offsetStr].model = options
253 | hasOptions = true
254 | end
255 | end
256 | end
257 |
258 | if netId and store.offsets.entities and store.offsets.entities[netId] then
259 | for offsetStr, options in pairs(store.offsets.entities[netId]) do
260 | if #options > 0 then
261 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {}
262 | offsetOptions[offsetStr].entity = options
263 | hasOptions = true
264 | end
265 | end
266 | end
267 |
268 | if not netId and store.offsets.localEntities and store.offsets.localEntities[entity] then
269 | for offsetStr, options in pairs(store.offsets.localEntities[entity]) do
270 | if #options > 0 then
271 | offsetOptions[offsetStr] = offsetOptions[offsetStr] or {}
272 | offsetOptions[offsetStr].localEntity = options
273 | hasOptions = true
274 | end
275 | end
276 | end
277 |
278 | return hasOptions and offsetOptions or nil
279 | end
280 |
281 | ---@param coords vector3
282 | ---@return NearbyItem[]
283 | local function checkNearbyEntities(coords)
284 | local valid = {}
285 | local num = 0
286 |
287 | local function processEntities(entities, globalType)
288 | for i = 1, #entities do
289 | local ent = entities[i]
290 | local entity = ent.object or ent.vehicle or ent.ped
291 | local model = cachedEntityInfo(entity)
292 | local entCoords = GetEntityCoords(entity)
293 | local options = getOptionsForEntity(entity, globalType)
294 | local boneOptions = getBoneOptionsForEntity(entity, globalType)
295 | local offsetOptions = getOffsetOptionsForEntity(entity, globalType)
296 |
297 |
298 | if options then
299 | num = num + 1
300 | valid[num] = {
301 | entity = entity,
302 | coords = entCoords,
303 | currentDistance = #(coords - entCoords),
304 | currentScreenDistance = utils.getScreenDistanceSquared(entCoords),
305 | options = options
306 | }
307 | end
308 |
309 | if boneOptions then
310 | for boneId, _options in pairs(boneOptions) do
311 | local boneIndex = GetEntityBoneIndexByName(entity, boneId)
312 | if boneIndex ~= -1 then
313 | local boneCoords = GetEntityBonePosition_2(entity, boneIndex)
314 | num = num + 1
315 | valid[num] = {
316 | entity = entity,
317 | bone = boneId,
318 | coords = boneCoords,
319 | currentDistance = #(coords - boneCoords),
320 | currentScreenDistance = utils.getScreenDistanceSquared(boneCoords),
321 | options = _options
322 | }
323 | end
324 | end
325 | end
326 |
327 | if offsetOptions then
328 | for offsetStr, _options in pairs(offsetOptions) do
329 | local x, y, z, offsetType = utils.getCoordsAndTypeFromOffsetId(offsetStr)
330 | if x and y and z and offsetType then
331 | local offset = vec3(tonumber(x), tonumber(y), tonumber(z))
332 | local worldPos
333 | if offsetType == "offset" then
334 | local min, max = GetModelDimensions(model)
335 | offset = (max - min) * offset + min
336 | end
337 | worldPos = GetOffsetFromEntityInWorldCoords(entity, offset.x, offset.y, offset.z)
338 | num = num + 1
339 | valid[num] = {
340 | entity = entity,
341 | offset = offsetStr,
342 | coords = worldPos,
343 | currentDistance = #(coords - worldPos),
344 | currentScreenDistance = utils.getScreenDistanceSquared(worldPos),
345 | options = _options
346 | }
347 | end
348 | end
349 | end
350 | end
351 | end
352 |
353 | processEntities(getNearbyObjects(coords, 4.0), 'objects')
354 | processEntities(getNearbyVehicles(coords, 4.0), 'vehicles')
355 | processEntities(getNearbyPlayers(coords, 4.0, false), 'players')
356 | processEntities(getNearbyPeds(coords, 4.0), 'peds')
357 |
358 | return valid
359 | end
360 |
361 | ---@param coords vector3
362 | ---@param update NearbyItem[]
363 | ---@return NearbyItem[]
364 | local function checkNearbyCoords(coords, update)
365 | for id, _coords in pairs(store.coordIds) do
366 | local dist = #(coords - _coords)
367 | if dist < config.maxInteractDistance then
368 | update[#update + 1] = {
369 | coords = _coords,
370 | currentDistance = dist,
371 | currentScreenDistance = utils.getScreenDistanceSquared(_coords),
372 | coordId = id,
373 | options = { coords = store.coords[id] }
374 | }
375 | end
376 | end
377 | return update
378 | end
379 |
380 |
381 | local function shouldHideInteract()
382 | if IsNuiFocused() or LocalPlayer.state.hideInteract or (lib and lib.progressActive()) or hidePerKeybind or LocalPlayer.state.invOpen then
383 | return true
384 | end
385 | return false
386 | end
387 |
388 | local activeOptions = {}
389 |
390 | local aspectRatio = GetAspectRatio(true)
391 | local function drawLoop()
392 | if drawLoopRunning then return end
393 | drawLoopRunning = true
394 |
395 | lib.requestStreamedTextureDict(config.IndicatorSprite.dict)
396 | local lastClosestItem, lastValidCount, lastValidOptions = nil, 0, nil
397 | local nearbyData = {}
398 | local playerCoords
399 |
400 | local entityStartCoords = {}
401 | local movingEntity = {}
402 |
403 | CreateThread(function()
404 | while drawLoopRunning do
405 | if shouldHideInteract() then
406 | table.wipe(store.nearby)
407 | break
408 | end
409 |
410 | playerCoords = GetEntityCoords(cache.ped)
411 | nearbyData = {}
412 | for i = 1, #store.nearby do
413 | local item = store.nearby[i]
414 |
415 | local coords = utils.getDrawCoordsForInteract(item)
416 |
417 | if coords then
418 | if item.entity then
419 | if not entityStartCoords[item.entity] then
420 | entityStartCoords[item.entity] = coords
421 | end
422 |
423 | if coords ~= entityStartCoords then
424 | movingEntity[item.entity] = true
425 | end
426 | end
427 |
428 | local distance = #(playerCoords - coords)
429 | local validOpts, validCount, hideCompletely = filterValidOptions(item.options, item.entity, distance, coords)
430 | local id = item.bone or item.offset or item.entity or item.coordId
431 | local shouldUpdate = false
432 |
433 | if id == lastClosestItem then
434 | if lastValidOptions then
435 | shouldUpdate = not lib.table.matches(validOpts, lastValidOptions)
436 | end
437 | end
438 |
439 | nearbyData[i] = {
440 | item = item,
441 | coords = coords,
442 | shouldUpdate = shouldUpdate,
443 | hideCompletely = hideCompletely,
444 | distance = distance,
445 | validOpts = validOpts,
446 | validCount = validCount
447 | }
448 | end
449 | end
450 | Wait(150)
451 | end
452 | end)
453 |
454 | while #store.nearby > 0 do
455 | Wait(0)
456 | local foundValid = false
457 |
458 | for i = 1, #store.nearby do
459 | local data = nearbyData[i]
460 |
461 | if data and data.coords and not data.hideCompletely then
462 | local item = data.item
463 | local coords = (item.entity and not movingEntity[item.entity] and data.coords) or utils.getDrawCoordsForInteract(item)
464 |
465 | SetDrawOrigin(coords.x, coords.y, coords.z)
466 |
467 | if not foundValid and data.validOpts and data.validCount > 0 then
468 | foundValid = true
469 |
470 | DrawSprite(dui.instance.dictName, dui.instance.txtName, 0.0, 0.0, 1.0, 1.0, 0.0, 255, 255, 255, 255)
471 | local newClosestId = item.bone or item.offset or item.entity or item.coordId
472 | if data.shouldUpdate or lastClosestItem ~= newClosestId or lastValidCount ~= data.validCount then
473 | local newOptions = {}
474 |
475 | if data.validOpts then
476 | for _, opts in pairs(data.validOpts) do
477 | for j = 1, #opts do
478 | local opt = opts[j]
479 | newOptions[opt] = true
480 | if not activeOptions[opt] then
481 | activeOptions[opt] = true
482 | local resp = (opt.onActive or opt.whileActive) and utils.getResponse(opt)
483 |
484 | if opt.onActive then
485 | pcall(opt.onActive, resp)
486 | end
487 |
488 | if opt.whileActive then
489 | CreateThread(function()
490 | while activeOptions[opt] do
491 | pcall(opt.whileActive, resp)
492 | Wait(0)
493 | end
494 | end)
495 | end
496 | end
497 | end
498 | end
499 | end
500 |
501 | if lastValidOptions then
502 | for _, opts in pairs(lastValidOptions) do
503 | for j = 1, #opts do
504 | local opt = opts[j]
505 |
506 | if opt.onInactive and not newOptions[opt] and activeOptions[opt] then
507 | pcall(opt.onInactive, utils.getResponse(opt))
508 | activeOptions[opt] = nil
509 | end
510 | end
511 | end
512 | end
513 |
514 | local resetIndex = lastClosestItem ~= newClosestId
515 | lastClosestItem = newClosestId
516 | lastValidCount = data.validCount
517 | lastValidOptions = data.validOpts
518 |
519 | store.current = {
520 | options = data.validOpts,
521 | entity = item.entity,
522 | distance = data.distance,
523 | coords = coords,
524 | index = 1,
525 | }
526 | dui.sendMessage('setOptions', { options = data.validOpts, resetIndex = resetIndex })
527 | end
528 | else
529 | local distance = #(playerCoords - coords)
530 | if distance < config.maxInteractDistance and item.currentScreenDistance < math.huge then
531 | local distanceRatio = math.min(0.5 + (0.25 * (distance / 10.0)), 1.0)
532 | local scale = 0.025 * distanceRatio
533 | DrawSprite(config.IndicatorSprite.dict, config.IndicatorSprite.txt, 0.0, 0.0, scale, scale * aspectRatio, 0.0, r, g, b, a)
534 | end
535 | end
536 |
537 | ClearDrawOrigin()
538 | end
539 | end
540 |
541 | if not foundValid and next(store.current) then
542 | for _, opts in pairs(store.current.options) do
543 | for j = 1, #opts do
544 | local opt = opts[j]
545 |
546 | if opt.onInactive and activeOptions[opt] then
547 | pcall(opt.onInactive, utils.getResponse(opt))
548 | activeOptions[opt] = nil
549 | end
550 | end
551 | end
552 | store.current = {}
553 | lastClosestItem = nil
554 | end
555 | end
556 |
557 | drawLoopRunning = false
558 | end
559 |
560 | local function BuilderLoop()
561 | while true do
562 | if shouldHideInteract() then
563 | table.wipe(store.nearby)
564 | else
565 | local coords = GetEntityCoords(cache.ped)
566 | local update = checkNearbyEntities(coords)
567 | update = checkNearbyCoords(coords, update)
568 |
569 | store.nearby = update
570 |
571 | table.sort(store.nearby, function(a, b)
572 | return a.currentScreenDistance < b.currentScreenDistance
573 | end)
574 |
575 | if #store.nearby > 0 and not drawLoopRunning then
576 | CreateThread(drawLoop)
577 | end
578 | end
579 | Wait(1000)
580 | end
581 | end
582 |
583 | RegisterNUICallback('select', function(data, cb)
584 | local currentTime = GetGameTimer()
585 | if store.current.options and currentTime > (store.cooldownEndTime or 0) then
586 | local option = store.current.options?[data[1]]?[data[2]]
587 | if option then
588 | if option.onSelect then
589 | option.onSelect(option.qtarget and store.current.entity or utils.getResponse(option))
590 | elseif option.export then
591 | exports[option.resource][option.export](nil, utils.getResponse(option))
592 | elseif option.event then
593 | TriggerEvent(option.event, utils.getResponse(option))
594 | elseif option.serverEvent then
595 | TriggerServerEvent(option.serverEvent, utils.getResponse(option, true))
596 | elseif option.command then
597 | ExecuteCommand(option.command)
598 | end
599 | local cooldown = option.cooldown or 1500
600 | store.cooldownEndTime = currentTime + cooldown
601 | if cooldown > 0 then
602 | dui.sendMessage('setCooldown', true)
603 | Wait(cooldown)
604 | dui.sendMessage('setCooldown', false)
605 | end
606 | end
607 | end
608 | cb(1)
609 | end)
610 |
611 | CreateThread(BuilderLoop)
612 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |