Event System
Add Interactive Functions to Items
Overview
The event system enables your items to respond to player actions, such as right-clicking, attacking enemies, and more. With simple scripts, you can equip items with a variety of functions.
Basic Concepts
What is an Event
An event refers to an interaction between a player and an item, such as:
- Right-clicking an item
- Attacking an enemy with an item
- Consuming an item (e.g., food)
- Dropping an item
Event Scripts
When an event occurs, the system executes pre-written script commands you have defined.
Common Event Types
Event Name | Trigger Timing | Example Usage |
---|---|---|
on_right_click | When the item is right-clicked | Activate skills, open menus |
on_left_click | When the item is left-clicked | Quick attacks, switch modes |
on_attack | When an entity is attacked with the item | Extra damage, special effects |
on_consume | When the item is consumed | Restore health, gain buffs |
on_drop | When the item is dropped | Prevent dropping, special prompts |
Script Writing Syntax
Recommended Syntax: Multi-Line Strings
Use YAML's multi-line string syntax (|
) to write event scripts for better readability:
Complex Script Example
Conditional Judgment and Logic
Using Conditional Statements
Using Item Data
Reference item data using &variable_name
: