Overview
Game content in GRPG is created through Go code that registers event handlers for objects and NPCs. The scripting system provides contexts with helper methods for common operations like managing object states, player inventory, XP, and dialogue.Content Types
GRPG supports two main types of interactive content:- Interactive Objects - Stateful objects that players can interact with
- NPCs - Non-player characters that can talk to players and wander within an area
Creating Interactive Objects
Define Object Constants
First, define constants for your objects in
server-go/scripts/constants.go:server-go/scripts/constants.go
Object IDs start from 1 (using iota with blank identifier). ID 0 is reserved.
Create Content File
Create a new file in This creates a berry bush that:
server-go/content/ for your object behavior:server-go/content/berry_bush.go
- Checks if it’s in the “full” state (state 0)
- When harvested, switches to “empty” state (state 1)
- Gives the player berries and foraging XP
- Resets to full state after 100 game ticks
Available Context Methods
The
ObjInteractCtx provides these methods:| Method | Description |
|---|---|
GetObjState() | Returns the current state of the object (uint8) |
SetObjState(new uint8) | Updates object state and notifies all players in the chunk |
PlayerInvAdd(itemId ItemConstant) | Adds an item to the player’s inventory |
PlayerAddXp(skill Skill, amount uint32) | Gives the player XP in a specific skill |
AddTimer(ticks uint32, fn TimerFunc) | Schedules a function to run after N game ticks |
Creating NPCs
Spawn and Register NPC
Create a content file that spawns the NPC and registers its dialogue:
server-go/content/test_npc.go
NPC Context Methods
The
NpcTalkCtx provides these methods:| Method | Description |
|---|---|
TalkPlayer(msg string) | Adds a player dialogue line to the queue |
TalkNpc(msg string) | Adds an NPC dialogue line to the queue |
ClearDialogueQueue() | Clears all pending dialogue |
StartDialogue() | Sends the dialogue to the player’s client |
Always call
ClearDialogueQueue() at the start to ensure clean state, then add dialogue lines, and finish with StartDialogue().Advanced Examples
Stateful Object with Multiple States
Complex NPC Dialogue
Best Practices
Use Clear Constant Names
Use Clear Constant Names
Name your constants descriptively to make your content code self-documenting:
Handle All States
Handle All States
For stateful objects, always check the current state before performing actions:
Use Timers for Respawns
Use Timers for Respawns
Use Timer duration is in game ticks (server update cycles).
AddTimer to create respawning resources:Clear Dialogue Before Building
Clear Dialogue Before Building
Always clear the dialogue queue before building new conversations:
Next Steps
Custom Objects
Learn how to create custom object types with the data packer
Map Creation
Place your content on the map using the map editor