mod

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mod writes Modlock mods in Go. A mod registers its handlers in an init function; modlock-host compiles the module to a sandbox inside the game server and calls the handlers on the server's frame thread, one at a time.

package main

import "github.com/paralin/modlock/mod"

func init() {
	mod.Command("hello", func(p mod.Player, args string) {
		p.Chat("Hello from Go!")
	})
}

func main() {}

Build it with:

GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o hello.wasm

The calls into the game and their types are generated from the schema in host.gen.go.

Index

Constants

View Source
const (
	// ButtonAttack is the primary fire button.
	ButtonAttack uint64 = 1
	// ButtonUse is the interact key.
	ButtonUse uint64 = 1 << 5
	// ButtonMelee is the light melee button.
	ButtonMelee uint64 = 1 << 11
	// ButtonReload is the reload key.
	ButtonReload uint64 = 1 << 13
	// ButtonAbility1 to ButtonAbility3 are the hero's first three ability
	// keys.
	ButtonAbility1 uint64 = 1 << 33
	ButtonAbility2 uint64 = 1 << 34
	ButtonAbility3 uint64 = 1 << 35
	// ButtonParry is the melee parry button.
	ButtonParry uint64 = 1 << 42
)

Button bits name inputs for BlockInput, WatchInput and Player.Press.

View Source
const (
	// LayerSolid is the world and solid objects.
	LayerSolid uint64 = 1 << 0
	// LayerHitbox is the hit boxes of heroes and units.
	LayerHitbox uint64 = 1 << 1
	// LayerTrigger is invisible volumes that react to touch.
	LayerTrigger uint64 = 1 << 2
	// LayerPlayerClip is walls that only stop heroes.
	LayerPlayerClip uint64 = 1 << 4
	// LayerWorldGeometry is the map's static geometry.
	LayerWorldGeometry uint64 = 1 << 14
	// LayerPlayer is player-controlled heroes.
	LayerPlayer uint64 = 1 << 18
	// LayerNpc is units that are not players.
	LayerNpc uint64 = 1 << 19
	// LayerHero, LayerTrooper and LayerBuilding are those units' bodies.
	LayerHero     uint64 = 1 << 37
	LayerTrooper  uint64 = 1 << 38
	LayerBuilding uint64 = 1 << 40
)

Layer bits name collision layers for Trace.

View Source
const (
	MovementActionLanded          = wasm.MovementAction_MOVEMENT_ACTION_LANDED
	MovementActionZiplineAttached = wasm.MovementAction_MOVEMENT_ACTION_ZIPLINE_ATTACHED
	MovementActionGroundDash      = wasm.MovementAction_MOVEMENT_ACTION_GROUND_DASH
	MovementActionSlide           = wasm.MovementAction_MOVEMENT_ACTION_SLIDE
	MovementActionBouncePad       = wasm.MovementAction_MOVEMENT_ACTION_BOUNCE_PAD
	MovementActionDashJump        = wasm.MovementAction_MOVEMENT_ACTION_DASH_JUMP
	MovementActionAirJump         = wasm.MovementAction_MOVEMENT_ACTION_AIR_JUMP
	MovementActionWallJump        = wasm.MovementAction_MOVEMENT_ACTION_WALL_JUMP
	MovementActionAirDash         = wasm.MovementAction_MOVEMENT_ACTION_AIR_DASH
	MovementActionMeleeStarted    = wasm.MovementAction_MOVEMENT_ACTION_MELEE_STARTED
	// AbilityExecuted is any ability the hero cast.
	MovementActionAbilityExecuted = wasm.MovementAction_MOVEMENT_ACTION_ABILITY_EXECUTED
)

The values of MovementAction.

View Source
const (
	// ScreenEffectKilled is the death treatment.
	ScreenEffectKilled = wasm.ScreenEffect_SCREEN_EFFECT_KILLED
	// ScreenEffectBlack fades the view to black.
	ScreenEffectBlack = wasm.ScreenEffect_SCREEN_EFFECT_BLACK
	// ScreenEffectBlinded is the blind treatment.
	ScreenEffectBlinded = wasm.ScreenEffect_SCREEN_EFFECT_BLINDED
	// ScreenEffectDarkness is Drifter's darkness view.
	ScreenEffectDarkness = wasm.ScreenEffect_SCREEN_EFFECT_DARKNESS
	// ScreenEffectMatchIntro is the match start treatment.
	ScreenEffectMatchIntro = wasm.ScreenEffect_SCREEN_EFFECT_MATCH_INTRO
)

The values of ScreenEffect.

