Left 4 Dead 2

Left 4 Dead 2

Not enough ratings
Creating new commands using project_smok
By randy
A quick guide on how to create your own commands using project_smok administration system.
   
Award
Favorite
Favorited
Unfavorite
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.

https://sp.zhabite.com/sharedfiles/filedetails/?id=2229460523

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
[IMPORTANT] Versions Higher Than v3.0.0
project_smok v3.0.0 was released mainly to solve addon conflict issues. This was done by renaming lot of things in the background.

If you are reading this guide and using a version higher than v3.0.0, read the notes written here[github.com]

If you have other add-ons using VSLib library, you'll have to use the new references mentioned in the scripting notes[github.com]

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
\Steam\steamapps\common\Left 4 Dead 2\left4dead2\ems\admin 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. )

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.
    • NOTE: As mentioned before for versions > v3.0.0, use GetArg instead of GetArgument


  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 https://github.com/semihM/project_smok#user-levels-system): // + 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") }