Skip to content

New library: ents

dounai2333 edited this page Jan 4, 2025 · 1 revision

Introduction

The ents library provides functions for creating and finding entities in the game.

Create

dounai_lib.ents.Create(classname)

Creates an entity. This function does not spawn the entity, use entity:Spawn() for that.

Return: entity or nil

classname: string

CreateBrush

dounai_lib.ents.CreateBrush(classname, origin, mins, maxs, keyvalues, ...)

Creates an brush entity.

Return: entity or nil

classname: string

origin: vector

mins: vector

maxs: vector

keyvalues: string

CreateWithKeyValues

dounai_lib.ents.CreateWithKeyValues(classname, origin, angles, model, keyvalues, ...)

A advanced version of dounai_lib.ents.Create(), creates an entity with given values.

Return: entity or nil

classname: string

origin: vector (can be nil)

angles: angle

model: string

keyvalues: string

FindByClass

dounai_lib.ents.FindByClass(class)

Gets all entities with the given class, supports wildcards.

Return: table

class: string

FindByName

dounai_lib.ents.FindByName(name, first_result)

Gets all entities with the given hammer targetname. If first_result is true, only the first found entity will be returns.

NOTE: Using first_result is always recommended as it will have better performance.

Return: table, entity or nil

name: string

first_result: bool

FindByPos

dounai_lib.ents.FindByPos(pos, class)

Gets all entities with the same pos as given one. If class is set, only the entities with classname matches will be returns.

Return: table

pos: vector

class: string

GetAll

dounai_lib.ents.GetAll()

Returns a table of all existing entities.

Return: table

GetByHandle

dounai_lib.ents.GetByHandle(handle)

Gets a entity by a entity handle.

Return: entity or nil

handle: string

GetByIndex

dounai_lib.ents.GetByIndex(index)

-- Wrapper
Entity(index)

This is advanced version of original GetEntityByIndex(), and will automatic convert entity to it's proper type.

Return: entity, player, weapon and mathCounter or nil

GetWorld

dounai_lib.ents.GetWorld()

Returns the worldspawn entity.

Return: entity

Clone this wiki locally