Compiling Metin2 quests and the usual qc errors
The quest won't compile, qc complains about a missing end, or it compiles and nothing happens in game. How compiling with qc works and what's behind the messages you'll see most.
Paths and file names aren't the same in every set of files, so check yours before you copy a command. And try new quests on a test server first, not live.
Where the quest files are
Normally share/locale/<country>/quest/ in the game folder, so share/locale/germany/quest/ or share/locale/english/quest/, depending on the locale your files use. Some files skip the share part. If you can't find it, search for quest_list:
That folder has your .quest files, quest_list, qc and object/. quest_list is just the list of what gets compiled, one file per line. object/ is the output, and that's what the game core actually loads. It never reads your .quest files. So an edit does nothing until you compile and reload, and a file that isn't in quest_list never gets compiled at all.
Older files call the list locale_list and the script make, make_de or make.py. Same thing, just change the file name in the script below.
Use the qc built from your own source. It usually lives in a quest folder next to game and db. A qc from some other files may know a different set of events, and one built on FreeBSD won't run on Linux anyway.
Compiling with qc
qc writes to object/ in whatever directory you're in, so change into the quest folder first. One quest looks like this (the path is an example):
0 means qc went through. With most qc versions anything else means it stopped, and the reason is printed right above.
For the whole list you need a script that goes through quest_list line by line. Lots of files come with a make.sh or make.py, but the older make.py scripts are Python 2 and fail on Python 3. If python make.py gives you "Command not found", Python isn't even installed.
We'd rather use a plain shell script. It runs under /bin/sh on FreeBSD and Linux. Save it as make.sh in the quest folder:
It clears object/ before every run (more on why further down), strips Windows line endings from quest_list, skips blank lines and lines starting with #, prints every file that fails and exits with 1 if anything did. One catch: the make.py that ships with many files doesn't understand those # comments, so if you use both scripts, keep comments out of quest_list.
Make it executable, run it and search the log for errors:
If that grep finds anything, those quests are missing from object/. Don't reload and don't start a core until the run is clean, or they're gone in game.
When qc stops
You usually get the file, the line and the word qc got stuck on. The exact wording depends on your qc build, but it's nearly always one of these:
when doesn't have begin-end clausemeans awhenhas nobegin, or the block never gets itsend.`end' expected near `<eof>'is at least oneendmissing at the end of the file. The general form`A' expected near `B'means qc wanted A where B is, usually a missingend,thenordo.- With
assertion failure : nested==0the blocks and ends don't add up. Count again in thewhenor function it names. Calls undeclared function!says the function isn't inquest_functions. Check the spelling first. Your own functions fromquestlib.luahave to be added there by name.- And
must start with 'quest'is a file that doesn't begin withquest name begin. Often there's a BOM or some other invisible character in front of it.
The missing end is the big one. Every begin, if, for, while and function needs its own end, and qc often only notices way later: at the next when, the next state or the end of the file. So the reported line is where the problem became visible, not where it is. Go back to the last when before that line and count from there.
else if instead of elseif is another classic. It opens a new if that needs one more end. Four spaces per level and an editor with Lua highlighting that shows matching blocks make these much easier to spot.
In the when line itself: a missing dot (when 20354.chat "Text" instead of when 20354.chat."Text"), a then after with (the condition is just an expression), or = instead of ==, which is an assignment in Lua and a syntax error in a condition. Then there are events your source simply doesn't have. Depending on qc that's rejected at compile time, or the trigger just never fires in game. Most sources keep the list of events in questmanager.cpp of the game core.
About quest_functions: many qc versions check every call against it, which is why a typo like pc.get_levle() gets caught early. If you add a quest function to the source, it has to go in there too, otherwise no quest using it compiles.
It doesn't prove the function exists, though. If your quest_functions came from other files, a quest can compile fine and still fail in game because the core doesn't have that function. In most sources the functions are registered in files like questlua_pc.cpp or questlua_npc.cpp, so a grep in your source folder tells you:
Encoding, BOM and line endings
The client doesn't read quest text as UTF-8. With most files it wants a Windows code page, Windows-1252 for German and other Western European locales. A UTF-8 quest often still compiles, but umlauts and accented letters turn into pairs of garbage characters in game. Stick to whatever encoding your other quests and locale files use. Check first, and only convert if file says UTF-8:
For Windows-1252, file usually says "ISO-8859" or "Non-ISO extended-ASCII". Some Windows editors also put a BOM at the start of the file, three invisible bytes that can make qc fail on line 1. Save without a BOM.
If quest_list was edited on Windows, every line ends in an invisible \r and qc can't find files whose names look perfectly fine. make.sh above deals with that, but you can also fix the file for good:
Same goes for make.sh itself. With Windows line endings you get odd errors like "bad interpreter", or the shell can't find commands that are clearly there.
Compiles fine, still broken
qc can't see everything. A function the core doesn't have, a nil value, a wrong vnum: all of that only shows up when a character actually hits the trigger, and the player just sees the dialog close or nothing at all. The error lands in the syserr of the core that character was on. To search all cores at once (example path again):
In many sources the line contains RunState or LUA_ERROR, followed by the Lua message. The usual ones, roughly worded:
attempt to call field 'get_levle' (a nil value): no such function in that namespace (pchere), a typo or missing from your sourceattempt to call global 'say_tilte' (a nil value): same thing without a namespace, mostly a typoattempt to index global 'pcc' (a nil value): the namespace before the dot doesn't existattempt to concatenate a nil value,attempt to compare number with nil,attempt to perform arithmetic on a nil value: something isnilwhile joining text with.., comparing or doing math
Don't trust the line number in there. It often doesn't match your .quest file because qc stores every trigger as its own chunk, so search for the function or variable name instead. The nil itself often comes from a variable without local (global in Lua, shared by every character on that core) or from a local of another trigger, which doesn't exist in the next one. For reading syserr in general, see the guide on syserr and crash analysis.
Reloading and cleaning up object/
Many sources have /reload q as a GM command. It reloads the compiled quests from object/ without restarting the core. It usually only hits the core your GM is on, though, so with four channels plus separate dungeon or map cores you run it on each of them or restart them.
A reload also rebuilds the core's Lua environment. Quest flags in the database survive, but running timers, open dialogs and global Lua variables can be lost. Don't reload while a dungeon run or a timed event is going.
You still need a restart if your source doesn't have the command, if syserr fills up with errors after a reload, or if you added new quest functions to the source, since only the rebuilt core knows those.
Now the reason make.sh wipes object/ every time: qc writes new files there but never deletes old ones. Remove a quest from quest_list, rename a state or change a trigger, and the old parts just stay and keep getting loaded. Then an NPC offers an option that isn't in any source file anymore, or a reward gets handed out twice.
If you never cleaned object/ before, this shows what's left over. In most files object/state/ has one file per compiled quest:
Every line it prints is a quest the core loads even though it's not in your list anymore.
Debug output and flags
The quickest way to see what a quest is doing is the chat. syschat("text") sends the character a system message, and behind a GM check players never see it:
Whether your source knows pc.is_gm and syschat under exactly these names is something to check in quest_functions and in the source. Take the debug lines out once everything works.
The example also shows how quest flags are meant to be used. pc.setqf and pc.getqf store and read a number for the current character and quest, and a flag that was never set returns 0. Times go in as a number from get_time(), a day is 86400 seconds. And the flag is set before the reward, not after. If the quest stops between the two, a player can otherwise claim the reward again and again. How that kind of bug shows up in your economy is covered in the dupe detection guide.
Custom quests and ready-made modules
If a core crashes after a new quest goes live, the free monitoring in Servergilde tells you on Discord and by email. If you'd rather not write a quest yourself, we build it at a fixed price on our own test server, and nothing goes onto your server until you approve it, just get in touch. For common requests there are ready-made modules such as the daily bonus, the event calendar, seasonal events and the world boss, and the pricing page shows what each plan includes.
Frequently asked questions
How do I reload quests without restarting the server?
/reload q, which many sources have. It usually only affects the core your GM is on, so run it on every channel and dungeon core. Running timers and open dialogs can get lost, so don't reload in the middle of a dungeon run or event.Why does qc report an error on a line that looks fine?
end is missing further up. qc often only notices at the next when, the next state or the end of the file. Start at the last when before the reported line, count the blocks and look for else if where it should be elseif.What does "attempt to call field (a nil value)" mean in syserr?
attempt to call field 'get_levle' (a nil value) it's missing in pc. Mostly a typo, or the function is listed in quest_functions but your core doesn't have it. A grep in game/src/questlua*.cpp tells you.Why do deleted quests still show up in game?
object/. qc writes new files there but never removes old ones. Empty object/ before every build, compile everything in quest_list again, then reload or restart the cores.Why are umlauts or accents broken in my quest?
file welcome.quest, convert with iconv -f UTF-8 -t CP1252, and save without a BOM.