Jump to content

Recommended Posts

Hey!

I always used the extension that's currently on the marketplace, but it's outdated and not really in great shape anymore.
Since I really wanted good feedback and have been working with extensions for years that actually give feedback about the code, I sat down and wrote Quest Lua - a completely new extension, not just a fork.

Note

This extension was partly created with AI, because honestly that was faster than digging through someone else's C++ code for hours and figuring everything out by trial & error. Don't worry, nothing is hardcoded - the completion, hover texts etc. are pulled live by a dedicated script from your questlua_*.cpp files and questmanager.cpp, so it runs automatically with your own source. And this isn't a prototype either - it's been running against a real core with real quest scripts on my end for a while now.

Features

  • Syntax & Semantic Highlighting
    • custom grammar for Lua 5.0/5.1 plus the Quest DSL (quest, state, when, define, ...)
    • local variables, parameters, API functions, define constants, and event names (login, kill, chat, take, ...) each get their own colors
    • even detects whether e.g. chat is currently being used as an event trigger or as an actual function call
  • Code Completion, Hover & Signature Help
    • complete C++ API (pc., npc., game., ...) incl. description, parameters, and return values
    • Lua standard library (string.*, table.*, math.*, tonumber, pairs, ...)
    • your own functions from every quest script in the folder, not just the currently open file
    • define constants and local variables/parameters with a best-effort type detection
  • Navigation
    • Go to Definition (F12 / Ctrl+Click) for variables, parameters, and functions - even across multiple files
    • Rename (F2), which automatically renames all calls in other quest scripts too
    • Outline/Breadcrumbs (Ctrl+Shift+O) for quest > state > when
  • Error Checking
    • live diagnostics while typing for unclosed begin/end blocks and strings
    • real qc.exe validation on save (and on demand), errors are shown directly on the correct line in the editor
  • Miscellaneous
    • snippets for quest/state/when/define
    • hovering over a define shows the macro's value & location
    • [LC;ID] hover & jump to the translation in locale_quest.txt (can be toggled off via setting)
    • API stubs are automatically generated from the C++ source code, no need to maintain them by hand
    • all paths freely configurable via VS Code settings, works with any server path of your own

What you need

This isn't a generic Lua tool, but tailored to the typical Metin2 quest-Lua structure. For it to work for you, you should have the following:

  • a Metin2-like server with quest Lua and a qc.exe (or something similar) for validation
  • questlua_*.cpp files in the usual luaL_reg/AddLuaFunctionTable style
  • C++ source and questmanager.cpp in CP949 (standard on most cores)
  • optionally a locale_quest.txt in the format ID<TAB>TEXT, if you want to use the [LC;ID] hover

You simply set the paths (server source, quest folder, locale folder...) via the VS Code settings - nothing is hardwired.

Known Limitations

So nobody expects more than what's actually in here, a few honest words about it:

  • The parser is custom-built and tailored to this DSL, not a full Lua parser. That's plenty for normal everyday use, only with really nested code (multiple assignments, nested if/elseif) can the detection sometimes be off
  • The squiggly underline while typing is only a heuristic, not a real error - in the end you should always rely on qc.exe
  • The function index only searches the folder you set at questLua.questScriptsDir, not the whole workspace - and if two files have a function with the same name, whichever was scanned last simply wins
  • Rename across multiple files is honestly built pretty simply - it just searches for the word, no real analysis. So take a quick look at the preview before confirming
  • I entered the Lua standard library by hand based on the official Lua 5.0 docs, not read out of the engine - if your core has its own patches there, the extension won't know about them

Installation

Not available on the Marketplace, only as a zip to build yourself - sounds more complicated than it is, takes less than 5 minutes total:

  1. install Node.JS, if not already installed (just the LTS version, click through normally)
  2. download the zip and extract it somewhere, e.g. to the desktop
  3. open the extracted vscode-quest-lua folder in VS Code and open a terminal in it (Terminal -> New Terminal), or right-click in Explorer -> "Open in Terminal"
  4. type npm run install:all in the terminal and wait, this downloads the necessary packages for the extension and generator
  5. in the generator folder, copy the file generator.config.json.example and rename it to generator.config.json, then in it at least adjust gameSourceDir to point to your server - without this the generator won't know where your source is when building, and the next step will fail with an error. questFunctionsListPath is optional, you can leave it empty - it's only used for an additional check to see if the scan accidentally missed a function
  6. then run npm run build - this builds the finished extension as a .vsix file in the extension folder
  7. install the .vsix: either in the terminal with code --install-extension extension/quest-lua-0.1.0.vsix, or in VS Code via the Extensions view -> the three dots at the top right -> "Install from VSIX..." -> select the file
  8. reload the VS Code window once (Ctrl+Shift+P -> "Reload Window") so the extension becomes active
  9. if your quest scripts are .lua files instead of .quest (the case for most cores): add { "files.associations": { "**/*.lua": "quest" } } to your server workspace's .vscode/settings.json, otherwise VS Code will just treat them as normal Lua and the whole extension stays inactive

The generator.config.json from before is only meant for the one-time build via the terminal. For daily use in VS Code itself, the extension needs to separately know where your server is - this is the most important step, without it nothing will work later. Go to the VS Code settings (Ctrl+,), search for questLua and enter at least these two paths:

  • questLua.gameSourceDir - the folder with your questlua_*.cpp files and questmanager.cpp, on most cores this is not the game folder itself but game/src inside it
  • questLua.questScriptsDir - the folder with qc.exe and your actual quest scripts

Important: both folders must follow a certain structure, otherwise the generator won't find anything. For gameSourceDir, the questlua_*.cpp files must be directly inside it, not in subfolders - the scan doesn't look recursively. For questScriptsDir, qc.exe must be directly in the folder (otherwise you additionally need to set questLua.qcExePath), together with your .lua/.quest scripts and the quest_functions file. If your folder structure differs from this, just enter the respective matching subfolder directly.
After that, run "Quest Lua: Regenerate API Stubs" once via the command palette (Ctrl+Shift+P) so it pulls the API from your source. Without this step the extension stays completely empty - no highlighting for events, no completion, nothing. Optionally there's also questLua.clientLocaleDir and questLua.locale for the [LC;ID] hover, if you want that.

It's also explained in more detail with all the options in the README, in case something doesn't work.

 

I'd love to hear feedback, bugs, or suggestions - just drop them here in the thread.

This is the hidden content, please
  • Metin2 Dev 1
Link to comment
https://metin2.dev/topic/34696-metin-2-quest-extension-for-vscode/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.