Skip to content

Add a ping ​

A ping kind is a PingDef in the view (label, mark, colour, chat line, sound, who hears it). The rules allow it by id, so pings travel through the simulation and play back in replays.

ts
// in src/rules.ts: the kinds the engine lets a player send (kept apart from the client, so a server runs it as it is)
import { defineIds, type Rules } from '@v12-engine/engine'

export const PING_KINDS = ['look', 'danger', 'assist', 'onMyWay', 'rally']

export const rules: Rules = {
	id: 'my-game',
	name: 'My game',
	units: [{ id: defineIds('scout').scout, name: 'Scout', kind: 'unit', radius: 0.4, sight: 10, stats: { health: 100, moveSpeed: 5 } }],
	settings: {
		talk: {
			pings: {
				kinds: PING_KINDS,
				// what each asks of a computer ally: help, attack, defend, rally or ignore
				meanings: { danger: 'help', assist: 'help', rally: 'rally' }
			}
		}
	}
}
ts
// in src/game.ts
import { presetPings, type GameView, type PingDef } from '@v12-engine/client'
import { createGame } from '@v12-engine/engine'
import { rules } from './rules'

const rally: PingDef = {
	id: 'rally',
	label: 'Rally here',
	short: 'R', // under the mark and on the minimap, where the label is long
	glyph: '⚑', // or `icon`: a picture's path
	color: '#ffd23c',
	says: 'Rally here!', // the chat line; false for none
	sound: 'horn',
	seconds: 8,
	audience: 'allies', // or 'all': the enemy hears it too
	wheel: { slot: 2 }, // 0 is the top, clockwise; `hidden: true` to send it from code alone
	cooldown: 4
}

export const view: GameView = {
	units: {
		looks: {}
	},
	pings: {
		// four of the nine ready-made kinds, the danger one redder, and the game's own
		kinds: [...presetPings(['look', 'danger', 'assist', 'onMyWay'], { danger: { color: '#ff2020' } }), rally],
		// the wheel (Ctrl and the left button held): a ring of six, labels as the pointer goes over them
		wheel: { slots: 6, radius: 92, labels: 'hover' }
	}
}

export const game = createGame(rules).view(view)

Done: hold Ctrl and the left mouse button for a six-slot wheel; Rally here is in slot 2 and tells computer allies to rally.

Send a ping in code ​

ts
import type { ShownPing } from '@v12-engine/client'

client.pings.send('rally', { x: 40, z: 22 }) // as the player: the rules, the limits and the cooldown apply
client.pings.send('danger', { x: 40, z: 22 }, 'all')
client.pings.define({ id: 'gather', label: 'Gather', glyph: '◎', color: '#7ad1ff' }) // the wheel is made again
client.pings.onPing((ping: ShownPing) => console.log(`${ping.name}: ${ping.def.label}`, ping.x, ping.z, ping.to))
client.pingWheel.look.radius = 120

From the rules, as a player would: ping(world, player, { x: 40, z: 22 }, 'rally', 'all'). The beforeTalk hook can mute, rewrite or redirect any ping.

In the editor ​

  1. Open the Look panel and its Pings fold. It lists your kinds in their colours.
  2. Pick one and edit its fields and its wheel slot.
  3. Click Show here, or Ping here while the map plays.
  4. It writes pings.json, which the view lays over its code (layFiles with PINGS_FILE).

Reference ​

FieldWhat it does
label, shortIts name, and a short one for the mark and the minimap.
glyph, iconThe mark: a character, or a picture's path.
saysThe chat line, or false.
audienceallies or all.
wheel{ slot } (0 is the top, clockwise), or { hidden: true }.
renderscene (above units and trees), overlay, or a PingDraw of yours.
seconds, cooldown, sound, colorAs named.

A def whose id the rules don't list is logged once. See Pings, floating words and plates, and Computer players for what an AI ally does with a ping.