View Source
const (
	// FieldTypeBool is one byte read as a boolean.
	FieldTypeBool = wasm.FieldType_FIELD_TYPE_BOOL
	// FieldTypeInt8 through FIELD_TYPE_UINT32 are integers read as numbers.
	FieldTypeInt8   = wasm.FieldType_FIELD_TYPE_INT8
	FieldTypeInt16  = wasm.FieldType_FIELD_TYPE_INT16
	FieldTypeInt32  = wasm.FieldType_FIELD_TYPE_INT32
	FieldTypeUint8  = wasm.FieldType_FIELD_TYPE_UINT8
	FieldTypeUint16 = wasm.FieldType_FIELD_TYPE_UINT16
	FieldTypeUint32 = wasm.FieldType_FIELD_TYPE_UINT32
	// FieldTypeInt64 and FIELD_TYPE_UINT64 are 64-bit integers.
	FieldTypeInt64  = wasm.FieldType_FIELD_TYPE_INT64
	FieldTypeUint64 = wasm.FieldType_FIELD_TYPE_UINT64
	// FieldTypeFloat32 and FIELD_TYPE_FLOAT64 are floating point numbers.
	FieldTypeFloat32 = wasm.FieldType_FIELD_TYPE_FLOAT32
	FieldTypeFloat64 = wasm.FieldType_FIELD_TYPE_FLOAT64
	// FieldTypeVector is three floats, such as a position or angles.
	FieldTypeVector = wasm.FieldType_FIELD_TYPE_VECTOR
	// FieldTypeHandle is an entity handle, read as a number.
	FieldTypeHandle = wasm.FieldType_FIELD_TYPE_HANDLE
	// FieldTypeString is a string the field points to.
	FieldTypeString = wasm.FieldType_FIELD_TYPE_STRING
)

The values of FieldType.

View Source
const (
	// PickupKindUrn is the soul urn, which its carrier delivers.
	PickupKindUrn = wasm.PickupKind_PICKUP_KIND_URN
	// PickupKindMovementBuff is the movement speed buff.
	PickupKindMovementBuff = wasm.PickupKind_PICKUP_KIND_MOVEMENT_BUFF
)

The values of PickupKind.

Variables

This section is empty.

Functions

func BlockInput

func BlockInput(buttons uint64) error

BlockInput withholds buttons from every player's hero until called again. Stopping the mod releases them.

func CallService

func CallService(service, method string, payload []byte) ([]byte, error)

CallService calls method of a service the host provides outside Modlock, such as a game mode's match, and returns the service's answer. The service defines the payload's encoding.

func ClearMap

func ClearMap() error

ClearMap removes the map's own units and objectives, such as troopers, guardians and walkers, so a mode can use the map as an arena.

func Command

func Command(name string, handler func(p Player, args string))

Command calls handler when a player types /name in chat. The handler receives the text after the name, trimmed of surrounding spaces. Registering a name again replaces its handler.

func CreateEntity added in v0.1.1

func CreateEntity(options *EntityOptions) (uint32, error)

CreateEntity creates any entity the server knows by its designer name, such as npc_trooper_boss or prop_dynamic, with spawn key values and fields written before it spawns. The world removes it when the world ends; stopping the mod removes it too. It refuses an ability, item or weapon, which only a hero holds: GiveItem and ReplaceAbility give one.

func Damage

func Damage(options *HitOptions) error

Damage deals a hit as the game would. The mod's Damage events do not include its own hits.

func EmitSound

func EmitSound(entity uint32, sound string) error

EmitSound plays one game sound on any entity, such as a projectile.

func EncodeSpot

func EncodeSpot(s *Spot) ([]byte, error)

EncodeSpot returns the spot document. Equal spots encode to equal bytes; positions and angles keep single precision.

func FindEntities added in v0.1.3

func FindEntities(className string) ([]uint32, error)

FindEntities returns the handle of every live entity of a class, such as zip_line_node.

func FireInput added in v0.1.1

func FireInput(entity uint32, input string, value any, activator *uint32) (bool, error)

FireInput sends an input to a live entity, as a map's output would, such as Skin with the integer 1. The value must have the type the input reads. It reports false once the entity is gone.

func HoldMatchClock

func HoldMatchClock(seconds *float32) error

HoldMatchClock keeps the match time at seconds every frame until called again; omitted seconds let it run.

func HoldModifierState

func HoldModifierState(entity uint32, state string, active *bool) error

HoldModifierState holds a modifier state, such as MODIFIER_STATE_FRIENDLY_FIRE_ENABLED, on an entity while the mod runs, or releases the hold. The hold ends with the entity.

func HoldReload added in v0.1.2

func HoldReload(held bool) error

HoldReload keeps the running build through a reload while held is true, such as while a player is partway through something a new build would lose. A reload that arrives meanwhile waits, and the newest one applies on the first frame after the mod releases the hold. A new build starts without a hold.

func Log

func Log(args ...any)

Log writes one line to the server log under the mod's name. Arguments are formatted as by fmt.Sprint.

func MatchClock

func MatchClock() (float32, error)

MatchClock returns the match time in seconds that the scoreboard shows.

