Script Types
There are three main types of content scripts:- Object Interaction Scripts - Handle player interactions with objects
- NPC Talk Scripts - Handle dialogue with NPCs
- NPC Spawning - Place NPCs in the world
Object Interaction Scripts
OnObjInteract
Register an interaction handler for an object usingOnObjInteract:
server-go/content/berry_bush.go
ObjInteractCtx API
The interaction context provides methods for manipulating object state and player data:Returns the current state of the object (0-255)
Updates the object state and broadcasts the change to nearby players
Adds an item to the player’s inventory and sends an update packet
Grants XP to the player for the specified skill and sends an update packet
Schedules a callback to execute after the specified number of game ticks
NPC Talk Scripts
OnTalkNpc
Register a dialogue handler for an NPC:server-go/content/test_npc.go
NpcTalkCtx API
Clears the player’s dialogue queue and sends a clear talkbox packet
Adds a player dialogue line to the queue
Adds an NPC dialogue line to the queue
Begins playing the dialogue sequence to the player
Dialogue is displayed sequentially. The client advances through the queue as the player presses the interact key.
NPC Spawning
SpawnNpc
Place NPCs in the world during initialization:server-go/content/test_npc.go
npcId- The NPC type constantx- X coordinate in the worldy- Y coordinate in the worldwanderRange- Number of tiles the NPC can wander from spawn point
Registration System
All content scripts use theinit() function to register handlers:
server-go/scripts/listeners.go
- Object interaction scripts are stored in
InteractScriptsmap - NPC talk scripts are stored in
NpcTalkScriptsmap - NPC spawns create entries in
game.TrackedNpcs
Constants
Content uses type-safe constants for referencing game entities:server-go/scripts/constants.go
These constants should eventually be auto-generated from
.gcfg files as part of the data-packer tool.Next Steps
Objects
Learn about the object system and state management
NPCs
Understand NPC behavior and movement