Skip to main content

Zone

A box in the world that tells you when players walk into it and out of it, through Entered and Left. Use it for checkpoints, start and finish lines, reset areas, safe areas, or anything else you'd otherwise check by hand every frame.

public sealed class Zone : IDisposable

Namespace: DeadworksManaged.Api.Utils
Inherits / implements: IDisposable
Source: Utils/Zone.cs#L39

Notes​

Zones check each player's position every game tick. The position is at the hero's feet, so to catch a player standing in an area, start the box a little below the floor and go up to about head height. Dead players, and players who haven't picked a hero yet, count as outside every zone.

Because positions are only checked once a tick, a fast player (dashing, on a zipline) can cross a thin zone between two checks without ever being inside. Make zones that catch moving players, like finish lines, at least 100 units deep in the direction they're crossed.

A zone keeps working until you call Dispose or your plugin unloads. To show it in the world, draw it with CBeam.CreateBox(zone.Mins, zone.Maxs).

Example​

var finish = new Zone(new Vector3(-100, -100, 0), new Vector3(100, 100, 128)) { Name = "finish" };
finish.Entered += (zone, player, pawn) => Chat.PrintToChat(player, "You finished!");

var safeSpot = new Vector3(0, 0, 64);
var pit = new Zone(new Vector3(-500, -500, -300), new Vector3(500, 500, -200));
pit.Entered += (zone, player, pawn) => pawn.Teleport(position: safeSpot);

Constructors​

new Zone()​

Creates a zone between two opposite corners, given in any order.

Signature

public Zone(Vector3 mins, Vector3 maxs)

Source: Utils/Zone.cs#L74

Properties​

Zone.Name​

Optional label, handy in logs and when one handler serves several zones.

Signature

public string? Name { get; set; }

Source: Utils/Zone.cs#L46

Zone.Tag​

Anything you want to attach to the zone, such as a checkpoint number.

Signature

public object? Tag { get; set; }

Source: Utils/Zone.cs#L49

Zone.Enabled​

Turns the zone on and off. While off, everyone counts as outside: players inside get Left, and no Entered fires until it's turned back on.

Signature

public bool Enabled { get; set; } = true;

Source: Utils/Zone.cs#L55

Zone.Mins​

The corner with the lowest coordinates. Setting it beyond Maxs on an axis swaps the two on that axis.

Signature

public Vector3 Mins { get; set; }

Source: Utils/Zone.cs#L97

Zone.Maxs​

The corner with the highest coordinates. Setting it below Mins on an axis swaps the two on that axis.

Signature

public Vector3 Maxs { get; set; }

Source: Utils/Zone.cs#L103

Zone.Center​

The middle of the zone.

Signature

public Vector3 Center { get; }

Source: Utils/Zone.cs#L109

Zone.Size​

How big the zone is along each axis.

Signature

public Vector3 Size { get; }

Source: Utils/Zone.cs#L112

Zone.Occupants​

The players inside right now.

Signature

public IReadOnlyList<CCitadelPlayerController> Occupants { get; }

Source: Utils/Zone.cs#L139

Zone.OccupantCount​

How many players are inside right now.

Signature

public int OccupantCount { get; }

Source: Utils/Zone.cs#L150

Methods​

Zone.FromCenter()​

Creates a zone of the given size with its middle at center.

Signature

public static Zone FromCenter(Vector3 center, Vector3 size)

Source: Utils/Zone.cs#L84

Zone.FromOrigin()​

Creates a zone from a point and corners relative to it, the way map triggers are set up. For example, an origin on the floor with minsOffset (-64, -64, -8) and maxsOffset (64, 64, 96) covers a 128 wide area from just below the floor to about head height.

Signature

public static Zone FromOrigin(Vector3 origin, Vector3 minsOffset, Vector3 maxsOffset)

Source: Utils/Zone.cs#L93

Zone.SetBounds()​

Moves both corners at once. They can be given in any order. On the next tick, players the zone no longer covers get Left and players it now covers get Entered.

Signature

public void SetBounds(Vector3 a, Vector3 b)

Source: Utils/Zone.cs#L118

Zone.MoveTo()​

Moves the zone so its middle is at center, keeping its size. Enter and leave events follow as for SetBounds.

Signature

public void MoveTo(Vector3 center)

Source: Utils/Zone.cs#L124

Zone.Contains()​

True if point is inside the zone. Points exactly on the edge count as inside.

Signature

public bool Contains(Vector3 point)

Source: Utils/Zone.cs#L130

Zone.IsInside()​

True if the player in slot was inside at the last check.

Signature

public bool IsInside(int slot)
public bool IsInside(CBasePlayerController player)

Source: Utils/Zone.cs#L133, Utils/Zone.cs#L136

Zone.ResetOccupants()​

Forgets who is inside, without firing Left. Players still inside get Entered again on the next tick, which is useful when restarting a round.

Signature

public void ResetOccupants()

Source: Utils/Zone.cs#L159

Zone.Dispose()​

Stops the zone for good. No more events fire, not even Left for players still inside.

Signature

public void Dispose()

Source: Utils/Zone.cs#L185

Zone.ToString()​

Signature

public override string ToString()

Source: Utils/Zone.cs#L194

Events​

Zone.Entered​

Fires when a player gets inside the zone, whether they walked, teleported or respawned there. Along with the player you get their hero, which is alive and inside the zone.

Signature

public event Action<Zone, CCitadelPlayerController, CCitadelPlayerPawn>? Entered;

Source: Utils/Zone.cs#L61

Zone.Left​

Fires when a player who was inside leaves, dies or loses their hero. Moving the zone off them or turning it off counts too. Along with the player you get their hero, which may be dead, or null if they no longer have one.

Signature

public event Action<Zone, CCitadelPlayerController, CCitadelPlayerPawn?>? Left;

Source: Utils/Zone.cs#L67