Skip to Content
Modlock

Go

Go mods: a main package, errors you may ignore and typed entities.

A Go mod is a main package. It imports github.com/paralin/modlock/mod and registers its handlers in init:

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() {}

Choose Go with the switch in the sidebar, and the guides show every call in it. Build interfaces with the mod/ui, mod/hud and mod/theme packages.

Errors and tests

Each call into the game returns an error. You may ignore it when the mod should keep playing anyway, such as when a chat message fails to send. Keep your game rules in functions that never call the game, as the race example does, and you can test them with plain go test.

Typed entities and the console

mod/entity has a typed accessor for every entity field and a method for every input, and mod/console has a typed setter for every console variable and a function for every command:

// Set a hero's health.
hero := entity.CBaseEntity(entity.CCitadelPlayerPawn{Handle: pawn.GetEntity()})
_ = hero.IHealth().Set(500)

// Raise the trooper bounty and change the map.
_ = console.CitadelTrooperGoldReward.Set(40)
_ = console.Changelevel.Run("street_test")

On this page