scripting

package
v0.0.0-...-800faa1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package scripting provides Lua scripting support for Dark Pawns MUD. Based on original C code from scripts.c.

Package scripting provides Lua scripting support for Dark Pawns MUD.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine manages the Lua VM. Based on boot_lua() in scripts.c lines 1703-1716.

func NewEngine

func NewEngine(scriptsDir string, world ScriptableWorld) *Engine

NewEngine creates a new Lua scripting engine.

func (*Engine) LState

func (e *Engine) LState() *lua.LState

LState returns the underlying Lua state. The caller must NOT hold the engine mutex when calling into the LState — use RunScript or the lua* methods instead. This accessor exists only for code that needs read-only access outside of script execution.

func (*Engine) RunScript

func (e *Engine) RunScript(ctx *ScriptContext, fname string, triggerName string) (bool, error)

RunScript loads and executes a named trigger function in a script file. fname is relative to scriptsDir (e.g. "mob/144/hisc.lua"). triggerName is the function to call (e.g. "oncmd", "sound", "fight"). Returns true if the script handled the event (returned TRUE), false otherwise. Based on run_script() in scripts.c lines 1718-1810.

type ScriptContext

type ScriptContext struct {
	Ch       ScriptablePlayer
	Me       ScriptableMob
	Obj      ScriptableObject
	RoomVNum int
	Argument string
	World    ScriptableWorld
}

ScriptContext holds the game objects exposed to Lua as globals.

type ScriptableMob

type ScriptableMob interface {
	GetVNum() int
	GetName() string
	GetLevel() int
	GetHealth() int
	SetHealth(int)
	GetMaxHealth() int
	GetGold() int
	GetRoomVNum() int
	GetPrototype() ScriptableMobPrototype
	GetFighting() string // Returns the name of the mob's combat target, or "" if not fighting
}

ScriptableMob represents a mob that can be exposed to Lua scripts.

type ScriptableMobPrototype

type ScriptableMobPrototype interface {
	GetShortDesc() string
	GetGold() int
	GetLevel() int
	GetAlignment() int
	GetScriptName() string
	GetLuaFunctions() int
}

ScriptableMobPrototype represents mob prototype data.

type ScriptableObject

type ScriptableObject interface {
	GetVNum() int
	GetKeywords() string
	GetShortDesc() string
	GetCost() int
	GetTimer() int
	SetTimer(int)
}

ScriptableObject represents an object that can be exposed to Lua scripts.

type ScriptablePlayer

type ScriptablePlayer interface {
	GetID() int
	GetName() string
	GetLevel() int
	GetHealth() int
	SetHealth(int)
	GetMaxHealth() int
	GetGold() int
	SetGold(int)
	GetRace() int
	GetClass() int
	GetAlignment() int
	GetRoomVNum() int
	SendMessage(string)
	// GetFlags returns the raw PLR flags bitmask.
	// Source: structs.h PLR_FLAGS, utils.h PLR_FLAGGED() macro.
	GetFlags() uint64
}

ScriptablePlayer represents a player that can be exposed to Lua scripts.

type ScriptableWorld

type ScriptableWorld interface {
	// GetPlayersInRoom returns all players in a given room.
	GetPlayersInRoom(roomVNum int) []ScriptablePlayer
	// GetMobsInRoom returns all mobs in a given room.
	GetMobsInRoom(roomVNum int) []ScriptableMob
	// GetMobByVNumAndRoom returns a mob by its vnum and room.
	GetMobByVNumAndRoom(vnum int, roomVNum int) ScriptableMob
	// GetObjPrototype returns an object prototype by vnum.
	GetObjPrototype(vnum int) ScriptableObject
	// AddItemToRoom adds an item to a room.
	AddItemToRoom(obj ScriptableObject, roomVNum int) error
	// HandleNonCombatDeath handles player death from non-combat damage.
	HandleNonCombatDeath(player ScriptablePlayer)
	// HandleSpellDeath handles death caused by a spell.
	HandleSpellDeath(victimName string, spellNum int, roomVNum int)
	// SendTell delivers a private tell message to a named player.
	// Source: act.comm.c do_tell().
	SendTell(targetName, message string)
	// GetItemsInRoom returns all items in a given room as ScriptableObject.
	GetItemsInRoom(roomVNum int) []ScriptableObject
	// HasItemByVNum returns true if the named character has an item with the given vnum.
	HasItemByVNum(charName string, vnum int) bool
	// RemoveItemFromRoom removes the first item with the given vnum from the room and returns it.
	RemoveItemFromRoom(vnum int, roomVNum int) ScriptableObject
	// RemoveItemFromChar removes the first item with the given vnum from the character's inventory.
	RemoveItemFromChar(charName string, vnum int) ScriptableObject
	// GiveItemToChar adds an item to the named character's inventory.
	GiveItemToChar(charName string, obj ScriptableObject) error
	// CreateEvent schedules a timed event on the world's event queue.
	// delay is in game pulses (1 pulse = 1/10 second in original C).
	// trigger is the Lua function name to call when the event fires.
	// eventType is LT_MOB (1), LT_OBJ (2), or LT_ROOM (3) from structs.h.
	// Returns the event ID, or 0 if the event could not be scheduled.
	// Source: scripts.c lua_create_event() — create_event(source, target, obj, argument, trigger, delay, type)
	CreateEvent(delay int, source, target, obj, argument int, trigger string, eventType int) uint64
}

ScriptableWorld represents the game world for script context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL