Left 4 Dead 2 Guide

How to alias commands using project_smok for Left 4 Dead 2

How to alias commands using project_smok

Overview

A detailed guide on creating aliases using project_smok

Introduction

This guide explains how to create dynamic aliases for existing commands in detail using the project_smok add-on. Everything about this add-on is documented in it’s source code page[github.com]. This guide was made for versions of project_smok v2.0.0 and higher.

[link]

Follow each section in order to successfully create a custom command. If you have any questions, suggestions or issue reports, feel free to ask, share and report them in the add-on’s discussions:

This topic is a quite complicated compared to any other feature project_smok provides. If you get lost or get error messages, feel free to ask questions!

This guide will be updated in the future to include more complicated examples.

Aliases in project_smok

Aliases in project_smok were meant to be created for making commands more customizable an enable various features that allow commands to be called in ways that isn’t possible otherwise.Some of these features are:

  • Delayed command calls: Wait a certain time before executing the command. A similar thing is actually possible with the wait console command, but this is much easier and dynamic.
  • Repeated commands calls: Repeat the command execution given times with given delays. Allows commands to be called more than once with a single call, allowing custom delays between calls.
  • Expressional arguments: Compile expressional arguments to get dynamic values. Use the returned result of evaluated expressions as arguments. This is basically the same thing using $[expression] format as your command arguments.
  • Alias variables: Access to some variables easily. Let’s you access to command caller player’s information and some other features using $variable format.

Locating the configuration files

project_smok lets you customize settings and create commands and much more through the configuration files. These configuration files are created after you start a map at least once.

You can locate the configuration files under the directory

SteamsteamappscommonLeft 4 Dead 2left4dead2emsadmin system

The aliases folder allows you to alias commands with dynamic settings.

In this folder, there are at least 4 files:

  • example_alias_file.txt: An example alias file introduced in v1.0.0
  • example_alias_file_v{x}_{y}_{z}.txt: An example alias file introduced in v{x}.{y}.{z}
  • file_list.txt: List of file names to include from this folder

You can read/edit the example files with any text editor.

Creating a new alias file

Create a new text file and name it however you want with .txt text file extension.

Start editing the file you’ve created with a text editor ( notepad, VS Code etc. )

Alias file format

Alias files follow the table data type syntax of Squirrel language:

// Things after “//” characters are comments, lets you take notes // Key-value pairs enclosed with { and } characters { key = value // value’s type may vary }

Collapsed definition of a basic alias table

The alias tables must contain certain key-value pairs in order for them to be a valid alias. Names of the keys in these pairs are given in the following table. Default value column shows what value is used when key is not present or value type is incorrect.

Key
Value Type
Default value
Explanation
MinimumUserLevel
user level
PS_USER_NONE
Minimum user level required to use the alias. Check user levels[github.com]
Help
table
{}
Documentation for the alias
Parameters
table
{}
Parameters of this alias
Commands
table
{}
Commands which will be called when this alias is called


Expected key-value pairs for table data typed values are given as below. All of these pairs in these tables are optional.

Help table
Key
Value Type
Default value
Explanation
docs
string
“”
Explanation of what this alias does
param_{x}
table or string
Will not be shown
Details for xth parameter in a table or short description string

Help.param_{x} tables
Key
Value Type
Default value
Explanation
name
string
“param_{x}
Name of this parameter
docs
string
“Unknown…”
Explanation of what this parameter is for
when_null
string
Default value from Parameters table or not shown
What value is used when this parameters doesn’t get an argument


Parameters table
Key
Value Type
Default value
Explanation
param_{x}
string or null
null
{x}th parameter declaration and it’s default value.


Commands table
Key
Value Type
Default value
Explanation
{command_name}
table
{}
{command_name} call information table. Contains arguments and timing settings. Accepts alias names which were loaded from other files before this one.

