NPC Structure
GameNpc
The server-side NPC representation:server-go/shared/npc.go
Current position of the NPC in world coordinates
Reference to the NPC’s static data (name, texture, ID)
The chunk coordinates containing this NPC (for efficient spatial queries)
Maximum distance in tiles the NPC can wander from its spawn point
NPC Data Format
NPC definitions are stored in the GRPGNPC data format:data-go/grpgnpc/grpgnpc.go
Unique identifier for the NPC type
Display name shown to players
Reference to the sprite texture for rendering
Spawning NPCs
NPCs are spawned during server initialization using the scripting system:server-go/content/test_npc.go
server-go/scripts/script_manager.go
NPCs are tracked using their position as the key in
game.TrackedNpcs map. This allows O(1) lookup when a player interacts with an NPC.Movement System
Wander Range
NPCs can wander within a configurable radius from their spawn point:- The
WanderRangefield defines the maximum distance in tiles - Movement is constrained to a square area: spawn point ± wander range
- Example: spawn at (3,3) with range 2 allows movement between (1,1) and (5,5)
Chunk-based Tracking
NPCs store their chunk position for efficient spatial queries:- Efficient player visibility checks
- Network packet optimization (only send updates for nearby chunks)
- Spatial partitioning for collision detection
Dialogue System
NPCs can engage in scripted dialogue with players. See the Content Scripting page for details on implementing NPC conversations.Example Dialogue
server-go/content/test_npc.go
server-go/shared/dialog_queue.go
Data Format
NPCs are loaded from the GRPGNPC binary format with the following structure:Reading NPCs
data-go/grpgnpc/grpgnpc.go
Client Synchronization
NPC state is synchronized to clients through network packets:- Initial NPC data sent when player enters chunk
- Movement updates sent to all players in affected chunks
- Dialogue updates sent only to the interacting player
Next Steps
Content Scripting
Learn how to script NPC behavior and dialogue
Objects
Explore the interactive object system