Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Bill3621/CustomItems/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The CustomItems framework provides a comprehensive event system that allows you to respond to player interactions with your custom items. Events are automatically routed from LabAPI to your custom item instances based on their serial numbers.Event flow
When a player interacts with a custom item:- Game action occurs: Player performs an action (use, drop, pickup, etc.)
- LabAPI captures event: The event is intercepted by LabAPI
- EventHandler checks serial:
EventHandler.csverifies if the item is a custom item - Delegate to instance: Event is forwarded to the specific
CustomIteminstance - Your code executes: Your override of the event method runs
Available event hooks
All event hooks are virtual methods in theCustomItem class, meaning they have default (empty) implementations and you only need to override the ones you care about.
Using events
Fired when a player uses a consumable item.OnUsing
ev.Player- The player using the itemev.UsableItem- The item being usedev.IsAllowed- Set tofalseto cancel the action
HealingSyringe.cs:25-35
OnUsed
ev.Player- The player who used the itemev.UsableItem- The item that was used
OnUsing is called at the start of use, while OnUsed is called after completion. For instant effects, use OnUsing. For effects that should occur after the animation, use OnUsed.Dropping events
Fired when a player drops an item from their inventory.OnDropping
ev.Player- The player dropping the itemev.Item- The item being dropped (still in inventory)ev.IsAllowed- Set tofalseto prevent dropping
OnDropped
ev.Player- The player who dropped the itemev.Pickup- The pickup object now in the world
Pickup events
Fired when a player picks up an item from the world.OnPickingUp
ev.Player- The player picking up the itemev.Pickup- The pickup being picked upev.IsAllowed- Set tofalseto prevent pickup
OnPickedUp
ev.Player- The player who picked up the itemev.Item- The item now in their inventory
The framework automatically shows a hint when items are picked up (if
ShowItemHints and ShowPickupHints are true). This happens in EventHandler.cs:65-72.Selection events
Fired when a player changes their currently held item.OnSelecting
ev.Player- The player changing itemsev.OldItem- The previously held item (may be null)ev.NewItem- The item being selected (your custom item)ev.IsAllowed- Set tofalseto prevent selection
OnUnselecting
ev.Player- The player changing itemsev.OldItem- The item being unselected (your custom item)ev.NewItem- The item being switched to (may be null)ev.IsAllowed- Set tofalseto prevent unselection
OnSelected
ev.Player- The player who selected the itemev.OldItem- The previously held itemev.NewItem- The now-selected item (your custom item)
OnUnselected
ev.Player- The player who unselected the itemev.OldItem- The item that was unselected (your custom item)ev.NewItem- The newly selected item
Event implementation in framework
Here’s how the framework routes events to your custom items:EventHandler.cs:34-43
EventHandler:
- Checks if the serial number exists in
CurrentItemsdictionary - Retrieves the specific
CustomIteminstance - Calls the corresponding event method on that instance
Advanced: Subscribing to additional events
You can subscribe to other LabAPI events inOnRegistered() for more complex behavior:
EMPGrenade.cs:10-50
- Subscribes to
ProjectileExplodingevent inOnRegistered() - Uses
Check()to verify it’s this custom item - Cancels the normal explosion
- Implements custom behavior (flicker lights, lock doors)
- Cleans up the grenade object
Event patterns
Canceling vs modifying behavior
Canceling vs modifying behavior
You can prevent actions by setting Or allow the action but add side effects:
ev.IsAllowed = false:Instant vs delayed effects
Instant vs delayed effects
For instant effects, use the “before” events:For effects after completion, use “after” events:
Using coroutines for ongoing effects
Using coroutines for ongoing effects
Use MEC coroutines for effects over time:
Next steps
- Learn about custom item properties and the base class
- Understand registration to make your items available
- Review the architecture to see how events flow through the system