Commands.{command_name} tables
Key
Value Type
Default value
Minimum value
Evaluation
Explanation
start_delay
integer, float or string(only $variable or $[expressions])
0
0
Once before first call
Time in seconds to wait after using the alias to call this command
repeat
integer or string(only $variable or $[expressions])
1
1
Once before first call
Times to repeat this command
delay_between
integer, float or string(only $variable or $[expressions])
0.1
0.1
Before every call
Time in seconds between repeats
specific_target
string
“”
not checked
Before every call
Specific target name to overwrite aimed object, helps making commands act like something else was aimed at
skip_expression
string
“$[false]”
not checked
Before every call
An expression to decide wheter to skip current command repeat. Use with expressional value $[expression] format
arg_{x}
string or null
null
not checked
Before every call
{x}th argument’s value. Most commands expect string or null as arguments. If $[expression] format is used, result of evaluating the expression will be used directly, make sure the expression evaluates to a string or null

Alias variables

There are variables available for each alias call which are accessible using $variable format inside Commands table of the alias table. This format can be used directly as a string.

{ key = “$variable” }

These variables can also be used inside a $[expression] format. In this case all known $variable variables will be replaced using sub-string replace methods, meaning both values will be treated as strings during replacement process.

// These variables don’t exist, named to self-document { key = “$[ “$non_string” + “concatenated string” ]” // – Used ” to use as strings key2 = “$[ $string_variable ]” key3 = “$[ $string_variable.len().tostring() ]” }

All available variables are given in the table below.

Variables (dynamic)
Variable Name
Value Type
Explanation
Example Use
$repeat_id
integer
Repeat number of the current command call. Starts 1, increased by 1 at the end of the repeat
“$repeat_id”
$repeats_left
integer
Repeat number left of the current command call. Starts Commands.{command_name}.repeat, decreased by 1 at the start of the repeat.
“$repeats_left”
$last_call_time
float
Stores last repeat’s Time() at the start of that repeat. Will be same as Time() call for the first command call
“$last_call_time”
$caller_target
VSLib.Entity, VSLib.Player or null
Command’s caller’s target (object they’re aiming at) or null. Uses GetLookingEntity() method.
“$caller_target”
$specific_target
VSLib.Entity, VSLib.Player or null
Target specified by specific_target option if any. If specific_target option wasn’t created, this is the same as $caller_target variable
“$specific_target”


Variables (non-dynamic)
Variable Name
Value Type
Explanation
Example Use
$param_{x}
string or null
Access to {x}th argument passed in alias call. “$param_{x}” will be replaced with {x}th argument is passed, otherwise Parameters.param_{x} default value is used
“$param_1”

,

“$[ $param_1 == 5 ? “is 5” : “not 5″ ]”
$caller_ent
VSLib.Player
Command’s caller as VSLib.Player, can be used to access to this classes methods.
“$[$caller_ent.GetSteamID()]”
$caller_id
integer
Command’s caller’s entity index.
“$caller_id”
$caller_char
string
Command’s caller’s character name fist character capitilized.
“$caller_char”
$caller_name
string
Command’s caller’s steam name.
“$caller_name”

Full view of the basic alias table shown in last section:

NOTE: This alias won’t work since existing_command_1 isn’t really a command(unless you create one yourself!)

Registering the alias

After the alias table file is created, you need to write the file name of the file name without the extension to the file_list.txt file to register the aliases in that file.

Check your console to see if the aliases were registered.

Some basic examples

Contents of my_alias_file.txt are given below.

// Make sure to: // + Start with a { character // + End with a } character { my_basic_alias = { MinimumUserLevel = PS_USER_ADMIN Help = { docs = “a cool alias” param_1 = “used as 1st argument” param_2 = { name = “second_param” docs = “is passed as 3rd argument” when_null = “nothing is passed to 3rd argument” } } Parameters = { param_1 = “default_value_1” param_2 = null // no default value } Commands = { // Calls below will be equivelant: // !my_basic_alias arg1 arg2 // !existing_command_1 arg1 static_value arg2 existing_command_1 = { start_delay = 0 repeat = 1 delay_between = 0.5 arg_1 = “$param_1” // Use param_1’s value arg_2 = “static_value” arg_3 = “$param_2” // Use param_2’s value } } } }

Here are some other very basic alias tables:

// Some basic alias table examples { throw_grabbed = { MinimumUserLevel = PS_USER_ADMIN Help = { docs = “alternative command to yeet command” } Commands = { yeet = {} } } random_francis_line = { MinimumUserLevel = PS_USER_SCRIPTER Help = { docs = “speak a random line by Francis” } Commands = { randomline = { arg_1 = “self” arg_2 = “francis” } } } }

More information will be given in the future…

SteamSolo.com