AV Scripts
StoreDiscord
  • Documentation
  • Guides
    • Dealerships
      • Installation
      • Admin Panel
        • All Vehicles
        • Dealerships
        • Auctions
      • Dealership Panel
        • Overview
        • Auctions
        • Employees
        • Orders
        • Payments
        • Showroom
        • Warehouse
        • Pre Owned
        • Settings
      • Buy/Sell Vehicles
      • Catalogue
      • Exports
      • FAQ
    • House Robbery
      • Installation
      • Add Shells
      • Dispatch
      • Exports
      • Weather
      • Minigames
      • Notifications
      • New Houses
      • Object Types
      • Sell Items
    • Illegal Runs
      • Installation
      • Customization
      • Ox Inventory
      • QB Inventory
    • Multicharacter
      • Installation
      • Character Slots
      • Clothes
      • Scenes
        • Previews
      • Exports
      • Weather
    • Paleto Heist
      • Buy here
    • Refund System
      • Installation
        • Inventories
    • Tuning Script
      • Installation
      • Events and Controls
      • Exports
      • Price Multiplier
    • Vehicleshop
      • Installation
      • Admin Panel
      • Addon Vehicles
      • Functions
        • Fuel
        • Keys
        • VIP
        • Weather
      • Garages
      • HUD
      • Society
    • Weather Script
      • Installation
      • Breath Condensation
      • Fog
      • Real Time Sync
      • Exports
    • VIP Script
      • Installation
      • Exports
      • Categories
      • Admin
      • Tebex
      • Free Tokens
  • LAPTOP PACK V3
    • Laptop v3
      • Installation
        • Inventory
        • Cosmo
        • Permissions
        • QBCore
        • Custom Framework/Inventory
        • Phone
        • Translate
      • Browser
      • Terminal
      • Documents
      • APPs Config
      • Exports
    • Boosting
      • Create Profile
      • APP
      • Contracts
      • Dispatch
      • Lockpick Export
      • VIN Export
    • Business
      • Installation
        • Inventories
          • Origen Inventory
            • ESX
            • QBCore
          • OX Inventory
          • QB/PS/LJ Inventory
          • Quasar Inventory
            • ESX
            • QBCore
          • Codem Inventory
          • Tgiann Inventory
        • ESX
      • Admin Panel
        • Create Zones
        • Edit Zones
      • Config
        • Animations
        • Blips
        • Buttons
        • Crafting
        • Effects
        • Events
          • Items
          • Zones
        • Logs
          • Custom Logs
        • Permissions
      • Exports
      • Banking Scripts
      • Multijobs
    • Cameras
      • Installation
        • Vehicle Cameras
      • Place Camera
      • Job Cameras
    • Drugs
      • Installation
      • Admin Panel
      • APP
      • Tables
      • Labs
        • PC
        • Raids
      • Alert Cops
      • Shells
      • Exports
    • Gangs
      • Installation
      • Admin Panel
        • Gangs
        • Whitelist
      • Properties
      • Register Gang
      • APP
        • Members
        • Settings
        • Missions
        • Blackmarket
        • Properties
      • Graffitis
      • Missions
      • Gang NPC
      • Shells
      • Exports
      • Labs
    • Groups
      • Events
      • Exports
    • Music
      • Installation
      • Music Labels
      • APP
        • Search Music
        • Playlists
        • Headphones
      • CDs
    • Racing
      • Installation
        • Permissions
        • Discord Logs
        • Addon Vehicles
      • Admin Panel
      • Categories
      • Events
      • Exports
      • Personal Settings
      • The Underground
    • Custom APPs
    • Discord Support
Powered by GitBook
On this page
  1. LAPTOP PACK V3
  2. Business
  3. Config
  4. Events

Items

config/events.lua > Config.OnUseEvents

In this little guide I'll show you how to trigger a specific event when the player uses an item crafted in av_business.

Trigger a custom event

  • For this example we are gonna add a custom event for an item type named 'drugs', new item types can be added in config/items.lua > Config.ItemTypes.

  • We are gonna add a new entry to Config.OnUseEvents table:

Config.OnUseEvents = { 
    -- event: Client side event triggered when a player consumes an item from this script
    -- remove: remove item on use?
    ['drink'] = {event = "av_business:consumable", remove = true}, -- this event is on client/editable/items.lua
    ['food'] = {event = "av_business:consumable", remove = true}, -- this event is on client/editable/items.lua
    ['joint'] = {event = "av_business:consumable", remove = true}, -- this event is on client/editable/items.lua
    ['alcohol'] = {event = "av_business:consumable", remove = true}, -- this event is on client/editable/items.lua
    ['box'] = {event = "av_business:box", remove = false}, -- this event is on client/editable/items.lua
    ['drugs'] = {event = "av_business:drugs", remove = true}, -- this event is on client/editable/items.lua
}

['index_key'] = needs to match the item type value,

event = is the event to trigger when you use this item, the event should be client side.

remove = can be true/false, depends if you want to remove the item from player on use

  • The event to trigger can be located in any resource that you want but for this example we are gonna create it in av_business/client/editable/items.lua.

  • We are gonna add our custom event at the end of the file:

RegisterNetEvent("av_business:drugs", function(metadata)
    local type = metadata['type']
    local ingredients = metadata['ingredients']
    local prop = metadata['prop']
    print(type, json.encode(ingredients), prop) -- I'm adding a print to see the info in F8 console, remove it in live server
    -- From here you can trigger an export or event based on item type, ingredients or the prop
    -- If you want to trigger an animation from Config.Animations you can use this:
    -- doAnimation function is in client/editable/animations.lua
    local completed = doAnimation(prop)
    if completed then -- means the progress bar was completed and not canceled at some point
        -- trigger your custom effect, event, export, etc...
    else
        -- do nothing?
    end
end)
  • As you can see the event receives an argument named metadata this info is stored in the item and it contains the item type, ingredients and the prop.

  • Using this info is on you to trigger an export, event or any function you want.

Last updated 11 months ago