func ModifierState

func ModifierState(entity uint32, state string) (bool, error)

ModifierState reports whether an entity has a modifier state, such as MODIFIER_STATE_PARRY_ACTIVE.

func MoveEntity

func MoveEntity(entity uint32, position *Vector, facing *Angles, velocity *Vector) error

MoveEntity places any entity, such as a projectile, and replaces its facing and motion when given.

func OnDamage

func OnDamage(handler func(hit *DamageEvent) *DamageResult)

OnDamage calls handler before each hit lands, so it can block the hit or change its damage by returning a result; nil lets the hit through. Later handlers see the earlier ones' amount.

func OnDamaged

func OnDamaged(handler func(hit *DamagedEvent))

OnDamaged calls handler on the frame after each hit lands.

func OnFrame

func OnFrame(handler func(f *FrameEvent))

OnFrame calls handler once per server frame.

func OnImpact

func OnImpact(handler func(impact *ImpactEvent))

OnImpact calls handler when a watched projectile strikes something, inside the game's impact: its calls apply before the game continues.

func OnInput

func OnInput(handler func(p Player, pressed, released uint64))

OnInput calls handler with the watched buttons a player pressed and released, as Button bits, before the next frame. A button is held from its press until its release.

func OnLanded

func OnLanded(handler func(landing *LandedEvent))

OnLanded calls handler when a hero lands under the manifest's QuakeWorld movement, before the next frame.

func OnLaunch

func OnLaunch(handler func(projectile *LaunchEvent))

OnLaunch calls handler with each watched projectile's first frame, before the next frame. WatchProjectiles names the projectiles.

func OnNpcsRestored

func OnNpcsRestored(handler func(err error))

OnNpcsRestored calls handler when RestoreNpcs ends: err is nil once the map holds every target, or says why it does not.

func OnRestored

func OnRestored(handler func(p Player, err error))

OnRestored calls handler when a player's Player.RestoreHero ends: err is nil once the target held for a second, or says why it did not.

func OnSettingChanged

func OnSettingChanged(handler func(p Player, key, value string))

OnSettingChanged calls handler when a player's setting changes outside the mod, such as on the player's profile. The mod's own Player.SetSetting calls do not reach it.

func OnStart

func OnStart(handler func(args []string))

OnStart calls handler once when the server starts the mod, with the arguments that follow -- on the modlock-host command line.

func OnWorld

func OnWorld(handler func(mapName string))

OnWorld calls handler with the map's name each time a world loads, and at start when one already has. Objects and bots from an earlier world are gone by then.

func Pause

func Pause(paused bool) error

Pause stops or resumes the game clock, as the pause command would. Stopping the mod resumes it.

func Precache

func Precache(options *PrecacheOptions) error

Precache loads heroes and resources with the next world. Call it during start, before the first world loads.

func ReadField

func ReadField(entity uint32, className, field string, kind FieldType) (any, error)

ReadField reads one schema field of a live entity, such as the int32 m_iHealth of CBaseEntity. The host finds the field by name, so it survives game updates that move it, and refuses an entity that is not of the named class or a subclass. The match's state, such as the gold of each team or the winning team, is a field of CCitadelGameRules, which the citadel_gamerules entity reads.

func ReadFieldList added in v0.1.3

func ReadFieldList(entity uint32, className, field string, kind FieldType) ([]any, error)

ReadFieldList reads a field that holds a list, such as the m_vecBannedHeroes of CCitadelGameRules. The type is the type of one element: a number, a handle, a boolean or a vector. A list of structures cannot be read.

func RemapInput

func RemapInput(from, to uint64, repeat *bool) error

RemapInput makes the from buttons act as the to buttons for every player's hero until called again; from reads as up. With repeat, a held from button uses the to ability again as soon as it is ready. A zero from stops remapping, and stopping the mod does too. BlockInput applies after the remap.

func RemoveEntities

func RemoveEntities(className string) (int32, error)

RemoveEntities removes every entity of a class, such as npc_trooper, without rewards, and returns how many it removed.

func RemoveEntity added in v0.1.1

func RemoveEntity(entity uint32) (bool, error)

RemoveEntity takes an entity the mod created out of the world without rewards. It reports false when the entity was already gone.

func RestoreNpcs

func RestoreNpcs(npcs []*NpcTarget) error

RestoreNpcs replaces the map's lane units and objectives with targets over the next frames. Units of these classes not in the list are removed, structures that match are kept, and moving units are spawned again in place. An NpcsRestored event reports when every target stands as its own unit, or why not. A new call replaces the running one.

func Serve

func Serve(service string, handler Service)

Serve answers the host's calls to service with handler. Registering a service again replaces its handler.

func ServerCommand

func ServerCommand(command string) error

ServerCommand runs one line at the server console, as if typed there. A line that sets a variable may set a development-only or cheat-protected one.

