VERGELua API

vector

Vector math helpers.

vector.New(x:number, y:number, z:number):Vector3

Create a new vector from components.

vector.Add(a:Vector3, b:Vector3):Vector3

Add two vectors.

vector.Subtract(a:Vector3, b:Vector3):Vector3

Subtract two vectors.

vector.Multiply(v:Vector3, s:number):Vector3

Scale the vector by a scalar.

vector.Divide(v:Vector3, s:number):Vector3

Divide the vector by a scalar.

vector.Length(v:Vector3):number

Length of the vector.

vector.LengthSqr(v:Vector3):number

Squared length of the vector.

vector.Distance(a:Vector3, b:Vector3):number

Distance between two vectors.

vector.Normalize(v:Vector3):Vector3

Return a normalized copy of the vector.

vector.Angles(v:Vector3):Vector3

Convert a direction vector to Euler angles.

vector.AngleForward(a:Vector3):Vector3

Forward vector from angles.

vector.AngleRight(a:Vector3):Vector3

Right vector from angles.

vector.AngleUp(a:Vector3):Vector3

Up vector from angles.

vector.AngleVectors(a:Vector3):Vector3, Vector3, Vector3

Forward, right and up vectors from angles.

vector.AngleNormalize(a:Vector3):Vector3

Normalize each angle to the -180 to 180 range.

Examples

Aim at the nearest enemy

While holding the aim key, points your view at the closest living enemy head.

local AIM_KEY = 0x51 -- VK_Q

callbacks.Register("CreateMove", function(cmd)
    if not client.IsKeyDown(AIM_KEY) then return end

    local me = client.GetLocalPlayer()
    if not me:IsValid() then return end

    local best, bestDist = nil, math.huge
    for _, ent in pairs(entities.GetPlayers()) do
        if ent:IsValid() and ent:IsAlive() and ent:GetTeam() ~= me:GetTeam() then
            local d = vector.Distance(me:GetAbsOrigin(), ent:GetAbsOrigin())
            if d < bestDist then best, bestDist = ent, d end
        end
    end
    if not best then return end

    local to = vector.Subtract(best:GetEyePosition(), me:GetEyePosition())
    cmd.viewangles = vector.Angles(to)
end)