Code Monkey home page Code Monkey logo

qb-decay's Introduction

Description

This is a proof-of-concept for a server-sided item degradation system that uses a cron schedule, and run whether players are on or not. This can adjust qualities of items in player inventories, stashes, gloveboxes and trunks. I found adjustements needed to be made to the inventory js, for this to make sense. In this example, I've added a degrade value on the shared.lua QBShared.Items table. If no amount is set, it will not degrade the item.

Acknowledgment

Thanks to mknzz for the locations in the inventory javascript to comment, to display Quality on all items. Shoutout to sgtherbz and SnipeOP for helping test.

Usage

Set the hours of the day that you want the decay to occur, this is according to the server's clock. Next, add a degrade value with a float amount that an item will be decayed by, to each item you want affected, in your QBShared.Items. This decay will take place at each point of the day you set in the config.

["degrade"] = 1.0

Depending on the inventory system you are using, you might need to comment out all the locations listed in this. These locations may be different depending on the inventory you're using. You can start to see the pattern.

This was just personal preference and needed for the v3 qb-inventory script I'm using, but I wanted stacked items to have the lower of the two items' Quality, to prevent exploitation and the following code change does that. Within the following block:

if ( (toData != undefined || toData != null) && toData.name == fromData.name && !fromData.unique ) {

Place the following code at the top:

if (fromData.info.quality < toData.info.quality) { toData.info.quality = fromData.info.quality }

To make sense, this would probably require a check in a LOT of places to see if the used item is Broken or not. Implementing it in the core's CreateUseableItem function, is pretty straight-forward, but items can be consumed/used/combined/crafted/etc in other ways than that, and would need this check there. This POC is only to provide the decay mechanism and will not include code changes needed elsewhere for that sanity-checking and implementation; that's up to you.

Commands

I left a testdecay command for players with god permission, that can manually trigger the degradation event.

Dependencies

  • oxmysql (Written for ver. 1.8.7, I know they've dont a syntax change since then.)
  • cron

TODO

  • Lots of oppurtunity for code cleanup. It's currently very repetitive and dirty.
  • An export to return whether the item is broken or not.
  • Needs checking for if stashes or player inventories are currently opened by a played. This decay code could could be placed in the inventory, and would have direct access to those values.
  • Integrating it with Inventory would also technically give it access to Drops, and could be applied to those tables too, to prevent players from exploiting, as this is a place where items could exist and not be affected by decay.

Qbus.xyz Discord:

Discord

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.