func StartRift

func StartRift(position *Vector) error

StartRift opens the Rift objective at position now.

func WatchInput

func WatchInput(buttons uint64) error

WatchInput replaces the buttons whose presses and releases arrive as Input events. Watching does not withhold a press; block it with BlockInput.

func WatchProjectiles

func WatchProjectiles(options *ProjectileOptions) error

WatchProjectiles reports the projectiles with these designer names, such as rocket_launcher_rocket_projectile, in Launch and Impact events. A new call replaces the list; an empty list stops watching.

func WriteField

func WriteField(entity uint32, className, field string, kind FieldType, value any) error

WriteField writes one schema field of a live entity and sends the change to the players. The value takes the form ReadField returns for the type; text fields cannot be written. A write to the match's state sends all of it, so players already in the match see the change.

func WriteFieldList added in v0.1.3

func WriteFieldList(entity uint32, className, field string, kind FieldType, values []any) error

WriteFieldList replaces the elements of a list field and sends the change to the players, growing the list when it holds fewer elements than the new ones.

Types

type Ability

type Ability = wasm.Ability

Ability is one ability a hero owns.

type AbilityOptions

type AbilityOptions = wasm.AbilityOptions

AbilityOptions changes one ability of a player's hero.

type Angles

type Angles = modlock.EulerAngles

Angles is a rotation in degrees.

type BotOptions

type BotOptions = wasm.BotOptions

BotOptions describes a bot player.

type BotOptionsHeroId

type BotOptionsHeroId = wasm.BotOptions_HeroId

BotOptionsHeroId sets BotOptions.Hero to HeroId.

type BotOptionsHeroName

type BotOptionsHeroName = wasm.BotOptions_HeroName

BotOptionsHeroName sets BotOptions.Hero to HeroName.

type CommandEvent

type CommandEvent = wasm.CommandEvent

CommandEvent carries one command line from a player: a chat line that starts with a slash (or ".", "+" or "-"), without that prefix, or a console command the server received.

type CommandResult

type CommandResult = wasm.CommandResult

CommandResult answers whether the mod handled a command.

type Connection

type Connection = wasm.Connection

Connection is one occupied player slot.

func Players

func Players() ([]*Connection, error)

Players lists the occupied player slots in slot order.

type DamageEvent

type DamageEvent = wasm.DamageEvent

DamageEvent is one hit before the game applies it. Handles are zero when the game names no such entity.

type DamageResult

type DamageResult = wasm.DamageResult

DamageResult answers a DamageEvent. An empty result lets the hit through.

type DamagedEvent

type DamagedEvent = wasm.DamagedEvent

DamagedEvent reports one hit the game applied.

type EntityClassName added in v0.1.1

type EntityClassName = wasm.EntityClassName

EntityClassName names one entity's class two ways.

func EntityClass added in v0.1.1

func EntityClass(entity uint32) (*EntityClassName, error)

EntityClass returns a live entity's schema class, such as CCitadelPlayerPawn, whose fields ReadField reads, and its designer name.

type EntityOptions added in v0.1.1

type EntityOptions = wasm.EntityOptions

EntityOptions describes an entity to create.

type EquipmentTarget

type EquipmentTarget = wasm.EquipmentTarget

EquipmentTarget is one ability or item a HeroTarget gives the hero.

type FieldType

type FieldType = wasm.FieldType

FieldType is how ReadField and WriteField interpret a field's storage.

type FieldWrite added in v0.1.1

type FieldWrite = wasm.FieldWrite

FieldWrite writes one schema field of an entity the host creates.

type FogOptions

type FogOptions = wasm.FogOptions

FogOptions describes an oriented box of tinted fog.

type FrameEvent

type FrameEvent = wasm.FrameEvent

FrameEvent identifies one server frame.

type HeroTarget

type HeroTarget = wasm.HeroTarget

HeroTarget is the state RestoreHero gives one hero. Omitted parts keep the hero's own.

type HitOptions

type HitOptions = wasm.HitOptions

HitOptions describes damage the mod deals.

type ImpactEvent

type ImpactEvent = wasm.ImpactEvent

ImpactEvent is a watched projectile striking something.

type InputEvent

type InputEvent = wasm.InputEvent

InputEvent is one player's watched buttons that went down or up.

type KeyValue added in v0.1.1

type KeyValue = wasm.KeyValue

KeyValue is one spawn key value.

type LandedEvent

type LandedEvent = wasm.LandedEvent

LandedEvent is one hero landing.

type LaunchEvent

type LaunchEvent = wasm.LaunchEvent

LaunchEvent is a watched projectile's first frame.

type LoadedSpot

type LoadedSpot struct {
	Map string
	// contains filtered or unexported fields
}

LoadedSpot is a spot standing in the world, in placement order.

func LoadSpot

func LoadSpot(s *Spot) *LoadedSpot

