Promoveaza serverul
87 lines 6.6 KiB Markdown Source Rendered Raw Permalink History
---
title: "VS Code Setup for AMX Mod X (Syntax, Snippets, Build Task)"
excerpt: "Turn VS Code into a real AMXX editor: Pawn syntax highlighting, include-aware navigation, and a build task that runs amxxpc and jumps to the failing line. Config included."
category: "plugin-dev"
tags: "vscode, tooling"
image: ""
read_time: "8 min read"
---
<p>Editing <code>.sma</code> files in Notepad is a needless handicap. VS Code gives you Pawn syntax highlighting, symbol navigation across the AMXX includes, and &mdash; the real win &mdash; a build task that runs <code>amxxpc</code> with a single shortcut and puts the compiler's errors directly in the Problems panel, clickable to the exact line. This is a one-time setup.</p>

<h2>1. Install a Pawn / AMXX extension</h2>
<p>Open the Extensions view (<code>Ctrl+Shift+X</code>) and search for <strong>AMXX Pawn</strong> or <strong>Pawn</strong>. Install an extension that provides Pawn language support &mdash; syntax highlighting, bracket matching, and ideally snippets for AMXX natives. There are community extensions dedicated to AMX Mod X Pawn; pick one with recent updates and a reasonable install count. If none suits you, a generic Pawn grammar still gives correct highlighting because AMXX Pawn shares the base syntax.</p>

<h2>2. Point the editor at the AMXX includes</h2>
<p>Symbol lookup and go-to-definition only work if the editor can see the <code>.inc</code> files. Open your plugin folder as a workspace and add the scripting include path to the workspace settings. Create <code>.vscode/settings.json</code>:</p>
<pre>{
  "files.associations": {
    "*.sma": "pawn",
    "*.inc": "pawn"
  }
}</pre>
<p>Then either work directly inside <code>addons/amxmodx/scripting/</code> (so <code>include/</code> is present), or copy the <code>include/</code> folder next to your sources. Extensions that support an include-path setting will expose one &mdash; set it to the folder containing <code>amxmodx.inc</code>.</p>

<h2>3. Create a build task that runs amxxpc</h2>
<p>This is the part that makes VS Code worth it. Create <code>.vscode/tasks.json</code>. On Linux:</p>
<pre>{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Compile AMXX",
      "type": "shell",
      "command": "./amxxpc",
      "args": [ "${file}" ],
      "options": {
        "cwd": "/home/steam/hlds/cstrike/addons/amxmodx/scripting"
      },
      "group": { "kind": "build", "isDefault": true },
      "problemMatcher": {
        "owner": "pawn",
        "fileLocation": [ "absolute" ],
        "pattern": {
          "regexp": "^(.*)\\((\\d+)\\) : (warning|error) \\d+: (.*)$",
          "file": 1, "line": 2, "severity": 3, "message": 4
        }
      }
    }
  ]
}</pre>
<p>On Windows, change <code>command</code> to <code>amxxpc.exe</code> and <code>cwd</code> to your Windows scripting path (for example <code>C:\\hlds\\cstrike\\addons\\amxmodx\\scripting</code>).</p>

<h2>4. What the problemMatcher does</h2>
<p><code>amxxpc</code> prints errors in the form <code>myplugin.sma(42) : error 017: undefined symbol "foo"</code>. The regex above parses that line into a filename, line number, severity, and message, so VS Code populates the Problems panel and underlines line&nbsp;42. Clicking the entry jumps straight there. That turns the compile-fix-recompile loop from copy-pasting line numbers into pressing one key.</p>

<h2>5. Bind the build key</h2>
<p>With the task set as <code>"isDefault": true</code>, press <code>Ctrl+Shift+B</code> to compile the open <code>.sma</code>. The compiler output appears in the integrated terminal and errors appear in Problems. No shell juggling, no leaving the editor.</p>

<h2>6. Snippets (optional but worth it)</h2>
<p>Add your own snippets for the boilerplate you type constantly. <em>File &rarr; Preferences &rarr; Configure Snippets &rarr; pawn</em>, then add:</p>
<pre>{
  "plugin_init": {
    "prefix": "plugininit",
    "body": [
      "public plugin_init() {",
      "\tregister_plugin(\"$1\", \"1.0.0\", \"$2\")",
      "\t$0",
      "}"
    ]
  }
}</pre>
<p>Type <code>plugininit</code> and press Tab to expand the whole stub.</p>

<h2>7. Editing on a remote server</h2>
<p>If your sources live on a Linux game server rather than your PC, use the VS Code Remote&nbsp;-&nbsp;SSH extension to edit them in place. You open the remote <code>scripting/</code> folder as a workspace, and the exact same <code>tasks.json</code> runs <code>amxxpc</code> on the server itself &mdash; no uploading, no version-mismatch risk, because you are compiling with the server's own compiler against the server's own <code>include/</code>. The Problems panel still works over the SSH connection. This is the cleanest setup when you administer several remote servers: one editor, and each server compiles with its own toolchain.</p>

<h2>8. Auto-install on successful build</h2>
<p>You can chain the build task to copy the compiled plugin into <code>plugins/</code> so it is ready to <code>amxx reload</code>. Add a second task that depends on the compile and copies <code>compiled/${fileBasenameNoExtension}.amxx</code> into the plugins folder, then make that the default build task. Keep the copy step separate from the compile so a failed build never overwrites a working plugin &mdash; only a clean <code>Done.</code> should reach the live <code>plugins/</code> directory.</p>

<h2>Common errors</h2>
<ul>
<li><strong>Build task does nothing / "command not found"</strong> &mdash; wrong <code>cwd</code>, or <code>amxxpc</code> is not executable. On Linux run <code>chmod +x amxxpc</code> and confirm the 32-bit runtime is installed (see <a href="/tutorials/compile-sma-to-amxx">compiling a .sma</a>).</li>
<li><strong>Errors compile but do not appear in Problems</strong> &mdash; the <code>problemMatcher</code> regex does not match your compiler's output format; compile once in a terminal and adjust the regex to the exact line shape.</li>
<li><strong>No syntax highlighting</strong> &mdash; the file is not associated with <code>pawn</code>; check <code>files.associations</code>.</li>
<li><strong>Go-to-definition fails on natives</strong> &mdash; the include path is not set, so the editor cannot see <code>amxmodx.inc</code>.</li>
</ul>

<h2>Verification</h2>
<p>Open a known-good <code>.sma</code>, press <code>Ctrl+Shift+B</code>, and confirm the terminal prints <code>Done.</code> and a <code>compiled/*.amxx</code> appears. Then introduce a deliberate error &mdash; delete a semicolon &mdash; rebuild, and check the Problems panel lists it and clicking jumps to the line. When both work, your edit-compile loop is complete; pair it with <a href="/tutorials/write-first-amxx-plugin">your first plugin</a> and iterate.</p>