VERGELua API

entities

Find and iterate entities.

entities.GetLocalPlayer():Entity

The local player entity.

entities.GetLocalWeapon():Entity

The local player's active weapon.

entities.GetPlayerResources():Entity

The CTFPlayerResource entity, or nil.

entities.GetByIndex(index:number):Entity

Entity by index, nil if invalid.

entities.GetByUserID(userID:number):Entity

Entity by user ID, nil if invalid.

entities.GetPlayers():table

All player entities as an array table.

entities.GetEntities():table

All non-player entities as an array table.

entities.FindByClass(class:string):table

Entities of a client class, keyed by index.

Examples

Scout enemy sentries

Press slot 3 to list every enemy sentry with its distance.

callbacks.Register("CreateMove", function()
    if not input.IsButtonPressed(KEY_3) then return end

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

    for _, bld in pairs(entities.FindByClass("CObjectSentrygun")) do
        if bld:IsValid() and bld:GetTeam() ~= me:GetTeam() then
            local d = vector.Distance(me:GetAbsOrigin(), bld:GetAbsOrigin())
            print(string.format("sentry #%d at %.0f meters, hp %d", bld:GetIndex(), d / 52, bld:GetHealth()))
        end
    end
end)