LoadSpot places every object of s and returns it standing. Objects the game cannot place are skipped with a log line; the rest load.

func (*LoadedSpot) At

func (l *LoadedSpot) At(entity uint32) *Placed

At returns the placed object whose entity a trace hit, or nil.

func (*LoadedSpot) Bounce

func (l *LoadedSpot) Bounce(movement []*MovementSample)

Bounce launches each sampled hero who stands on a bouncing object. A mode calls it with each frame's movement samples, for the heroes it watches.

func (*LoadedSpot) Clear

func (l *LoadedSpot) Clear()

Clear removes every placed object.

func (*LoadedSpot) Objects

func (l *LoadedSpot) Objects() []*Placed

Objects returns the placed objects in placement order.

func (*LoadedSpot) Place

func (l *LoadedSpot) Place(object *SpotObject) (*Placed, error)

Place spawns object as a solid model and adds it to the spot. A model the game cannot place logs why and returns the error.

func (*LoadedSpot) Remove

func (l *LoadedSpot) Remove(placed *Placed)

Remove takes a placed object out of the world and the spot.

func (*LoadedSpot) Spot

func (l *LoadedSpot) Spot() *Spot

Spot returns the spot as it stands.

type ModelOptions

type ModelOptions = wasm.ModelOptions

ModelOptions describes a model placed in the world.

type MovementAction

type MovementAction = wasm.MovementAction

MovementAction is a movement fact the game announced for a hero.

type MovementCommand added in v0.1.1

type MovementCommand = wasm.MovementCommand

MovementCommand is the movement a player commanded over one tick. The server runs a player's commands as they arrive, so a tick may run several or none: every press among them is kept once, and a tick that ran none holds the last buttons without pressing them again.

type MovementSample

type MovementSample = wasm.MovementSample

MovementSample is one watched hero's movement on one tick, as the game keeps it. A hero whose position, velocity or ground the game does not provide has no sample; another field the game did not provide is absent or zero.

type Npc

type Npc struct {
	// Entity is the unit's entity handle, as damage events report it.
	Entity uint32
}

Npc is one unit the mod spawned.

func SpawnNpc

func SpawnNpc(options *NpcOptions) (Npc, error)

SpawnNpc adds a unit that is not a player, such as a trooper, as CreateEntity does, then sets its health and lane. It thinks from the next frame. The world removes it when the world ends; stopping the mod removes it too.

func (Npc) Move

func (n Npc) Move(position *Vector, facing *Angles, velocity *Vector) (bool, error)

Move places the unit and sets its velocity, which drives its walk animation. It reports false once the unit is gone.

func (Npc) Read

func (n Npc) Read() (*NpcState, error)

Read returns the unit's state, or nothing once it is gone.

func (Npc) Remove

func (n Npc) Remove() (bool, error)

Remove takes a unit the mod spawned out of the world without rewards. It reports false when the unit was already gone.

func (Npc) SetHealth

func (n Npc) SetHealth(health int32, maxHealth *int32) (bool, error)

SetHealth sets the unit's health, and its maximum when given. It reports false once the unit is gone.

type NpcOptions

type NpcOptions = wasm.NpcOptions

NpcOptions describes a unit that is not a player, such as a trooper.

type NpcState

type NpcState = wasm.NpcState

NpcState is a unit's state this frame.

type NpcTarget

type NpcTarget = wasm.NpcTarget

NpcTarget is one unit or objective RestoreNpcs places, as replays record it.

type NpcsRestoredEvent

type NpcsRestoredEvent = wasm.NpcsRestoredEvent

NpcsRestoredEvent reports how a RestoreNpcs ended.

type ParticleOptions

type ParticleOptions = wasm.ParticleOptions

ParticleOptions describes a particle effect.

type ParticlePoint

type ParticlePoint = wasm.ParticlePoint

ParticlePoint places one control point of a particle effect.

type Pawn

type Pawn = wasm.Pawn

Pawn is one player's hero this frame.

type Pickup

type Pickup struct {
	// Entity is the pickup's entity handle.
	Entity uint32
}

Pickup is one pickup the mod placed.

func CreatePickup

func CreatePickup(kind PickupKind, position *Vector) (Pickup, error)

CreatePickup places an urn, which a hero carries once collected, or a movement buff. Stopping the mod removes it.

func (Pickup) Present

func (p Pickup) Present() (bool, error)

Present reports whether the pickup still lies in the world, uncollected.

func (Pickup) Remove

func (p Pickup) Remove() (bool, error)

Remove takes the pickup out of the world. It reports false when a player had collected it.

type PickupKind

type PickupKind = wasm.PickupKind

PickupKind is a kind of item players collect by walking over it.

type Placed

type Placed struct {
	Object *SpotObject
	World  WorldObject
	// Entity is the model's entity handle, as traces report it.
	Entity uint32
}

