diff --git a/resources/[ps]/ps-inventory/LICENSE b/resources/[ps]/ps-inventory/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/resources/[ps]/ps-inventory/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/resources/[ps]/ps-inventory/README.md b/resources/[ps]/ps-inventory/README.md new file mode 100644 index 0000000..7fa402a --- /dev/null +++ b/resources/[ps]/ps-inventory/README.md @@ -0,0 +1,114 @@ +# PS-Inventory + +lj-Inventory has been fully redesigned by [OK1ez](https://github.com/OK1ez), under the name ps-inventory. + +Future updates will be coming and we will of course support all normal monitor sizes. + +# Previews + +### Simple item guidelines (found in main directory ps-inventory) + +![ps-inventory Guideline](https://user-images.githubusercontent.com/91661118/146315681-c67f542d-e2bc-43ca-9957-7f1971b84268.png) + +### Full Inventory + +![image](https://github.com/Project-Sloth/ps-inventory/assets/82112471/fda2588d-e468-4fd5-8bf5-2f584f059609) + +### Options Menu + +![image](https://github.com/Project-Sloth/ps-inventory/assets/82112471/1782f97a-27e6-441b-90a1-ff150cd846e2) + +### Hotbar Slots + +![image](https://github.com/Project-Sloth/ps-inventory/assets/82112471/c0a77f4a-f482-42f5-a5da-1f3571d14130) + +### Inventory Glovebox + +![image](https://github.com/Project-Sloth/ps-inventory/assets/82112471/432f8c79-1a9f-44d1-8062-50b596194752) + +### Inventory Trunk + +![image](https://github.com/Project-Sloth/ps-inventory/assets/82112471/f9c78e49-ec51-4d55-9ac0-b7058951d31a) + +# Key Features + +* ALL IMAGES FOLLOW THE SAME DIMENSIONS +* Easy Photoshop guideline template for creating custom images within ps-inventory +* Custom brand logo above option buttons +* Options menu +* Help box +* Custom inventory images (more always being added in each new update) +* Default weight icon easily changeable with Font Awesome icons +* Hotkey numbers visible in inventory and hotbar slots +* Weight progress bar +* Tooltip has a determined height (so it won't ever go higher than visible or cut off) +* Text overflow ellipsis used (so your product titles with never overlap the containers and instead do "...") +* Blurred inventory background +* Elements of NoPixel 3.5 design ideas interwoven + +# How to install ps-inventory (Latest QBCore Update) + +* Download `ps-inventory` from our GitHub +* Make sure you have the latest update of [qb-core](https://github.com/qbcore-framework/qb-core) +* Make sure you have the latest update of [qb-smallresources](https://github.com/qbcore-framework/qb-smallresources) +* Make sure you have the latest update of [qb-weapons](https://github.com/qbcore-framework/qb-weapons) +* Drag `ps-inventory` into your resources folder or any subfolder +* Make sure that the folder is named `ps-inventory` and **not** `ps-inventory-main` +* Replace all occurrences of `qb-inventory` with `ps-inventory`.
The example below uses Visual Studio Code to replace all instances. + +![image](https://github.com/Z3rio/ps-inventory/assets/54480523/00fa21a5-4be2-443f-aff2-4b3202b662dc) + +## Set up the decay system + +If you want the decay system to work, then please read the information below, otherwise it won't work. + +You need to add a decay value for all items in your `qb-core/shared/items.lua` file, the variable stands for the number of days it takes to decay. + +### Examples: + +#### Example of what you have to add + +```lua +-- decay = The number of days it takes for an item to decay +-- delete = If set to true, the item will be removed once it decays +["decay"] = 28.0, ["delete"] = true +``` + +#### Example with the full item in QB-Core's shared file + +```lua +['sandwich'] = {['name'] = 'sandwich', ['label'] = 'Sandwich', ['weight'] = 200, ['type'] = 'item', ['image'] = 'sandwich.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Nice bread for your stomach', ["decay"] = 3.0, ["delete"] = true}, +``` + +In this example, the sandwich item would take 3 days to decay and once it does, it would be removed. + +# Dependencies + +* [qbcore framework](https://github.com/qbcore-framework) +* [qb-target](https://github.com/BerkieBb/qb-target) +* [qb-core](https://github.com/qbcore-framework/qb-core) +* [qb-logs](https://github.com/qbcore-framework/qb-logs) +* [qb-traphouse](https://github.com/qbcore-framework/qb-traphouse) +* [qb-radio](https://github.com/qbcore-framework/qb-radio) +* [qb-drugs](https://github.com/qbcore-framework/qb-drugs) +* [qb-shops](https://github.com/qbcore-framework/qb-shops) + +## Performance + +Runs at ~ 0.00 to 0.01 ms if you have more optimization suggestions feel free to reach out + +# Credits + +* [OK1ez](https://github.com/OK1ez) for full redesign. +* ihyajb (Aj) for [original version](https://github.com/ihyajb/aj-inventory) +* Jay for [decay](https://github.com/tnj-development/inventory) +* i-kulgu for [updated decay](https://github.com/i-kulgu/qb-inventory-decay) +* [OnlyCats](https://github.com/onlycats) who helped reorganize and also created some custom images. + +# Issues and Suggestions + +Please use the GitHub issues system to report issues or make suggestions, when making suggestions, please keep [Suggestion] in the title to make it clear that it is a suggestion. + +## Connect with us + +Join our [**Discord**](https://discord.gg/projectsloth) for updates, support, and special early testing! diff --git a/resources/[ps]/ps-inventory/client/main.lua b/resources/[ps]/ps-inventory/client/main.lua new file mode 100644 index 0000000..fccc7b0 --- /dev/null +++ b/resources/[ps]/ps-inventory/client/main.lua @@ -0,0 +1,1123 @@ +-- Variables +local QBCore = exports['qb-core']:GetCoreObject() +local PlayerData = QBCore.Functions.GetPlayerData() +local inInventory = false +local currentWeapon = nil +local currentOtherInventory = nil +local Drops = {} +local CurrentDrop = nil +local DropsNear = {} +local CurrentVehicle = nil +local CurrentGlovebox = nil +local CurrentStash = nil +local isCrafting = false +local isHotbar = false +local WeaponAttachments = {} +local showBlur = true + +local function HasItem(items, amount) + local isTable = type(items) == 'table' + local isArray = isTable and table.type(items) == 'array' or false + local totalItems = #items + local count = 0 + local kvIndex = 2 + if isTable and not isArray then + totalItems = 0 + for _ in pairs(items) do totalItems += 1 end + kvIndex = 1 + end + for _, itemData in pairs(PlayerData.items) do + if isTable then + for k, v in pairs(items) do + local itemKV = {k, v} + if itemData and itemData.name == itemKV[kvIndex] and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then + count += 1 + end + end + if count == totalItems then + return true + end + else -- Single item as string + if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then + return true + end + end + end + return false +end + +exports("HasItem", HasItem) + +RegisterNUICallback('showBlur', function() + Wait(50) + TriggerEvent("ps-inventory:client:showBlur") +end) +RegisterNetEvent("ps-inventory:client:showBlur", function() + Wait(50) + showBlur = not showBlur +end) + +-- Functions + +local function GetClosestVending() + local ped = PlayerPedId() + local pos = GetEntityCoords(ped) + local object = nil + for _, machine in pairs(Config.VendingObjects) do + local ClosestObject = GetClosestObjectOfType(pos.x, pos.y, pos.z, 0.75, GetHashKey(machine), 0, 0, 0) + if ClosestObject ~= 0 then + if object == nil then + object = ClosestObject + end + end + end + return object +end + +local function OpenVending() + local ShopItems = {} + ShopItems.label = "Automat" + ShopItems.items = Config.VendingItem + ShopItems.slots = #Config.VendingItem + TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems) +end + +local function DrawText3Ds(x, y, z, text) + SetTextScale(0.35, 0.35) + SetTextFont(4) + SetTextProportional(1) + SetTextColour(255, 255, 255, 215) + SetTextEntry("STRING") + SetTextCentre(true) + AddTextComponentString(text) + SetDrawOrigin(x,y,z, 0) + DrawText(0.0, 0.0) + local factor = (string.len(text)) / 370 + DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75) + ClearDrawOrigin() +end + +local function LoadAnimDict(dict) + if HasAnimDictLoaded(dict) then return end + + RequestAnimDict(dict) + while not HasAnimDictLoaded(dict) do + Wait(10) + end +end + +local function FormatWeaponAttachments(itemdata) + local attachments = {} + itemdata.name = itemdata.name:upper() + if itemdata.info.attachments ~= nil and next(itemdata.info.attachments) ~= nil then + for _, v in pairs(itemdata.info.attachments) do + attachments[#attachments+1] = { + attachment = v.item, + label = v.label, + image = QBCore.Shared.Items[v.item].image, + component = v.component + } + end + end + return attachments +end + +local function IsBackEngine(vehModel) + return BackEngineVehicles[vehModel] +end + + +local function OpenTrunk() + local vehicle = QBCore.Functions.GetClosestVehicle() + LoadAnimDict("amb@prop_human_bum_bin@idle_b") + TaskPlayAnim(PlayerPedId(), "amb@prop_human_bum_bin@idle_b", "idle_d", 4.0, 4.0, -1, 50, 0, false, false, false) + if IsBackEngine(GetEntityModel(vehicle)) then + SetVehicleDoorOpen(vehicle, 4, false, false) + else + SetVehicleDoorOpen(vehicle, 5, false, false) + end +end + +---Closes the trunk of the closest vehicle +local function CloseTrunk() + local vehicle = QBCore.Functions.GetClosestVehicle() + LoadAnimDict("amb@prop_human_bum_bin@idle_b") + TaskPlayAnim(PlayerPedId(), "amb@prop_human_bum_bin@idle_b", "exit", 4.0, 4.0, -1, 50, 0, false, false, false) + if IsBackEngine(GetEntityModel(vehicle)) then + SetVehicleDoorShut(vehicle, 4, false) + else + SetVehicleDoorShut(vehicle, 5, false) + end +end + +---Closes the inventory NUI +local function closeInventory() + SendNUIMessage({ + action = "close", + }) +end + +local function ToggleHotbar(toggle) + local HotbarItems = { + [1] = PlayerData.items[1], + [2] = PlayerData.items[2], + [3] = PlayerData.items[3], + [4] = PlayerData.items[4], + [5] = PlayerData.items[5], + [41] = PlayerData.items[41], + } + + SendNUIMessage({ + action = "toggleHotbar", + open = toggle, + items = HotbarItems + }) +end + + +local function openAnim() + local ped = PlayerPedId() + LoadAnimDict('pickup_object') + TaskPlayAnim(ped,'pickup_object', 'putdown_low', 5.0, 1.5, 1.0, 48, 0.0, 0, 0, 0) + Wait(500) + StopAnimTask(ped, 'pickup_object', 'putdown_low', 1.0) +end + +local function ItemsToItemInfo() + local item_count = 0 + for _, _ in pairs(Config.CraftingItems) do + item_count = item_count + 1 + end + + local itemInfos = {} + + for i = 1, item_count do + local ex_string = "" + + for key, value in pairs(Config.CraftingItems[i].costs) do + ex_string = ex_string .. QBCore.Shared.Items[key]["label"] .. ": " .. value .. "x " + end + + itemInfos[i] = { costs = ex_string } + end + + local items = {} + for _, item in pairs(Config.CraftingItems) do + local itemInfo = QBCore.Shared.Items[item.name:lower()] + items[item.slot] = { + name = itemInfo["name"], + amount = tonumber(item.amount), + info = itemInfos[item.slot], + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + slot = item.slot, + costs = item.costs, + threshold = item.threshold, + points = item.points, + } + end + Config.CraftingItems = items +end + +local function SetupAttachmentItemsInfo() + local item_count = 0 + for _, _ in pairs(Config.AttachmentCrafting) do + item_count = item_count + 1 + end + + local itemInfos = {} + + for i = 1, item_count do + local ex_string = "" + + for key, value in pairs(Config.AttachmentCrafting[i].costs) do + ex_string = ex_string .. QBCore.Shared.Items[key]["label"] .. ": " .. value .. "x " + end + + itemInfos[i] = { costs = ex_string } + end + + local items = {} + for _, item in pairs(Config.AttachmentCrafting) do + local itemInfo = QBCore.Shared.Items[item.name:lower()] + items[item.slot] = { + name = itemInfo["name"], + amount = tonumber(item.amount), + info = itemInfos[item.slot], + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + slot = item.slot, + costs = item.costs, + threshold = item.threshold, + points = item.points, + } + end + Config.AttachmentCrafting = items +end + + +local function GetThresholdItems() + ItemsToItemInfo() + local items = {} + for k in pairs(Config.CraftingItems) do + if PlayerData.metadata["craftingrep"] >= Config.CraftingItems[k].threshold then + items[k] = Config.CraftingItems[k] + end + end + return items +end + + +local function GetAttachmentThresholdItems() + SetupAttachmentItemsInfo() + local items = {} + for k in pairs(Config.AttachmentCrafting) do + if PlayerData.metadata["attachmentcraftingrep"] >= Config.AttachmentCrafting[k].threshold then + items[k] = Config.AttachmentCrafting[k] + end + end + return items +end + +local function RemoveNearbyDrop(index) + if not DropsNear[index] then return end + + local dropItem = DropsNear[index].object + if DoesEntityExist(dropItem) then + DeleteEntity(dropItem) + end + + DropsNear[index] = nil + + if not Drops[index] then return end + + Drops[index].object = nil + Drops[index].isDropShowing = nil +end + +---Removes all drops in the area of the client +local function RemoveAllNearbyDrops() + for k in pairs(DropsNear) do + RemoveNearbyDrop(k) + end +end + + +local function CreateItemDrop(index) + local dropItem = CreateObject(Config.ItemDropObject, DropsNear[index].coords.x, DropsNear[index].coords.y, DropsNear[index].coords.z, false, false, false) + DropsNear[index].object = dropItem + DropsNear[index].isDropShowing = true + PlaceObjectOnGroundProperly(dropItem) + FreezeEntityPosition(dropItem, true) + if Config.UseTarget then + exports['qb-target']:AddTargetEntity(dropItem, { + options = { + { + icon = 'fa-solid fa-bag-shopping', + label = "Åben taske", + action = function() + TriggerServerEvent("inventory:server:OpenInventory", "drop", index) + end, + } + }, + distance = 2.5, + }) + end +end + +-- Events + +RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() + LocalPlayer.state:set("inv_busy", false, true) + PlayerData = QBCore.Functions.GetPlayerData() + QBCore.Functions.TriggerCallback("inventory:server:GetCurrentDrops", function(theDrops) + Drops = theDrops + end) +end) + +RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() + LocalPlayer.state:set("inv_busy", true, true) + PlayerData = {} + RemoveAllNearbyDrops() +end) + +RegisterNetEvent('QBCore:Client:UpdateObject', function() + QBCore = exports['qb-core']:GetCoreObject() +end) + +RegisterNetEvent('QBCore:Player:SetPlayerData', function(val) + PlayerData = val +end) + +AddEventHandler('onResourceStop', function(name) + if name ~= GetCurrentResourceName() then return end + if Config.UseItemDrop then RemoveAllNearbyDrops() end +end) + +RegisterNetEvent('inventory:client:CheckOpenState', function(type, id, label) + local name = QBCore.Shared.SplitStr(label, "-")[2] + if type == "stash" then + if name ~= CurrentStash or CurrentStash == nil then + TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id) + end + elseif type == "trunk" then + if name ~= CurrentVehicle or CurrentVehicle == nil then + TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id) + end + elseif type == "glovebox" then + if name ~= CurrentGlovebox or CurrentGlovebox == nil then + TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id) + end + elseif type == "drop" then + if name ~= CurrentDrop or CurrentDrop == nil then + TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id) + end + end +end) + +RegisterNetEvent('inventory:client:ItemBox', function(itemData, type, amount) + amount = amount or 1 + SendNUIMessage({ + action = "itemBox", + item = itemData, + type = type, + itemAmount = amount + }) +end) + +RegisterNetEvent('inventory:client:requiredItems', function(items, bool) + local itemTable = {} + if bool then + for k in pairs(items) do + itemTable[#itemTable+1] = { + item = items[k].name, + label = QBCore.Shared.Items[items[k].name]["label"], + image = items[k].image, + } + end + end + + SendNUIMessage({ + action = "requiredItem", + items = itemTable, + toggle = bool + }) +end) + +RegisterNetEvent('inventory:server:RobPlayer', function(TargetId) + SendNUIMessage({ + action = "RobMoney", + TargetId = TargetId, + }) +end) + +RegisterNetEvent('inventory:client:OpenInventory', function(PlayerAmmo, inventory, other) + if not IsEntityDead(PlayerPedId()) then + if Config.Progressbar.Enable then + QBCore.Functions.Progressbar('open_inventory', 'Åbner inventar...', math.random(Config.Progressbar.minT, Config.Progressbar.maxT), false, true, { -- Name | Label | Time | useWhileDead | canCancel + disableMovement = false, + disableCarMovement = false, + disableMouse = false, + disableCombat = false, + }, {}, {}, {}, function() -- Play When Done + ToggleHotbar(false) + if showBlur == true then + TriggerScreenblurFadeIn(1000) + end + SetNuiFocus(true, true) + if other then + currentOtherInventory = other.name + end + QBCore.Functions.TriggerCallback('inventory:server:ConvertQuality', function(data) + inventory = data.inventory + other = data.other + SendNUIMessage({ + action = "open", + inventory = inventory, + slots = Config.MaxInventorySlots, + other = other, + maxweight = Config.MaxInventoryWeight, + Ammo = PlayerAmmo, + maxammo = Config.MaximumAmmoValues, + Name = PlayerData.charinfo.firstname .." ".. PlayerData.charinfo.lastname .." - [".. GetPlayerServerId(PlayerId()) .."]", + }) + inInventory = true + end, inventory, other) + + end) + else + Wait(500) + ToggleHotbar(false) + if showBlur == true then + TriggerScreenblurFadeIn(1000) + end + SetNuiFocus(true, true) + if other then + currentOtherInventory = other.name + end + QBCore.Functions.TriggerCallback('inventory:server:ConvertQuality', function(data) + inventory = data.inventory + other = data.other + SendNUIMessage({ + action = "open", + inventory = inventory, + slots = Config.MaxInventorySlots, + other = other, + maxweight = Config.MaxInventoryWeight, + Ammo = PlayerAmmo, + maxammo = Config.MaximumAmmoValues, + Name = PlayerData.charinfo.firstname .." ".. PlayerData.charinfo.lastname .." - [".. GetPlayerServerId(PlayerId()) .."]", + }) + inInventory = true + end,inventory,other) + end + end +end) + +RegisterNetEvent('inventory:client:UpdateOtherInventory', function(items, isError) + SendNUIMessage({ + action = "update", + inventory = items, + maxweight = Config.MaxInventoryWeight, + slots = Config.MaxInventorySlots, + error = isError, + }) +end) + +RegisterNetEvent('inventory:client:UpdatePlayerInventory', function(isError) + SendNUIMessage({ + action = "update", + inventory = PlayerData.items, + maxweight = Config.MaxInventoryWeight, + slots = Config.MaxInventorySlots, + error = isError, + }) +end) + +RegisterNetEvent('inventory:client:CraftItems', function(itemName, itemCosts, amount, toSlot, points) + local ped = PlayerPedId() + SendNUIMessage({ + action = "close", + }) + isCrafting = true + QBCore.Functions.Progressbar("repair_vehicle", "Crafter..", (math.random(2000, 5000) * amount), false, true, { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + }, { + animDict = "mini@repair", + anim = "fixing_a_player", + flags = 16, + }, {}, {}, function() -- Done + StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0) + TriggerServerEvent("inventory:server:CraftItems", itemName, itemCosts, amount, toSlot, points) + TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items[itemName], 'add') + isCrafting = false + end, function() -- Cancel + StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0) + QBCore.Functions.Notify("Failed", "error") + isCrafting = false + end) +end) + +RegisterNetEvent('inventory:client:CraftAttachment', function(itemName, itemCosts, amount, toSlot, points) + local ped = PlayerPedId() + SendNUIMessage({ + action = "close", + }) + isCrafting = true + QBCore.Functions.Progressbar("repair_vehicle", "Crafter..", (math.random(2000, 5000) * amount), false, true, { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + }, { + animDict = "mini@repair", + anim = "fixing_a_player", + flags = 16, + }, {}, {}, function() -- Done + StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0) + TriggerServerEvent("inventory:server:CraftAttachment", itemName, itemCosts, amount, toSlot, points) + TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items[itemName], 'add') + isCrafting = false + end, function() -- Cancel + StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0) + QBCore.Functions.Notify("Failed", "error") + isCrafting = false + end) +end) + +RegisterNetEvent('inventory:client:PickupSnowballs', function() + local ped = PlayerPedId() + LoadAnimDict('anim@mp_snowball') + TaskPlayAnim(ped, 'anim@mp_snowball', 'pickup_snowball', 3.0, 3.0, -1, 0, 1, 0, 0, 0) + QBCore.Functions.Progressbar("pickupsnowball", "Collecting snowballs..", 1500, false, true, { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + }, {}, {}, {}, function() -- Done + ClearPedTasks(ped) + TriggerServerEvent('inventory:server:snowball', 'add') + TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["snowball"], "add") + end, function() -- Cancel + ClearPedTasks(ped) + QBCore.Functions.Notify("Canceled", "error") + end) +end) + +RegisterNetEvent('inventory:client:UseSnowball', function(amount) + local ped = PlayerPedId() + GiveWeaponToPed(ped, `weapon_snowball`, amount, false, false) + SetPedAmmo(ped, `weapon_snowball`, amount) + SetCurrentPedWeapon(ped, `weapon_snowball`, true) +end) + +RegisterNetEvent('inventory:client:UseWeapon', function(weaponData, shootbool) + local ped = PlayerPedId() + local weaponName = tostring(weaponData.name) + local weaponHash = joaat(weaponData.name) + local weaponinhand = GetCurrentPedWeapon(PlayerPedId()) + if currentWeapon == weaponName and weaponinhand then + TriggerEvent('weapons:client:DrawWeapon', nil) + SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true) + RemoveAllPedWeapons(ped, true) + TriggerEvent('weapons:client:SetCurrentWeapon', nil, shootbool) + currentWeapon = nil + elseif weaponName == "weapon_stickybomb" or weaponName == "weapon_pipebomb" or weaponName == "weapon_smokegrenade" or weaponName == "weapon_flare" or weaponName == "weapon_proxmine" or weaponName == "weapon_ball" or weaponName == "weapon_molotov" or weaponName == "weapon_grenade" or weaponName == "weapon_bzgas" then + TriggerEvent('weapons:client:DrawWeapon', weaponName) + GiveWeaponToPed(ped, weaponHash, 1, false, false) + SetPedAmmo(ped, weaponHash, 1) + SetCurrentPedWeapon(ped, weaponHash, true) + TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool) + currentWeapon = weaponName + elseif weaponName == "weapon_snowball" then + TriggerEvent('weapons:client:DrawWeapon', weaponName) + GiveWeaponToPed(ped, weaponHash, 10, false, false) + SetPedAmmo(ped, weaponHash, 10) + SetCurrentPedWeapon(ped, weaponHash, true) + TriggerServerEvent('inventory:server:snowball', 'remove') + TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool) + currentWeapon = weaponName + else + TriggerEvent('weapons:client:DrawWeapon', weaponName) + TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool) + local ammo = tonumber(weaponData.info.ammo) or 0 + + if weaponName == "weapon_fireextinguisher" then + ammo = 4000 + end + + GiveWeaponToPed(ped, weaponHash, ammo, false, false) + SetPedAmmo(ped, weaponHash, ammo) + SetCurrentPedWeapon(ped, weaponHash, true) + + if weaponData.info.attachments then + for _, attachment in pairs(weaponData.info.attachments) do + GiveWeaponComponentToPed(ped, weaponHash, joaat(attachment.component)) + end + end + + currentWeapon = weaponName + end +end) + +RegisterNetEvent('inventory:client:CheckWeapon', function(weaponName) + if currentWeapon ~= weaponName:lower() then return end + local ped = PlayerPedId() + TriggerEvent('weapons:ResetHolster') + SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true) + RemoveAllPedWeapons(ped, true) + currentWeapon = nil +end) + +RegisterNetEvent('inventory:client:AddDropItem', function(dropId, player, coords) + local forward = GetEntityForwardVector(GetPlayerPed(GetPlayerFromServerId(player))) + local x, y, z = table.unpack(coords + forward * 0.5) + Drops[dropId] = { + id = dropId, + coords = { + x = x, + y = y, + z = z - 0.3, + }, + } +end) + +RegisterNetEvent('inventory:client:RemoveDropItem', function(dropId) + Drops[dropId] = nil + if Config.UseItemDrop then + RemoveNearbyDrop(dropId) + else + DropsNear[dropId] = nil + end +end) + +RegisterNetEvent('inventory:client:DropItemAnim', function() + local ped = PlayerPedId() + SendNUIMessage({ + action = "close", + }) + RequestAnimDict("pickup_object") + while not HasAnimDictLoaded("pickup_object") do + Wait(7) + end + TaskPlayAnim(ped, "pickup_object" ,"pickup_low" ,8.0, -8.0, -1, 1, 0, false, false, false ) + Wait(2000) + ClearPedTasks(ped) +end) + +RegisterNetEvent('inventory:client:SetCurrentStash', function(stash) + CurrentStash = stash +end) + + +RegisterNetEvent('inventory:client:craftTarget',function() + local crafting = {} + crafting.label = "Crafting" + crafting.items = GetThresholdItems() + TriggerServerEvent("inventory:server:OpenInventory", "crafting", math.random(1, 99), crafting) +end) + +-- Commands + +RegisterCommand('closeinv', function() + closeInventory() +end, false) + +RegisterNetEvent("ps-inventory:client:closeinv", function() + closeInventory() +end) + +RegisterCommand('inventory', function() + if IsNuiFocused() then return end + if not isCrafting and not inInventory then + if not PlayerData.metadata["isdead"] and not PlayerData.metadata["inlaststand"] and not PlayerData.metadata["ishandcuffed"] and not IsPauseMenuActive() then + local ped = PlayerPedId() + local curVeh = nil + local VendingMachine = nil + if not Config.UseTarget then VendingMachine = GetClosestVending() end + + if IsPedInAnyVehicle(ped, false) then -- Is Player In Vehicle + local vehicle = GetVehiclePedIsIn(ped, false) + CurrentGlovebox = QBCore.Functions.GetPlate(vehicle) + curVeh = vehicle + CurrentVehicle = nil + else + local vehicle = QBCore.Functions.GetClosestVehicle() + if vehicle ~= 0 and vehicle ~= nil then + local pos = GetEntityCoords(ped) + local dimensionMin, dimensionMax = GetModelDimensions(GetEntityModel(vehicle)) + local trunkpos = GetOffsetFromEntityInWorldCoords(vehicle, 0.0, (dimensionMin.y), 0.0) + if (IsBackEngine(GetEntityModel(vehicle))) then + trunkpos = GetOffsetFromEntityInWorldCoords(vehicle, 0.0, (dimensionMax.y), 0.0) + end + if #(pos - trunkpos) < 1.5 and not IsPedInAnyVehicle(ped) then + if GetVehicleDoorLockStatus(vehicle) < 2 then + CurrentVehicle = QBCore.Functions.GetPlate(vehicle) + curVeh = vehicle + CurrentGlovebox = nil + else + QBCore.Functions.Notify("Køretøj låst.", "error") + return + end + else + CurrentVehicle = nil + end + else + CurrentVehicle = nil + end + end + + if CurrentVehicle then -- Trunk + local vehicleClass = GetVehicleClass(curVeh) + local maxweight + local slots + if vehicleClass == 0 then + maxweight = 38000 + slots = 30 + elseif vehicleClass == 1 then + maxweight = 50000 + slots = 40 + elseif vehicleClass == 2 then + maxweight = 75000 + slots = 50 + elseif vehicleClass == 3 then + maxweight = 42000 + slots = 35 + elseif vehicleClass == 4 then + maxweight = 38000 + slots = 30 + elseif vehicleClass == 5 then + maxweight = 30000 + slots = 25 + elseif vehicleClass == 6 then + maxweight = 30000 + slots = 25 + elseif vehicleClass == 7 then + maxweight = 30000 + slots = 25 + elseif vehicleClass == 8 then + maxweight = 15000 + slots = 15 + elseif vehicleClass == 9 then + maxweight = 60000 + slots = 35 + elseif vehicleClass == 12 then + maxweight = 120000 + slots = 35 + elseif vehicleClass == 13 then + maxweight = 0 + slots = 0 + elseif vehicleClass == 14 then + maxweight = 120000 + slots = 50 + elseif vehicleClass == 15 then + maxweight = 120000 + slots = 50 + elseif vehicleClass == 16 then + maxweight = 120000 + slots = 50 + else + maxweight = 60000 + slots = 35 + end + local other = { + maxweight = maxweight, + slots = slots, + } + TriggerServerEvent("inventory:server:OpenInventory", "trunk", CurrentVehicle, other) + OpenTrunk() + elseif CurrentGlovebox then + TriggerServerEvent("inventory:server:OpenInventory", "glovebox", CurrentGlovebox) + elseif CurrentDrop ~= 0 then + TriggerServerEvent("inventory:server:OpenInventory", "drop", CurrentDrop) + elseif VendingMachine then + local ShopItems = {} + ShopItems.label = "Automat" + ShopItems.items = Config.VendingItem + ShopItems.slots = #Config.VendingItem + TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems) + else + openAnim() + TriggerServerEvent("inventory:server:OpenInventory") + end + end + end +end, false) + +RegisterKeyMapping('inventory', 'Åben inventar', 'keyboard', 'TAB') + +RegisterCommand('hotbar', function() + isHotbar = not isHotbar + if not PlayerData.metadata["isdead"] and not PlayerData.metadata["inlaststand"] and not PlayerData.metadata["ishandcuffed"] and not IsPauseMenuActive() then + ToggleHotbar(isHotbar) + end +end) + +RegisterKeyMapping('hotbar', 'Vis/gem keybinds', 'keyboard', 'z') + +for i = 1, 6 do + RegisterCommand('slot' .. i,function() + if not PlayerData.metadata["isdead"] and not PlayerData.metadata["inlaststand"] and not PlayerData.metadata["ishandcuffed"] and not IsPauseMenuActive() and not LocalPlayer.state.inv_busy then + if i == 6 then + i = Config.MaxInventorySlots + end + TriggerServerEvent("inventory:server:UseItemSlot", i) + end + end, false) + RegisterKeyMapping('slot' .. i, 'Bruger genstand i slot ' .. i, 'keyboard', i) +end + +RegisterNetEvent('ps-inventory:client:giveAnim', function() + LoadAnimDict('mp_common') + TaskPlayAnim(PlayerPedId(), 'mp_common', 'givetake1_b', 8.0, 1.0, -1, 16, 0, 0, 0, 0) +end) + +-- NUI + +RegisterNUICallback('RobMoney', function(data, cb) + TriggerServerEvent("police:server:RobPlayer", data.TargetId) + cb('ok') +end) + +RegisterNUICallback('Notify', function(data, cb) + QBCore.Functions.Notify(data.message, data.type) + cb('ok') +end) + +RegisterNUICallback('GetWeaponData', function(cData, cb) + local data = { + WeaponData = QBCore.Shared.Items[cData.weapon], + AttachmentData = FormatWeaponAttachments(cData.ItemData) + } + cb(data) +end) + +RegisterNUICallback('RemoveAttachment', function(data, cb) + local ped = PlayerPedId() + local WeaponData = QBCore.Shared.Items[data.WeaponData.name] + print(data.AttachmentData.attachment:gsub("(.*).*_",'')) + data.AttachmentData.attachment = data.AttachmentData.attachment:gsub("(.*).*_",'') + QBCore.Functions.TriggerCallback('weapons:server:RemoveAttachment', function(NewAttachments) + if NewAttachments ~= false then + local attachments = {} + RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(data.AttachmentData.component)) + for _, v in pairs(NewAttachments) do + attachments[#attachments+1] = { + attachment = v.item, + label = v.label, + image = QBCore.Shared.Items[v.item].image + } + end + local DJATA = { + Attachments = attachments, + WeaponData = WeaponData, + } + cb(DJATA) + else + RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(data.AttachmentData.component)) + cb({}) + end + end, data.AttachmentData, data.WeaponData) +end) + +RegisterNUICallback('getCombineItem', function(data, cb) + cb(QBCore.Shared.Items[data.item]) +end) + +RegisterNUICallback("CloseInventory", function() + if currentOtherInventory == "none-inv" then + CurrentDrop = nil + CurrentVehicle = nil + CurrentGlovebox = nil + CurrentStash = nil + SetNuiFocus(false, false) + inInventory = false + TriggerScreenblurFadeOut(1000) + ClearPedTasks(PlayerPedId()) + return + end + if CurrentVehicle ~= nil then + CloseTrunk() + TriggerServerEvent("inventory:server:SaveInventory", "trunk", CurrentVehicle) + CurrentVehicle = nil + elseif CurrentGlovebox ~= nil then + TriggerServerEvent("inventory:server:SaveInventory", "glovebox", CurrentGlovebox) + CurrentGlovebox = nil + elseif CurrentStash ~= nil then + TriggerServerEvent("inventory:server:SaveInventory", "stash", CurrentStash) + CurrentStash = nil + else + TriggerServerEvent("inventory:server:SaveInventory", "drop", CurrentDrop) + CurrentDrop = nil + end + Wait(50) + TriggerScreenblurFadeOut(1000) + SetNuiFocus(false, false) + inInventory = false +end) + +RegisterNUICallback("UseItem", function(data, cb) + TriggerServerEvent("inventory:server:UseItem", data.inventory, data.item) + cb('ok') +end) + +RegisterNUICallback("combineItem", function(data, cb) + Wait(150) + TriggerServerEvent('inventory:server:combineItem', data.reward, data.fromItem, data.toItem) + cb('ok') +end) + +RegisterNUICallback('combineWithAnim', function(data, cb) + local ped = PlayerPedId() + local combineData = data.combineData + local aDict = combineData.anim.dict + local aLib = combineData.anim.lib + local animText = combineData.anim.text + local animTimeout = combineData.anim.timeOut + QBCore.Functions.Progressbar("combine_anim", animText, animTimeout, false, true, { + disableMovement = false, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + }, { + animDict = aDict, + anim = aLib, + flags = 16, + }, {}, {}, function() -- Done + StopAnimTask(ped, aDict, aLib, 1.0) + TriggerServerEvent('inventory:server:combineItem', combineData.reward, data.requiredItem, data.usedItem) + end, function() -- Cancel + StopAnimTask(ped, aDict, aLib, 1.0) + QBCore.Functions.Notify("Fejlet", "error") + end) + cb('ok') +end) + +RegisterNUICallback("SetInventoryData", function(data, cb) + TriggerServerEvent("inventory:server:SetInventoryData", data.fromInventory, data.toInventory, data.fromSlot, data.toSlot, data.fromAmount, data.toAmount) + cb('ok') +end) + +RegisterNUICallback("PlayDropSound", function(_, cb) + PlaySound(-1, "CLICK_BACK", "WEB_NAVIGATION_SOUNDS_PHONE", 0, 0, 1) + cb('ok') +end) + +RegisterNUICallback("PlayDropFail", function(_, cb) + PlaySound(-1, "Place_Prop_Fail", "DLC_Dmod_Prop_Editor_Sounds", 0, 0, 1) + cb('ok') +end) + +RegisterNUICallback("GiveItem", function(data, cb) + local player, distance = QBCore.Functions.GetClosestPlayer(GetEntityCoords(PlayerPedId())) + if player ~= -1 and distance < 3 then + if data.inventory == 'player' then + local playerId = GetPlayerServerId(player) + SetCurrentPedWeapon(PlayerPedId(),'WEAPON_UNARMED',true) + TriggerServerEvent("inventory:server:GiveItem", playerId, data.item.name, data.amount, data.item.slot) + else + QBCore.Functions.Notify("Du ejer ikke denne genstand!", "error") + end + else + QBCore.Functions.Notify("Ingen i nærheden!", "error") + end + cb('ok') +end) + + +-- Threads + +CreateThread(function() + while true do + local sleep = 100 + if DropsNear ~= nil then + local ped = PlayerPedId() + local closestDrop = nil + local closestDistance = nil + for k, v in pairs(DropsNear) do + + if DropsNear[k] ~= nil then + if Config.UseItemDrop then + if not v.isDropShowing then + CreateItemDrop(k) + end + else + sleep = 0 + DrawMarker(20, v.coords.x, v.coords.y, v.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.15, 120, 10, 20, 155, false, false, false, 1, false, false, false) + end + + local coords = (v.object ~= nil and GetEntityCoords(v.object)) or vector3(v.coords.x, v.coords.y, v.coords.z) + local distance = #(GetEntityCoords(ped) - coords) + if distance < 2 and (not closestDistance or distance < closestDistance) then + closestDrop = k + closestDistance = distance + end + end + end + + + if not closestDrop then + CurrentDrop = 0 + else + CurrentDrop = closestDrop + end + end + Wait(sleep) + end +end) + +CreateThread(function() + while true do + if Drops ~= nil and next(Drops) ~= nil then + local pos = GetEntityCoords(PlayerPedId(), true) + for k, v in pairs(Drops) do + if Drops[k] ~= nil then + local dist = #(pos - vector3(v.coords.x, v.coords.y, v.coords.z)) + if dist < Config.MaxDropViewDistance then + DropsNear[k] = v + else + if Config.UseItemDrop and DropsNear[k] then + RemoveNearbyDrop(k) + else + DropsNear[k] = nil + end + end + end + end + else + DropsNear = {} + end + Wait(500) + end +end) + +CreateThread(function() + if Config.UseTarget then + exports['qb-target']:AddTargetModel(Config.VendingObjects, { + options = { + { + icon = 'fa-solid fa-cash-register', + label = "Åben Automat", + action = function() + OpenVending() + end + }, + }, + distance = 2.5 + }) + end +end) + + --qb-target + RegisterNetEvent("inventory:client:Crafting", function(dropId) + local crafting = {} + crafting.label = "Crafting" + crafting.items = GetThresholdItems() + TriggerServerEvent("inventory:server:OpenInventory", "crafting", math.random(1, 99), crafting) + end) + + + RegisterNetEvent("inventory:client:WeaponAttachmentCrafting", function(dropId) + local crafting = {} + crafting.label = "Tilføjelses crafting" + crafting.items = GetAttachmentThresholdItems() + TriggerServerEvent("inventory:server:OpenInventory", "attachment_crafting", math.random(1, 99), crafting) + end) + + local toolBoxModels = { + `prop_toolchest_05`, + `prop_tool_bench02_ld`, + `prop_tool_bench02`, + `prop_toolchest_02`, + `prop_toolchest_03`, + `prop_toolchest_03_l2`, + `prop_toolchest_05`, + `prop_toolchest_04`, + } + exports['qb-target']:AddTargetModel(toolBoxModels, { + options = { + { + event = "inventory:client:WeaponAttachmentCrafting", + icon = "fas fa-wrench", + label = "Tilføjelses Crafting", + }, + { + event = "inventory:client:Crafting", + icon = "fas fa-wrench", + label = "Crafting", + }, + }, + distance = 1.0 + }) diff --git a/resources/[ps]/ps-inventory/config.lua b/resources/[ps]/ps-inventory/config.lua new file mode 100644 index 0000000..a79c55c --- /dev/null +++ b/resources/[ps]/ps-inventory/config.lua @@ -0,0 +1,386 @@ +Config = {} + +Config.UseTarget = GetConvar('UseTarget', 'false') == 'true' -- Use qb-target interactions (don't change this, go to your server.cfg and add `setr UseTarget true` to use this and just that from true to false or the other way around) + +Config.MaxInventoryWeight = 150000 -- Max weight a player can carry (default 120kg, written in grams) +Config.MaxInventorySlots = 41 -- Max inventory slots for a player + +Config.CleanupDropTime = 15 * 60 -- How many seconds it takes for drops to be untouched before being deleted +Config.MaxDropViewDistance = 12.5 -- The distance in GTA Units that a drop can be seen +Config.UseItemDrop = true -- This will enable item object to spawn on drops instead of markers +Config.ItemDropObject = `sf_prop_sf_backpack_01a` -- if Config.UseItemDrop is true, this will be the prop that spawns for the item + +Config.Progressbar = { + Enable = false, -- True to Enable the progressbar while opening inventory + minT = 150, -- Min Time for Inventory to open + maxT = 250 -- Max Time for Inventory to open +} + +Config.VendingObjects = { + "prop_vend_soda_01", + "prop_vend_soda_02", + "prop_vend_water_01" +} + +Config.BinObjects = { + "prop_bin_05a", +} + +Config.CraftingObject = `prop_toolchest_05` -- Only needed if not using target | Line 928 to change Target Models + +Config.VendingItem = { + [1] = { + name = "kurkakola", + price = 4, + amount = 50, + info = {}, + type = "item", + slot = 1, + }, + [2] = { + name = "water_bottle", + price = 4, + amount = 50, + info = {}, + type = "item", + slot = 2, + }, +} + +Config.CraftingItems = { + [1] = { + name = "lockpick", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 22, + ["plastic"] = 32, + }, + type = "item", + slot = 1, + threshold = 0, + points = 1, + }, + [2] = { + name = "screwdriverset", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 30, + ["plastic"] = 42, + }, + type = "item", + slot = 2, + threshold = 0, + points = 2, + }, + [3] = { + name = "electronickit", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 30, + ["plastic"] = 45, + ["aluminum"] = 28, + }, + type = "item", + slot = 3, + threshold = 0, + points = 3, + }, + [4] = { + name = "radioscanner", + amount = 50, + info = {}, + costs = { + ["electronickit"] = 2, + ["plastic"] = 52, + ["steel"] = 40, + }, + type = "item", + slot = 4, + threshold = 0, + points = 4, + }, + [5] = { + name = "gatecrack", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 10, + ["plastic"] = 50, + ["aluminum"] = 30, + ["iron"] = 17, + ["electronickit"] = 2, + }, + type = "item", + slot = 5, + threshold = 110, + points = 5, + }, + [6] = { + name = "handcuffs", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 36, + ["steel"] = 24, + ["aluminum"] = 28, + }, + type = "item", + slot = 6, + threshold = 160, + points = 6, + }, + [7] = { + name = "repairkit", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 32, + ["steel"] = 43, + ["plastic"] = 61, + }, + type = "item", + slot = 7, + threshold = 200, + points = 7, + }, + [8] = { + name = "pistol_ammo", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 50, + ["steel"] = 37, + ["copper"] = 26, + }, + type = "item", + slot = 8, + threshold = 250, + points = 8, + }, + [9] = { + name = "ironoxide", + amount = 50, + info = {}, + costs = { + ["iron"] = 60, + ["glass"] = 30, + }, + type = "item", + slot = 9, + threshold = 300, + points = 9, + }, + [10] = { + name = "aluminumoxide", + amount = 50, + info = {}, + costs = { + ["aluminum"] = 60, + ["glass"] = 30, + }, + type = "item", + slot = 10, + threshold = 300, + points = 10, + }, + [11] = { + name = "armor", + amount = 50, + info = {}, + costs = { + ["iron"] = 33, + ["steel"] = 44, + ["plastic"] = 55, + ["aluminum"] = 22, + }, + type = "item", + slot = 11, + threshold = 350, + points = 11, + }, + [12] = { + name = "drill", + amount = 50, + info = {}, + costs = { + ["iron"] = 50, + ["steel"] = 50, + ["screwdriverset"] = 3, + ["advancedlockpick"] = 2, + }, + type = "item", + slot = 12, + threshold = 1750, + points = 12, + }, +} + +Config.AttachmentCraftingLocation = vector3(88.91, 3743.88, 40.77) -- Only needed if not using target + +Config.AttachmentCrafting = { + [1] = { + name = "pistol_extendedclip", + amount = 50, + info = {}, + costs = { + ["metalscrap"] = 140, + ["steel"] = 250, + ["rubber"] = 60, + }, + type = "item", + slot = 1, + threshold = 0, + points = 1, + }, + -- [2] = { + -- name = "pistol_suppressor", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 165, + -- ["steel"] = 285, + -- ["rubber"] = 75, + -- }, + -- type = "item", + -- slot = 2, + -- threshold = 10, + -- points = 2, + -- }, + -- [3] = { + -- name = "smg_extendedclip", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 190, + -- ["steel"] = 305, + -- ["rubber"] = 85, + -- }, + -- type = "item", + -- slot = 3, + -- threshold = 25, + -- points = 3, + -- }, + -- [4] = { + -- name = "microsmg_extendedclip", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 205, + -- ["steel"] = 340, + -- ["rubber"] = 110, + -- }, + -- type = "item", + -- slot = 4, + -- threshold = 50, + -- points = 4, + -- }, + -- [5] = { + -- name = "smg_drum", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 230, + -- ["steel"] = 365, + -- ["rubber"] = 130, + -- }, + -- type = "item", + -- slot = 5, + -- threshold = 75, + -- points = 5, + -- }, + -- [6] = { + -- name = "smg_scope", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 255, + -- ["steel"] = 390, + -- ["rubber"] = 145, + -- }, + -- type = "item", + -- slot = 6, + -- threshold = 100, + -- points = 6, + -- }, + -- [7] = { + -- name = "assaultrifle_extendedclip", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 270, + -- ["steel"] = 435, + -- ["rubber"] = 155, + -- ["smg_extendedclip"] = 1, + -- }, + -- type = "item", + -- slot = 7, + -- threshold = 150, + -- points = 7, + -- }, + -- [8] = { + -- name = "assaultrifle_drum", + -- amount = 50, + -- info = {}, + -- costs = { + -- ["metalscrap"] = 300, + -- ["steel"] = 469, + -- ["rubber"] = 170, + -- ["smg_extendedclip"] = 2, + -- }, + -- type = "item", + -- slot = 8, + -- threshold = 200, + -- points = 8, + -- }, +} + +BackEngineVehicles = { + [`ninef`] = true, + [`adder`] = true, + [`vagner`] = true, + [`t20`] = true, + [`infernus`] = true, + [`zentorno`] = true, + [`reaper`] = true, + [`comet2`] = true, + [`comet3`] = true, + [`jester`] = true, + [`jester2`] = true, + [`cheetah`] = true, + [`cheetah2`] = true, + [`prototipo`] = true, + [`turismor`] = true, + [`pfister811`] = true, + [`ardent`] = true, + [`nero`] = true, + [`nero2`] = true, + [`tempesta`] = true, + [`vacca`] = true, + [`bullet`] = true, + [`osiris`] = true, + [`entityxf`] = true, + [`turismo2`] = true, + [`fmj`] = true, + [`re7b`] = true, + [`tyrus`] = true, + [`italigtb`] = true, + [`penetrator`] = true, + [`monroe`] = true, + [`ninef2`] = true, + [`stingergt`] = true, + [`surfer`] = true, + [`surfer2`] = true, + [`gp1`] = true, + [`autarch`] = true, + [`tyrant`] = true +} + +Config.MaximumAmmoValues = { + ["pistol"] = 250, + ["smg"] = 250, + ["shotgun"] = 200, + ["rifle"] = 250, +} \ No newline at end of file diff --git a/resources/[ps]/ps-inventory/fxmanifest.lua b/resources/[ps]/ps-inventory/fxmanifest.lua new file mode 100644 index 0000000..36fe771 --- /dev/null +++ b/resources/[ps]/ps-inventory/fxmanifest.lua @@ -0,0 +1,35 @@ +fx_version 'cerulean' +game 'gta5' + +description 'ps-inventory' +version '1.0.3' + +shared_scripts { + 'config.lua', + '@qb-weapons/config.lua' +} + +server_scripts { + '@oxmysql/lib/MySQL.lua', + 'server/main.lua' +} + +client_script 'client/main.lua' + +ui_page { + 'html/ui.html' +} + +files { + 'html/ui.html', + 'html/css/main.css', + 'html/js/app.js', + 'html/images/*.svg', + 'html/images/*.png', + 'html/images/*.jpg', + 'html/ammo_images/*.png', + 'html/attachment_images/*.png', + 'html/*.ttf' +} + +lua54 'yes' diff --git a/resources/[ps]/ps-inventory/ps-inventory.sql b/resources/[ps]/ps-inventory/ps-inventory.sql new file mode 100644 index 0000000..bc17a66 --- /dev/null +++ b/resources/[ps]/ps-inventory/ps-inventory.sql @@ -0,0 +1,50 @@ +CREATE TABLE IF NOT EXISTS `gloveboxitems` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plate` varchar(255) DEFAULT NULL, + `items` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, + PRIMARY KEY (`plate`), + KEY `id` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; + +CREATE TABLE IF NOT EXISTS `stashitems` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `stash` varchar(255) DEFAULT NULL, + `items` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, + PRIMARY KEY (`stash`), + KEY `id` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; + +CREATE TABLE IF NOT EXISTS `trunkitems` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plate` varchar(255) DEFAULT NULL, + `items` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, + PRIMARY KEY (`plate`), + KEY `id` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; + +CREATE TABLE IF NOT EXISTS `player_vehicles` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `license` varchar(50) DEFAULT NULL, + `citizenid` varchar(50) DEFAULT NULL, + `vehicle` varchar(50) DEFAULT NULL, + `hash` varchar(50) DEFAULT NULL, + `mods` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, + `plate` varchar(50) NOT NULL, + `fakeplate` varchar(50) DEFAULT NULL, + `garage` varchar(50) DEFAULT NULL, + `fuel` int(11) DEFAULT 100, + `engine` float DEFAULT 1000, + `body` float DEFAULT 1000, + `state` int(11) DEFAULT 1, + `depotprice` int(11) NOT NULL DEFAULT 0, + `drivingdistance` int(50) DEFAULT NULL, + `status` text DEFAULT NULL, + `balance` int(11) NOT NULL DEFAULT 0, + `paymentamount` int(11) NOT NULL DEFAULT 0, + `paymentsleft` int(11) NOT NULL DEFAULT 0, + `financetime` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + KEY `plate` (`plate`), + KEY `citizenid` (`citizenid`), + KEY `license` (`license`) +) ENGINE=InnoDB AUTO_INCREMENT=1; diff --git a/resources/[ps]/ps-inventory/server/main.lua b/resources/[ps]/ps-inventory/server/main.lua new file mode 100644 index 0000000..413834c --- /dev/null +++ b/resources/[ps]/ps-inventory/server/main.lua @@ -0,0 +1,2711 @@ +-- Variables + +local QBCore = exports['qb-core']:GetCoreObject() +local Drops = {} +local Trunks = {} +local Gloveboxes = {} +local Stashes = {} +local ShopItems = {} + +-- Functions + +---Loads the inventory for the player with the citizenid that is provided + +local function LoadInventory(source, citizenid) + local inventory = MySQL.prepare.await('SELECT inventory FROM players WHERE citizenid = ?', { citizenid }) + local loadedInventory = {} + local missingItems = {} + + if not inventory then return loadedInventory end + + inventory = json.decode(inventory) + if table.type(inventory) == "empty" then return loadedInventory end + + for _, item in pairs(inventory) do + if item then + local itemInfo = QBCore.Shared.Items[item.name:lower()] + if itemInfo then + loadedInventory[item.slot] = { + name = itemInfo['name'], + amount = item.amount, + info = item.info or '', + label = itemInfo['label'], + description = itemInfo['description'] or '', + weight = itemInfo['weight'], + type = itemInfo['type'], + unique = itemInfo['unique'], + useable = itemInfo['useable'], + image = itemInfo['image'], + shouldClose = itemInfo['shouldClose'], + slot = item.slot, + combinable = itemInfo['combinable'], + created = item.created, + } + else + missingItems[#missingItems + 1] = item.name:lower() + end + end + end + + if #missingItems > 0 then + print(("The following items were removed for player %s as they no longer exist"):format(GetPlayerName(source))) + QBCore.Debug(missingItems) + end + + return loadedInventory +end + +exports("LoadInventory", LoadInventory) + +---Saves the inventory for the player with the provided source or PlayerData is they're offline + +local function SaveInventory(source, offline) + local PlayerData + if not offline then + local Player = QBCore.Functions.GetPlayer(source) + + if not Player then return end + + PlayerData = Player.PlayerData + else + PlayerData = source -- for offline users, the playerdata gets sent over the source variable + end + + local items = PlayerData.items + local ItemsJson = {} + if items and table.type(items) ~= "empty" then + for slot, item in pairs(items) do + if items[slot] then + ItemsJson[#ItemsJson+1] = { + name = item.name, + amount = item.amount, + info = item.info, + type = item.type, + slot = slot, + created = item.created + } + end + end + MySQL.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid }) + else + MySQL.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid }) + end +end + +exports("SaveInventory", SaveInventory) + +---Gets the totalweight of the items provided + +local function GetTotalWeight(items) + local weight = 0 + if not items then return 0 end + for _, item in pairs(items) do + weight += item.weight * item.amount + end + return tonumber(weight) +end + +exports("GetTotalWeight", GetTotalWeight) + +---Gets the slots that the provided item is in + +local function GetSlotsByItem(items, itemName) + local slotsFound = {} + if not items then return slotsFound end + for slot, item in pairs(items) do + if item.name:lower() == itemName:lower() then + slotsFound[#slotsFound+1] = slot + end + end + return slotsFound +end + +exports("GetSlotsByItem", GetSlotsByItem) + +---Get the first slot where the item is located + +local function GetFirstSlotByItem(items, itemName) + if not items then return nil end + for slot, item in pairs(items) do + if item.name:lower() == itemName:lower() then + return tonumber(slot) + end + end + return nil +end + +exports("GetFirstSlotByItem", GetFirstSlotByItem) + +---Add an item to the inventory of the player + +local function AddItem(source, item, amount, slot, info, created) + local Player = QBCore.Functions.GetPlayer(source) + + if not Player then return false end + + local totalWeight = GetTotalWeight(Player.PlayerData.items) + local itemInfo = QBCore.Shared.Items[item:lower()] + local time = os.time() + if not created then + itemInfo['created'] = time + else + itemInfo['created'] = created + end + if not itemInfo and not Player.Offline then + QBCore.Functions.Notify(source, "Ting findes ikke", 'error') + return false + end + + amount = tonumber(amount) or 1 + slot = tonumber(slot) or GetFirstSlotByItem(Player.PlayerData.items, item) + info = info or {} + itemInfo['created'] = created or time + info.quality = info.quality or 100 + + if itemInfo['type'] == 'weapon' then + info.serie = info.serie or tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) + info.quality = info.quality or 100 + end + if (totalWeight + (itemInfo['weight'] * amount)) <= Config.MaxInventoryWeight then + if (slot and Player.PlayerData.items[slot]) and (Player.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo['type'] == 'item' and not itemInfo['unique']) then + if Player.PlayerData.items[slot].info.quality == info.quality then + Player.PlayerData.items[slot].amount = Player.PlayerData.items[slot].amount + amount + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + if Player.Offline then return true end + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. Player.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[slot].amount) + return true + else + for i = 1, Config.MaxInventorySlots, 1 do + if Player.PlayerData.items[i] == nil then + Player.PlayerData.items[i] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable'], created = itemInfo['created'] } + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + if Player.Offline then return true end + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** got item: [slot:' .. i .. '], itemname: ' .. Player.PlayerData.items[i].name .. ', added amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[i].amount) + return true + end + end + end + elseif not itemInfo['unique'] and slot or slot and Player.PlayerData.items[slot] == nil then + Player.PlayerData.items[slot] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = slot, combinable = itemInfo['combinable'], created = itemInfo['created'] } + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + if Player.Offline then return true end + + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. Player.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[slot].amount) + + return true + elseif itemInfo['unique'] or (not slot or slot == nil) or itemInfo['type'] == 'weapon' then + for i = 1, Config.MaxInventorySlots, 1 do + if Player.PlayerData.items[i] == nil then + Player.PlayerData.items[i] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable'], created = itemInfo['created'] } + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + if Player.Offline then return true end + + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** got item: [slot:' .. i .. '], itemname: ' .. Player.PlayerData.items[i].name .. ', added amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[i].amount) + + return true + end + end + end + elseif not Player.Offline then + QBCore.Functions.Notify(source, "Inventar er fyldt", 'error') + end + return false +end + +exports("AddItem", AddItem) + +---Remove an item from the inventory of the player + +local function RemoveItem(source, item, amount, slot) + local Player = QBCore.Functions.GetPlayer(source) + + if not Player then return false end + + amount = tonumber(amount) or 1 + slot = tonumber(slot) + + if slot then + if Player.PlayerData.items[slot].amount > amount then + Player.PlayerData.items[slot].amount = Player.PlayerData.items[slot].amount - amount + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + if not Player.Offline then + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. Player.PlayerData.items[slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[slot].amount) + end + + return true + elseif Player.PlayerData.items[slot].amount == amount then + Player.PlayerData.items[slot] = nil + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + if Player.Offline then return true end + + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed') + + return true + end + else + local slots = GetSlotsByItem(Player.PlayerData.items, item) + local amountToRemove = amount + + if not slots then return false end + + for _, _slot in pairs(slots) do + if Player.PlayerData.items[_slot].amount > amountToRemove then + Player.PlayerData.items[_slot].amount = Player.PlayerData.items[_slot].amount - amountToRemove + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + if not Player.Offline then + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. Player.PlayerData.items[_slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[_slot].amount) + end + + return true + elseif Player.PlayerData.items[_slot].amount == amountToRemove then + Player.PlayerData.items[_slot] = nil + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + if Player.Offline then return true end + + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed') + + return true + end + end + end + return false +end + +exports("RemoveItem", RemoveItem) + +---Get the item with the slot + +local function GetItemBySlot(source, slot) + local Player = QBCore.Functions.GetPlayer(source) + slot = tonumber(slot) + return Player.PlayerData.items[slot] +end + +exports("GetItemBySlot", GetItemBySlot) + +---Get the item from the inventory of the player with the provided source by the name of the item + +local function GetItemByName(source, item) + local Player = QBCore.Functions.GetPlayer(source) + item = tostring(item):lower() + local slot = GetFirstSlotByItem(Player.PlayerData.items, item) + return Player.PlayerData.items[slot] +end + +exports("GetItemByName", GetItemByName) + +---Get the item from the inventory of the player with the provided source by the name of the item in an array for all slots that the item is in + +local function GetItemsByName(source, item) + local Player = QBCore.Functions.GetPlayer(source) + item = tostring(item):lower() + local items = {} + local slots = GetSlotsByItem(Player.PlayerData.items, item) + for _, slot in pairs(slots) do + if slot then + items[#items+1] = Player.PlayerData.items[slot] + end + end + return items +end + +exports("GetItemsByName", GetItemsByName) + + +local function ClearInventory(source, filterItems) + local Player = QBCore.Functions.GetPlayer(source) + local savedItemData = {} + + if filterItems then + local filterItemsType = type(filterItems) + if filterItemsType == "string" then + local item = GetItemByName(source, filterItems) + + if item then + savedItemData[item.slot] = item + end + elseif filterItemsType == "table" and table.type(filterItems) == "array" then + for i = 1, #filterItems do + local item = GetItemByName(source, filterItems[i]) + + if item then + savedItemData[item.slot] = item + end + end + end + end + + Player.Functions.SetPlayerData("items", savedItemData) + + if Player.Offline then return end + + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'ClearInventory', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** inventory cleared') +end + +exports("ClearInventory", ClearInventory) + +---Sets the items playerdata to the provided items param + +local function SetInventory(source, items) + local Player = QBCore.Functions.GetPlayer(source) + + Player.Functions.SetPlayerData("items", items) + + if Player.Offline then return end + + TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'SetInventory', 'blue', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** items set: ' .. json.encode(items)) +end + +exports("SetInventory", SetInventory) + +---Set the data of a specific item + +local function SetItemData(source, itemName, key, val) + if not itemName or not key then return false end + + local Player = QBCore.Functions.GetPlayer(source) + + if not Player then return end + + local item = GetItemByName(source, itemName) + + if not item then return false end + + item[key] = val + Player.PlayerData.items[item.slot] = item + Player.Functions.SetPlayerData("items", Player.PlayerData.items) + + return true +end + +exports("SetItemData", SetItemData) + +---Checks if you have an item or not +local function HasItem(source, items, amount) + local Player = QBCore.Functions.GetPlayer(source) + if not Player then return false end + local isTable = type(items) == 'table' + local isArray = isTable and table.type(items) == 'array' or false + local totalItems = #items + local count = 0 + local kvIndex = 2 + if isTable and not isArray then + totalItems = 0 + for _ in pairs(items) do totalItems += 1 end + kvIndex = 1 + end + if isTable then + for k, v in pairs(items) do + local itemKV = {k, v} + local item = GetItemByName(source, itemKV[kvIndex]) + if item and ((amount and item.amount >= amount) or (not isArray and item.amount >= v) or (not amount and isArray)) then + count += 1 + end + end + if count == totalItems then + return true + end + else -- Single item as string + local item = GetItemByName(source, items) + if item and (not amount or (item and amount and item.amount >= amount)) then + return true + end + end + return false +end + +exports("HasItem", HasItem) + +---Create a usable item with a callback on use +---@param itemName string The name of the item to make usable +---@param data any +local function CreateUsableItem(itemName, data) + QBCore.Functions.CreateUseableItem(itemName, data) +end + +exports("CreateUsableItem", CreateUsableItem) + +---Get the usable item data for the specified item +---@param itemName string The item to get the data for +---@return any usable_item +local function GetUsableItem(itemName) + return QBCore.Functions.CanUseItem(itemName) +end + +exports("GetUsableItem", GetUsableItem) + +---Use an item from the QBCore.UsableItems table if a callback is present +---@param itemName string The name of the item to use +---@param ... any Arguments for the callback, this will be sent to the callback and can be used to get certain values +local function UseItem(itemName, ...) + local itemData = GetUsableItem(itemName) + local callback = type(itemData) == 'table' and (rawget(itemData, '__cfx_functionReference') and itemData or itemData.cb or itemData.callback) or type(itemData) == 'function' and itemData + if not callback then return end + callback(...) +end + +exports("UseItem", UseItem) + +local function recipeContains(recipe, fromItem) + for _, v in pairs(recipe.accept) do + if v == fromItem.name then + return true + end + end + + return false +end + + +local function hasCraftItems(source, CostItems, amount) + for k, v in pairs(CostItems) do + local item = GetItemByName(source, k) + + if not item then return false end + + if item.amount < (v * amount) then return false end + end + return true +end + +local function IsVehicleOwned(plate) + local result = MySQL.scalar.await('SELECT 1 from player_vehicles WHERE plate = ?', {plate}) + return result +end + +-- Shop Items +local function SetupShopItems(shopItems) + local items = {} + if shopItems and next(shopItems) then + for _, item in pairs(shopItems) do + local itemInfo = QBCore.Shared.Items[item.name:lower()] + if itemInfo then + items[item.slot] = { + name = itemInfo["name"], + amount = tonumber(item.amount), + info = item.info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + price = item.price, + image = itemInfo["image"], + slot = item.slot, + } + end + end + end + return items +end + +-- Stash Items +local function GetStashItems(stashId) + local items = {} + local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', {stashId}) + if not result then return items end + + local stashItems = json.decode(result) + if not stashItems then return items end + + for _, item in pairs(stashItems) do + local itemInfo = QBCore.Shared.Items[item.name:lower()] + if itemInfo then + items[item.slot] = { + name = itemInfo["name"], + amount = tonumber(item.amount), + info = item.info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = item.created, + slot = item.slot, + } + end + end + return items +end + +local function SaveStashItems(stashId, items) + if Stashes[stashId].label == "Stash-None" or not items then return end + + for _, item in pairs(items) do + item.description = nil + end + + MySQL.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { + ['stash'] = stashId, + ['items'] = json.encode(items) + }) + + Stashes[stashId].isOpen = false +end + +local function AddToStash(stashId, slot, otherslot, itemName, amount, info, created) + amount = tonumber(amount) or 1 + local ItemData = QBCore.Shared.Items[itemName] + if not ItemData.unique then + if Stashes[stashId].items[slot] and Stashes[stashId].items[slot].name == itemName then + Stashes[stashId].items[slot].amount = Stashes[stashId].items[slot].amount + amount + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Stashes[stashId].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + } + end + else + if Stashes[stashId].items[slot] and Stashes[stashId].items[slot].name == itemName then + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Stashes[stashId].items[otherslot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = otherslot, + } + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Stashes[stashId].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + } + end + end +end + +local function RemoveFromStash(stashId, slot, itemName, amount) + amount = tonumber(amount) or 1 + if Stashes[stashId].items[slot] and Stashes[stashId].items[slot].name == itemName then + if Stashes[stashId].items[slot].amount > amount then + Stashes[stashId].items[slot].amount = Stashes[stashId].items[slot].amount - amount + else + Stashes[stashId].items[slot] = nil + end + else + Stashes[stashId].items[slot] = nil + if Stashes[stashId].items == nil then + Stashes[stashId].items[slot] = nil + end + end +end + +-- Trunk items +local function GetOwnedVehicleItems(plate) + local items = {} + local result = MySQL.scalar.await('SELECT items FROM trunkitems WHERE plate = ?', {plate}) + if not result then return items end + + local trunkItems = json.decode(result) + if not trunkItems then return items end + + for _, item in pairs(trunkItems) do + local itemInfo = QBCore.Shared.Items[item.name:lower()] + if itemInfo then + items[item.slot] = { + name = itemInfo["name"], + amount = tonumber(item.amount), + info = item.info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = item.created, + slot = item.slot, + } + end + end + return items +end + +local function SaveOwnedVehicleItems(plate, items) + if Trunks[plate].label == "Trunk-None" or not items then return end + + for _, item in pairs(items) do + item.description = nil + end + + MySQL.insert('INSERT INTO trunkitems (plate, items) VALUES (:plate, :items) ON DUPLICATE KEY UPDATE items = :items', { + ['plate'] = plate, + ['items'] = json.encode(items) + }) + + Trunks[plate].isOpen = false +end + +local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, created) + amount = tonumber(amount) or 1 + local ItemData = QBCore.Shared.Items[itemName] + + if not ItemData.unique then + if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then + Trunks[plate].items[slot].amount = Trunks[plate].items[slot].amount + amount + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Trunks[plate].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + } + end + else + if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Trunks[plate].items[otherslot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = otherslot, + } + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Trunks[plate].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + } + end + end +end + +local function RemoveFromTrunk(plate, slot, itemName, amount) + amount = tonumber(amount) or 1 + if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then + if Trunks[plate].items[slot].amount > amount then + Trunks[plate].items[slot].amount = Trunks[plate].items[slot].amount - amount + else + Trunks[plate].items[slot] = nil + end + else + Trunks[plate].items[slot] = nil + if Trunks[plate].items == nil then + Trunks[plate].items[slot] = nil + end + end +end + + +-- Glovebox items +local function GetOwnedVehicleGloveboxItems(plate) + local items = {} + local result = MySQL.scalar.await('SELECT items FROM gloveboxitems WHERE plate = ?', {plate}) + if not result then return items end + + local gloveboxItems = json.decode(result) + if not gloveboxItems then return items end + + for _, item in pairs(gloveboxItems) do + local itemInfo = QBCore.Shared.Items[item.name:lower()] + if itemInfo then + items[item.slot] = { + name = itemInfo["name"], + amount = tonumber(item.amount), + info = item.info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = item.created, + slot = item.slot, + } + end + end + return items +end + +local function SaveOwnedGloveboxItems(plate, items) + if Gloveboxes[plate].label == "Glovebox-None" or not items then return end + + for _, item in pairs(items) do + item.description = nil + end + + MySQL.insert('INSERT INTO gloveboxitems (plate, items) VALUES (:plate, :items) ON DUPLICATE KEY UPDATE items = :items', { + ['plate'] = plate, + ['items'] = json.encode(items) + }) + + Gloveboxes[plate].isOpen = false +end + +local function AddToGlovebox(plate, slot, otherslot, itemName, amount, info, created) + amount = tonumber(amount) or 1 + local ItemData = QBCore.Shared.Items[itemName] + + if not ItemData.unique then + if Gloveboxes[plate].items[slot] and Gloveboxes[plate].items[slot].name == itemName then + Gloveboxes[plate].items[slot].amount = Gloveboxes[plate].items[slot].amount + amount + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Gloveboxes[plate].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + } + end + else + if Gloveboxes[plate].items[slot] and Gloveboxes[plate].items[slot].name == itemName then + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Gloveboxes[plate].items[otherslot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = otherslot, + } + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Gloveboxes[plate].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + } + end + end +end + +local function RemoveFromGlovebox(plate, slot, itemName, amount) + amount = tonumber(amount) or 1 + if Gloveboxes[plate].items[slot] and Gloveboxes[plate].items[slot].name == itemName then + if Gloveboxes[plate].items[slot].amount > amount then + Gloveboxes[plate].items[slot].amount = Gloveboxes[plate].items[slot].amount - amount + else + Gloveboxes[plate].items[slot] = nil + end + else + Gloveboxes[plate].items[slot] = nil + if Gloveboxes[plate].items == nil then + Gloveboxes[plate].items[slot] = nil + end + end +end + +---Add an item to a drop +---@param dropId integer The id of the drop +---@param slot number The slot of the drop inventory to add the item to +---@param itemName string Name of the item to add +---@param amount? number The amount of the item to add +---@param info? table Extra info to add to the item +local function AddToDrop(dropId, slot, itemName, amount, info, created) + amount = tonumber(amount) or 1 + Drops[dropId].createdTime = os.time() + if Drops[dropId].items[slot] and Drops[dropId].items[slot].name == itemName then + Drops[dropId].items[slot].amount = Drops[dropId].items[slot].amount + amount + else + local itemInfo = QBCore.Shared.Items[itemName:lower()] + Drops[dropId].items[slot] = { + name = itemInfo["name"], + amount = amount, + info = info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = slot, + id = dropId, + } + end +end + +local function RemoveFromDrop(dropId, slot, itemName, amount) + amount = tonumber(amount) or 1 + Drops[dropId].createdTime = os.time() + if Drops[dropId].items[slot] and Drops[dropId].items[slot].name == itemName then + if Drops[dropId].items[slot].amount > amount then + Drops[dropId].items[slot].amount = Drops[dropId].items[slot].amount - amount + else + Drops[dropId].items[slot] = nil + end + else + Drops[dropId].items[slot] = nil + if Drops[dropId].items == nil then + Drops[dropId].items[slot] = nil + end + end +end + +local function CreateDropId() + if Drops then + local id = math.random(10000, 99999) + local dropid = id + while Drops[dropid] do + id = math.random(10000, 99999) + dropid = id + end + return dropid + else + local id = math.random(10000, 99999) + local dropid = id + return dropid + end +end + +local function CreateNewDrop(source, fromSlot, toSlot, itemAmount, created) + itemAmount = tonumber(itemAmount) or 1 + local Player = QBCore.Functions.GetPlayer(source) + local itemData = GetItemBySlot(source, fromSlot) + + if not itemData then return end + + local coords = GetEntityCoords(GetPlayerPed(source)) + if RemoveItem(source, itemData.name, itemAmount, itemData.slot) then + TriggerClientEvent("inventory:client:CheckWeapon", source, itemData.name) + local itemInfo = QBCore.Shared.Items[itemData.name:lower()] + local dropId = CreateDropId() + Drops[dropId] = {} + Drops[dropId].coords = coords + Drops[dropId].createdTime = os.time() + + Drops[dropId].items = {} + + Drops[dropId].items[toSlot] = { + name = itemInfo["name"], + amount = itemAmount, + info = itemData.info or "", + label = itemInfo["label"], + description = itemInfo["description"] or "", + weight = itemInfo["weight"], + type = itemInfo["type"], + unique = itemInfo["unique"], + useable = itemInfo["useable"], + image = itemInfo["image"], + created = created, + slot = toSlot, + id = dropId, + } + TriggerEvent("qb-log:server:CreateLog", "drop", "New Item Drop", "red", "**".. GetPlayerName(source) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..source.."*) dropped new item; name: **"..itemData.name.."**, amount: **" .. itemAmount .. "**") + TriggerClientEvent("inventory:client:DropItemAnim", source) + TriggerClientEvent("inventory:client:AddDropItem", -1, dropId, source, coords) + if itemData.name:lower() == "radio" then + TriggerClientEvent('Radio.Set', source, false) + end + else + TriggerClientEvent("QBCore:Notify", source, "Du har ikke den ting", "error") + return + end +end + +local function OpenInventory(name, id, other, origin) + local src = origin + local ply = Player(src) + local Player = QBCore.Functions.GetPlayer(src) + if ply.state.inv_busy then + return QBCore.Functions.Notify(src, Lang:t("notify.noaccess"), 'error') + end + if name and id then + local secondInv = {} + if name == "stash" then + if Stashes[id] then + if Stashes[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Stashes[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Stashes[id].isOpen, name, id, Stashes[id].label) + else + Stashes[id].isOpen = false + end + end + end + local maxweight = 1000000 + local slots = 50 + if other then + maxweight = other.maxweight or 1000000 + slots = other.slots or 50 + end + secondInv.name = "stash-"..id + secondInv.label = "Stash-"..id + secondInv.maxweight = maxweight + secondInv.inventory = {} + secondInv.slots = slots + if Stashes[id] and Stashes[id].isOpen then + secondInv.name = "none-inv" + secondInv.label = "Stash-None" + secondInv.maxweight = 1000000 + secondInv.inventory = {} + secondInv.slots = 0 + else + local stashItems = GetStashItems(id) + if next(stashItems) then + secondInv.inventory = stashItems + Stashes[id] = {} + Stashes[id].items = stashItems + Stashes[id].isOpen = src + Stashes[id].label = secondInv.label + else + Stashes[id] = {} + Stashes[id].items = {} + Stashes[id].isOpen = src + Stashes[id].label = secondInv.label + end + end + elseif name == "trunk" then + if Trunks[id] then + if Trunks[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Trunks[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Trunks[id].isOpen, name, id, Trunks[id].label) + else + Trunks[id].isOpen = false + end + end + end + secondInv.name = "trunk-"..id + secondInv.label = "Trunk-"..id + secondInv.maxweight = other.maxweight or 60000 + secondInv.inventory = {} + secondInv.slots = other.slots or 50 + if (Trunks[id] and Trunks[id].isOpen) or (QBCore.Shared.SplitStr(id, "PLZI")[2] and (Player.PlayerData.job.name ~= "police" or Player.PlayerData.job.type ~= "leo")) then + secondInv.name = "none-inv" + secondInv.label = "Trunk-None" + secondInv.maxweight = other.maxweight or 60000 + secondInv.inventory = {} + secondInv.slots = 0 + else + if id then + local ownedItems = GetOwnedVehicleItems(id) + if IsVehicleOwned(id) and next(ownedItems) then + secondInv.inventory = ownedItems + Trunks[id] = {} + Trunks[id].items = ownedItems + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + elseif Trunks[id] and not Trunks[id].isOpen then + secondInv.inventory = Trunks[id].items + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + else + Trunks[id] = {} + Trunks[id].items = {} + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + end + end + end + elseif name == "glovebox" then + if Gloveboxes[id] then + if Gloveboxes[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Gloveboxes[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Gloveboxes[id].isOpen, name, id, Gloveboxes[id].label) + else + Gloveboxes[id].isOpen = false + end + end + end + secondInv.name = "glovebox-"..id + secondInv.label = "Glovebox-"..id + secondInv.maxweight = 10000 + secondInv.inventory = {} + secondInv.slots = 5 + if Gloveboxes[id] and Gloveboxes[id].isOpen then + secondInv.name = "none-inv" + secondInv.label = "Glovebox-None" + secondInv.maxweight = 10000 + secondInv.inventory = {} + secondInv.slots = 0 + else + local ownedItems = GetOwnedVehicleGloveboxItems(id) + if Gloveboxes[id] and not Gloveboxes[id].isOpen then + secondInv.inventory = Gloveboxes[id].items + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + elseif IsVehicleOwned(id) and next(ownedItems) then + secondInv.inventory = ownedItems + Gloveboxes[id] = {} + Gloveboxes[id].items = ownedItems + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + else + Gloveboxes[id] = {} + Gloveboxes[id].items = {} + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + end + end + elseif name == "shop" then + secondInv.name = "itemshop-"..id + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = SetupShopItems(other.items) + ShopItems[id] = {} + ShopItems[id].items = other.items + secondInv.slots = #other.items + elseif name == "traphouse" then + secondInv.name = "traphouse-"..id + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = other.slots + elseif name == "crafting" then + secondInv.name = "crafting" + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = #other.items + elseif name == "attachment_crafting" then + secondInv.name = "attachment_crafting" + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = #other.items + elseif name == "otherplayer" then + local OtherPlayer = QBCore.Functions.GetPlayer(tonumber(id)) + if OtherPlayer then + secondInv.name = "otherplayer-"..id + secondInv.label = "Player-"..id + secondInv.maxweight = Config.MaxInventoryWeight + secondInv.inventory = OtherPlayer.PlayerData.items + if (Player.PlayerData.job.name == "police" or Player.PlayerData.job.type == "leo") and Player.PlayerData.job.onduty then + secondInv.slots = Config.MaxInventorySlots + else + secondInv.slots = Config.MaxInventorySlots - 1 + end + Wait(250) + end + else + if Drops[id] then + if Drops[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Drops[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Drops[id].isOpen, name, id, Drops[id].label) + else + Drops[id].isOpen = false + end + end + end + if Drops[id] and not Drops[id].isOpen then + secondInv.coords = Drops[id].coords + secondInv.name = id + secondInv.label = "Dropped-"..tostring(id) + secondInv.maxweight = 100000 + secondInv.inventory = Drops[id].items + secondInv.slots = 30 + Drops[id].isOpen = src + Drops[id].label = secondInv.label + Drops[id].createdTime = os.time() + else + secondInv.name = "none-inv" + secondInv.label = "Dropped-None" + secondInv.maxweight = 100000 + secondInv.inventory = {} + secondInv.slots = 0 + end + end + TriggerClientEvent("ps-inventory:client:closeinv", id) + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items, secondInv) + else + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items) + end +end +exports('OpenInventory',OpenInventory) + +-- Events + +AddEventHandler('QBCore:Server:PlayerLoaded', function(Player) + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "AddItem", function(item, amount, slot, info) + return AddItem(Player.PlayerData.source, item, amount, slot, info) + end) + + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "RemoveItem", function(item, amount, slot) + return RemoveItem(Player.PlayerData.source, item, amount, slot) + end) + + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "GetItemBySlot", function(slot) + return GetItemBySlot(Player.PlayerData.source, slot) + end) + + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "GetItemByName", function(item) + return GetItemByName(Player.PlayerData.source, item) + end) + + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "GetItemsByName", function(item) + return GetItemsByName(Player.PlayerData.source, item) + end) + + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "ClearInventory", function(filterItems) + ClearInventory(Player.PlayerData.source, filterItems) + end) + + QBCore.Functions.AddPlayerMethod(Player.PlayerData.source, "SetInventory", function(items) + SetInventory(Player.PlayerData.source, items) + end) +end) + +AddEventHandler('onResourceStart', function(resourceName) + if resourceName ~= GetCurrentResourceName() then return end + local Players = QBCore.Functions.GetQBPlayers() + for k in pairs(Players) do + QBCore.Functions.AddPlayerMethod(k, "AddItem", function(item, amount, slot, info) + return AddItem(k, item, amount, slot, info) + end) + + QBCore.Functions.AddPlayerMethod(k, "RemoveItem", function(item, amount, slot) + return RemoveItem(k, item, amount, slot) + end) + + QBCore.Functions.AddPlayerMethod(k, "GetItemBySlot", function(slot) + return GetItemBySlot(k, slot) + end) + + QBCore.Functions.AddPlayerMethod(k, "GetItemByName", function(item) + return GetItemByName(k, item) + end) + + QBCore.Functions.AddPlayerMethod(k, "GetItemsByName", function(item) + return GetItemsByName(k, item) + end) + + QBCore.Functions.AddPlayerMethod(k, "ClearInventory", function(filterItems) + ClearInventory(k, filterItems) + end) + + QBCore.Functions.AddPlayerMethod(k, "SetInventory", function(items) + SetInventory(k, items) + end) + end +end) + +RegisterNetEvent('QBCore:Server:UpdateObject', function() + if source ~= '' then return end -- Safety check if the event was not called from the server. + QBCore = exports['qb-core']:GetCoreObject() +end) + +function addTrunkItems(plate, items) + Trunks[plate] = {} + Trunks[plate].items = items +end + +exports('addTrunkItems',addTrunkItems) + +function addGloveboxItems(plate, items) + Gloveboxes[plate] = {} + Gloveboxes[plate].items = items +end + +exports('addGloveboxItems',addGloveboxItems) + +RegisterNetEvent('inventory:server:combineItem', function(item, fromItem, toItem) + local src = source + + -- Check that inputs are not nil + -- Most commonly when abusing this exploit, this values are left as + if fromItem == nil then return end + if toItem == nil then return end + + -- Check that they have the items + fromItem = GetItemByName(src, fromItem) + toItem = GetItemByName(src, toItem) + + if fromItem == nil then return end + if toItem == nil then return end + + -- Check the recipe is valid + local recipe = QBCore.Shared.Items[toItem.name].combinable + + if recipe and recipe.reward ~= item then return end + if not recipeContains(recipe, fromItem) then return end + + TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add') + AddItem(src, item, 1) + RemoveItem(src, fromItem.name, 1) + RemoveItem(src, toItem.name, 1) +end) + +RegisterNetEvent('inventory:server:CraftItems', function(itemName, itemCosts, amount, toSlot, points) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + + amount = tonumber(amount) + + if not itemName or not itemCosts then return end + + for k, v in pairs(itemCosts) do + RemoveItem(src, k, (v*amount)) + end + AddItem(src, itemName, amount, toSlot) + Player.Functions.SetMetaData("craftingrep", Player.PlayerData.metadata["craftingrep"] + (points * amount)) + TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, false) +end) + +RegisterNetEvent('inventory:server:CraftAttachment', function(itemName, itemCosts, amount, toSlot, points) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + + amount = tonumber(amount) + + if not itemName or not itemCosts then return end + + for k, v in pairs(itemCosts) do + RemoveItem(src, k, (v*amount)) + end + AddItem(src, itemName, amount, toSlot) + Player.Functions.SetMetaData("attachmentcraftingrep", Player.PlayerData.metadata["attachmentcraftingrep"] + (points * amount)) + TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, false) +end) + +RegisterNetEvent('inventory:server:SetIsOpenState', function(IsOpen, type, id) + if IsOpen then return end + + if type == "stash" then + Stashes[id].isOpen = false + elseif type == "trunk" then + Trunks[id].isOpen = false + elseif type == "glovebox" then + Gloveboxes[id].isOpen = false + elseif type == "drop" then + Drops[id].isOpen = false + end +end) + +RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other) + local src = source + local ply = Player(src) + local Player = QBCore.Functions.GetPlayer(src) + if ply.state.inv_busy then + return QBCore.Functions.Notify(src, Lang:t("notify.noaccess"), 'error') + end + if name and id then + local secondInv = {} + if name == "stash" then + if Stashes[id] then + if Stashes[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Stashes[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Stashes[id].isOpen, name, id, Stashes[id].label) + else + Stashes[id].isOpen = false + end + end + end + local maxweight = 1000000 + local slots = 50 + if other then + maxweight = other.maxweight or 1000000 + slots = other.slots or 50 + end + secondInv.name = "stash-"..id + secondInv.label = "Stash-"..id + secondInv.maxweight = maxweight + secondInv.inventory = {} + secondInv.slots = slots + if Stashes[id] and Stashes[id].isOpen then + secondInv.name = "none-inv" + secondInv.label = "Stash-None" + secondInv.maxweight = 1000000 + secondInv.inventory = {} + secondInv.slots = 0 + else + local stashItems = GetStashItems(id) + if next(stashItems) then + secondInv.inventory = stashItems + Stashes[id] = {} + Stashes[id].items = stashItems + Stashes[id].isOpen = src + Stashes[id].label = secondInv.label + else + Stashes[id] = {} + Stashes[id].items = {} + Stashes[id].isOpen = src + Stashes[id].label = secondInv.label + end + end + elseif name == "trunk" then + if Trunks[id] then + if Trunks[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Trunks[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Trunks[id].isOpen, name, id, Trunks[id].label) + else + Trunks[id].isOpen = false + end + end + end + secondInv.name = "trunk-"..id + secondInv.label = "Trunk-"..id + secondInv.maxweight = other.maxweight or 60000 + secondInv.inventory = {} + secondInv.slots = other.slots or 50 + if (Trunks[id] and Trunks[id].isOpen) or (QBCore.Shared.SplitStr(id, "PLZI")[2] and (Player.PlayerData.job.name ~= "police" or Player.PlayerData.job.type ~= "leo")) then + secondInv.name = "none-inv" + secondInv.label = "Trunk-None" + secondInv.maxweight = other.maxweight or 60000 + secondInv.inventory = {} + secondInv.slots = 0 + else + if id then + local ownedItems = GetOwnedVehicleItems(id) + if IsVehicleOwned(id) and next(ownedItems) then + secondInv.inventory = ownedItems + Trunks[id] = {} + Trunks[id].items = ownedItems + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + elseif Trunks[id] and not Trunks[id].isOpen then + secondInv.inventory = Trunks[id].items + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + else + Trunks[id] = {} + Trunks[id].items = {} + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + end + end + end + elseif name == "glovebox" then + if Gloveboxes[id] then + if Gloveboxes[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Gloveboxes[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Gloveboxes[id].isOpen, name, id, Gloveboxes[id].label) + else + Gloveboxes[id].isOpen = false + end + end + end + secondInv.name = "glovebox-"..id + secondInv.label = "Glovebox-"..id + secondInv.maxweight = 10000 + secondInv.inventory = {} + secondInv.slots = 5 + if Gloveboxes[id] and Gloveboxes[id].isOpen then + secondInv.name = "none-inv" + secondInv.label = "Glovebox-None" + secondInv.maxweight = 10000 + secondInv.inventory = {} + secondInv.slots = 0 + else + local ownedItems = GetOwnedVehicleGloveboxItems(id) + if Gloveboxes[id] and not Gloveboxes[id].isOpen then + secondInv.inventory = Gloveboxes[id].items + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + elseif IsVehicleOwned(id) and next(ownedItems) then + secondInv.inventory = ownedItems + Gloveboxes[id] = {} + Gloveboxes[id].items = ownedItems + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + else + Gloveboxes[id] = {} + Gloveboxes[id].items = {} + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + end + end + elseif name == "shop" then + secondInv.name = "itemshop-"..id + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = SetupShopItems(other.items) + ShopItems[id] = {} + ShopItems[id].items = other.items + secondInv.slots = #other.items + elseif name == "traphouse" then + secondInv.name = "traphouse-"..id + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = other.slots + elseif name == "crafting" then + secondInv.name = "crafting" + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = #other.items + elseif name == "attachment_crafting" then + secondInv.name = "attachment_crafting" + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = #other.items + elseif name == "otherplayer" then + local OtherPlayer = QBCore.Functions.GetPlayer(tonumber(id)) + if OtherPlayer then + secondInv.name = "otherplayer-"..id + secondInv.label = "Player-"..id + secondInv.maxweight = Config.MaxInventoryWeight + secondInv.inventory = OtherPlayer.PlayerData.items + if (Player.PlayerData.job.name == "police" or Player.PlayerData.job.type == "leo") and Player.PlayerData.job.onduty then + secondInv.slots = Config.MaxInventorySlots + else + secondInv.slots = Config.MaxInventorySlots - 1 + end + Wait(250) + end + else + if Drops[id] then + if Drops[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Drops[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Drops[id].isOpen, name, id, Drops[id].label) + else + Drops[id].isOpen = false + end + end + end + if Drops[id] and not Drops[id].isOpen then + secondInv.coords = Drops[id].coords + secondInv.name = id + secondInv.label = "Dropped-"..tostring(id) + secondInv.maxweight = 100000 + secondInv.inventory = Drops[id].items + secondInv.slots = 30 + Drops[id].isOpen = src + Drops[id].label = secondInv.label + Drops[id].createdTime = os.time() + else + secondInv.name = "none-inv" + secondInv.label = "Dropped-None" + secondInv.maxweight = 100000 + secondInv.inventory = {} + secondInv.slots = 0 + end + end + TriggerClientEvent("ps-inventory:client:closeinv", id) + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items, secondInv) + else + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items) + end +end) + +RegisterNetEvent('inventory:server:SaveInventory', function(type, id) + if type == "trunk" then + if IsVehicleOwned(id) then + SaveOwnedVehicleItems(id, Trunks[id].items) + else + Trunks[id].isOpen = false + end + elseif type == "glovebox" then + if (IsVehicleOwned(id)) then + SaveOwnedGloveboxItems(id, Gloveboxes[id].items) + else + Gloveboxes[id].isOpen = false + end + elseif type == "stash" then + SaveStashItems(id, Stashes[id].items) + elseif type == "drop" then + if Drops[id] then + Drops[id].isOpen = false + if Drops[id].items == nil or next(Drops[id].items) == nil then + Drops[id] = nil + TriggerClientEvent("inventory:client:RemoveDropItem", -1, id) + end + end + end +end) + +RegisterNetEvent('inventory:server:UseItemSlot', function(slot) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + local itemData = Player.Functions.GetItemBySlot(slot) + if itemData then + local itemInfo = QBCore.Shared.Items[itemData.name] + if itemData.type == "weapon" then + if itemData.info.quality then + if itemData.info.quality > 0 then + TriggerClientEvent("inventory:client:UseWeapon", src, itemData, true) + else + TriggerClientEvent("inventory:client:UseWeapon", src, itemData, false) + end + else + TriggerClientEvent("inventory:client:UseWeapon", src, itemData, true) + end + TriggerClientEvent('inventory:client:ItemBox', src, itemInfo, "use") + elseif itemData.useable then + if itemData.info.quality then + if itemData.info.quality > 0 then + UseItem(itemData.name, src, itemData) + TriggerClientEvent('inventory:client:ItemBox', src, itemInfo, "use") + else + if itemInfo['delete'] and RemoveItem(src,itemData.name,1,slot) then + TriggerClientEvent('inventory:client:ItemBox',src, itemInfo, "remove") + else + TriggerClientEvent("QBCore:Notify", src, "Du kan ikke bruge denne ting!", "error") + end + end + else + UseItem(itemData.name, src, itemData) + TriggerClientEvent('inventory:client:ItemBox', src, itemInfo, "use") + end + end + end +end) + +RegisterNetEvent('inventory:server:UseItem', function(inventory, item) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + if inventory == "player" or inventory == "hotbar" then + local itemData = Player.Functions.GetItemBySlot(item.slot) + if itemData then + local itemInfo = QBCore.Shared.Items[itemData.name] + if itemData.type ~= "weapon" then + if itemData.info.quality then + if itemData.info.quality <= 0 then + if itemInfo['delete'] and RemoveItem(src,itemData.name,1,item.slot) then + TriggerClientEvent("QBCore:Notify", src, "Du kan ikke bruge denne ting!", "error") + TriggerClientEvent('inventory:client:ItemBox',src, itemInfo, "remove") + return + else + TriggerClientEvent("QBCore:Notify", src, "Du kan ikke bruge denne ting!", "error") + return + end + end + end + end + UseItem(itemData.name, src, itemData) + TriggerClientEvent('inventory:client:ItemBox', src, itemInfo, "use") + end + end +end) + +RegisterNetEvent('inventory:server:SetInventoryData', function(fromInventory, toInventory, fromSlot, toSlot, fromAmount, toAmount) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + fromSlot = tonumber(fromSlot) + toSlot = tonumber(toSlot) + + if (fromInventory == "player" or fromInventory == "hotbar") and (QBCore.Shared.SplitStr(toInventory, "-")[1] == "itemshop" or toInventory == "crafting") then + return + end + + if fromInventory == "player" or fromInventory == "hotbar" then + local fromItemData = GetItemBySlot(src, fromSlot) + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + RemoveItem(src, toItemData.name, toAmount, toSlot) + AddItem(src, toItemData.name, toAmount, fromSlot, toItemData.info) + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "**") + end + end + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + elseif QBCore.Shared.SplitStr(toInventory, "-")[1] == "otherplayer" then + local playerId = tonumber(QBCore.Shared.SplitStr(toInventory, "-")[2]) + local OtherPlayer = QBCore.Functions.GetPlayer(playerId) + local toItemData = OtherPlayer.PlayerData.items[toSlot] + local itemDataTest = OtherPlayer.Functions.GetItemBySlot(toSlot) + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if itemDataTest.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + OtherPlayer.Functions.RemoveItem(itemInfo["name"], toAmount, fromSlot) + Player.Functions.AddItem(toItemData.name, toAmount, fromSlot, toItemData.info) + TriggerEvent("qb-log:server:CreateLog", "robbing", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** with player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | id: *"..OtherPlayer.PlayerData.source.."*)") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** with player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | id: *"..OtherPlayer.PlayerData.source.."*)") + end + else + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + TriggerEvent("qb-log:server:CreateLog", "robbing", "Dropped Item", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) dropped new item; name: **"..itemInfo["name"].."**, amount: **" .. fromAmount .. "** to player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | id: *"..OtherPlayer.PlayerData.source.."*)") + end + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddItem(playerId, itemInfo["name"], fromAmount, toSlot, fromItemData.info, itemInfo["created"]) + elseif QBCore.Shared.SplitStr(toInventory, "-")[1] == "trunk" then + local plate = QBCore.Shared.SplitStr(toInventory, "-")[2] + local toItemData = Trunks[plate].items[toSlot] + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + RemoveFromTrunk(plate, fromSlot, itemInfo["name"], toAmount) + Player.Functions.AddItem(toItemData.name, toAmount, fromSlot, toItemData.info) + TriggerEvent("qb-log:server:CreateLog", "trunk", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount .. "** - plate: *" .. plate .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** - plate: *" .. plate .. "*") + end + else + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + TriggerEvent("qb-log:server:CreateLog", "trunk", "Dropped Item", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) dropped new item; name: **"..itemInfo["name"].."**, amount: **" .. fromAmount .. "** - plate: *" .. plate .. "*") + end + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToTrunk(plate, toSlot, fromSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + elseif QBCore.Shared.SplitStr(toInventory, "-")[1] == "glovebox" then + local plate = QBCore.Shared.SplitStr(toInventory, "-")[2] + local toItemData = Gloveboxes[plate].items[toSlot] + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + RemoveFromGlovebox(plate, fromSlot, itemInfo["name"], toAmount) + Player.Functions.AddItem(toItemData.name, toAmount, fromSlot, toItemData.info) + TriggerEvent("qb-log:server:CreateLog", "glovebox", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount .. "** - plate: *" .. plate .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** - plate: *" .. plate .. "*") + end + else + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + TriggerEvent("qb-log:server:CreateLog", "glovebox", "Dropped Item", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) dropped new item; name: **"..itemInfo["name"].."**, amount: **" .. fromAmount .. "** - plate: *" .. plate .. "*") + end + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToGlovebox(plate, toSlot, fromSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + elseif QBCore.Shared.SplitStr(toInventory, "-")[1] == "stash" then + local stashId = QBCore.Shared.SplitStr(toInventory, "-")[2] + local toItemData = Stashes[stashId].items[toSlot] + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + --RemoveFromStash(stashId, fromSlot, itemInfo["name"], toAmount) + RemoveFromStash(stashId, toSlot, itemInfo["name"], toAmount) + Player.Functions.AddItem(toItemData.name, toAmount, fromSlot, toItemData.info) + TriggerEvent("qb-log:server:CreateLog", "stash", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount .. "** - stash: *" .. stashId .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** - stash: *" .. stashId .. "*") + end + else + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + TriggerEvent("qb-log:server:CreateLog", "stash", "Dropped Item", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) dropped new item; name: **"..itemInfo["name"].."**, amount: **" .. fromAmount .. "** - stash: *" .. stashId .. "*") + end + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToStash(stashId, toSlot, fromSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + elseif QBCore.Shared.SplitStr(toInventory, "-")[1] == "traphouse" then + -- Traphouse + local traphouseId = QBCore.Shared.SplitStr(toInventory, "_")[2] + local toItemData = exports['qb-traphouse']:GetInventoryData(traphouseId, toSlot) + local IsItemValid = exports['qb-traphouse']:CanItemBeSaled(fromItemData.name:lower()) + if IsItemValid then + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + exports['qb-traphouse']:RemoveHouseItem(traphouseId, fromSlot, itemInfo["name"], toAmount) + Player.Functions.AddItem(toItemData.name, toAmount, fromSlot, toItemData.info) + TriggerEvent("qb-log:server:CreateLog", "traphouse", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount .. "** - traphouse: *" .. traphouseId .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** - traphouse: *" .. traphouseId .. "*") + end + else + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + TriggerEvent("qb-log:server:CreateLog", "traphouse", "Dropped Item", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) dropped new item; name: **"..itemInfo["name"].."**, amount: **" .. fromAmount .. "** - traphouse: *" .. traphouseId .. "*") + end + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + exports['qb-traphouse']:AddHouseItem(traphouseId, toSlot, itemInfo["name"], fromAmount, fromItemData.info, src) + else + TriggerClientEvent('QBCore:Notify', src, "Du kan ikke sælge denne ting..", 'error') + end + else + -- drop + toInventory = tonumber(toInventory) + if toInventory == nil or toInventory == 0 then + CreateNewDrop(src, fromSlot, toSlot, fromAmount) + else + local toItemData = Drops[toInventory].items[toSlot] + RemoveItem(src, fromItemData.name, fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", src, fromItemData.name) + if toItemData ~= nil then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + Player.Functions.AddItem(toItemData.name, toAmount, fromSlot, toItemData.info) + RemoveFromDrop(toInventory, fromSlot, itemInfo["name"], toAmount) + TriggerEvent("qb-log:server:CreateLog", "drop", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount .. "** - dropid: *" .. toInventory .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** - dropid: *" .. toInventory .. "*") + end + else + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + TriggerEvent("qb-log:server:CreateLog", "drop", "Dropped Item", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) dropped new item; name: **"..itemInfo["name"].."**, amount: **" .. fromAmount .. "** - dropid: *" .. toInventory .. "*") + end + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToDrop(toInventory, toSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + if itemInfo["name"] == "radio" then + TriggerClientEvent('Radio.Set', src, false) + end + end + end + else + TriggerClientEvent("QBCore:Notify", src, "Du har ikke denne ting!", "error") + end + elseif QBCore.Shared.SplitStr(fromInventory, "-")[1] == "otherplayer" then + local playerId = tonumber(QBCore.Shared.SplitStr(fromInventory, "-")[2]) + local OtherPlayer = QBCore.Functions.GetPlayer(playerId) + local fromItemData = OtherPlayer.PlayerData.items[fromSlot] + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + RemoveItem(playerId, itemInfo["name"], fromAmount, fromSlot) + TriggerClientEvent("inventory:client:CheckWeapon", OtherPlayer.PlayerData.source, fromItemData.name) + if toItemData ~= nil then + itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + Player.Functions.RemoveItem(toItemData.name, toAmount, toSlot) + OtherPlayer.Functions.AddItem(itemInfo["name"], toAmount, fromSlot, toItemData.info) + TriggerEvent("qb-log:server:CreateLog", "robbing", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** from player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | *"..OtherPlayer.PlayerData.source.."*)") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** with player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | id: *"..OtherPlayer.PlayerData.source.."*)") + end + else + TriggerEvent("qb-log:server:CreateLog", "robbing", "Retrieved Item", "green", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) took item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** from player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | *"..OtherPlayer.PlayerData.source.."*)") + end + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + else + local toItemData = OtherPlayer.PlayerData.items[toSlot] + local itemDataTest = OtherPlayer.Functions.GetItemBySlot(toSlot) + RemoveItem(playerId, itemInfo["name"], fromAmount, fromSlot) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if itemDataTest.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + OtherPlayer.Functions.RemoveItem(itemInfo["name"], toAmount, toSlot) + OtherPlayer.Functions.AddItem(itemInfo["name"], toAmount, fromSlot, toItemData.info) + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** with name: **" .. fromItemData.name .. "**, amount: **" .. fromAmount.. "** with player: **".. GetPlayerName(OtherPlayer.PlayerData.source) .. "** (citizenid: *"..OtherPlayer.PlayerData.citizenid.."* | id: *"..OtherPlayer.PlayerData.source.."*)") + end + end + itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddItem(playerId, itemInfo["name"], fromAmount, toSlot, fromItemData.info, itemInfo["created"]) + end + else + QBCore.Functions.Notify(src, "Ting findes ikke!", "error") + end + elseif QBCore.Shared.SplitStr(fromInventory, "-")[1] == "trunk" then + local plate = QBCore.Shared.SplitStr(fromInventory, "-")[2] + local fromItemData = Trunks[plate].items[fromSlot] + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + RemoveFromTrunk(plate, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + Player.Functions.RemoveItem(toItemData.name, toAmount, toSlot) + AddToTrunk(plate, fromSlot, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + TriggerEvent("qb-log:server:CreateLog", "trunk", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** plate: *" .. plate .. "*") + else + TriggerEvent("qb-log:server:CreateLog", "trunk", "Stacked Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) stacked item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** from plate: *" .. plate .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with name: **" .. itemInfo["name"] .. "**, amount: **" .. toAmount.. "** plate: *" .. plate .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "trunk", "Received Item", "green", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) received item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount.. "** plate: *" .. plate .. "*") + end + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + else + local toItemData = Trunks[plate].items[toSlot] + RemoveFromTrunk(plate, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + RemoveFromTrunk(plate, toSlot, itemInfo["name"], toAmount) + AddToTrunk(plate, fromSlot, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with name: **" .. itemInfo["name"] .. "**, amount: **" .. toAmount.. "** plate: *" .. plate .. "*") + end + end + itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToTrunk(plate, toSlot, fromSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + end + else + QBCore.Functions.Notify(src, Lang:t("notify.itemexist"), "error") + end + elseif QBCore.Shared.SplitStr(fromInventory, "-")[1] == "glovebox" then + local plate = QBCore.Shared.SplitStr(fromInventory, "-")[2] + local fromItemData = Gloveboxes[plate].items[fromSlot] + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + RemoveFromGlovebox(plate, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + Player.Functions.RemoveItem(toItemData.name, toAmount, toSlot) + AddToGlovebox(plate, fromSlot, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + TriggerEvent("qb-log:server:CreateLog", "glovebox", "Swapped", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src..")* swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..itemInfo["name"].."**, amount: **" .. toAmount .. "** plate: *" .. plate .. "*") + else + TriggerEvent("qb-log:server:CreateLog", "glovebox", "Stacked Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) stacked item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** from plate: *" .. plate .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with name: **" .. itemInfo["name"] .. "**, amount: **" .. toAmount.. "** plate: *" .. plate .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "glovebox", "Received Item", "green", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) received item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount.. "** plate: *" .. plate .. "*") + end + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + else + local toItemData = Gloveboxes[plate].items[toSlot] + RemoveFromGlovebox(plate, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + RemoveFromGlovebox(plate, toSlot, itemInfo["name"], toAmount) + AddToGlovebox(plate, fromSlot, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with name: **" .. itemInfo["name"] .. "**, amount: **" .. toAmount.. "** plate: *" .. plate .. "*") + end + end + itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToGlovebox(plate, toSlot, fromSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + end + else + QBCore.Functions.Notify(src, Lang:t("notify.itemexist"), "error") + end + elseif QBCore.Shared.SplitStr(fromInventory, "-")[1] == "stash" then + local stashId = QBCore.Shared.SplitStr(fromInventory, "-")[2] + local fromItemData = Stashes[stashId].items[fromSlot] + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + RemoveFromStash(stashId, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + Player.Functions.RemoveItem(toItemData.name, toAmount, toSlot) + AddToStash(stashId, fromSlot, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + TriggerEvent("qb-log:server:CreateLog", "stash", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** stash: *" .. stashId .. "*") + else + TriggerEvent("qb-log:server:CreateLog", "stash", "Stacked Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) stacked item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** from stash: *" .. stashId .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** stash: *" .. stashId .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "stash", "Received Item", "green", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) received item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount.. "** stash: *" .. stashId .. "*") + end + SaveStashItems(stashId, Stashes[stashId].items) + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + else + local toItemData = Stashes[stashId].items[toSlot] + RemoveFromStash(stashId, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + RemoveFromStash(stashId, toSlot, itemInfo["name"], toAmount) + AddToStash(stashId, fromSlot, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** stash: *" .. stashId .. "*") + end + end + itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToStash(stashId, toSlot, fromSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + end + else + QBCore.Functions.Notify(src, Lang:t("notify.itemexist"), "error") + end + elseif QBCore.Shared.SplitStr(fromInventory, "-")[1] == "traphouse" then + local traphouseId = QBCore.Shared.SplitStr(fromInventory, "_")[2] + local fromItemData = exports['qb-traphouse']:GetInventoryData(traphouseId, fromSlot) + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + exports['qb-traphouse']:RemoveHouseItem(traphouseId, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + Player.Functions.RemoveItem(toItemData.name, toAmount, toSlot) + exports['qb-traphouse']:AddHouseItem(traphouseId, fromSlot, itemInfo["name"], toAmount, toItemData.info, src) + TriggerEvent("qb-log:server:CreateLog", "stash", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** stash: *" .. traphouseId .. "*") + else + TriggerEvent("qb-log:server:CreateLog", "stash", "Stacked Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) stacked item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** from stash: *" .. traphouseId .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** stash: *" .. traphouseId .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "stash", "Received Item", "green", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) received item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount.. "** stash: *" .. traphouseId .. "*") + end + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + else + local toItemData = exports['qb-traphouse']:GetInventoryData(traphouseId, toSlot) + exports['qb-traphouse']:RemoveHouseItem(traphouseId, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + exports['qb-traphouse']:RemoveHouseItem(traphouseId, toSlot, itemInfo["name"], toAmount) + exports['qb-traphouse']:AddHouseItem(traphouseId, fromSlot, itemInfo["name"], toAmount, toItemData.info, src) + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** stash: *" .. traphouseId .. "*") + end + end + itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + exports['qb-traphouse']:AddHouseItem(traphouseId, toSlot, itemInfo["name"], fromAmount, fromItemData.info, src) + end + else + QBCore.Functions.Notify(src, "Ting findes ikke??", "error") + end + elseif QBCore.Shared.SplitStr(fromInventory, "-")[1] == "itemshop" then + local shopType = QBCore.Shared.SplitStr(fromInventory, "-")[2] + local itemData = ShopItems[shopType].items[fromSlot] + local itemInfo = QBCore.Shared.Items[itemData.name:lower()] + local bankBalance = Player.PlayerData.money["bank"] + local price = tonumber((itemData.price*fromAmount)) + + if QBCore.Shared.SplitStr(shopType, "_")[1] == "Dealer" then + if QBCore.Shared.SplitStr(itemData.name, "_")[1] == "weapon" then + price = tonumber(itemData.price) + if Player.Functions.RemoveMoney("cash", price, "dealer-item-bought") then + itemData.info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) + itemData.info.quality = 100 + AddItem(src, itemData.name, 1, toSlot, itemData.info) + TriggerClientEvent('qb-drugs:client:updateDealerItems', src, itemData, 1) + QBCore.Functions.Notify(src, itemInfo["label"] .. " købt!", "success") + TriggerEvent("qb-log:server:CreateLog", "dealers", "Dealer item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price) + else + QBCore.Functions.Notify(src, "Du har ikke nok penge..", "error") + end + else + if Player.Functions.RemoveMoney("cash", price, "dealer-item-bought") then + AddItem(src, itemData.name, fromAmount, toSlot, itemData.info) + TriggerClientEvent('qb-drugs:client:updateDealerItems', src, itemData, fromAmount) + QBCore.Functions.Notify(src, itemInfo["label"] .. " købt!", "success") + TriggerEvent("qb-log:server:CreateLog", "dealers", "Dealer item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price) + else + QBCore.Functions.Notify(src, "Du har ikke nok penge..", "error") + end + end + elseif QBCore.Shared.SplitStr(shopType, "_")[1] == "Itemshop" then + if Player.Functions.RemoveMoney("cash", price, "itemshop-bought-item") then + if QBCore.Shared.SplitStr(itemData.name, "_")[1] == "weapon" then + itemData.info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) + itemData.info.quality = 100 + end + local serial = itemData.info.serie + local imageurl = ("https://cfx-nui-ps-inventory/html/images/%s.png"):format(itemData.name) + local notes = "Purchased at Ammunation" + local owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname + local weapClass = 1 + local weapModel = QBCore.Shared.Items[itemData.name].label + AddItem(src, itemData.name, fromAmount, toSlot, itemData.info) + TriggerClientEvent('qb-shops:client:UpdateShop', src, QBCore.Shared.SplitStr(shopType, "_")[2], itemData, fromAmount) + QBCore.Functions.Notify(src, itemInfo["label"] .. " købt!", "success") + exports['ps-mdt']:CreateWeaponInfo(serial, imageurl, notes, owner, weapClass, weapModel) + TriggerEvent("qb-log:server:CreateLog", "shops", "Shop item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price) + elseif bankBalance >= price then + Player.Functions.RemoveMoney("bank", price, "itemshop-bought-item") + if QBCore.Shared.SplitStr(itemData.name, "_")[1] == "weapon" then + itemData.info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) + itemData.info.quality = 100 + end + local serial = itemData.info.serie + local imageurl = ("https://cfx-nui-ps-inventory/html/images/%s.png"):format(itemData.name) + local notes = "Purchased at Ammunation" + local owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname + local weapClass = 1 + local weapModel = QBCore.Shared.Items[itemData.name].label + AddItem(src, itemData.name, fromAmount, toSlot, itemData.info) + TriggerClientEvent('qb-shops:client:UpdateShop', src, QBCore.Shared.SplitStr(shopType, "_")[2], itemData, fromAmount) + QBCore.Functions.Notify(src, itemInfo["label"] .. " købt!", "success") + exports['ps-mdt']:CreateWeaponInfo(serial, imageurl, notes, owner, weapClass, weapModel) + TriggerEvent("qb-log:server:CreateLog", "shops", "Shop item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price) + else + QBCore.Functions.Notify(src, "Du har ikke nok penge..", "error") + end + else + if Player.Functions.RemoveMoney("cash", price, "unkown-itemshop-bought-item") then + AddItem(src, itemData.name, fromAmount, toSlot, itemData.info) + QBCore.Functions.Notify(src, itemInfo["label"] .. " købt!", "success") + TriggerEvent("qb-log:server:CreateLog", "shops", "Shop item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price) + elseif bankBalance >= price then + Player.Functions.RemoveMoney("bank", price, "unkown-itemshop-bought-item") + AddItem(src, itemData.name, fromAmount, toSlot, itemData.info) + QBCore.Functions.Notify(src, itemInfo["label"] .. " købt!", "success") + TriggerEvent("qb-log:server:CreateLog", "shops", "Shop item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price) + else + TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok penge..", "error") + end + end + elseif fromInventory == "crafting" then + local itemData = Config.CraftingItems[fromSlot] + if hasCraftItems(src, itemData.costs, fromAmount) then + TriggerClientEvent("inventory:client:CraftItems", src, itemData.name, itemData.costs, fromAmount, toSlot, itemData.points) + else + TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, true) + TriggerClientEvent('QBCore:Notify', src, "Du har ikke de rigtige ting..", "error") + end + elseif fromInventory == "attachment_crafting" then + local itemData = Config.AttachmentCrafting[fromSlot] + if hasCraftItems(src, itemData.costs, fromAmount) then + TriggerClientEvent("inventory:client:CraftAttachment", src, itemData.name, itemData.costs, fromAmount, toSlot, itemData.points) + else + TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, true) + TriggerClientEvent('QBCore:Notify', src, "Du har ikke de rigtige ting..", "error") + end + else + -- drop + fromInventory = tonumber(fromInventory) + local fromItemData = Drops[fromInventory].items[fromSlot] + fromAmount = tonumber(fromAmount) or fromItemData.amount + if fromItemData and fromItemData.amount >= fromAmount then + local itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + if toInventory == "player" or toInventory == "hotbar" then + local toItemData = GetItemBySlot(src, toSlot) + RemoveFromDrop(fromInventory, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + toAmount = tonumber(toAmount) and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + Player.Functions.RemoveItem(toItemData.name, toAmount, toSlot) + AddToDrop(fromInventory, toSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + if itemInfo["name"] == "radio" then + TriggerClientEvent('Radio.Set', src, false) + end + TriggerEvent("qb-log:server:CreateLog", "drop", "Swapped Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** - dropid: *" .. fromInventory .. "*") + else + TriggerEvent("qb-log:server:CreateLog", "drop", "Stacked Item", "orange", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) stacked item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** - from dropid: *" .. fromInventory .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** - dropid: *" .. fromInventory .. "*") + end + else + TriggerEvent("qb-log:server:CreateLog", "drop", "Received Item", "green", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) received item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount.. "** - dropid: *" .. fromInventory .. "*") + end + AddItem(src, fromItemData.name, fromAmount, toSlot, fromItemData.info, fromItemData["created"]) + else + toInventory = tonumber(toInventory) + local toItemData = Drops[toInventory].items[toSlot] + RemoveFromDrop(fromInventory, fromSlot, itemInfo["name"], fromAmount) + if toItemData ~= nil then + local toAmount = tonumber(toAmount) ~= nil and tonumber(toAmount) or toItemData.amount + if toItemData.amount >= toAmount then + if toItemData.name ~= fromItemData.name then + local itemInfo = QBCore.Shared.Items[toItemData.name:lower()] + RemoveFromDrop(toInventory, toSlot, itemInfo["name"], toAmount) + AddToDrop(fromInventory, fromSlot, itemInfo["name"], toAmount, toItemData.info, itemInfo["created"]) + if itemInfo["name"] == "radio" then + TriggerClientEvent('Radio.Set', src, false) + end + end + else + TriggerEvent("qb-log:server:CreateLog", "anticheat", "Dupe log", "red", "**".. GetPlayerName(src) .. "** (citizenid: *"..Player.PlayerData.citizenid.."* | id: *"..src.."*) swapped item; name: **"..toItemData.name.."**, amount: **" .. toAmount .. "** with item; name: **"..fromItemData.name.."**, amount: **" .. fromAmount .. "** - dropid: *" .. fromInventory .. "*") + end + end + itemInfo = QBCore.Shared.Items[fromItemData.name:lower()] + AddToDrop(toInventory, toSlot, itemInfo["name"], fromAmount, fromItemData.info, itemInfo["created"]) + if itemInfo["name"] == "radio" then + TriggerClientEvent('Radio.Set', src, false) + end + end + else + QBCore.Functions.Notify(src, "Ting findes ikke??", "error") + end + end +end) + +RegisterNetEvent('ps-inventory:server:SaveStashItems', function(stashId, items) + MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { + ['stash'] = stashId, + ['items'] = json.encode(items) + }) +end) + +RegisterServerEvent("inventory:server:GiveItem", function(target, name, amount, slot) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + target = tonumber(target) + local OtherPlayer = QBCore.Functions.GetPlayer(target) + local dist = #(GetEntityCoords(GetPlayerPed(src))-GetEntityCoords(GetPlayerPed(target))) + if Player == OtherPlayer then return QBCore.Functions.Notify(src, "Du kan ikke give dig selv ting?") end + if dist > 2 then return QBCore.Functions.Notify(src, "Du er for langt væk!") end + local item = GetItemBySlot(src, slot) + if not item then QBCore.Functions.Notify(src, "Tingen du prøvede at give væk findes ikke!"); return end + if item.name ~= name then QBCore.Functions.Notify(src, "Forkert ting, prøv igen!"); return end + + if amount <= item.amount then + if amount == 0 then + amount = item.amount + end + if RemoveItem(src, item.name, amount, item.slot) then + if AddItem(target, item.name, amount, false, item.info, item.created) then + TriggerClientEvent('inventory:client:ItemBox',target, QBCore.Shared.Items[item.name], "add") + QBCore.Functions.Notify(target, "Du fik "..amount..' '..item.label.." fra "..Player.PlayerData.charinfo.firstname.." "..Player.PlayerData.charinfo.lastname) + TriggerClientEvent("inventory:client:UpdatePlayerInventory", target, true) + TriggerClientEvent('inventory:client:ItemBox',src, QBCore.Shared.Items[item.name], "remove") + QBCore.Functions.Notify(src, "Du gav " .. OtherPlayer.PlayerData.charinfo.firstname.." "..OtherPlayer.PlayerData.charinfo.lastname.. " " .. amount .. " " .. item.label .."!") + TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, true) + TriggerClientEvent('ps-inventory:client:giveAnim', src) + TriggerClientEvent('ps-inventory:client:giveAnim', target) + else + AddItem(src, item.name, amount, item.slot, item.info, item.created) + QBCore.Functions.Notify(src, "Personens inventar er fyldt!", "error") + QBCore.Functions.Notify(target, "Personens inventar er fyldt!", "error") + TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, false) + TriggerClientEvent("inventory:client:UpdatePlayerInventory", target, false) + end + else + TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok ting", "error") + end + else + TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok ting at overfører") + end +end) + +RegisterNetEvent('inventory:server:snowball', function(action) + if action == "add" then + AddItem(source, "weapon_snowball") + elseif action == "remove" then + RemoveItem(source, "weapon_snowball") + end +end) + +-- callback + +QBCore.Functions.CreateCallback('ps-inventory:server:GetStashItems', function(source, cb, stashId) + cb(GetStashItems(stashId)) +end) + +QBCore.Functions.CreateCallback('inventory:server:GetCurrentDrops', function(_, cb) + cb(Drops) +end) + +QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, amount) + print("^3QBCore:HasItem is deprecated, please use QBCore.Functions.HasItem, it can be used on both server- and client-side and uses the same arguments.^0") + local retval = false + local Player = QBCore.Functions.GetPlayer(source) + if not Player then return cb(false) end + local isTable = type(items) == 'table' + local isArray = isTable and table.type(items) == 'array' or false + local totalItems = #items + local count = 0 + local kvIndex = 2 + if isTable and not isArray then + totalItems = 0 + for _ in pairs(items) do totalItems += 1 end + kvIndex = 1 + end + if isTable then + for k, v in pairs(items) do + local itemKV = {k, v} + local item = GetItemByName(source, itemKV[kvIndex]) + if item and ((amount and item.amount >= amount) or (not amount and not isArray and item.amount >= v) or (not amount and isArray)) then + count += 1 + end + end + if count == totalItems then + retval = true + end + else -- Single item as string + local item = GetItemByName(source, items) + if item and not amount or (item and amount and item.amount >= amount) then + retval = true + end + end + cb(retval) +end) + +-- command + +QBCore.Commands.Add("resetinv", "Nulstil inventar (Admin)", {{name="type", help="stash/trunk/glovebox"},{name="id/nummerplade", help="ID på stash eller nummerplade"}}, true, function(source, args) + local invType = args[1]:lower() + table.remove(args, 1) + local invId = table.concat(args, " ") + if invType and invId then + if invType == "trunk" then + if Trunks[invId] then + Trunks[invId].isOpen = false + end + elseif invType == "glovebox" then + if Gloveboxes[invId] then + Gloveboxes[invId].isOpen = false + end + elseif invType == "stash" then + if Stashes[invId] then + Stashes[invId].isOpen = false + end + else + TriggerClientEvent('QBCore:Notify', source, "Ikke gyldig type..", "error") + end + else + TriggerClientEvent('QBCore:Notify', source, "Du har ikke fyldt alt ud..", "error") + end +end, "admin") + +QBCore.Commands.Add("rob", "Røv spiller", {}, false, function(source, args) + TriggerClientEvent("police:client:RobPlayer", source) +end) + +QBCore.Commands.Add("giveitem", "Giv ting (Admin Only)", {{name="id", help="Spiller ID"},{name="genstand", help="Objekt-navnet på genstanden (Ikke label)"}, {name="mængde", help="Antal du vil give"}}, false, function(source, args) + local id = tonumber(args[1]) + local Player = QBCore.Functions.GetPlayer(id) + local amount = tonumber(args[3]) or 1 + local itemData = QBCore.Shared.Items[tostring(args[2]):lower()] + if Player then + if itemData then + -- check iteminfo + local info = {} + if itemData["name"] == "id_card" then + info.citizenid = Player.PlayerData.citizenid + info.firstname = Player.PlayerData.charinfo.firstname + info.lastname = Player.PlayerData.charinfo.lastname + info.birthdate = Player.PlayerData.charinfo.birthdate + info.gender = Player.PlayerData.charinfo.gender + info.nationality = Player.PlayerData.charinfo.nationality + elseif itemData["name"] == "driver_license" then + info.firstname = Player.PlayerData.charinfo.firstname + info.lastname = Player.PlayerData.charinfo.lastname + info.birthdate = Player.PlayerData.charinfo.birthdate + info.type = "B Kørekort" + elseif itemData["type"] == "weapon" then + amount = 1 + info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) + info.quality = 100 + elseif itemData["name"] == "harness" then + info.uses = 20 + elseif itemData["name"] == "markedbills" then + info.worth = math.random(5000, 10000) + elseif itemData["name"] == "labkey" then + info.lab = exports["qb-methlab"]:GenerateRandomLab() + elseif itemData["name"] == "printerdocument" then + info.url = "https://cdn.discordapp.com/attachments/870094209783308299/870104331142189126/Logo_-_Display_Picture_-_Stylized_-_Red.png" + elseif QBCore.Shared.Items[itemData["name"]]["decay"] and QBCore.Shared.Items[itemData["name"]]["decay"] > 0 then + info.quality = 100 + end + + if AddItem(id, itemData["name"], amount, false, info) then + QBCore.Functions.Notify(source, "Du hav " ..Player.PlayerData.charinfo.firstname.." "..Player.PlayerData.charinfo.lastname.." "..amount.." "..itemData["name"].. "", "success") + else + QBCore.Functions.Notify(source, "Du kan ikke give ting!", "error") + end + else + QBCore.Functions.Notify(source, "Dette item findes ikke", "error") + end + else + QBCore.Functions.Notify(source, "Spilleren er offline", "error") + end +end, "admin") + +QBCore.Commands.Add("randomitems", "Giv tilfældige ting (God)", {}, false, function(source, _) + local filteredItems = {} + for k, v in pairs(QBCore.Shared.Items) do + if QBCore.Shared.Items[k]["type"] ~= "weapon" then + filteredItems[#filteredItems+1] = v + end + end + for _ = 1, 10, 1 do + local randitem = filteredItems[math.random(1, #filteredItems)] + local amount = math.random(1, 10) + if randitem["unique"] then + amount = 1 + end + if AddItem(source, randitem["name"], amount) then + TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[randitem["name"]], 'add') + Wait(500) + end + end +end, "god") + +QBCore.Commands.Add('clearinv', 'Nulstil spillers inventar (Admin)', { { name = 'id', help = 'Spillerens ID' } }, false, function(source, args) + local playerId = args[1] ~= '' and tonumber(args[1]) or source + local Player = QBCore.Functions.GetPlayer(playerId) + if Player then + ClearInventory(playerId) + else + QBCore.Functions.Notify(source, "Spilleren er ikke online", 'error') + end +end, 'admin') + +-- item + +-- QBCore.Functions.CreateUseableItem("snowball", function(source, item) +-- local Player = QBCore.Functions.GetPlayer(source) +-- local itemData = Player.Functions.GetItemBySlot(item.slot) -- --- DID THIS GET PUT ELSEWHERE?? IDK +-- if Player.Functions.GetItemBySlot(item.slot) then +-- TriggerClientEvent("inventory:client:UseSnowball", source, itemData.amount) +-- end +-- end) + +CreateUsableItem("driver_license", function(source, item) + local playerPed = GetPlayerPed(source) + local playerCoords = GetEntityCoords(playerPed) + local players = QBCore.Functions.GetPlayers() + for _, v in pairs(players) do + local targetPed = GetPlayerPed(v) + local dist = #(playerCoords - GetEntityCoords(targetPed)) + if dist < 3.0 then + TriggerClientEvent('chat:addMessage', v, { + template = '', + args = { + "Kørekort", + item.info.firstname, + item.info.lastname, + item.info.birthdate, + item.info.type + } + } + ) + end + end +end) + +CreateUsableItem("id_card", function(source, item) + local playerPed = GetPlayerPed(source) + local playerCoords = GetEntityCoords(playerPed) + local players = QBCore.Functions.GetPlayers() + for _, v in pairs(players) do + local targetPed = GetPlayerPed(v) + local dist = #(playerCoords - GetEntityCoords(targetPed)) + if dist < 3.0 then + local gender = "Mand" + if item.info.gender == 1 then + gender = "Kvinde" + end + TriggerClientEvent('chat:addMessage', v, { + template = '', + args = { + "ID Kort", + item.info.citizenid, + item.info.firstname, + item.info.lastname, + item.info.birthdate, + gender, + item.info.nationality + } + } + ) + end + end +end) + + +CreateThread(function() + while true do + for k, v in pairs(Drops) do + if v and (v.createdTime + Config.CleanupDropTime < os.time()) and not Drops[k].isOpen then + Drops[k] = nil + TriggerClientEvent("inventory:client:RemoveDropItem", -1, k) + end + end + Wait(60 * 1000) + end +end) + +-- Decay System + +local TimeAllowed = 60 * 60 * 24 * 1 -- Maths for 1 day dont touch its very important and could break everything +function ConvertQuality(item) + local StartDate = item.created + local DecayRate = QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil and QBCore.Shared.Items[item.name:lower()]["decay"] or 0.0 + if DecayRate == nil then + DecayRate = 0 + end + local TimeExtra = math.ceil((TimeAllowed * DecayRate)) + local percentDone = 100 - math.ceil((((os.time() - StartDate) / TimeExtra) * 100)) + if DecayRate == 0 then + percentDone = 100 + end + if percentDone < 0 then + percentDone = 0 + end + return percentDone +end + +QBCore.Functions.CreateCallback('inventory:server:ConvertQuality', function(source, cb, inventory, other) + local src = source + local data = {} + local Player = QBCore.Functions.GetPlayer(src) + for _, item in pairs(inventory) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if type(item.info) == "string" then + item.info = {} + end + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + if other then + local inventoryType = QBCore.Shared.SplitStr(other.name, "-")[1] + local uniqueId = QBCore.Shared.SplitStr(other.name, "-")[2] + if inventoryType == "trunk" then + for _, item in pairs(other.inventory) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + Trunks[uniqueId].items = other.inventory + TriggerClientEvent("inventory:client:UpdateOtherInventory", Player.PlayerData.source, other.inventory, false) + elseif inventoryType == "glovebox" then + for _, item in pairs(other.inventory) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + Gloveboxes[uniqueId].items = other.inventory + TriggerClientEvent("inventory:client:UpdateOtherInventory", Player.PlayerData.source, other.inventory, false) + elseif inventoryType == "stash" then + for _, item in pairs(other.inventory) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if type(item.info) == "string" then + item.info = {} + end + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + Stashes[uniqueId].items = other.inventory + TriggerClientEvent("inventory:client:UpdateOtherInventory", Player.PlayerData.source, other.inventory, false) + end + end + Player.Functions.SetInventory(inventory) + TriggerClientEvent("inventory:client:UpdatePlayerInventory", Player.PlayerData.source, false) + data.inventory = inventory + data.other = other + cb(data) +end) + +-- Warning Messages + +RegisterNetEvent('inventory:server:addTrunkItems', function() + print('inventory:server:addTrunkItems has been deprecated please use exports[\'ps-inventory\']:addTrunkItems(plate, items)') +end) +RegisterNetEvent('inventory:server:addGloveboxItems', function() + print('inventory:server:addGloveboxItems has been deprecated please use exports[\'ps-inventory\']:addGloveboxItems(plate, items)') +end)