TWH-Scripts
  • 👋Welcome!
  • About us
    • 🚀Vision, Mission & Focus
      • Vision
      • Mission
      • Focus
    • 💖Values
  • Team
    • 👋Meet the Team!
  • Collaborating
    • 🤝How we Work Together
  • Resources
    • 📄Script-Documentations
      • Addiction
      • Bankrob
      • BodyStatusText
      • Calendar-Rewards
      • Collect
      • Lumber & Mining Essentials
      • Collector's Conquest Bundle
        • Tradingcards
        • Boosterpacks
        • Tradingcard Upgrades
      • Custom Dates
      • Dispatch-System
      • Lawmen
      • Mapmarker
      • NPC-Guides
      • Oilcorp.
      • Processing
      • Promotion-Pass
      • Social-Level System
      • Social-Pass
      • Storage
    • 📂Open Source
    • 📝Useful Snippets and Info
      • Addiction and Metabolism
  • Services
    • 🛠️Custom Orders and Personalized Development Services
    • 📖Advanced Logging System
Powered by GitBook
On this page
  1. Resources
  2. Useful Snippets and Info

Addiction and Metabolism

An example of using twh_addiction with fred_metabolism

PreviousUseful Snippets and InfoNextCustom Orders and Personalized Development Services

Last updated 2 years ago

To make it more easy to configurate later on i recommend defining items in an list/dictionary. For example:

local cocaineItems = {"cocain"}
local alcoholItems = {"beer","whisky"}

You can also set this up in the config file ofc. For checking if an item is in the defined items you can use a simple function like this:

function Contains(table, value)
    for k, v in pairs(table) do
        if v == value then
            return true
        end
    end
    return false
end

Now look for the "fred_meta:useItem" Event, where everything is defined. Before or after the definition of the animations you now can just do something like this to determine which addiction should be encountered:

if Contains(alcoholItems,Config.ItemsToUse[index]["Name"]) then
    AddictAPI.itemUsed("Alcohol",1)
elseif Contains(cocaineItems,Config.ItemsToUse[index]["Name"]) then
    AddictAPI.itemUsed("Cocaine",1)
end

Reminder: Don't forget to define the AddictAPI like mentioned in the .

📝
Documentation