Placed is one spot object standing in the world.

type Player

type Player struct {
	// Slot identifies the player on the server.
	Slot int32
}

Player addresses one connected player by their server slot.

func AddBot

func AddBot(options *BotOptions) (Player, error)

AddBot adds a bot player and returns it. The bot leaves when the world ends or the mod stops.

func (Player) Abilities

func (p Player) Abilities() ([]*Ability, error)

Abilities lists the abilities of the player's hero in the hero's order, or none without a live hero.

func (Player) AddMetric

func (p Player) AddMetric(name string, value float64, label *string) error

AddMetric adds to the player's total of a metric the manifest declares. The host keeps each player's totals in memory and hands them on once, when the player leaves or the mod stops; a bot keeps none.

func (Player) AdjustSouls

func (p Player) AdjustSouls(delta int32, silent *bool) error

AdjustSouls gives the player delta souls, or takes them when delta is negative. A spend larger than the player's souls fails and spends nothing. Silent skips the pickup's sound and number.

func (Player) Announce

func (p Player) Announce(title, text string) error

Announce shows a game announcement with a title to the player.

func (Player) BlockInput

func (p Player) BlockInput(buttons uint64) error

BlockInput withholds buttons from the player's hero until called again, on top of the block on everyone. Zero releases the player.

func (Player) Buttons

func (p Player) Buttons() (uint64, error)

Buttons returns the buttons a player holds, as Buttons bits, while the player is alive or dead.

func (Player) CenterText

func (p Player) CenterText(text string) error

CenterText shows text in the middle of the player's screen until it is replaced. Empty text clears it.

func (Player) Chat

func (p Player) Chat(text string) error

Chat sends a server chat line to the player.

func (Player) ClearItems

func (p Player) ClearItems() error

ClearItems removes every item the player's hero owns.

func (Player) ClearScreenEffect

func (p Player) ClearScreenEffect(effect ScreenEffect) error

ClearScreenEffect ends every running instance of effect on the player's view.

func (Player) Freeze

func (p Player) Freeze(frozen *bool) error

Freeze holds the player's hero in place, without input or damage, until it is released. Stopping the mod releases it.

func (Player) GiveItem

func (p Player) GiveItem(item string) error

GiveItem gives the hero an item, enabled and free. A hero that owns it keeps its one copy.

func (Player) GiveModifier

func (p Player) GiveModifier(modifier string, seconds float32) error

GiveModifier gives the hero an ability's modifier, named "<ability>/<modifier>", for seconds, as if the hero's own ability applied it; a hero without that ability applies it with its first ability. The game may end it sooner, as invisibility ends on a shot.

func (Player) Heal

func (p Player) Heal(amount int32) error

Heal restores health to the player's hero, up to its maximum.

func (Player) HoldModifier

func (p Player) HoldModifier(modifier string, active *bool) error

HoldModifier keeps an ability's modifier, named "<ability>/<modifier>", on the hero with no expiry, giving it back whenever the game removes it or the hero returns. The hero must own the ability or item. Every hero that gains the modifier from the same ability keeps it until the hold ends. Releasing leaves the hero's current modifier until it dies.

func (Player) Kill

func (p Player) Kill() error

Kill kills a player's hero, crediting no one.

func (Player) Move added in v0.1.1

func (p Player) Move(position *Vector, facing *Angles, velocity *Vector) error

Move carries the player's hero to a position as continuous motion, as a recording plays back. Unlike Teleport it keeps the hero's animated model drawn when repeated every tick, and leaves the camera alone.

func (Player) Pawn

func (p Player) Pawn() (*Pawn, error)

Pawn returns the player's hero this frame, or nothing without one.

func (Player) Press

func (p Player) Press(buttons uint64) error

Press presses buttons at the player's next input, even through a block. A bot presses them as a player would.

func (Player) RefreshAbility

func (p Player) RefreshAbility(ability string) error

RefreshAbility ends the cooldown of the hero's ability named ability, such as citadel_ability_melee_parry.

func (Player) RemoveBot

func (p Player) RemoveBot() error

RemoveBot removes a bot the mod added.

func (Player) ReplaceAbility

func (p Player) ReplaceAbility(index uint32, ability string) error

ReplaceAbility puts the ability named ability, untrained, in the hero's ability slot index, as Ability.slot, removing the ability there.

func (Player) ResetHero added in v0.1.3

func (p Player) ResetHero(souls int32) error

ResetHero rebuilds the player's hero as it first spawned, without items, ability upgrades, levels or ability points, holding souls.

func (Player) Respawn

func (p Player) Respawn() error

Respawn revives the player's dead hero.

func (Player) RestoreHero

func (p Player) RestoreHero(target *HeroTarget) error

RestoreHero gives the player's live hero target over the next few seconds: the build first, then health, stamina and pose once it settles, then charges and cooldowns. A Restored event reports when the result has held for a second, or why it could not. A new call replaces the running one.

