Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 35c617f

Browse files
Add tutorial for new interaction system
1 parent df0e836 commit 35c617f

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

Writerside/fp.tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<toc-element topic="FN-API.md"/>
1414
<toc-element topic="FN-Examples.md"/>
1515
<toc-element topic="FN-Tutorials.md">
16+
<toc-element topic="FN_Tutorials-new-interaction-system.md"/>
1617
<toc-element topic="FN-Tutorials-MiniMessages.md"/>
1718
<toc-element topic="FN-Multiple-lines.md"/>
1819
<toc-element topic="FN-Sitting-NPCs.md"/>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# New Interaction System
2+
3+
The **NPC Action System** in FancyNPCs allows server administrators to create interactive and engaging NPCs by assigning
4+
actions that trigger based on player interactions or custom events. This article explains the general concept of the
5+
system and provides a guide on how server admins can leverage it through commands.
6+
7+
## How the NPC Action System Works
8+
9+
In FancyNPCs, the NPC Action System revolves around assigning actions to an NPC based on **triggers**. These triggers
10+
can be events like:
11+
12+
- **LEFT_CLICK**: When a player left-clicks the NPC.
13+
- **RIGHT_CLICK**: When a player right-clicks the NPC.
14+
- **CUSTOM**: Custom events triggered through the API.
15+
16+
Each trigger can execute a series of **actions**. Actions determine what the NPC does when the trigger is activated,
17+
such as sending messages, executing commands, teleporting players, or waiting for a certain duration before performing
18+
the next action. Administrators can add, modify, and reorder these actions using commands.
19+
20+
### Supported Action Types
21+
22+
The system currently supports the following action types:
23+
24+
- **Message**: Sends a message to the player.
25+
- **ConsoleCommand**: Executes a command as the server/console.
26+
- **PlayerCommand**: Executes a command as the player.
27+
- **SendToServer**: Sends the player to another server (using BungeeCord plugin messaging).
28+
- **WaitAction**: Pauses the action sequence for a specific duration.
29+
- **ExecuteRandomAction**: Randomly selects and performs one action from a list, below the current action.
30+
31+
## Command Overview
32+
33+
FancyNPCs provides a range of commands for managing actions attached to an NPC. The following sections describe each
34+
command and its usage.
35+
36+
### 1. Adding Actions to an NPC
37+
38+
**Command**:
39+
`/npc action <npc> <trigger> add <actionType> [value]`
40+
41+
This command adds an action to an NPC under a specific trigger. For example, you might assign a **Message** action to
42+
the **RIGHT_CLICK** trigger, so when a player right-clicks the NPC, they receive a message.
43+
44+
Example:
45+
`/npc action Bob RIGHT_CLICK add message <green>Welcome to the server!`
46+
47+
If the action type requires a value (such as a message or command), it must be provided.
48+
49+
### 2. Inserting Actions Before or After
50+
51+
**Command**:
52+
`/npc action <npc> <trigger> add_before <index> <actionType> [value]`
53+
54+
**Command**:
55+
`/npc action <npc> <trigger> add_after <index> <actionType> [value]`
56+
57+
These commands allow you to insert an action before or after an existing action at a specific position (index). This is
58+
helpful for fine-tuning the sequence of actions.
59+
60+
Example:
61+
`/npc action Bob RIGHT_CLICK add_before 2 message <green>Goodbye!`
62+
63+
### 3. Setting (Replacing) an Action
64+
65+
**Command**:
66+
`/npc action <npc> <trigger> set <number> <actionType> [value]`
67+
68+
This command replaces an action at a specific position in the action list for a trigger. If you want to change the
69+
action at position 3 to a **PlayerCommand**, you can use this command.
70+
71+
Example:
72+
`/npc action Bob LEFT_CLICK set 3 player_command warp home`
73+
74+
### 4. Removing an Action
75+
76+
**Command**:
77+
`/npc action <npc> <trigger> remove <number>`
78+
79+
To remove an action from the list, use this command, specifying the position of the action to be removed.
80+
81+
Example:
82+
`/npc action Bob RIGHT_CLICK remove 2`
83+
84+
### 5. Moving Actions
85+
86+
**Move Up**:
87+
`/npc action <npc> <trigger> move_up <number>`
88+
89+
**Move Down**:
90+
`/npc action <npc> <trigger> move_down <number>`
91+
92+
These commands allow you to rearrange the sequence of actions by moving an action up or down in the list.
93+
94+
Example:
95+
`/npc action Bob RIGHT_CLICK move_up 3`
96+
97+
### 6. Clearing All Actions
98+
99+
**Command**:
100+
`/npc action <npc> <trigger> clear`
101+
102+
To remove all actions associated with a trigger, use the `clear` command.
103+
104+
Example:
105+
`/npc action Bob LEFT_CLICK clear`
106+
107+
### 7. Listing All Actions
108+
109+
**Command**:
110+
`/npc action <npc> <trigger> list`
111+
112+
This command lists all the actions assigned to a specific trigger for an NPC. It helps you review and manage the current
113+
actions.
114+
115+
Example:
116+
`/npc action Bob RIGHT_CLICK list`
117+
118+
## Practical Example
119+
120+
Let’s create an NPC called **"Bob"** who greets players when right-clicked, executes a server command, waits, and then
121+
sends them to a different server:
122+
123+
1. Add a message:
124+
`/npc action Bob RIGHT_CLICK add message Hello, adventurer!`
125+
126+
2. Execute a console command:
127+
`/npc action Bob RIGHT_CLICK add console_command say Bob has been clicked!`
128+
129+
3. Wait for 5 seconds:
130+
`/npc action Bob RIGHT_CLICK add wait 5`
131+
132+
4. Send the player to another server:
133+
`/npc action Bob RIGHT_CLICK add send_to_server Hub`
134+
135+
If you wanted to insert a random action after the message, you could use:
136+
137+
`/npc action Bob RIGHT_CLICK add_after 1 execute_random_action`
138+
139+
## Outlook
140+
141+
The NPC Action System in FancyNPCs provides a flexible and powerful way to create interactive NPCs on your server. By
142+
combining triggers and actions, server administrators can design engaging interactions that enhance the player
143+
experience.
144+
145+
In future updates, we plan to expand the system with additional action types and triggers, enabling even more creative
146+
and dynamic NPC behaviors. Stay tuned for more exciting features and improvements!

0 commit comments

Comments
 (0)