Left 4 Dead 2 Guide

How to create new commands using project_smok for Left 4 Dead 2

How to create new commands using project_smok

Overview

A quick guide on how to create your own commands using project_smok administration system.

Introduction

This guide explains how you can create your own chat and console commands 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:

You can also find some shared custom commands in this discussion

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 scripts folder allows you to create custom commands (or run custom scripts).

In this folder, there are 2 files

  • example_command_file.nut: An example command file
  • file_list.txt: List of file names to include from this folder

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

Creating a new command file

Create a new text file and name it however you want with .nut Squirrel language file extension.

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

Custom command file format

To start creating a command, you need to know a bit of programming, the Squirrel scripting language and what is provided to you in the global scope. You can check the example command file for some help.

If you just want to use someone else’s script, you can copy and paste it into this file and skip to step 5.

If you want to create a new command from scratch, follow these steps

  1. Pick a command name and initialize a table under PS_Scripts table.
  2. Decide the minimum user level required for the use of this command with MinimumUserLevel value.
  3. Write some documentation about the command with Help table.
  4. Write the function which takes 3 parameters (player, arguments, text) with Main function.
  5. Scripting part is completed. Write the file name into file_list.txt to include your command script.
  6. DONE. Start a game and check your console to see if the command was registered.

Using the command you’ve created

Check how your documentation of the command looks from chat

?my_command

Result of the command called from chat

Result of the command called from console

Reloading custom commands in-game

You can edit your custom command files and then reload them while you’re in-game, using the reload_scripts command. This command will apply all the changes you’ve made to the command files.

Example used in this guide

Example contents of my_command_file.nut file is given below.

/*——————————–*/ // – Pick a name for the command and initialize // a table inside the ::PS_Scripts table // // – Example: !my_command ::PS_Scripts.my_command <- {} /*——————————–*/ // – Decide the minimum user level required // for this command with MinimumUserLevel value // // – Levels (see [link]: // + PS_USER_NONE: (Default level) Available for everyone // + PS_USER_BASIC: Available for guest players and more privileged // + PS_USER_ADMIN: Available for admins and more privileged // + PS_USER_SCRIPTER: Available for scripters and host // + PS_USER_HOST: Only available for the host // // – Example: Require PS_USER_ADMIN privileges ::PS_Scripts.my_command.MinimumUserLevel <- PS_USER_ADMIN /*——————————–*/ // – Create documentation for the command // with Help table // // – Example: ?my_command ::PS_Scripts.my_command.Help <- { // Basic information docs = “explain this command here” // Parameter information param_1 = { name = “first parameter’s name => !my_command param_1” docs = “first parameter explanation” when_null = “what happens when nothing is given => !my_command” } // For other parameters use param_2, param_3, …, param_n } /*——————————–*/ // – Write your function into a Main function which // has 3 parameters: // + player : VSLib.Player command caller // + args : arguments table (integer keys, string values ; first argument = key 0) // + text : chat or console message which triggered this command ::PS_Scripts.my_command.Main <- function (player, args, text) { // Get the expected arguments into local variables local argument1 = GetArgument(1) local argument2 = GetArgument(2) // … // Use ‘GetArgument(int)’ function to get arguments instead of ‘args’, if nothing is given returns null // … // Write instructions here // … // Write a success message ::Printer(player, “Things worked, here’s a success message!”) // Or write an error message // ::Printer(player, “Things failed, here’s a failure message!”, “error”) }
SteamSolo.com