func (Player) RestoreStamina

func (p Player) RestoreStamina() error

RestoreStamina refills the player's stamina.

func (Player) ScreenEffect

func (p Player) ScreenEffect(effect ScreenEffect, timing *ScreenTiming) error

ScreenEffect plays a full-screen effect on the player's view. Effects of one kind stack. The player's hero must be alive.

func (Player) SelectHero

func (p Player) SelectHero(hero any, team int32) (uint32, error)

SelectHero gives the player a hero on a team, 2 or 3, and returns the hero's identifier as Pawn.hero reports it. The hero appears on a later frame.

func (Player) SetAbility

func (p Player) SetAbility(options *AbilityOptions) error

SetAbility changes the upgrades, charges or timers of one of the hero's abilities. An omitted option stays as it is.

func (Player) SetSetting

func (p Player) SetSetting(key, value string) error

SetSetting changes the player's value of a setting the manifest declares. The value follows the player to later games and other mods' servers of the same mod; a bot keeps the defaults.

func (Player) SetStamina added in v0.1.3

func (p Player) SetStamina(stamina float32) error

SetStamina sets the player's stamina, as Pawn.stamina reads it. The game regenerates it as usual afterwards.

func (Player) SetVelocity

func (p Player) SetVelocity(velocity *Vector) error

SetVelocity replaces the motion of a player's hero without moving it.

func (Player) Setting

func (p Player) Setting(key string) (string, error)

Setting returns the player's value of a setting the manifest declares: the value they chose, or the setting's default. A bot has the defaults.

func (Player) SettingNumber

func (p Player) SettingNumber(key string) (float64, error)

SettingNumber returns the player's value of a number setting the manifest declares.

func (Player) SettingOn

func (p Player) SettingOn(key string) (bool, error)

SettingOn returns the player's value of a switch setting the manifest declares.

func (Player) Sound

func (p Player) Sound(sound string) error

Sound plays a game sound event, such as Damage.Send.Crit, on the player's hero.

func (Player) Spectate added in v0.1.1

func (p Player) Spectate() error

Spectate moves the player to the spectators, without a hero. The player watches until a hero selection seats them again.

func (Player) StartingSouls

func (p Player) StartingSouls(souls int32) error

StartingSouls sets the souls the player's hero spawns with.

func (Player) Steer added in v0.1.1

func (p Player) Steer(steering *Steering) error

Steer replays a recorded movement command on the player's hero, usually a bot: the game runs the command's buttons and axes, so the hero crouches, slides, jumps and mantles with its own animation, and the step then ends on the recorded pose. The steering stays until the next Steer replaces it, its presses counting once; a Steer without one releases the hero.

func (Player) Teleport

func (p Player) Teleport(position *Vector, facing *Angles, velocity *Vector) error

Teleport moves the player's hero and turns it and the camera. With a velocity it also sets the hero's motion, as a launch, and the camera follows the hero.

func (Player) Unwatch added in v0.1.3

func (p Player) Unwatch() error

Unwatch returns a player watching from their hero back to it. Stopping the mod returns every such player.

func (Player) Watch added in v0.1.2

func (p Player) Watch(target uint32) error

Watch points the player's camera at a hero, through the hero's own view, as the game's spectator camera follows it. A spectator watches through their spectator camera, once it exists. A player with a hero watches while the hero stays where it stands, keeping its level, souls and items, until Unwatch returns them to it.

func (Player) WatchMovement

func (p Player) WatchMovement(watch bool) error

WatchMovement adds a player's hero to the movement samples of each Frame event on a new tick, or removes it.

type PrecacheOptions

type PrecacheOptions = wasm.PrecacheOptions

PrecacheOptions names what the next world loads ahead of use.

type ProjectileOptions

type ProjectileOptions = wasm.ProjectileOptions

ProjectileOptions selects the projectiles a mod watches.

type RestoredEvent

type RestoredEvent = wasm.RestoredEvent

RestoredEvent reports how a RestoreHero ended.

type RiftState

type RiftState = wasm.RiftState

RiftState is the Rift objective's timing as the game holds it. Times are game times in seconds, or zero when unset.

func Rift

func Rift() (*RiftState, error)

Rift reads the Rift objective's state.

type Score added in v0.1.3

type Score = wasm.Score

Score is one player's scoreboard counters since the match began, as the game counts them.

type ScreenEffect

type ScreenEffect = wasm.ScreenEffect

ScreenEffect is a stock full-screen view effect.

type ScreenTiming

type ScreenTiming = wasm.ScreenTiming

ScreenTiming is a screen effect's timing in seconds.

type Service

type Service func(method string, payload []byte) ([]byte, error)

Service answers calls to one service the mod serves: the method's name and payload in, the answer out.

type ServiceCall

type ServiceCall = wasm.ServiceCall

