Type Conversions - tayjay/SCriPt GitHub Wiki

Type Conversions

To make scripts read more naturally, SCriPt registers a few automatic conversions. They apply anywhere the C# side expects that type — method arguments and settable properties alike — so you rarely need helper constructors.

Tables → Unity types

A Lua table is converted to a Vector3, Vector2, Quaternion, or Color automatically. You can use named fields or positional values:

-- Named
player.Position = { x = 10.5, y = 1.0, z = -3.2 }

-- Positional (x, y, z)
player.Position = { 10.5, 1.0, -3.2 }

-- Color (r, g, b, a) — alpha defaults to 1 if omitted
local light = AdminToys.SpawnLightSource(player.Position, 2.0)
light.Color = { 1, 0, 0 }
Target type Fields Positional order
Vector2 x, y {x, y}
Vector3 x, y, z {x, y, z}
Quaternion x, y, z, w {x, y, z, w}
Color r, g, b, a {r, g, b, a}

The New global is still available if you prefer to construct these explicitly.

Strings → enums

Where a method or property expects one of these enums, you can pass the value's name as a string (case-insensitive):

  • RoleTypeId
  • ItemType
  • Team
  • Faction
player:SetRole("ClassD")          -- same as RoleTypeId.ClassD
player:AddItem("Coin")            -- same as ItemType.Coin
local scps = Players.ByTeam("SCPs")

If the string isn't a valid name for that enum, the call raises a clear error. You can always pass the enum value directly instead (e.g. RoleTypeId.ClassD).