Skip to content

Script Builtin Functions

BraXi edited this page Sep 23, 2023 · 8 revisions

This is the overview of script builtins provided by engine, they are autogenerated by engine and defined in inc/pragma_builtins.qc.

They are grouped into three categories:

  • shared - can be executed by all programs
  • client - can only be executed by client programs progs/client.dat
  • server - can only be executed by server programs progs/server.dat

Shared

builtins listed below can be executed by client and server programs


void print(string s)

Prints text to server's console

example: print("hello world!\n");


void dprint(string s)

Prints text to server's console when developer mode is enabled (cvar developer 1 must be set)

example: dprint("this message shows when developer is set to 1\n");


void resetrunaway()

Resets the infinite loop error counter, this should be used in heavy functions that do a lot of operations and accidentally trigger this error.


void traceon()

Enable script execution trace, code you want to trace should be between traceon() and traceoff(). The stack trace will be printed to console after QC program has ended execution. developer 1 must be set to use this.


void traceoff()

Stops tracking program execution, see traceon(). developer 1 must be set to use this.


void crash()

Hard crashes engine, useful for debugging (legends say). developer 1 must be set to use this.


void printstack()

Prints script stack execution to console. developer 1 must be set to use this.


void localcmd(string str)

Executes string in local command buffer

example: localcmd("name player; reconnect\n");


float argc()

Returns arguments count of a command, this is used in ClientCommand and ServerCommand functions.

example: float num_args = argc();


string argv(float idx)

Returns argument number idx as a string, this is used in ClientCommand and ServerCommand functions.

example: string command = argv(0);


float cvar(string str)

Returns cvar value as float

example: if( cvar("sv_cheats") > 0 )


string cvarstring(string str)

Returns cvar value as string

example: cprint( self, cvarstring("welcome_message") );


void cvarset(string str, string val)

Sets value of a local cvar, this will not change cvars flagged as CVAR_ROM.

example: cvarset("sv_hostname", "pragma test server");


void cvarforceset(string str, string val)

Sets value of a local cvar, this will change even cvars marked as CVAR_ROM, be very careful with this.

example: cvarforceset("sv_gravity", ftos(self.gravity));


string ftos(float f)

returns float as string

example: ``cprint3(self, "your health is ", ftos(self.health), "\n");


string vtos(vector v1)

returns vector as string

example: cprint3(self, "current origin: ", vtos(self.origin), "\n");


float rint(float val)

Rounds val to an integral value


float floor(float val)

Rounds val downward, returning the largest integral value that is not greater than val


float ceil(float val)

Rounds val upward, returning the smallest integral value that is not less than val.


float sin(float val)

Returns the sine of an angle of val radians.


float cos(float val)

Returns the cosine of an angle of val radians.


float sqrt(float val)

Returns the square root of val.


vector normalize(vector in)

Returns the normalized in vector.


float vectorlength(vector in)

Return the length of in vector, in other words, cab ne used to calculate distance between two vectors.

example: float distance = vectorlength(self.origin - other.origin);


float vectoyaw(vector in)

Returns the YAWangle of in vector.

example: self.angles_y = vectoyaw(self.origin - other.origin);


float vectoangles(vector in)

vectoangles


float random()

Returns random number in range [0.0 - 1.0]

example: if( random() > 0.5 )


float randomint(float num)

Returns random number in range [0,num]

example: sound = self.pain_sounds[ randomint(3) ];


Server

float precache_model(string name)

loads model or sprite and returns a modelindex to it

example: self.modelindex = precache_model("models/test.md2");


float precache_sound(string name)

loads sound relative to 'sound/' directory and returns a soundindex to it

example: self.loopsound = precache_sound("elevator/moveup.md2");


float precache_image(string name)

loads image relative to 'pics/' directory and returns a imageindex to it

example: self.pic_health = precache_image("hud_health_icon");


entity spawn()

Creates new gentity object

example: entity rocket = spawn();


remove(entity ent)

Delete gentity object from game

example: remove(rocket);


entity getent(float num)

returns gentity by its index, if gentity is not in use returns world entity

example:

// if singleplayer, find the local player entity
if( cvar("sv_maxclients") == 1 )
    local_player = getent(1);

entity nextent(entity previousEnt)

Grabs next active gentity after previousentity

example:

entity e = world;
while( (e = nextent(e)) != world )
    print2( e.classname, "\n");

Client

builtins listed below can be executed by client programs TODO fixme

Clone this wiki locally