ServiceCall calls one method of a service outside Modlock. A host that embeds Modlock provides services of its own, such as a game mode's match, and a mod may serve one to the host. The service and its caller agree on the payload's encoding.

type ServiceReply

type ServiceReply = wasm.ServiceReply

ServiceReply is a service's answer.

type SettingChangedEvent

type SettingChangedEvent = wasm.SettingChangedEvent

SettingChangedEvent is one player's new value of one setting.

type Spot

type Spot struct {
	Map string
	// Objects are the placed objects in placement order.
	Objects []*SpotObject
}

Spot is a base map and the objects players placed on it. Nothing is compiled: loading a spot spawns each object as a solid model on the map the world already runs.

func DecodeSpot

func DecodeSpot(data []byte) (*Spot, error)

DecodeSpot reads a spot document.

type SpotObject

type SpotObject struct {
	// Model is the model's path, which the mode precached.
	Model    string
	Position *Vector
	Facing   *Angles
	// Scale multiplies the model's size.
	Scale float32
	// Bounce launches a hero who stands on the object upward at this speed,
	// in units per second; zero makes an ordinary object.
	Bounce float32
	// PlacedBy is the Steam ID of the player who placed the object, or zero.
	PlacedBy uint64
}

SpotObject is one solid object placed in a spot.

type StartEvent

type StartEvent = wasm.StartEvent

StartEvent describes the server the mod starts in.

type StartResult

type StartResult = wasm.StartResult

StartResult declares which events the mod consumes.

type Steering added in v0.1.1

type Steering = wasm.Steering

Steering is one recorded movement command and the pose its step ends on.

type TextOptions

type TextOptions = wasm.TextOptions

TextOptions describes text that floats in the world.

type TimerTarget

type TimerTarget = wasm.TimerTarget

TimerTarget sets one owned ability's or item's charges and cooldowns. Times are seconds from the moment the host writes them; an omitted start and end mean no timer.

type TraceHit

type TraceHit = wasm.TraceHit

TraceHit is where a traced line first hit something.

func Trace

func Trace(options *TraceOptions) (*TraceHit, error)

Trace returns where a line first hits something, or nothing when it hits nothing or the world's collision is not ready.

type TraceOptions

type TraceOptions = wasm.TraceOptions

TraceOptions describes a line to test against the world. Layers are bits of the game's collision layers: bit 0 is solid, 2 trigger, 4 player clip, 18 player and 19 NPC.

type UiPressEvent

type UiPressEvent = wasm.UiPressEvent

UiPressEvent reports a press on a button in a player's interface.

type Vector

type Vector = modlock.Vec3

Vector is a position or direction in the world, in game units.

type WorldEvent

type WorldEvent = wasm.WorldEvent

WorldEvent announces a loaded world.

type WorldObject

type WorldObject struct {
	// ID identifies the object among the mod's objects.
	ID uint32
}

WorldObject is one object the mod placed in the world.

func CreateFog

func CreateFog(options *FogOptions) (WorldObject, error)

CreateFog fills a box with tinted fog whose density fades across the box's boundary. Removing the object clears it; moving it moves the box.

func CreateModel

func CreateModel(options *ModelOptions) (WorldObject, error)

CreateModel places a model in the world, solid when the options ask. The world removes it when the world ends; stopping the mod removes it too.

func CreateParticle

func CreateParticle(options *ParticleOptions) (WorldObject, error)

CreateParticle starts a particle effect. Removing the object stops it; moving it moves the effect.

func CreateText

func CreateText(options *TextOptions) (WorldObject, error)

CreateText places text that floats in the world.

func (WorldObject) Entity

func (w WorldObject) Entity() (uint32, error)

Entity returns the entity handle of a model, as traces report it.

func (WorldObject) Move

func (w WorldObject) Move(position *Vector, facing *Angles) error

Move places the object at position, turning it to facing.

func (WorldObject) Remove

func (w WorldObject) Remove() error

Remove takes the object out of the world.

func (WorldObject) SetHidden added in v0.1.2

func (w WorldObject) SetHidden(player Player, hidden bool) error

SetHidden hides the object from one player or shows it again. Other players still see it. A player who leaves sees every object when they return.

func (WorldObject) SetText

func (w WorldObject) SetText(text string) error

SetText replaces a text object's words.

Directories

Path Synopsis
Package console sets the server's console variables and runs its console commands, through values modlock-entitygen generates from the game's console:
Package console sets the server's console variables and runs its console commands, through values modlock-entitygen generates from the game's console:
Package entity reads and writes the fields of live entities, sends them inputs and creates them, through typed classes generated from the game's schema and entity dump by modlock-entitygen.
Package entity reads and writes the fields of live entities, sends them inputs and creates them, through typed classes generated from the game's schema and entity dump by modlock-entitygen.

Jump to

Keyboard shortcuts

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