root/doc/script_commands.txt @ 10

Revision 1, 240.2 kB (checked in by jinshiro, 17 years ago)
Line 
1//===== Athena Doc ========================================
2//= eAthena Script Commands
3//===== Description =======================================
4//= A reference manual for the eAthena scripting language.
5//= Commands are sorted depending on their functionality.
6//===== Version ===========================================
7//= 3.22.20080622
8//=========================================================
9//= 1.0 - First release, filled will as much info as I could
10//=       remember or figure out, most likely there are errors,
11//=       and things I have missed out [Fredzilla]
12//= 1.1 - Added better discription for "getmapxy" (by Terminal Vertex & Z3R0)
13//= 1.2b- Added a description for getpartymember (by HappyDenn)
14//=       (+few spelling mistakes corrected)
15//= 2.0 - +79kb extra stuff and numerous corrections by
16//=       Maeki Rika.
17//= 2.1 - Small but important corrections, more proofreading.
18//=       Some important discoveries in item functions, the
19//=       secret of making VVS weapons with 'getitem2' and
20//=       other news. (Rika again) +10kb :)
21//= 2.2 - added getItemInfo description [Lupus]
22//= 2.3 - added plenty of info for recent (and not so) script commands I added
23//=       [Skotlex]
24//= 2.4 - Explained the upper parameter of jobchange. [Skotlex]
25//= 2.5 - Added pow, sqrt and distance. [Lance]
26//= 2.6 - Added setd and getd. [Lance]
27//= 2.7 - petstat command. [Lance]
28//= 2.7a- delitem2, countitems2 commands [Lupus]
29//= 2.7b- clone command [Skotlex]
30//= 2.7c- disguise / undisguise, query_sql commands [Lupus]
31//= 2.8 - Deleted a copy of the nude command. Added axtoi command (needing a
32//=       clearer explanation of atoi.Gave a better explanation of OnLabels
33//=       and modified monster explanation due that L_Label isn't working with
34//=       monster.
35//= 2.9.20061230 - Updated getitem and guardian. [FlavioJS]
36//= 2.10.20070101 - added sleep,sleep2,awake and updated the variables section.
37//=       [FlavioJS]
38//= 2.11.20070109 - removed the unused flag argument in guildskill, added an
39//=       optional argument to setcart,setfalcon,setriding and other cleanups
40//=       [FlavioJS]
41//= 2.12.20070201 - Added npcshopitem, npcshopadditem, npcshopdelitem and
42//=       npcshopattach [Skotlex]
43//= 3.00.20070208
44//=       - Explained Logical Bitwise Operators.
45//=         Dj-Yhn contributed to AND (&) operator, rest by myself. [erKURITA]
46//=       - Added a resume of allowed variable and arrays scopes. [erKURITA]
47//=       - Re-organized the script commands, and grouped them depending
48//=         on what they do. [erKURITA]
49//=       - Added a packload of commands that were missing,
50//=         and corrected some of the wrong ones [Dj-Yhn, erKURITA & Trancid]
51//= 3.01.20070209
52//=       Updated 'cutin' (removed lies, removed outdated bmp list) [ultramage]
53//=       Removed 'cutincard' since eA no longer implements it
54//= 3.02.20070209
55//=       Corrected/updated info on Xor/setd/getd/callfunc/callsub/return and
56//=       updated some examples to use "better" code. [FlavioJS]
57//= 3.03.20070216
58//=       Expanded/clarified information on npc timers, added info about the
59//=       new attach flag for script commands startnpctimer/ stopnpctimer/
60//=       initnpctimer [Skotlex]
61//= 3.03.20070226
62//=       Updated makeitem and how to include " in strings [Lupus]
63//= 3.03.20070228
64//=       Added info on OnTimerQuit label to npctimer section. [Skotlex]
65//= 3.04.20070317
66//=       Removed all .gat refferences from the examples [Lupus]
67//= 3.04.20070330
68//=       Adjusted the 'itemskill' description due to recent change [ultramage]
69//= 3.04.20070409
70//=       Fixed the incorrect order of parameters in 'makeitem' [ultramage]
71//= 3.05.20070423
72//=       menu/select/prompt produce consistent results for grouped and empty
73//=       options [FlavioJS]
74//= 3.05.20070819
75//=       Removed the messy 'unitdeadsit' command reference [ultramage]
76//= 3.05.20070823
77//=       Fixed typo in 'areamonster' description (missing argument) [ultramage]
78//= 3.06 20070909
79//=       Added 'gethominfo' description [Skotlex]
80//= 3.06.20070910
81//=       Added info about the new behavior of 'getexp' [ultramage]
82//= 3.07.20070915
83//=       Fixed 'duplicate' missing the target 'name' parameter! [ultramage]
84//= 3.08.20071018
85//=       Clarified how npc names work. [FlavioJS]
86//= 3.09.20071103
87//=       Added script function 'strnpcinfo' [ultramage]
88//= 3.10.20071122
89//=       Added setnpcdisplay. [FlavioJS]
90//= 3.10.20071211
91//=       Added query_logsql. [Skotlex]
92//= 3.11.20071215
93//=       Updated guardianinfo and get-/setcastledata [ultramage]
94//= 3.12.20071218
95//=       Corrected various mistakes mentioned in bugreport:373 [ultramage]
96//= 3.12.20071227
97//=       Corrected description of scope and npc variables. [FlavioJS]
98//= 3.13.20080104
99//=       Updated 'setcell' desc to match latest code changes [ultramage]
100//= 3.14.20080211
101//=       Updated 'input' (new arguments and return value). [FlavioJS]
102//= 3.15.20080227
103//=       Updated 'checkweight' description slightly. [L0ne_W0lf]
104//= 3.16.20080229
105//=       Updated 'Shop' NPC type description to include cashshop. [L0ne_W0lf]
106//=       Woopth. Fixed spelling. ;P Should be a bit clearer now. [L0ne_W0lf]
107//= 3.17.20080312
108//=       Corrected cashshop description. (#FREEPOINTS->#KAFRAPOINTS) [L0ne_W0lf]
109//= 3.18.20080327
110//=       Added documentation for the 'checkcell' command [ultramage]
111//= 3.19.20080407
112//=       Extended the behaviour of 'guardian'. [FlavioJS]
113//= 3.20.20080425
114//=       Corrected 'getitem', 'getitem2' & 'delitem2' (charid instead of accountid) [Toms]
115//=       Modified 'delitem' (added optional accountid parameter) [Toms]
116//= 3.21.20080612
117//=       Script commands extended to support skill names: [FlavioJS]
118//=       skill, addtoskill, guildskill, getskilllv, getgdskilllv, itemskill,
119//=       petskillattack, petskillattack2, petskillsupport, skilleffect, npcskilleffect,
120//=       unitskilluseid, unitskillusepos, bonus/bonus2/bonus3/bonus4/bonus5
121//= 3.22.20080622
122//=       Extended 'set' to return the variable reference. [FlavioJS]
123//=========================================================
124
125This document is a reference manual for all the scripting commands and functions
126available in current eAthena SVN. It is not a simple tutorial. When people tell
127you to "Read The F***ing Manual", they mean this.
128
129The information was mostly acquired through looking up how things actually work
130in the source code of the server, which was written by many people over time,
131and lots of them don't speak English and never left any notes - or are otherwise
132not available for comments. As such, anything written in here might not be
133correct, it is only correct to the best of our knowledge, which is limited.
134
135This is not a place to teach you basic programming. This document will not teach
136you basic programming by itself. It's more of a reference for those who have at
137least a vague idea of what they want to do and want to know what tools they have
138available to do it. We've tried to keep it as simple as feasible, but if you
139don't understand it, getting a clear book on programming in general will help
140better than yelling around the forum for help.
141
142A little learning never caused anyone's head to explode.
143
144Structure
145---------
146
147The commands and functions are listed in no particular order:
148
149*Name of the command and how to call it.
150
151Descriptive text
152
153    Small example if possible. Will usually be incomplete, it's there just to
154    give you an idea of how it works in practice.
155
156To find a specific command, use Ctrl+F, (or whatever keys call up a search
157function in whatever you're reading this with) put an * followed by the command
158name, and it should find the command description for you.
159
160If you find anything omitted, please respond. :)
161
162Syntax
163------
164
165Throughout this document, wherever a command wants an argument, it is given in
166<angle brackets>. This doesn't mean you should type the angle brackets. :) If an
167argument of a command is optional, it is given in {curly brackets}. You've
168doubtlessly seen this convention somewhere, if you didn't, get used to it,
169that's how big boys do it. If a command can optionally take an unspecified
170number of arguments, you'll see a list like this:
171
172command <argument>{,<argument>...<argument>}
173
174This still means they will want to be separated by commas.
175
176Where a command wants a string, it will be given in "quotes", if it's a number,
177it will be given without them. Normally, you can put an expression, like a bunch
178of functions or operators returning a value, in (round brackets) instead of most
179numbers. Round brackets will not always be required, but they're often a good
180idea.
181
182Wherever you refer to a map name, it's always 'mapname' or 'mapname.gat'
183(Please, don't use .gat suffix anymore. It's useless.)
184
185
186Script loading structure
187------------------------
188
189Scripts are loaded by the map server as referenced in the 'conf/map_athena.conf'
190configuration file, but in the default configuration, it doesn't load any script
191files itself. Instead, it loads the file 'npc/scripts_main.conf' which itself
192contains references to other files. The actual scripts are loaded from txt
193files, which are linked up like this:
194
195npc: <path to a filename>
196
197Any line like this, invoked, ultimately, by 'map_athena.conf' will load up the
198script contained in this file, which will make the script available. No file
199will get loaded twice, to prevent possible errors.
200
201Another configuration file option of relevance is:
202
203delnpc: <path to a filename>
204
205This will unload a specifiled script filename from memory, which, while
206seemingly useless, may sometimes be required.
207
208Whenever '//' is encountered in a line upon reading, everything beyond this on
209that line is considered to be a comment and is ignored. This works wherever you
210place it.
211
212Upon loading all the files, the server will execute all the top-level commands
213in them. No variables exist yet at this point, no commands can be called other
214than those given in this section. These commands set up the basic server script
215structure - create NPC objects, spawn monster objects, set map flags, etc. No
216code is actually executed at this point except them. The top-level commands the
217scripting are pretty confusing, since they aren't structured like you would
218expect commands, command name first, but rather, normally start with a map name.
219
220What's more confusing about the top-level commands is that most of them use a
221tab symbol to divide their arguments.
222
223To prevent problems and confusion, the tab symbols are written as '%TAB%'
224throughout this document, even though this makes the text a bit less readable.
225Using an invisible symbol to denote arguments is one of the bad things about
226this language, but we're stuck with it for now. :)
227
228Here is a list of valid top-level commands:
229
230** Set a map flag:
231
232<map name>%TAB%mapflag%TAB%<flag>
233
234This will, upon loading, set a specified map flag on a map you like. These are
235normally in files inside 'conf/mapflag' and are loaded first, so by the time the
236server's up, all the maps have the flags they should have. Map flags determine
237the behavior of the map regarding various common problems, for a better
238explanation, see 'setmapflag'.
239
240** Create a permanent monster spawn:
241
242<map name>,<x>,<y>,<xs>,<ys>%TAB%monster%TAB%<monster name>%TAB%<mob id>,<amount>,<delay1>,<delay2>,<event>
243
244Map name is the name of the map the monsters will spawn on. x,y are the
245coordinates where the mob should spawn. If xs and ys are non-zero, they
246specify the diameters of a spawn-rectangle area who's center is x,y.
247Putting zeros instead of these coordinates will spawn the monsters randomly.
248Note this is only the initial spawn zone, as mobs random-walk, they are free
249to move away from their specified spawn region.
250
251Monster name is the name the monsters will have on screen, and has no relation
252whatsoever to their names anywhere else. It's the mob id that counts, which
253identifies monster record in 'mob_db.txt' database of monsters. If the mob name
254is given as "--ja--", the 'japanese name' field from the monster database is
255used, (which, in eAthena, actually contains an english name) if it's "--en--",
256it's the 'english name' from the monster database (which contains an uppercase
257name used to summon the monster with a GM command).
258
259If you add 20000 to the monster ID, the monster will be spawned in a 'big
260version', (monster size class will increase) and if you add 10000, the 'tiny
261version' of the monster will be created. However, this method is deprecated
262and not recommended, as the values to add can change at a later time (20000
263and 10000 actually stand for 2*MAX_MOB_DB and MAX_MOB_DB respectively, which
264is defined on mob.h, and can change in the future as more mobs are created).
265The recommended way to change a mob's size is to use the event-field (see
266below).
267
268Amount is the amount of monsters that will be spawned when this command is
269executed, it is affected by spawn rates in 'battle_athena.conf'.
270
271Delay1 and delay2 are the monster respawn delays - the first one counts the time
272since a monster defined in this spawn was last respawned and the second one
273counts the time since the monster of this spawn was last killed. Whichever turns
274out to be higher will be used. If the resulting number is smaller than a random
275value between 5 and 10 seconds, this value will be used instead. (Which is
276normally the case if both delay values are zero.) The times are given in
2771/1000ths of a second.
278
279You can specify a custom level to use for the mob different from the one of
280the database by adjoining the level after the name with a comma. eg:
281"Poring,50" for a name will spawn a monster with name Poring and level 50.
282
283Event is a script event to be executed when the mob is killed. The event must
284be in the form "NPCName::OnEventName" to execute, and the event name label
285should start with "On". As with all events, if the NPC is an on-touch npc, the
286player who triggers the script must be within 'trigger' range for the event to
287work.
288
289The Event field can be used alternatively to specify other mob properties. Use
2902 to specify that the mob should be small, 4 for big monsters, and 8 for
291special ai mobs (which by default attack other monsters instead of players).
292You can add these, so using 10 will spawn small monsters that attack other
293mobs (if you specify both 2 and 4, the small version takes priority).
294
295** Npc names
296
297/!\ WARNING: this applies to warps, npcs, duplicates and shops /!\
298
299Npc names are kinda special and are formatted this way:
300
301<Display name>{::<Unique name>}
302
303All npcs need to have a unique name that is used for identification purposes.
304When you have to identify a npc by it's name, you should use <Unique name>.
305If <Unique name> is not provided, use <Display name> instead.
306
307The client has a special feature when displaying names:
308if the display name contains a '#' character, it hides that part of the name.
309ex: if your npc is named 'Hunter#hunter1', it will be displayed as 'Hunter'
310
311<Display name> must be at most 24 characters in length.
312<Unique name> must be at most 24 characters in length.
313
314** Define a warp point
315
316<from map name>,<fromX>,<fromY>,<facing>%TAB%warp%TAB%<warp name>%TAB%<spanx>,<spany>,<to map name>,<toX>,<toY>
317
318This will define a warp NPC that will warp a player between maps, and while most
319arguments of that are obvious, some deserve special mention.
320
321SpanX and SpanY will make the warp sensitive to a character who didn't step
322directly on it, but walked into a zone which is centered on the warp from
323coordinates and is SpanX in each direction across the X axis and SpanY in each
324direction across the Y axis.
325
326Warp NPC objects also have a name, because you can use it to refer to them later
327with 'enablenpc'/'disablenpc'
328
329Facing of a warp object is irrelevant, it is not used in the code and all
330current scripts have a zero in there.
331
332** Define an NPC object.
333
334<map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,{<code>}
335<map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,<triggerX>,<triggerY>,{<code>}
336
337This will place an NPC object on a specified map at the specified location, and
338is a top-level command you will use the most in your custom scripting. The NPCs
339are triggered by clicking on them, and/or by walking in their trigger area, if
340defined, see that below.
341
342Facing is a direction the NPC sprite will face in. Not all NPC sprites have
343different images depending on the direction you look from, so for some facing
344will be meaningless. Facings are counted counterclockwise in increments of 45
345degrees, where 0 means facing towards the top of the map. (So to turn the sprite
346towards the bottom of the map, you use facing 4, and to make it look southeast
347it's facing 5.)
348
349Sprite id is the sprite number used to display this particular NPC. For a full
350list of sprite id numbers see http://kalen.s79.xrea.com/npc/npce.shtml You may
351also use a monster's ID number instead to display a monster sprite for this NPC.
352It is possible to use a job sprite as well, but you must first define it as a
353monster sprite in 'mob_avail.txt', a full description on how to do this is not
354in the scope of this manual.
355A '-1' sprite id will make the NPC invisible (and unclickable).
356A '111' sprite id will make an NPC which does not have a sprite, but is still
357clickable, which is useful if you want to make a clickable object of the 3D
358terrain.
359
360TriggerX and triggerY, if given, will define an area, centered on NPC and
361spanning triggerX cells in every direction across X and triggerY in every
362direction across Y. Walking into that area will trigger the NPC. If no
363'OnTouch:' special label is present in the NPC code, the execution will start
364from the beginning of the script, otherwise, it will start from the 'OnTouch:'
365label.
366
367The code part is the script code that will execute whenever the NPC is
368triggered. It may contain commands and function calls, descriptions of which
369compose most of this document. It has to be in curly brackets, unlike elsewhere
370where we use curly brackets, these do NOT signify an optional parameter.
371
372** Define an NPC duplicate.
373
374<map name>,<x>,<y>,<facing>%TAB%duplicate(<label>)%TAB%<name>%TAB%<sprite id>
375<map name>,<x>,<y>,<facing>%TAB%duplicate(<label>)%TAB%<name>%TAB%<sprite id>,<triggerX>,<triggerY>
376
377This will duplicate an NPC referred to by 'label'. The duplicate runs the same
378code as the source NPC, but has its own name, location, facing, sprite ID and
379trigger area (in other words, the duplicate does not 'inherit' any of these).
380
381** Define a 'floating' NPC object.
382
383-%TAB%script%TAB%<NPC Name>%TAB%-1,{<code>}
384
385This will define an NPC object not triggerable by normal means. This would
386normally mean it's pointless since it can't do anything, but there are
387exceptions, mostly related to running scripts at specified time, which is what
388these floating NPC objects are for. More on that below.
389
390** Define a shop NPC.
391
392<map name>,<x>,<y>,<facing>%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
393
394This will define a shop NPC, which, when triggered (which can only be done by
395clicking) will cause a shop window to come up. No code whatsoever runs in shop
396NPCs and you can't change the prices otherwise than by editing the script
397itself. (No variables even exist at this point of scripting, so don't even
398bother trying to use them.)
399
400The item id is the number of item in the 'item_db.txt' database. If Price is set
401to -1, the 'buy price' given in the item database will be used. Otherwise, the
402price you gave will be used for this item, which is how you create differing
403prices for items in different shops.
404
405Since trunk r12264 you can alternatively use "cashshop" in place of "shop"
406to use the Cash Shop interface, allowing you to buy items with special points
407(Currently stored as account vars in global_reg #CASHPOINTS and #KAFRAPOINTS.)
408This type of shop will not allow you to sell items at it, you may only
409purchase items here. The layout used to define sale items still count, and
410"<price>" refers to how many points will be spent purchasing the them.
411
412** Define a function object
413
414function%TAB%script%TAB%<function name>%TAB%{<code>}
415
416This will define a function object, callable with the 'callfunc' command (see
417below). This object will load on every map server separately, so you can get at
418it from anywhere. It's not possible to call the code in this object by
419anything other than the 'callfunc' script command.
420
421The code part is the script code that will execute whenever the function is
422called with 'callfunc'. It has to be in curly brackets, unlike elsewhere where
423we use curly brackets, these do NOT signify an optional parameter.
424
425
426Once an object is defined which has a 'code' field to it's definition, it
427contains script commands which can actually be triggered and executed.
428
429~ RID? GID? ~
430
431What a RID is and why do you need to know
432-----------------------------------------
433
434Most scripting commands and functions will want to request data about a
435character, store variables referenced to that character, send stuff to the
436client connected to that specific character. Whenever a script is invoked by a
437character, it is passed a so-called RID - this is the character ID number of a
438character that caused the code to execute by clicking on it, walking into it's
439OnTouch zone, or otherwise.
440
441If you are only writing common NPCs, you don't need to bother with it. However,
442if you use functions, if you use timers, if you use clock-based script
443activation, you need to be aware of all cases when a script execution can be
444triggered without a RID attached. This will make a lot of commands and functions
445unusable, since they want data from a specific character, want to send stuff to
446a specific client, want to store variables specific to that character, and they
447would not know what character to work on if there's no RID.
448
449Unless you use 'attachrid' to explicitly attach a character to the script first.
450
451Whenever we say 'invoking character', we mean 'the character who's RID is
452attached to the running script. The script function "playerattached" can be
453used to check which is the currently attached player to the script (it will
454return 0 if the there is no player attached or the attached player no longer
455is logged on to the map-server).
456
457But what about GID?
458--- ---- ----- ----
459
460GID stands for the Game ID of something, this can either be the GID obtained
461through mobspawn (mob control commands) or the account ID of a character.
462Another way would be to right click on a mob,
463NPC or char as GM sprited char to view the GID.
464
465This is mostly used for the new version of skill and the mob control commmands
466implemented (but NEVER documented by Lance. Shame on you...).
467
468Item and pet scripts
469--------------------
470
471Each item in the item database has two special fields - EquipScript and
472UseScript. The first is script code run every time a character equips the item,
473with the RID of the equipping character. Every time they unequip an item, all
474temporary bonuses given by the script commands are cleared, and all the scripts
475are executed once again to rebuild them. This also happens in several other
476situations (like upon login) but the full list is currently unknown.
477
478UseScript is a piece of script code run whenever the item is used by a character
479by doubleclicking on it.
480
481Not all script commands work properly in the item scripts. Where commands and
482functions are known to be meant specifically for use in item scripts, they are
483described as such.
484
485Every pet in the pet database has a PetScript field, which determines pet
486behavior. It is invoked wherever a pet of the specified type is spawned.
487(hatched from an egg, or loaded from the char server when a character who had
488that pet following them connects) This may occur in some other situations as
489well. Don't expect anything other than commands definitely marked as usable in
490pet scripts to work in there reliably.
491
492Numbers
493-------
494
495Beside the common decimal numbers, which are nothing special whatsoever (though
496do not expect to use fractions, since ALL numbers are integer in this language),
497the script engine also handles hexadecimal numbers, which are otherwise
498identical. Writing a number like '0x<hex digits>' will make it recognised as a
499hexadecimal value. Notice that 0x10 is equal to 16. Also notice that if you try
500to 'mes 0x10' it will print '16'.
501
502This is not used much, but it pays to know about it.
503
504Variables
505---------
506
507The meat of every programming language is variables - places where you store
508data.
509
510Variables are divided into and uniquely identified by the combination of:
511prefix  - determines the scope and extent (or lifetime) of the variable
512name    - an identifier consisting of '_' and alfanumeric characters
513postfix - determines the type of the variable: integer or string
514
515Scope can be:
516global    - global to all servers
517local     - local to the server
518account   - attached to the account of the character identified by RID
519character - attached to the character identified by RID
520npc       - attached to the NPC
521scope     - attached to the scope of the instance
522
523Extent can be:
524permanent - They still exist when the server resets.
525temporary - They cease to exist when the server resets.
526
527Prefix: scope and extent
528nothing  - A permanent variable attached to the character, the default
529           variable type.
530"@"      - A temporary variable attached to the character.
531           SVN versions before 2094 revision and RC5 version will also treat
532           'l' as a temporary variable prefix, so beware of having variable
533           names starting with 'l' if you want full backward compatibility.
534"$"      - A global permanent variable.
535           They are stored in "save\mapreg.txt" or database table `mapreg`,
536           depending on server type and the MAPREGSQL compilation flag.
537"$@"     - A global temporary variable.
538           This is important for scripts which are called with no RID
539           attached, that is, not triggered by a specific character object.
540"."      - A NPC variable.
541           They exist in the NPC and dissapear when the server restarts or the
542           npc is reloaded. Can be accessed from inside the NPC or by calling
543           'getvariableofnpc'.
544".@"     - A scope variable.
545           They are unique to the instance and scope. Each instance has it's
546           own scope that ends when the script ends. Calling a function with
547           callsub/callfunc starts a new scope, returning from the function
548           ends it. When a scope ends, it's variables are converted to values
549           ('return .@var;' returns a value, not a reference).
550"#"      - A permanent local account variable.
551           They are stored with all the account data in "save\accreg.txt" in
552           TXT versions and in the SQL versions in the 'global_reg_value'
553           table using type 2.
554"##"     - A permanent global account variable stored by the login server.
555           They are stored in "save\account.txt" and in the SQL versions in the
556           'global_reg_value' table, using type 1. The only difference you will
557           note from normal # variables is when you have multiple char-servers
558           connected to the same login server. The # variables are unique to
559           each char-server, while the ## variables are shared by all these
560           char-servers.
561
562Postfix: integer or string
563nothing - integer variable, can store positive and negative numbers, but only
564          whole numbers (so don't expect to do any fractional math)
565'$'     - string variable, can store text
566
567Examples:
568  name  - permanent character integer variable
569  name$ - permanent character string variable
570 @name  - temporary character integer variable
571 @name$ - temporary character string variable
572 $name  - permanent global integer variable
573 $name$ - permanent global string variable
574$@name  - temporary global integer variable
575$@name$ - temporary global string variable
576 .name  - npc integer variable
577 .name$ - npc string variable
578.@name  - scope integer variable
579.@name$ - scope string variable
580 #name  - permanent local account integer variable
581 #name$ - permanent local account string variable
582##name  - permanent global account integer variable
583##name$ - permanent global account string variable
584
585If a variable was never set, it is considered to equal zero for integer
586variables or an empty string ("", nothing between the quotes) for string
587variables. Once you set it to that, the variable is as good as forgotten
588forever, and no trace remains of it even if it was stored with character or
589account data.
590
591Some variables are special, that is, they are already defined for you by the
592scripting engine. You can see the full list somewhere in 'db/const.txt', which
593is a file you should read, since it also allows you to replace lots of numbered
594arguments for many commands with easier to read text. The special variables most
595commonly used are all permanent character-based variables:
596
597StatusPoint - Amount of status points remaining.
598BaseLevel   - Current base level
599SkillPoint  - Amount of skill points remaining
600Class       - Current job
601Upper       - 1 if the character is an advanced job class.
602Zeny        - Current amount of zeny
603Sex         - Character's gender, 0 if female, 1 if male.
604Weight      - The weight the character currently carries.
605MaxWeight   - The maximum weight the character can carry.
606JobLevel    - Character's job level
607BaseExp     - The amount of base experience points the character has.
608              Notice that it's zero (or close) if the character just got a level.
609JobExp      - Same for job levels
610NextBaseExp - Amount of experience points needed to reach the next base level.
611NextJobExp  - Same for job levels.
612Hp          - Current amount of hit points.
613MaxHp       - Maximum amount of hit points.
614Sp          - Current spell points.
615MaxSp       - Maximum amount of spell points.
616BaseJob     - This is sneaky, apparently meant for baby class support.
617              This will supposedly equal Job_Acolyte regardless of whether the
618              character is an acolyte or a baby acolyte, for example.
619Karma       - The character's karma. Karma system is not fully functional, but
620              this doesn't mean this doesn't work at all. Not tested.
621Manner      - The character's manner rating. Becomes negative if the player
622              utters words forbidden through the use of 'manner.txt' client-side
623              file.
624
625While these behave as variables, do not always expect to just set them - it is
626not certain whether this will work for all of them. Whenever there is a command
627or a function to set something, it's usually preferable to use that instead. The
628notable exception is Zeny, which you can and often will address directly -
629setting it will make the character own this number of zeny.
630
631Strings
632-------
633
634To include symbol '"' in a string you should use prefix '\"'
635
636
637Arrays
638------
639
640Arrays (in eAthena at least) are essentially a set of variables going under the
641same name. You can tell between the specific variables of an array with an
642'array index', a number of a variable in that array:
643
644<variable name>[<array index>]
645
646Variables stored in this way, inside an array, are also called 'array elements'.
647Arrays are specifically useful for storing a set of similar data (like several
648item IDs for example) and then looping through it. You can address any array
649variable as if it was a normal variable:
650
651    set @arrayofnumbers[0],1;
652
653You can also do sneaky things like using a variable (or an expression, or even a
654value from an another array) to get at an array value:
655
656    set @x,100;
657    set @arrayofnumbers[@x],10;
658   
659This will make @arrayofnumbers[100] equal to 10.
660
661Notice that index numbering always starts with 0. Arrays cannot hold more than
662128 variables. (So the last one can't have a number higher than 127)
663
664And array indices probably can't be negative. Nobody tested what happens when
665you try to get a negatively numbered variable from an array, but it's not going
666to be pretty. :)
667
668Arrays can naturaly store strings:
669
670@menulines$[0] is the 0th element of the @menulines$ array of strings. Notice
671the '$', normally denoting a string variable, before the square brackets that
672denotes an array index.
673
674Resume of the allowed variable and array scopes
675------ -- --- ------- -------- --- ----- ------
676
677+==========+======+=======+
678|VarType   | Norm | Array |
679+==========+======+=======+
680|$Str$     | OK!  | OK!   |
681+----------+------+-------+
682|$@Str$    | OK!  | OK!   |
683+----------+------+-------+
684|@Str$     | OK!  | OK!   |
685+----------+------+-------+
686|#Str$     | OK!  | FAIL! |
687+----------+------+-------+
688|Str$      | OK!  | FAIL! |
689+----------+------+-------+
690|$Int      | OK!  | OK!   |
691+----------+------+-------+
692|$@Int     | OK!  | OK!   |
693+----------+------+-------+
694|@Int      | OK!  | OK!   |
695+----------+------+-------+
696|#Int      | OK!  | FAIL! |
697+----------+------+-------+
698|Int       | OK!  | FAIL! |
699+----------+------+-------+
700|.Str$     | OK!  | OK!   |
701+----------+------+-------+
702|.Int      | OK!  | OK!   |
703+----------+------+-------+
704|.@Str$    | OK!  | OK!   |
705+----------+------+-------+
706|.@Int     | OK!  | OK!   |
707+----------+------+-------+
708
709Variable References
710-------------------
711
712//##TODO
713
714
715
716Operators
717---------
718
719Operators are things you can do to variables and numbers. They are either the
720common mathematical operations or conditional operators
721
722+ - will add two numbers. If you try to add two strings, the result will be a
723    string glued together at the +. You can add a number to a string, and the
724    result will be a string. No other math operators work with strings.
725- - will subtract two numbers.
726* - will multiply two numbers.
727/ - will divide two numbers. Note that this is an integer division, i.e.
728    7/2 is not equal 3.5, it's equal 3.
729% - will give you the remainder of the division. 7%2 is equal to 1.
730
731There are also conditional operators. This has to do with the conditional
732command 'if' and they are meant to return either 1 if the condition is satisfied
733and 0 if it isn't. (That's what they call 'boolean' variables. 0 means 'False'.
734Anything except the zero is 'True' Odd as it is, -1 and -5 and anything below
735zero will also be True.)
736
737You can compare numbers to each other and you compare strings to each other, but
738you can not compare numbers to strings.
739
740 ==  - Is true if both sides are equal. For strings, it means they are the same.
741 >=  - True if the first value is equal to, or greater than, the second value.
742 <=  - True if the first value is equal to, or less than, the second value
743 >   - True if the first value greater than the second value
744 <   - True if the first value is less than the second value
745 !=  - True if the first value IS NOT equal to the second one
746
747Examples:
748
749 1==1 is True.
750 1<2 is True while 1>2 is False.
751 @x>2 is True if @x is equal to 3. But it isn't true if @x is 2.
752
753Only '==' and '!=' have been tested for comparing strings. Since there's no way
754to code a seriously complex data structure in this language, trying to sort
755strings by alphabet would be pointless anyway.
756
757Comparisons can be stacked in the same condition:
758
759 && - Is True if and only if BOTH sides are true.
760      ('1==1 && 2==2' is true. '2==1 && 1==1' is false.)
761 || - Is True if either side of this expression is True.
762
763 1==1 && 2==2 is True.
764 1==1 && 2==1 is False.
765 1==1 || 2==1 is True.
766
767Logical bitwise operators work only on numbers, and they are the following:
768
769 << - Left shift.
770 >> - Right shift.
771        Left shift moves the binary 1(s) of a number n positions to the left,
772        which is the same as multiplying by 2, n times.
773        In the other hand, Right shift moves the binary 1(s) of a number n positions
774        to the right, which is the same as dividing by 2, n times.
775                Example:
776                set b,2;
777                set a, b << 3;
778                mes a;
779                set a, a >> 2;
780                mes a;
781        The first mes command would display 16, which is the same as 2 x (2 x 2 x 2) = 16.
782        The second mes command would display 4, which is the same as 16 / 2 = 8. 8 / 2 = 4.
783 &  - And.
784 |  - Or.
785        The bitwise operator AND (&) is used to test two values against eachother,
786        and results in setting bits which are active in both arguments. This can
787        be used for a few things, but in eAthena this operator is usually used to
788        create bitmasks in scripts.
789       
790        The bitwise operator OR (|)sets to 1 a binary position if the binary position
791        of one of the numbers is 1. This way a variable can hold several values we can check,
792        known as bitmaks. A variable currently can hold up to 32 bitmasks (from position 0
793        to position 1). This is a cheap(skate) and easy way to avoid using arrays to store several checks
794        that a player can have.
795       
796        A bitmask basically is (ab)using the variables bits to set various options in
797        one variable. With the current limit if variables it is possible to store 32
798        different options in one variable (by using the bits on position 0 to 31).
799
800        Example(s):
801        - Basic example of the & operator, bit example:
802                10 & 2 = 2
803        Why? :
804                10 = 2^1 + 2^3 (2 + 8), so in bits, it would be 1010
805                2 = 2^1 (2), so in bits (same size) it would be 0010
806                The & (AND) operator sets bits which are active (1) in both arguments, so in the
807                example 1010 & 0010, only the 2^1 bit is active (1) in both. Resulting in the bit
808                0010, which is 2.
809        - Basic example of creating and using a bit mask:
810                set @options,2|4|16; //(note: this is the same as 2+4+16, or 22)
811                if (@options & 1)       mes "Option 1 is activated";
812                if (@options & 2) mes "Option 2 is activated";
813                if (@options & 4) mes "Option 3 is activated";
814                if (@options & 8) mes "Option 4 is activated";
815                if (@options & 16) mes "Options 5 is activated";
816        This would return the messages about option 2, 3 and 5 being shown (since we've set
817        the 2,4 and 16 bit to 1).
818 ^  - Xor.
819        The bitwise operator XOR (eXclusive OR) sets a binary position to 0 if both
820        numbers have the same value in the said position. On the other hand, it
821        sets to 1 if they have different values in the said binary position.
822        This is another way of setting and unsetting bits in bitmasks.
823       
824        Example:
825        - First let's set the quests that are currently in progress:
826                set inProgress,1|8|16; // quest 1,8 and 16 are in progress
827        - After playing for a bit, the player starts another quest:
828                if( inProgress&2 == 0 ){
829                        // this will set the bit for quest 2 (inProgress has that bit set to 0)
830                        set inProgress,inProgress^2;
831                        mes "Quest 2: find a newbie and be helpful to him for an hour.";
832                        close;
833                }
834        - After spending some time reading info on Xor's, the player finally completes quest 1:
835                if( inProgress&1 && isComplete ){
836                        // this will unset the bit for quest 1 (inProgress has that bit set to 1)
837                        set inProgress,inProgress^1;
838                        mes "Quest 1 complete!! You unlocked the secrets of the Xor dinasty, use them wisely.";
839                        close;
840                }
841
842Labels
843------
844
845Within executable script code, some lines can be labels:
846
847<label name>:
848
849Labels are points of reference in your script, which can be used to route
850execution with 'goto', 'menu' and 'jump_zero' commands, invoked with 'doevent'
851and 'donpcevent' commands and are otherwise essential. A label's name may not be
852longer than 22 characters. (23rd is the ':'.) There is some confusion in the
853source about whether it's 22, 23 or 24 all over the place, so keeping labels
854under 22 characters could be wise. In addition to labels you name yourself,
855there are also some special labels which the script engine will start execution
856from if a special event happens:
857
858OnClock<hour><minute>:
859OnMinute<minute>:
860OnHour<hour>:
861On<weekday><hour><minute>:
862OnDay<month><day>:
863
864This will execute when the server clock hits the specified date or time. Hours
865and minutes are given in military time. ('0105' will mean 01:05 AM). Weekdays
866are Sun,Mon,Tue,Wed,Thu,Fri,Sat. Months are 01 to 12, days are 01 to 31.
867Remember the zero. :)
868
869OnInit:
870OnInterIfInit:
871OnInterIfInitOnce:
872
873OnInit will execute every time the scripts loading is complete, including when
874they are reloaded with @reloadscript command. OnInterIfInit will execute when
875the map server connects to a char server, OnInterIfInitOnce will only execute
876once and will not execute if the map server reconnects to the char server later.
877
878OnAgitStart:
879OnAgitEnd:
880OnAgitInit:
881
882OnAgitStart will run whenever the server shifts into WoE mode, whether it is
883done with @agitstart GM command or with 'AgitStart' script command. OnAgitEnd
884will do likewise for the end of WoE. OnAgitInit will run when castle data is
885loaded from the char-server by the map server.
886
887No RID will be attached while any of the abovementioned labels are triggered, so
888no character or account-based variables will be accessible, until you attach a
889RID with 'attachrid' (see below).
890
891OnTouch:
892
893This label will be executed if a trigger area is defined for the NPC object it's
894in. If it isn't present, the execution will start from the beginning of the NPC
895code. The RID of the triggering character object will be attached.
896
897OnPCLoginEvent:
898OnPCLogoutEvent:
899OnPCBaseLvUpEvent:
900OnPCJobLvUpEvent:
901
902It's pretty obvious when these four special labels will be invoked. For more
903information, see 'npc/sample/PCLoginEvent.txt'
904
905OnPCDieEvent:
906
907This special label triggers when a player dies. The variable 'killerrid' is
908set to the ID of the killer.
909
910OnPCKillEvent:
911
912This special label triggers when a player kills another player. The variable
913'killedrid' is set to the ID of the player killed.
914
915OnNPCKillEvent:
916
917This special label triggers when a player kills a monster. The variable
918'killedrid' is set to the Class of the monster killed.
919
920OnPCLoadMapEvent:
921
922This special label will trigger once a player steps in a map marked with the
923'loadevent' mapflag and attach its RID. The fact that this label requires a
924mapflag for it to work is because, otherwise, it'd be server-wide and trigger
925everytime a player would change maps. Imagine the server load with 1,000 players
926(oh the pain...)
927
928Only the special labels which are not associated with any script command are
929listed here. There are other kinds of labels which may be triggered in a similar
930manner, but they are described with their associated commands.
931
932On<label name>:
933
934These special labels are used with Mob scripts mostly, and script commands
935that requires you to point/link a command to a mob or another npc, giving a label
936name to start from. The label name can be any of your liking, but must be
937
938Example:
939
940monster "prontera",123,42,"Poringz0rd",2341,23,"Master::OnThisMobDeath";
941
942amatsu,13,152,4 script  Master  767,{
943        mes "Hi there";
944        close;
945
946OnThisMobDeath:
947        announce "Hey, "+strcharinfo(0)+" just killed a Poringz0rd!",bc_blue|bc_all;
948        end;
949}
950
951Each time you kill one, that announce will appear in blue to everyone.
952
953Scripting commands and functions
954--------------------------------
955
956The commands and functions are listed here in no particular order. There's a
957difference between commands and functions - commands leave no 'return value'
958which might be used in a conditional statement, as a command argument, or stored
959in a variable. Calling commands as if they were functions will sometimes work,
960but is not advised, as this can lead to some hard to track errors. Calling
961functions as if they were commands will mess up the stack, so 'return' command
962will not return correctly after this happens in a particular script.
963
964All commands must end with a ';'. Actually, you may expect to have multiple
965commands on one line if you properly terminate them with a ';', but it's better
966if you don't, since it is not certain just whether the scripting engine will
967behave nicely if you do.
968
969-------------------------
970
971
972From here on, we will have the commands sorted as follow:
973
9741.- Basic commands.
9752.- Information-retrieving commands.
9763.- Checking commands.
9774.- Player-related commands.
9785.- Mob / NPC -related commands.
9796.- Other commands.
980
981=====================
982|1.- Basic commands.|
983=====================
984---------------------------------------
985
986*mes "<string>";
987
988This command will displays a box on the screen for the invoking character, if no
989such box is displayed already, and will print the string specified into that
990box. There is normally no 'close' or 'next' button on this box, unless you
991create one with 'close' or 'next', and while it's open the player can't do much
992else, so it's important to create a button later. If the string is empty, it
993will show up as an empty line.
994
995    mes "Text that will appear in the box";
996
997Inside the string you may put color codes, which will alter the color of the
998text printed after them. The color codes are all '^<R><G><B>' and contain three
999hexadecimal numbers representing colors as if they were HTML colors - ^FF0000 is
1000bright red, ^00FF00 is bright green, ^0000FF is bright blue, ^000000 is black.
1001^FF00FF is a pure magenta, but it's also a color that is considered transparent
1002whenever the client is drawing windows on screen, so printing text in that color
1003will have kind of a weird effect. Once you've set a text's color to something,
1004you have to set it back to black unless you want all the rest of the text be in
1005that color:
1006
1007    mes "This is ^FF0000 red ^000000 and this is ^00FF00 green, ^000000 so.";
1008   
1009Notice that the text coloring is handled purely by the client. If you use non-
1010english characters, the color codes might get screwed if they stick to letters
1011with no intervening space. Separating them with spaces from the letters on
1012either side solves the problem.
1013
1014---------------------------------------
1015
1016*next;
1017
1018This command will create a 'next' button in the message window for the invoking
1019character. If no window is currently on screen, it will be created. Used to
1020segment NPC talking, this command is used A LOT. See 'mes'.
1021
1022    mes "[Woman]";
1023    mes "This would appear on the page";
1024    next;
1025    // This is needed cause it is a new page and the top will now be blank
1026    mes "[Woman]";
1027    mes "This would appear on the 2nd page";
1028
1029---------------------------------------
1030
1031*close;
1032
1033This command will create a 'close' button in the message window for the invoking
1034character. If no window is currently on screen, it will be created. This is one
1035of the ways to end a speech from an NPC. Once the button is clicked, the NPC
1036script execution will end, and the message box will disappear.
1037
1038    mes "[Woman]";
1039    mes "I am finished talking to you, click the close button";
1040    close;
1041    mes "This command will not run at all, cause the script has ended.";
1042
1043---------------------------------------
1044
1045*close2;
1046
1047This command will create a 'close' button in the message window for the invoking
1048character. If no window is currently on screen, it will be created. See 'close'.
1049There is one important difference, though - even though the message box will
1050have closed, the script execution will not stop, and commands after 'close2'
1051will still run, meaning an 'end' has to be used to stop the script, unless you
1052make it stop in some other manner.
1053
1054    mes "[Woman]";
1055    mes "I will warp you now";
1056    close2;
1057    warp "place",50,50;
1058    end;
1059   
1060Don't expect things to run smoothly if you don't make your scripts 'end'.
1061
1062---------------------------------------
1063
1064*end;
1065
1066This command will stop the execution for this particular script. The two
1067versions are prefectly equivalent. It is the normal way to end a script which
1068does not use 'mes'.
1069
1070        if (BaseLevel<=10) goto L_Lvl10;
1071        if (BaseLevel<=20) goto L_Lvl20;
1072        if (BaseLevel<=30) goto L_Lvl30;
1073        if (BaseLevel<=40) goto L_Lvl40;
1074        if (BaseLevel<=50) goto L_Lvl50;
1075        if (BaseLevel<=60) goto L_Lvl60;
1076        if (BaseLevel<=70) goto L_Lvl70;
1077    L_Lvl10:
1078        npctalk "Look at that you are still a n00b";
1079        end;
1080    L_Lvl20:
1081        npctalk "Look at that you are getting better, but still a n00b";
1082        end;
1083    L_Lvl30:
1084        npctalk "Look at that you are getting there, you are almost 2nd profession now right???";
1085        end;
1086    L_Lvl40:
1087        npctalk "Look at that you are almost 2nd profession";
1088        end;
1089
1090Without the use if 'end' it would travel through the labels until the end of the
1091script. If you were lvl 10 or less, you would see all the speech lines, the use
1092of 'end' stops this, and ends the script.
1093
1094---------------------------------------
1095
1096*set <variable>,<expression>;
1097
1098This command will set a variable to the value that the expression results in.
1099This is the only way to set a variable directly.
1100
1101This is the most basic script command and is used a lot whenever you try to do
1102anything more advanced than just printing text into a messagebox.
1103
1104    set @x,100;
1105   
1106will make @x equal 100.
1107
1108    set @x,1+5/8+9;
1109   
1110will compute 1+5/8+9 (which is, surprisingly, 10 - remember, all numbers are
1111integer in this language) and make @x equal it.
1112
1113Returns the variable reference (since trunk r12870).
1114
1115---------------------------------------
1116
1117*setd "<variable name>",<value>;
1118
1119Works almost identical as set, just that the variable name is identified as a string,
1120thus can be constructed dynamically.
1121This command is equivalent to:
1122set getd("variable name"),<value>;
1123
1124Example:
1125set $var$, "Poring";
1126
1127setd "$var$", "Poporing";
1128mes $var$; // Will return Poporing
1129
1130setd "$" + $var$ + "123$", "Poporing is cool";
1131mes $Poporing123$; // Will return Poporing is cool.
1132
1133---------------------------------------
1134
1135*getd("<variable name>")
1136
1137Returns a reference to a variable, the name can be constructed dynamically.
1138Refer to setd for usage.
1139
1140Example:
1141set getd("$varRefence"), 1;
1142set @i, getd("$pikachu");
1143
1144---------------------------------------
1145
1146*getvariableofnpc(<variable>,"<npc name>")
1147
1148Returns a reference to a NPC variable (. prefix) from the target NPC.
1149This can only be used to get . variables.
1150Example(s):
1151
1152//This will return the value of .var, note that this can't be used, since the value isn't catched.
1153        getvariableofnpc(.var,"TargetNPC");
1154       
1155//This will set the .v variable to the value of the TargetNPC's .var variable.
1156        set .v,getvariableofnpc(.var,"TargetNPC");
1157       
1158//This will set the .var variable of TargetNPC to 1.
1159        set getvariableofnpc(.var,"TargetNPC"),1;
1160
1161---------------------------------------
1162
1163*goto <label>;
1164
1165This command will make the script jump to a label, usually used in conjunction
1166with other command, such as "if", but often used on it's own.
1167
1168        ...
1169        goto Label;
1170        mes "This will not be seen";
1171Label:
1172        mes "This will be seen";
1173
1174Note by FlavioJS: goto's are "evil" and should be avoided if possible (ò_ó)
1175
1176---------------------------------------
1177
1178*menu "<option_text>",<target_label>{,"<option_text>",<target_label>,...};
1179
1180This command will create a selectable menu for the invoking character. Only one
1181menu can be on screen at the same time.
1182
1183Depending on what the player picks from the menu, the script execution will
1184continue from the corresponding label. (it's string-label pairs, not label-
1185string)
1186
1187Options can be grouped together, separated by the character ':'.
1188
1189        menu "A:B",L_Wrong,"C",L_Right;
1190
1191It also sets a special temporary character variable @menu, which contains the
1192number of option the player picked. (Numbering of options starts at 1.)
1193This number is consistent with empty options and grouped options.
1194
1195       menu "A::B",L_Wrong,"",L_Impossible,"C",L_Right;
1196    L_Wrong:
1197       // If they click "A" or "B" they will end up here
1198           // @menu == 1 if "A"
1199           // @menu == 2 will never happen because the option is empty
1200           // @menu == 3 if "B"
1201        L_Impossible:
1202           // Empty options are not displayed and therefore can't be selected
1203           // this label will never be reached from the menu command
1204    L_Right:
1205       // If they click "C" they will end up here
1206           // @menu == 5
1207
1208If a label is '-', the script execution will continue right after the menu
1209command if that option is selected, this can be used to save you time, and
1210optimize big scripts.
1211
1212        menu "A::B:",-,"C",L_Right;
1213        // If they click "A" or "B" they will end up here
1214                // @menu == 1 if "A"
1215                // @menu == 3 if "B"
1216    L_Right:
1217        // If they click "C" they will end up here
1218                // @menu == 5
1219
1220Both these examples will perform the exact same task.
1221
1222If you give an empty string as a menu item, the item will not display. This
1223can effectively be used to script dynamic menus by using empty string for
1224entries that should be unavailable at that time.
1225
1226You can do it by using arrays, but watch carefully - this trick isn't high
1227wizardry, but minor magic at least. You can't expect to easily duplicate it
1228until you understand how it works.
1229
1230Create a temporary array of strings to contain your menu items, and populate it
1231with the strings that should go into the menu at this execution, making sure not
1232to leave any gaps. Normally, you do it with a loop and an extra counter, like
1233this:
1234
1235        setarray @possiblemenuitems$[0],<list of potential menu items>;
1236        set @j,0; // That's the menu lines counter.
1237       
1238        // We loop through the list of possible menu items.
1239        // @i is our loop counter.
1240        for( set @i,0; @i<getarraysize(@possiblemenuitems$) ; set @i,@i+1 )
1241        {
1242                // That 'condition' is whatever condition that determines whether
1243                // a menu item number @i actually goes into the menu or not.
1244               
1245                if (<condition>)
1246                {
1247                        // We record the option into the list of options actually available.
1248                       
1249                        set @menulist$[@j],@possiblemenuitems$[@i];
1250                       
1251                        // We just copied the string, we do need it's number for later
1252                        // though, so we record it as well.
1253                       
1254                        set @menureference[@j],@i;
1255                       
1256                        // Since we've just added a menu item into the list, we increment
1257                        // the menu lines counter.
1258                       
1259                        set @j,@j+1;
1260                }
1261               
1262                // We go on to the next possible menu item.
1263        }
1264
1265This will create you an array @menulist$ which contains the text of all items
1266that should actually go into the menu based on your condition, and an array
1267@menureference, which contains their numbers in the list of possible menu items.
1268(Remember, arrays start with 0.) There's less of them than the possible menu
1269items you've defined, but the menu command can handle the empty lines - only if
1270they are last in the list, and if it's made this way, they are. Now comes a
1271dirty trick:
1272
1273        // X is whatever the most menu items you expect to handle.
1274        menu @menulist$[0],-,@menulist$[1],-,....@menulist$[<X>],-;
1275
1276This calls up a menu of all your items. Since you didn't copy some of the
1277possible menu items into the list, it's end is empty and so no menu items will
1278show up past the end. But this menu call doesn't jump anywhere, it just
1279continues execution right after the menu command. (And it's a good thing it
1280doesn't, cause you can only explicitly define labels to jump to, and how do you
1281know which ones to define if you don't know beforehand which options will end up
1282where in your menu?)
1283But how do you figure out which option the user picked? Enter the @menu.
1284
1285@menu contains the number of option that the user selected from the list,
1286starting with 1 for the first option. You know now which option the user picked
1287and which number in your real list of possible menu items it translated to:
1288
1289    mes "You selected "+@possiblemenuitems$[@menureference[@menu-1]]+"!";
1290
1291@menu is the number of option the user picked.
1292@menu-1 is the array index for the list of actually used menu items that we
1293made.
1294@menureference[@menu-1] is the number of the item in the array of possible menu
1295items that we've saved just for this purpose.
1296
1297And @possiblemenuitems$[@menureference[@menu-1]] is the string that we used to
1298display the menu line the user picked. (Yes, it's a handful, but it works.)
1299
1300You can set up a bunch of 'if (@menureference[@menu-1]==X) goto Y' statements to
1301route your execution based on the line selected and still generate a different
1302menu every time, which is handy when you want to, for example, make users select
1303items in any specific order before proceeding, or make a randomly shuffled menu.
1304
1305Kafra code bundled with the standard distribution uses a similar array-based
1306menu technique for teleport lists, but it's much simpler and doesn't use @menu,
1307probably since that wasn't documented anywhere.
1308
1309See also 'select', which is probably better in this particular case. Instead of
1310menu, you could use 'select' like this:
1311
1312    set @dummy,select(@menulist$[0],@menulist$[1],....@menulist$[<X>]);
1313   
1314For the purposes of the technique described above these two statements are
1315perfectly equivalent.
1316
1317---------------------------------------
1318
1319*select("<option>"{,"<option>",...})
1320*prompt("<option>"{,"<option>",...})
1321
1322This function is a handy replacement for 'menu' for some specific cases where
1323you don't want a complex label structure - like, for example, asking simple yes-
1324no questions. It will return the number of menu option picked, starting with 1.
1325Like 'menu', it will also set the variable @menu to contain the option the user
1326picked.
1327
1328    if (select("Yes:No")==1) mes "You said yes, I know.";
1329
1330And like 'menu', the selected option is consistent with grouped options
1331and empty options.
1332
1333prompt works almost the same as select, except that when a character clicks
1334the Cancel button, this function will return 255 instead.
1335
1336---------------------------------------
1337
1338*input(<variable>{,<min>{,<max>}})
1339
1340This command will make an input box pop up on the client connected to the
1341invoking character, to allow entering of a number or a string. This has many
1342uses, one example would be a guessing game, also making use of the 'rand'
1343function:
1344
1345        mes "[Woman]";
1346        mes "Try and guess the number I am thinking of.";
1347        mes "The number will be between 1 and 10.";
1348        next;
1349        set @number, rand(1,10);
1350        input @guess;
1351        if(@guess==@number)
1352        {
1353                mes "[Woman]";
1354                mes "Well done that was the number I was thinking of";
1355                close;
1356        }
1357        else
1358        {
1359                mes "[Woman]";
1360                mes "Sorry, that wasn't the number I was thinking of.";
1361                close;
1362        }
1363
1364If you give the input command a string variable to put the input in, it will
1365allow the player to enter text. Otherwise, only numbers will be allowed.
1366
1367        mes "[Woman]";
1368        mes "Please say HELLO";
1369        next;
1370        input @var$;
1371        if(@var$=="HELLO")
1372        {
1373                mes "[Woman]";
1374                mes "Well done you typed it correctly";
1375                close;
1376        }
1377        else
1378        {
1379                mes "[Woman]";
1380                mes "Sorry you got it wrong";
1381                close;
1382        }
1383
1384Normally you may not input a negative number with this command.
1385This is done to prevent exploits in badly written scripts, which would
1386let people, for example, put negative amounts of zeny into a bank script and
1387receive free zeny as a result.
1388
1389Since trunk r12192 the command has two optional arguments and a return value.
1390The default value of 'min' and 'max' can be set with 'input_min_value' and
1391'input_max_value' in script_athena.conf.
1392For numeric inputs the value is capped to the range [min,max]. Returns 1 if
1393the value was higher than 'max', -1 if lower than 'min' and 0 otherwise.
1394For string inputs it returns 1 if the string was longer than 'max', -1 is
1395shorter than 'min' and 0 otherwise.
1396
1397---------------------------------------
1398
1399*callfunc "<function>"{,<argument>,...<argument>};
1400*callfunc("<function>"{,<argument>,...<argument>})
1401
1402This command lets you call up a function NPC. A function NPC can be called from
1403any script on any map server. Using the 'return' command it will come back to
1404the place that called it.
1405
1406        place,50,50,6%TAB%script%TAB%Woman%TAB%115,{
1407                mes "[Woman]"
1408                mes "Lets see if you win";
1409                callfunc "funcNPC";
1410                mes "Well done you have won";
1411                close;
1412        }
1413        function%TAB%script%TAB%funcNPC%TAB%{
1414                set @win, rand(2);
1415                if(@win==0) return;
1416                mes "Sorry you lost";
1417                end;
1418        }
1419
1420You can pass arguments to your function - values telling it what exactly to do -
1421which will be available there with getarg() (see 'getarg')
1422Notice that returning is not mandatory, you can end execution right there.
1423
1424If you want to return a real value from inside your function NPC, it is better
1425to write it in the function form, which will also work and will make the script
1426generally cleaner:
1427
1428        place,50,50,6%TAB%script%TAB%Man%TAB%115,{
1429                mes "[Man]"
1430                mes "Gimme a number!";
1431                next;
1432                input @number;
1433                if (callfunc("OddFunc",@number)) mes "It's Odd!";
1434                close;
1435        }
1436        function%TAB%script%TAB%OddFunc%TAB%{
1437                if (getarg(0)%2==0) return 0;// it's even
1438                return 1;// it's odd
1439        }
1440
1441---------------------------------------
1442
1443*callsub <label>{,<argument>,...<argument>};
1444
1445This command will go to a specified label within the current script (do NOT use
1446quotes around it) coming in as if it were a 'callfunc' call, and pass it
1447arguments given, if any, which can be recovered there with 'getarg'. When done
1448there, you should use the 'return' command to go back to the point from where
1449this label was called. This is used when there is a specific thing the script
1450will do over and over, this lets you use the same bit of code as many times as
1451you like, to save space and time, without creating extra NPC objects which are
1452needed with 'callfunc'. A label is not callable in this manner from another
1453script.
1454
1455                mes "[Woman]"
1456                mes "Lets see if you win";
1457                callsub Check;
1458                mes "Well done you have won";
1459                close;
1460        Check:
1461                set @win, rand(2);
1462                if(@win==0) return;
1463                mes "Sorry you lost";
1464                close;
1465
1466---------------------------------------
1467
1468*getarg(<index>{,<default_value>})
1469
1470This function is used when you use the 'callsub' or 'callfunc' commands. In the
1471call you can specify variables that will make that call different from another
1472one. This function will return an argument the function or subroutine was
1473called with, and is the normal way to get them.
1474This is another thing that can let you use the same code more than once.
1475
1476Argument numbering starts with 0, i.e. the first argument you gave is number 0.
1477If no such argument was given, a zero is returned.
1478
1479        place,50,50,6%TAB%script%TAB%Woman1%TAB%115,{
1480                mes "[Woman]";
1481                mes "Lets see if you win";
1482                callfunc "funcNPC",2;
1483                mes "Well done you have won";
1484
1485        ...
1486
1487        place,52,50,6%TAB%script%TAB%Woman2%TAB%115,{
1488                mes "[Woman]";
1489                mes "Lets see if you win";
1490                callfunc "funcNPC",5;
1491                mes "Well done you have won";
1492
1493        ...
1494
1495        function%TAB%script%TAB%funcNPC%TAB%{
1496                set @win, rand(getarg(0));
1497                if(@win==0) return;
1498                mes "Sorry you lost";
1499
1500"woman1" NPC object calls the funcNPC. The argument it gives in this call is
1501stated as 2, so when the random number is generated by the 'rand' function, it
1502can only be 0 or 1. Whereas "woman2" gives 5 as the argument number 0 when
1503calling the function, so the random number could be 0, 1, 2, 3 or 4, this makes
1504"woman2" less likely to say the player won.
1505
1506You can pass multiple arguments in a function call:
1507
1508        callfunc "funcNPC",5,4,3;
1509
1510getarg(0) would be 5, getarg(1) would be 4 and getarg(2) would be 3.
1511
1512Getarg has an optional argument since trunk r10773 and stable r10958.
1513If the target argument exists, it is returned.
1514Otherwise, if <default_value> is present it is returned instead,
1515if not the script terminates immediately.
1516
1517in the previous example getarg(2,-1) would be 3 and getarg(3,-1) would be -1
1518
1519---------------------------------------
1520
1521*return {<value>};
1522
1523When you use callsub or callfunc, this command allows you to go back to the
1524calling script. You can optionally return with a value telling the calling
1525program what exactly happened.
1526
1527        callfunc "<your function>";// when nothing is returned
1528        set <variable>,callfunc("<your function>");// when a value is being returned
1529
1530---------------------------------------
1531
1532*function <function name>;
1533*<function name>;
1534*function <function name> {
1535<code>
1536}
1537
1538(Skotlex stop being so selfish and give us all the commands T~T! J/k lol :P)
1539
1540This works like callfunc, but doesn't support arguments like callfunc. It's used for cleaner
1541and fast script that doesn't require arguments for it to work. Also they must be inside a script.
1542They're not separated scripts and they work more like labels.
1543
1544Note it looks like the normal declaration
1545
1546Usage:
1547
1548You first Declare the function with function <function name>;.
1549
1550Put the rest of your code. You can use then <function name>; to call the function. If it returns a value is unsure,
1551test it if you want and give us some comments ;3
1552
1553And at least, but inside the script itself, put the function <function name> {<code>}.
1554
1555Example:
1556
1557prontera,154,189,4      script  Item seller     767,{
1558
1559function SF_Selling;
1560
1561mes "I'll open this now if you have more than 50z and you are level 50 or bigger";
1562next;
1563
1564if (Zeny > 50) && (BaseLevel > 50) {
1565        mes "Welcome";
1566        next;
1567        SF_Selling;
1568        close;
1569} else
1570
1571set @needed,50-BaseLevel;
1572mes "You either are Level "+BaseLevel+", thus you need "+@needed+" more levels";
1573mes "to be able to use this npc; or you don't have enough zeny, so get some please";
1574close;
1575
1576function SF_Selling {
1577
1578        mes "Would you like to buy a phracon for 50z?";
1579        switch(select("Yes","No, thanks")) {
1580
1581        case 1:
1582                mes "Ok, how many?";
1583                input @quantity;
1584                set @check,Zeny/50;
1585                if (@quantity > @check) {
1586                        mes "Sorry but you can only have "+@check+" Phracons with "+Zeny;
1587                        close;
1588                } else
1589                next;
1590                mes "here you have";
1591                set Zeny,Zeny-@quantity*50;
1592                getitem 1010,@quantity;
1593                close;
1594        case 2:
1595                mes "Good bye then";
1596                close;
1597                }
1598        }
1599        return;
1600}
1601
1602
1603---------------------------------------
1604
1605*if (<condition>) <statement>;
1606
1607This is the basic conditional statement command, and just about the only one
1608available in this scripting language.
1609
1610The condition can be any expression. All expressions resulting in a non-zero
1611value will be considered True, including negative values. All expressions
1612resulting in a zero are false.
1613
1614If the expression results in True, the statement will be executed. If it isn't
1615true, nothing happens and we move on to the next line of the script.
1616
1617    if (1)  mes "This will always print.";
1618    if (0)  mes "And this will never print.";
1619    if (5)  mes "This will also always print.";
1620    if (-1) mes "Funny as it is, this will also print just fine.";
1621
1622For more information on conditional operators see the operators section above.
1623Anything that is returned by a function can be used in a condition check without
1624bothering to store it in a specific variable:
1625
1626    if (strcharinfo(0)=="Daniel Jackson") mes "It is true, you are Daniel!";
1627
1628More examples of using the 'if' command in the real world:
1629
1630Example 1:
1631
1632        set @var1,1;
1633        input @var2;
1634        if(@var1==@var2) goto L_Same;
1635        mes "Sorry that is wrong";
1636        close;
1637    L_Same:
1638        close;
1639
1640Example 2:
1641   
1642    set @var1,1;
1643    input @var2;
1644    if(@var1!=@var2) mes "Sorry that is wrong";
1645    close;
1646
1647(Notice examples 1 and 2 have the same effect.)
1648
1649Example 3:
1650
1651    set @var1,@var1+1;
1652    mes "[Forgetfull Man]";
1653    if (@var==1) mes "This is the first time you have talked to me";
1654    if (@var==2) mes "This is the second time you have talked to me";
1655    if (@var==3) mes "This is the third time you have talked to me";
1656    if (@var==4) mes "This is the forth time you have talked to me, but I think I am getting amnesia, I have forgoten about you";
1657    if (@var==4) set @var,0;
1658    close;
1659
1660Example 4:
1661
1662        mes "[Quest Person]";
1663        if(countitem(512)>=1) goto L_GiveApple;
1664        // The number 512 was found from item_db, it is the item number for the Apple.
1665        mes "Can you please bring me an apple?";
1666        close;
1667    L_GiveApple:
1668        mes "Oh an apple, I didnt want it, I just wanted to see one";
1669        close;
1670
1671Example 5:
1672
1673        mes "[Person Checker]";
1674        if($name$!=null) goto L_Check;
1675        mes "Please tell me someones name";
1676        next;
1677        input $name$;
1678        set $name2$,strcharinfo(0);
1679        mes "[Person Checker]";
1680        mes "Thank you";
1681    L_Check:
1682        if($name$==strcharinfo(0) ) goto L_SameName;
1683        mes "[Person Checker]";
1684        mes "You are not the person that " +$name2$+ " mentioned";
1685    L_End:
1686        set $name$,null;
1687        set $name2$,null;
1688        close;
1689    L_SameName:
1690        mes "[Person Checker]";
1691        mes "You are the person that " +$name2$+ " just mentioned";
1692        mes "nice to meet you";
1693        goto L_End;
1694
1695See 'strcharinfo' for explanation of what this function does.
1696
1697Example 6: Using complex conditions.
1698
1699        mes "[Multi Checker]";
1700        if( (@queststarted==1) && (countitem(512)>=5) ) goto L_MultiCheck;
1701        // Only if the quest has been started AND You have 5 apples will it goto "L_MultiCheck"
1702        mes "Please get me 5 apples";
1703        set @queststarted,1;
1704        close;
1705    L_MultiCheck:
1706        mes "[Multi Checker]";
1707        mes "Well done you have started the quest of got me 5 apples";
1708        mes "Thank you";
1709        set @queststarted,0;
1710        delitem 512,5;
1711        close;
1712
1713With the Advanced scripting engine, we got nested if's. That is:
1714
1715if (<condition>)
1716        dothis;
1717else
1718        dothat;
1719       
1720If the condition doesn't meet, it'll do the action following the else.
1721We can also group several actions depending on a condition, the following way:
1722
1723if (<condition)
1724{
1725        dothis1;
1726        dothis2;
1727        dothis3;
1728} else {
1729        dothat1;
1730        dothat2;
1731        dothat3;
1732        dothat4;
1733}
1734
1735Remember that if you plan to do several actions upon the condition being false, and
1736you forget to use the curlies (the { } ), the second action will be executed regardless
1737the output of the condition, unless of course, you stop the execution of the script if the
1738condition is true (that is, in the first grouping using a return; , and end; or a close; )
1739
1740Also, you can have multiple conditions nested or chained, and don't worry about limits as to
1741how many nested if you can have, there is no spoon ;)
1742
1743...
1744if (<condition 1>)
1745        dothis;
1746else if (<condition 2>)
1747{
1748        dotheother;
1749        do that;
1750        end;
1751} else
1752        do this;
1753...
1754
1755---------------------------------------
1756
1757*jump_zero (<condition>),<label>;
1758
1759This command works kinda like an 'if'+'goto' combination in one go. (See 'if').
1760If the condition is false (equal to zero) this command will immediately jump to
1761the specified label like in 'goto'.
1762
1763While 'if' is more generally useful, for some cases this could be an
1764optimisation.
1765
1766---------------------------------------
1767
1768*setarray <array name>[<first value>],<value>{,<value>...<value>};
1769
1770This command will allow you to quickly fill up an array in one go. Check the
1771Kafra scripts in the distribution to see this used a lot.
1772
1773    setarray @array[0], 100, 200, 300, 400, 500, 600;
1774
1775First value is the index of the first element of the array to alter. For
1776example:
1777
1778    setarray @array[0],200,200,200;
1779    setarray @array[1],300,150;
1780   
1781will produce:
1782
1783 @array[0]=200
1784 @array[1]=300
1785 @array[2]=150
1786
1787---------------------------------------
1788
1789*cleararray <array name>[<first value to alter>],<value>,<number of values to set>;
1790
1791This command will change many array values at the same time to the same value.
1792
1793    setarray @array[0], 100, 200, 300, 400, 500, 600;
1794    // This will make all 6 values 0
1795    cleararray @array[0],0,6;
1796    // This will make array element 0 change to 245
1797    cleararray @array[0],245,1;
1798    // This will make elements 1 and 2 change to 345
1799    cleararray @array[1],345,2;
1800
1801See 'setarray'.
1802
1803---------------------------------------
1804
1805*copyarray <destination array>[<first value>],<source array>[<first value>],<amount of data to copy>;
1806
1807This command lets you quickly shuffle a lot of data between arrays, which is in
1808some cases invaluable.
1809
1810    setarray @array[0], 100, 200, 300, 400, 500, 600;
1811    // So we have made @array[]
1812    copyarray @array2[0],@array[2],2;
1813   
1814    // Now, @array2[0] will be equal to @array[2] (300) and
1815    // @array2[1] will be equal to @array[3].
1816
1817So using the examples above:
1818 @array[0]  = 100
1819 @array[1]  = 200
1820 @array[2]  = 300
1821 @array[3]  = 400
1822 @array[4]  = 500
1823 @array[5]  = 600
1824 
1825New Array:
1826 @array2[0] = 300
1827 @array2[1] = 400
1828 @array2[2] = 0
1829 @array2[3] = 0
1830
1831Notice that @array[4] and @array[5] won't be copied to the second array, and it will return a
18320.
1833
1834---------------------------------------
1835
1836*deletearray <array name>[<first value>],<how much to delete>
1837
1838This command will delete a specified number of array elements totally from an
1839array, shifting all the elements beyond this towards the beginning.
1840
1841    // This will delete array element 0, and move all the other array elements
1842    // up one place.
1843    deletearray @array[0],1
1844
1845// This would delete array elements numbered 1, 2 and 3, leave element 0 in its
1846// place, and move the other elements ups, so there are no gaps.
1847
1848    deletearray @array[1],3
1849
1850IMPORTANT: deletarray is horribly broken since the earliest days of jAthena. It
1851tends to merrily remove much more variables than it's told to remove, which
1852makes it pretty much useless for anything other than removing an array from
1853memory entirely. This would be very handy, if it always worked.
1854
1855---------------------------------------
1856
1857======================================
1858|2.- Information-retrieving commands.|
1859======================================
1860---------------------------------------
1861
1862*strcharinfo(<type>)
1863
1864This function will return either the name, party name or guild name for the
1865invoking character. Whatever it returns is determined by type.
1866
1867 0 - Character's name.
1868 1 - The name of the party they're in if any.
1869 2 - The name of the guild they're in if any.
1870 
1871If a character is not a member of any party or guild, an empty string will be
1872returned when requesting that information.
1873
1874---------------------------------------
1875
1876*strnpcinfo(<type>)
1877
1878This function will return the various parts of the name of the calling npc.
1879Whatever it returns is determined by type.
1880
1881 0 - The NPC's display name (visible#hidden)
1882 1 - The visible part of the NPC's display name
1883 2 - The hidden part of the NPC's display name
1884 3 - The NPC's unique name (::name)
1885
1886---------------------------------------
1887
1888*getarraysize(<array name>)
1889
1890This function returns the number of values that are contained inside the
1891specified array. Notice that zeros and empty strings at the end of this array
1892are not counted towards this number.
1893
1894For example:
1895
1896    setarray @array[0], 100, 200, 300, 400, 500, 600;
1897    set @arraysize,getarraysize(@array);
1898
1899This will make @arraysize == 6. But if you try this:
1900
1901    setarray @array[0], 100, 200, 300, 400, 500, 600, 0;
1902    set @arraysize,getarraysize(@array);
1903   
1904@arraysize will still equal 6, even though you've set 7 values.   
1905
1906---------------------------------------
1907
1908*getelementofarray(<array name>,<index>)
1909
1910This function will return an array's element when given an index.
1911
1912    // This will find the 2nd array value
1913    getelementofarray(@array,1)
1914
1915Pretty pointless now when we have
1916
1917    @array[1]
1918
1919which has the same effect.
1920
1921---------------------------------------
1922
1923*readparam(<parameter number>)
1924
1925This function will return the basic stats of an invoking character, referred to
1926by the parameter number. Instead of a number, you can use a parameter name if it
1927is defined in "db/const.txt".
1928
1929For reference, in there these things are defined:
1930
1931StatusPoint, BaseLevel, SkillPoint, Class, Upper, Zeny, Sex, Weight, MaxWeight,
1932JobLevel, BaseExp, JobExp, NextBaseExp, NextJobExp, Hp, MaxHp, Sp, MaxSp,
1933BaseJob, Karma, Manner, bVit, bDex, bAgi, bStr, bInt, bLuk
1934
1935All of these also behave as variables, but don't expect to be able to just 'set'
1936all of them - some will not work for various internal reasons.
1937
1938    // This would return how many status points you haven't spent yet
1939    readparam(9)
1940
1941Using this particular information as a function call is not required. Just
1942putting
1943
1944    StatusPoint
1945
1946will give you the same result, and some of these parameters work just like
1947variables (i.e. you can 'set Zeny,100' to make the character have 100 zeny,
1948destroying whatever zeny they had before, or 'set Zeny,Zeny+100' to give them
1949100 zeny)
1950
1951You can also use this command to get stat values:
1952
1953    readparam(bVit)
1954    if(readparam(bVit)<=77) goto L_End;
1955    mes "Only people with over 77 Vit are reading this";
1956L_End:
1957    close;
1958
1959---------------------------------------
1960
1961*getcharid(<type>{,"<character name>"})
1962
1963This function will return a unique ID number of the invoking character, or, if a
1964character name is specified, of that character.
1965
1966Type is the kind of associated ID number required:
1967
1968 0 - Character ID number.
1969 1 - Party ID number.
1970 2 - Guild ID number.
1971 3 - Account ID number.
1972
1973For most purposes other than printing it, a number is better to have than a name
1974(people do horrifying things to their character names).
1975
1976If the character is not in a party or not in a guild, the function will return 0
1977if guild or party number is requested. If a name is specified and the character
1978is not found, 0 is returned.
1979
1980If getcharid(0) returns a zero, the script got called not by a character and
1981doesn't have an attached RID. Note that this will cause the map server to
1982print "player not attached!" error messages, so it is preferred to use
1983"playerattached" to check for the character attached to the script.
1984
1985if( getcharid(2) == 0 ) mes "Only members of a guild are allowed here!";
1986
1987---------------------------------------
1988
1989*getchildid()
1990*getmotherid()
1991*getfatherid()
1992
1993These functions return the characters (shild/mother/father) ID
1994
1995    if (getmotherid()) mes "Oh... I know your mother's ID:"+getmotherid();
1996
1997---------------------------------------
1998
1999*ispartneron()
2000
2001This function returns 1 if the invoking character's marriage partner is
2002currently online and 0 if they are not or if the character has no partner.
2003
2004---------------------------------------
2005
2006*getpartnerid()
2007
2008This function returns the character ID of the invoking character's marriage
2009partner, if any. If the invoking character is not married, it will return 0,
2010which is a quick way to see if they are married:
2011
2012    if (getpartnerid()) mes "I'm not going to be your girlfriend!";
2013    if (getpartnerid()) mes "You're married already!";
2014
2015---------------------------------------
2016
2017*getpartyname(<party id>)
2018
2019This function will return the name of a party that has the specified ID number.
2020If there is no such party ID, "null" will be returned.
2021
2022Lets say the ID of a party was saved as a global variable:
2023
2024    // This would return the name of the party from the ID stored in a variable
2025    mes "You're in the '"+getpartyname($@var)"' party, I know!";
2026
2027---------------------------------------
2028
2029*getpartymember <party id>,{<type>};
2030
2031Thank you to HappyDenn for all this information.
2032
2033This command will find all members of a specified party and returns their names
2034(or character id or account id depending on the value of "type") into an array
2035of temporary global variables. There's actually quite a few commands like this
2036which will fill a special variable with data upon execution and not do anything
2037else.
2038
2039Upon executing this,
2040
2041$@partymembername$[] is a global temporary stringarray which contains all the
2042                     names of these party members
2043                     (only set when type is 0 or not specified)
2044
2045$@partymembercid[]   is a global temporary number array which contains the
2046                     character id of these party members.
2047                     (only set when type is 1)
2048
2049$@partymemberaid[]   is a global temporary number array which contains the
2050                     account id of these party members.
2051                     (only set when type is 2)
2052
2053$@partymembercount   is the number of party members that were found.
2054
2055The party members will (apparently) be found regardless of whether they are
2056online or offline. Note that the names come in no particular order.
2057
2058Be sure to use $@partymembercount to go through this array, and not
2059'getarraysize', because it is not cleared between runs of 'getpartymember'. If
2060someone with 7 party members invokes this script, the array would have 7
2061elements. But if another person calls up the NPC, and he has a party of 5, the
2062server will not clear the array for you, overwriting the values instead. So in
2063addition to returning the 5 member names, the 6th and 7th elements from the last
2064call remain, and you will get 5+2 members, of which the last 2 don't belong to
2065the new guy's party. $@partymembercount will always contain the correct number,
2066(5) unlike 'getarraysize()' which will return 7 in this case.
2067
2068Example:
2069
2070   // get the character's party ID
2071       getpartymember(getcharid(1));
2072
2073   // immediately copy $@partymembercount value to a new variable, since
2074   // you don't know when 'getpartymember' will get called again for someone
2075   // else's party, overwriting your global array.
2076       set @partymembercount,$@partymembercount;
2077
2078   // copy $@partymembername array to a new array
2079       copyarray @partymembername$[0],$@partymembername$[0],@partymembercount;
2080
2081   //list the party members in NPC dialog
2082       set @count,0;
2083   L_DisplayMember:
2084       if(@count == @partymembercount) goto L_DisplayMemberEnd;
2085       mes (@count + 1) + ". ^0000FF" + @partymembername$[@count] + "^000000";
2086       set @count,@count+1;
2087       goto L_DisplayMember;
2088   L_DisplayMemberEnd:
2089       close;
2090
2091---------------------------------------
2092
2093*getpartyleader(<party id>,{<type>});
2094
2095This function returns some information about the given party-id's leader.
2096When type is ommitted, the default information retrieved is the leader's name.
2097Possible types are:
2098
2099        1: Leader account id
2100        2: Leader character id
2101        3: Leader's class
2102        4: Leader's current map name
2103        5: Leader's current level as stored on the party structure (may not be
2104           current level if leader leveled up recently).
2105
2106If retrieval fails (leader not found or party does not exist), this function
2107returns "null" instead of the character name, and -1 for the other types.
2108
2109---------------------------------------
2110
2111*getlook(<type>)
2112
2113This function will return the number for the currentcharacter look value
2114specified by type. See 'setlook' for valid look types.
2115
2116This can be used to make a certain script behave differently for characters
2117dressed in black. :)
2118
2119---------------------------------------
2120
2121*getsavepoint(<information type>)
2122
2123This function will return information about the invoking character's save point.
2124You can use it to let a character swap between several recorded savepoints.
2125Available information types are:
2126
2127 0 - Map name (a string)
2128 1 - X coordinate
2129 2 - Y coordinate
2130
2131---------------------------------------
2132\\
21332,2 Item-related commands
2134\\
2135---------------------------------------
2136
2137*getequipid(<equipment slot>)
2138
2139This function returns the item ID of the item equipped in the equipment slot
2140specified on the invoking character. If nothing is equpped there, it returns -1.
2141Valid equipment slots are:
2142
2143EQI_HEAD_TOP (1)  - Upper head gear
2144EQI_ARMOR (2)     - Armor (Where you keep your Jackets and Robes)
2145EQI_HAND_L (3)    - What is in your Left hand.
2146EQI_HAND_R (4)    - What is in your Right hand.
2147EQI_GARMENT (5)   - The garment slot (Mufflers, Hoods, Manteaus)
2148EQI_SHOES (6)     - What foot gear the player has on.
2149EQI_ACC_L (7)     - Accessory 1.
2150EQI_ACC_R (8)     - Accessory 2.
2151EQI_HEAD_MID (9)  - Middle Headgear (masks and glasses)
2152EQI_HEAD_LOW (10) - Lower Headgear (beards, some masks)
2153
2154Notice that a few items occupy several equipment slots, and if the character is
2155wearing such an item, 'getequipid' will return it's ID number for either slot.
2156
2157Can be used to check if you have something equiped, or if you haven't got
2158something equiped:
2159
2160        if(getequipid(EQI_HEAD_TOP)==2234) goto L_WearingTiara;
2161        mes "Come back when you have a Tiara on";
2162        close;
2163    L_WearingTiara:
2164        mes "What a lovely Tiara you have on";
2165        close;
2166
2167You can also use it to make sure people don't pass a point before removing an
2168item totally from them. Let's say you don't want people to wear Legion Plate
2169armor, but also don't want them to equip if after the check, you would do this:
2170
2171        if ((getequipid(EQI_ARMOR) == 2341) || (getequipid(EQI_ARMOR) == 2342) goto L_EquipedLegionPlate;
2172    // the || is used as an or argument, there is 2341 and 2342 cause there are
2173    // two different legion plate armors, one with a slot one without.
2174        if ((countitem(2341) > 0) || (countitem(2432) > 0) goto L_InventoryLegionPlate;
2175        mes "I will lets you pass";
2176        close2;
2177        warp "place",50,50;
2178        end;
2179    L_EquipedLegionPlate:
2180        mes "You are wearing some Legion Plate Armor, please drop that in your stash before continuing";
2181        close;
2182    L_InventoryLegionPlate:
2183        mes "You have some Legion Plate Armor in your inventory, please drop that in your stash before continuing";
2184        close;
2185
2186---------------------------------------
2187
2188*getequipname(<equpment slot>)
2189
2190This function will return the name of the item equipped in the specified
2191equipment slot on the invoking character. Almost identical to 'getequipid', good
2192for an NPC to state what your are wearing, or maybe saving as a string variable.
2193See 'getequipid' for a full list of valid equipment slots.
2194
2195        if (getequipname(EQI_HEAD_TOP)==0) goto L_No_HeadGear;
2196        mes "So you are wearing a "+getequipname(EQI_HEAD_TOP)+" on your head";
2197        close;
2198    L_No_HeadGear:
2199        mes "You are not wearing any head gear";
2200        close;
2201
2202---------------------------------------
2203
2204*getitemname(<item id>)
2205
2206Given the database ID number of an item, this function will return the text
2207stored in the 'japanese name' field (which, in eAthena, stores an english name
2208the players would normally see on screen.)
2209
2210---------------------------------------
2211
2212*getbrokenid(<number>)
2213
2214This function will search the invoking character's inventory for any broken
2215items, and will return their item ID numbers. Since the character may have
2216several broken items, 0 given as an argument will return the first one found, 1
2217will return the second one, etc. Will return 0 if no such item is found.
2218
2219    // Let's see if they have anything broken:
2220        if (getbrokenid(0)==0) goto Skip;
2221    // They do, so let's print the name of the first broken item:
2222        mes "Oh, I see you have a broken "+getitemname(getbrokenid(0))+" here!";
2223    Skip:
2224        mes "You don't have anything broken, quit bothering me.";
2225
2226---------------------------------------
2227
2228*getequipisequiped(<equipment slot>)
2229
2230This functions will return 1 if there is an equipment placed on the specified
2231equipment slot and 0 otherwise. For a list of equipment slots
2232see 'getequipid'. Function originally used by the refining NPCs:
2233
2234    if (getequipisequiped(EQI_HEAD_TOP)) goto L_equipped;
2235        mes "[Refiner]";
2236        mes "Do you want me to refine your dumb head?";
2237        close;
2238    L_equipped:
2239        mes "[Refiner]";
2240        mes "That's a fine hat you are wearing there...";
2241        close;
2242
2243
2244---------------------------------------
2245
2246*getequipisenableref(<equipment slot>)
2247
2248Will return 1 if the item equipped on the invoking character in the specified
2249equipment slot is refinable, and 0 if it isn't. For a list of equipment slots
2250see 'getequipid'.
2251
2252        if (getequipisenableref(EQI_HEAD_TOP)) goto L_Refine;
2253        mes "[Refiner]";
2254        mes "I can't refine this hat!...";
2255        close;
2256    L_Refine:
2257        mes "[Refiner]";
2258        mes "Ok I can refine this";
2259        close;
2260
2261---------------------------------------
2262
2263*getequiprefinerycnt(<equipment slot>)
2264
2265Returns the current number of plusses for the item in the specified equipment
2266slot. For a list of equipment slots see 'getequipid'.
2267
2268Can be used to check if you have reached a maximum refine value, default for
2269this is +10:
2270
2271        if(getequiprefinerycnt(EQI_HEAD_TOP) < 10) goto L_Refine_HeadGear;
2272        mes "Sorry, it's not possible to refine hats better than +10";
2273        close;
2274    L_Refine_HeadGear:
2275        mes "I will now upgrade your "+getequipname(EQI_HEAD_TOP);
2276
2277---------------------------------------
2278
2279*getequipweaponlv(<equipment slot>)
2280
2281This function returns the weapon level for the weapon equipped in the specified
2282equipment slot on the invoking character. For a list of equipment slots see
2283'getequipid'.
2284
2285Only EQI_HAND_L and EQI_HAND_R normally make sense, since only weapons
2286have a weapon level. You can, however, probably, use this field for other
2287equippable custom items as a flag or something.
2288If no item is equipped in this slot, or if it doesn't have a weapon level
2289according to the database, 0 will be returned.
2290
2291    switch (getequipweaponlv(EQI_HAND_R)) {
2292      case 1: mes "You are holding a lvl 1 weapon"; break;
2293                case 2: mes "You are holding a lvl 2 weapon"; break;
2294                case 3: mes "You are holding a lvl 3 weapon"; break;
2295      case 4: mes "You are holding a lvl 4 weapon"; break;
2296                case 5: mes "You are holding a lvl 5 weapon, hm, must be a custom design"; break;
2297                default: mes "Seems you don't have a weapon on"; break;
2298         }
2299
2300Or for the left hand, cause it can hold a weapon or a shield:
2301
2302        if(getequipid(EQI_HAND_R)==0) goto L_NothingEquiped;
2303        switch (getequipweaponlv(EQI_HAND_L)) {
2304          case 0: mes "You are holding a shield, so it doesnt have a level"; break;
2305          case 1: mes "You are holding a lvl 1 weapon"; break;
2306          case 2: mes "You are holding a lvl 2 weapon"; break;
2307          case 3: mes "You are holding a lvl 3 weapon"; break;
2308          case 4: mes "You are holding a lvl 4 weapon"; break;
2309          case 5: mes "You are holding a lvl 5 weapon, hm, must be a custom design"; break;
2310                  }
2311        close;
2312    L_NothingEquiped:
2313        mes "Seems you have nothing equiped";
2314        close;
2315
2316---------------------------------------
2317
2318*getequippercentrefinery(<equipment slot>)
2319
2320This function calculates and returns the percent value chance to successfully
2321refine the item found in the specified equipment slot of the invoking character
2322by +1. There is no actual formula, the sucess rate for a given weapon level of
2323a certain refine level is found in the db/refine_db.txt file. For a list of
2324equipment slots see 'getequipid'.
2325
2326These values can be displayed for the player to see, or used to calculate the
2327random change of a refine succeeding or failing and then going through with it
2328(which is what the official NPC refinery scripts use it for)
2329
2330// This will find a random number from 0 - 99 and if that is equal to or more
2331// than the value recoverd by this command it will go to L_Fail
2332    if (getequippercentrefinery(EQI_HAND_L)<=rand(100)) goto L_Fail;
2333
2334---------------------------------------
2335
2336*getareadropitem("<map name>",<x1>,<y1>,<x2>,<y2>,<item>)
2337
2338This function will count all the items with the specified ID number lying on the
2339ground on the specified map within the x1/y1-x2/y2 square on it and return that
2340number.
2341
2342This is the only function around where a parameter may be either a string or a
2343number! If it's a number, it means that only the items with that item ID number
2344will be counted. If it is a string, it is assumed to mean the 'english name'
2345field from the item database. If you give it an empty string, or something that
2346isn't found from the item database, it will count items number '512' (apples).
2347
2348---------------------------------------
2349
2350*getequipcardcnt(<equipment slot>)
2351
2352This function will return the number of cards that have been compounded onto a
2353specific equipped item for the invoking character. See 'getequipid' for a list
2354of possible equipment slots.
2355
2356---------------------------------------
2357
2358*getinventorylist;
2359
2360This command sets a bunch of arrays with a complete list of whatever the
2361invoking character has in their inventory, including all the data needed to
2362recreate these items perfectly if they are destroyed. Here's what you get:
2363
2364@inventorylist_id[]        - array of item ids.
2365@inventorylist_amount[]    - their corresponding item amounts.
2366@inventorylist_equip[]     - whether the item is equipped or not.
2367@inventorylist_refine[]    - for how much it is refined.
2368@inventorylist_identify[]  - whether it is identified.
2369@inventorylist_attribute[] - whether it is broken.
2370@inventorylist_card1[]     - These four arrays contain card data for the items.
2371@inventorylist_card2[]       These data slots are also used to store names
2372@inventorylist_card3[]       inscribed on the items, so you can explicitly check
2373@inventorylist_card4[]       if the character owns an item made by a specific
2374                             craftsman.
2375@inventorylist_count       - the number of items in these lists.
2376
2377This could be handy to save/restore a character's inventory, since no other
2378command returns such a complete set of data, and could also be the only way to
2379correctly handle an NPC trader for carded and named items who could resell them
2380- since NPC objects cannot own items, so they have to store item data in
2381variables and recreate the items.
2382
2383Notice that the variables this command generates are all local and numeric.
2384
2385---------------------------------------
2386
2387*cardscnt()
2388
2389This function will return the number of cards inserted into the weapon currently
2390equipped on the invoking character.
2391While this function was meant for item scripts, it will work outside them:
2392
2393    if (cardscnt()==4) mes "So you've stuck four cards into that weapon, think you're cool now?";
2394
2395---------------------------------------
2396
2397*getrefine()
2398
2399This function will return the number of plusses the weapon currently equipped on
2400the invoking character has been refined for.
2401While this function was meant for item scripts, it will work outside them:
2402
2403    if (getrefine()==10) mes "Wow. That's a murder weapon.";
2404
2405---------------------------------------
2406
2407*getnameditem(<item id>,"<name to inscribe>");
2408*getnameditem("<item name>","<name to inscribe>");
2409
2410This function is equivalent to using 'getitem', however, it will not just give
2411the character an item object, but will also inscribe it with a specified
2412character's name. You may not inscribe items with arbitrary strings, only with
2413names of characters that actually exist. While this isn't said anywhere
2414specifically, apparently, named items may not have cards in them, slots or no -
2415these data slots are taken by the character ID who's name is inscribed. Only one
2416remains free and it's not quite clear if a card may be there.
2417
2418This function will return 1 if an item was successfully created and 0 if it
2419wasn't for whatever reason. Like 'getitem', this function will also accept an
2420'english name' from the item database as an item name and will return 0 if no
2421such item exists.
2422
2423---------------------------------------
2424
2425*getitemslots(<item ID>)
2426
2427This function will look up the item with the specified ID number in the database
2428and return the number of slots this kind of items has - 0 if they are not
2429slotted. It will also be 0 for all non-equippable items, naturally, unless
2430someone messed up the item database. It will return -1 if there is no such item.
2431
2432---------------------------------------
2433
2434*getiteminfo(<item ID>,<type>)
2435
2436This function will look up the item with the specified ID number in the database
2437and return the info set by TYPE argument.
2438It will return -1 if there is no such item.
2439
2440Valid types are:
2441        0 - Buy Price; 1 - Sell Price; 2 - Item Type;
2442        3 - maxchance (Max drop chance of this item e.g. 1 = 0.01% , etc..
2443                if = 0, then monsters don't drop it at all (rare or a quest item)
2444                if = 10000, then this item is sold in NPC shops only
2445        4 - sex; 5 - equip; 6 - weight; 7 - atk; 8 - def; 9 - range;
2446        10 - slot; 11 - look; 12 - elv; 13 - wlv;
2447
2448Check sample in nps\sample\getiteminfo.txt
2449
2450---------------------------------------
2451
2452*getequipcardid (<equipment slot>,<card slot>);
2453
2454Returns value from equipped item slot in the indicated slot:
2455
2456getequipcardid(num,slot)
2457
2458where:
2459        num = equip position slot
2460        slot = 0,1,2,3 (Card Slot N)
2461
2462This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced) it's useful
2463when you want to check item cards or if it's signed. Useful for such quests as
2464"Sign this refined item with players name" etc;
2465        Hat[0] +4 -> Player's Hat[0] +4
2466       
2467--------------------------------------
2468
2469*getitemslots (<item id>);
2470
2471Returns the amount of slots the item has.
2472
2473Example(s):
2474
2475//@slots now has the amount of slots of the item with ID 1205.
2476        set @slots, getItemSlots(1205);
2477       
2478--------------------------------------
2479//
24802,1.- End of item-related commands.
2481//
2482---------------------------------------
2483
2484*getmapxy("<variable for map name>",<variable for x>,<variable for y>,<type>{,"<search string>"})
2485
2486This function will locate a character object, NPC object or pet's coordinates
2487and place their coordinates into the variables specified when calling it. It
2488will return 0 if the search was successful, and -1 if the parameters given were
2489not variables or the search was not successful.
2490
2491Type is the type of object to search for:
2492
2493  0 - Character object
2494  1 - NPC object
2495  2 - Pet object
2496  3 - Monster object.
2497 
2498While 3 is meant to look for a monster object, no searching will be done if you
2499specify type 3, and the function will always return -1.
2500
2501The search string is optional. If it is not specified, the location of the
2502invoking character will always be returned for types 0 and 2, the location of
2503the NPC running this function for type 1.
2504If a search string is specified, for types 0 and 1, the character or NPC with
2505the specified name will be located. If type is 3, the search will locate the
2506current pet of the character who's name is given in the search string, it will
2507NOT locate a pet by name.
2508
2509What a mess. Example, a working and tested one now:
2510
2511    prontera,164,301,3%TAB%script%TAB%Meh%TAB%730,{
2512        mes "My name is Meh. I'm here so that Nyah can find me.";
2513        close;
2514    }
2515
2516    prontera,164,299,3%TAB%script%TAB%Nyah%TAB%730,{
2517        mes "My name is Nyah.";
2518        mes "I will now search for Meh all across the world!";
2519        if (getmapxy(@mapname$,@mapx,@mapy,1,"Meh")!=0) goto Notfound;
2520        mes "And I found him on map "+@mapname$+" at X:"+@mapx+" Y:"+@mapy+" !";
2521        close;
2522    Notfound:
2523        mes "I can't seem to find Meh anywhere!";
2524        close;
2525   }
2526   
2527Notice that NPC objects disabled with 'disablenpc' will still be located.
2528
2529---------------------------------------
2530
2531*getgmlevel()
2532
2533This function will return the GM level of the account to which the invoking
2534character belongs. If this is somehow executed from a console command, 99 will
2535be returned, and 0 will be returned if the account has no GM level.
2536
2537This allows you to make NPC's only accessable for certain GM levels, or behave
2538specially when talked to by GMs.
2539
2540   if (getgmlevel()) mes "What is your command, your godhood?";
2541   if (getgmlevel()) goto Wherever;
2542
2543---------------------------------------
2544
2545*gettimetick(<tick type>)
2546
2547This function will return the system time in UNIX epoch time (if tick type is 2)
2548or the time since the start of the current day in seconds if tick type is 1.
2549Passing 0 will make it return the server's tick, which is a measurement in
2550milliseconds used by the server's timer system. The server's tick is an
2551unsigned int which loops every ~50 days.
2552
2553Just in case you don't know, UNIX epoch time is the number of seconds elapsed
2554since 1st of January 1970, and is useful to see, for example, for how long the
2555character has been online with OnPCLoginEvent and OnPCLogoutEvent, which could allow
2556you to make an 'online time counted for conviction only' jail script.
2557
2558---------------------------------------
2559
2560*gettime(<type>)
2561
2562This function will return specified information about the current system time.
2563
25641 - Seconds (of a minute)
25652 - Minutes (of an hour)
25663 - Hour (of a day)
25674 - Week day (0 for Sunday, 6 is Saturday)
25685 - Day of the month.
25696 - Number of the month.
25707 - Year.
25718 - Day of the year.
2572
2573It will only return numbers.
2574
2575    if (gettime(4)==6) mes "It's a Saturday. I don't work on Saturdays.";
2576
2577---------------------------------------
2578
2579*gettimestr(<format string>,<max length>)
2580
2581This function will return a string containing time data as specified by the
2582format string.
2583
2584This uses the C function 'strfmtime', which obeys special format characters. For
2585a full description see, for example, the description of 'strfmtime' at
2586http://www.delorie.com/gnu/docs/glibc/libc_437.html
2587All the format characters given in there should properly work.
2588Max length is the maximum length of a time string to generate.
2589
2590The example given in eAthena sample scripts works like this:
2591
2592  mes gettimestr("%Y-%m/%d %H:%M:%S",21);
2593 
2594This will print a full date and time like 'YYYY-MM/DD HH:MM:SS'.
2595
2596---------------------------------------
2597
2598*getusers(<type>)
2599
2600This function will return a number of users on a map or the whole server. What
2601it returns is specified by Type.
2602
2603Type is a bitmask, add up to get the effects you want:
2604
2605  8 - This will count all characters on the same map as the current NPC.
2606      (By default, it will count people on the same map as the character)
2607  7 - Return the amount of players for the entire server.
2608      (By default, only the players on the map will be counted.)
2609     
2610So 'getusers(0)' will return the number of characters on the same map as the
2611invoking character, while 'getusers(7)' will give the count for entire server.
2612
2613---------------------------------------
2614
2615*getmapusers("<map name>")
2616
2617This function will return the number of users currently located on the specified
2618map.
2619
2620Currently being used in the PVP scripts to check if a PVP room is full of not,
2621if the number returned it equal to the maximum allowed it will not let you
2622enter.
2623
2624---------------------------------------
2625
2626*getareausers("<map name>",<x1>,<y1>,<x2>,<y2>)
2627
2628This function will return the count of connected characters which are located
2629within the specified area - an x1/y1-x2/y2 square on the specified map.
2630
2631This is useful for maps that are split into many buildings, such as all the
2632"*_in" maps, due to all the shops and houses.
2633
2634---------------------------------------
2635
2636*getusersname;
2637
2638This command will give the invoking character a list of names of the connected
2639characters (including themselves) into an NPC script message window (see 'mes')
2640paging it by 10 names as if with the 'next' command.
2641
2642You need to put a 'close' after that yourself.
2643
2644---------------------------------------
2645\\
26462,2.- Guild-related commands
2647\\
2648---------------------------------------
2649*getguildname(<guild id>)
2650
2651This function returns a guild's name given an ID number. If there is no such
2652guild, "null" will be returned;
2653
2654   // Would print what ever guild 10007 is, in my case this would return "AlcoROhics"
2655   mes "The guild "+GetGuildName(10007)+" are all nice people.";
2656
2657   // This will do the same as above:
2658   set @var,10007;
2659   mes "We have some friends in "+GetGuildName(@var)+", you know.";
2660
2661This is used all over the WoE controlling scripts. You could also use it for a
2662guild-based event.
2663
2664---------------------------------------
2665
2666*getguildmaster(<guild id>)
2667
2668This function return the name of the master of the guild which has the specified
2669ID number. If there is no such guild, "null" will be returned.
2670
2671// Would return the guild master of guild 10007, whatever that might be.
2672// In this example it would return "MissDjax" cause she owns "AlcoROhics" (10007)
2673    mes getguildmaster(10007)+" runs "+getguildname(10007);
2674
2675Can be used to check if the character is the guildmaster of the specified guild.
2676
2677Maybe you want to make a room only guildmasters can enter:
2678
2679        set @GID,getcharid(2);
2680        if(@GID==0) goto L_NoGuild;
2681        if(strcharinfo(0)==getguildmaster(@GID)) goto L_GuildMaster;
2682        mes "Sorry you don't own the guild you are in";
2683        close;
2684    L_NoGuild:
2685        mes "Sorry you are not in a guild";
2686        close;
2687    L_GuildMaster:
2688        mes "Welcome guild master of "+GetGuildName(@GID);
2689        close;
2690
2691
2692---------------------------------------
2693
2694*getguildmasterid(<guild id>)
2695
2696This function will return the character ID number of the guildmaster of the
2697guild specified by the ID. 0 if the character is not a guildmaster of any guild.
2698
2699---------------------------------------
2700
2701*getcastlename("<map name>")
2702
2703This function returns the name of the castle when given the map name for that
2704castle. The data is read from 'db/castle_db.txt'.
2705
2706---------------------------------------
2707
2708*getcastledata("<map name>",<type of data>)
2709*setcastledata "<map name>",<type of data>,<value>;
2710
2711This function returns the castle ownership information for the castle referred
2712to by it's map name. Castle information stored in 'save\castle.txt' for the TXT
2713version of the server and in 'guild_castle' table for the SQL version.
2714
2715Valid types of data are:
2716
2717 0 - Will make the map server request the castle data from the char server, and
2718     always return 0. This, apparently, will also cause indirectly the execution
2719     of an 'OnAgitInit:' event mentioned at the beginning of this document.
2720 1 - Guild ID
2721 2 - Castle Economy score.
2722 3 - Castle Defence score.
2723 4 - Number of times the economy was invested in today.
2724 5 - Number of times the defence was invested in today.
2725 9 - Will return 1 if a Kafra was hired for this castle, 0 otherwise.
272610 - Is 1 if the 1st guardian is present (Soldier Guardian)
272711 - Is 1 if the 2nd guardian is present (Soldier Guardian)
272812 - Is 1 if the 3rd guardian is present (Soldier Guardian)
272913 - Is 1 if the 4th guardian is present (Archer Guardian)
273014 - Is 1 if the 5th guardian is present (Archer Guardian)
273115 - Is 1 if the 6th guardian is present (Knight Guardian)
273216 - Is 1 if the 7th guardian is present (Knight Guardian)
273317 - Is 1 if the 8th guardian is present (Knight Guardian)
2734
273518-25 types of data will return current hit point values for guardians 1-8
2736respectively.
2737
2738The 'setcastledata' command will behave identically, but instead of returning
2739values for the specified types of accessible data, it will alter them and cause
2740them to be sent to the char server for storage. Data type of 0 won't do
2741anything, obviously.
2742
2743---------------------------------------
2744
2745*getgdskilllv(<guild id>,<skill id>)
2746*getgdskilllv(<guild id>,"<skill name>")
2747
2748This function returns the level of the skill <skill id> of the guild <guild id>.
2749If the guild does not have that skill, 0 is returned.
2750If the guild does not exist, -1 is returned.
2751Refer to 'db/skill_db.txt' for the full list of skills. (GD_* are guild skills)
2752
2753---------------------------------------
2754
2755*requestguildinfo <guild id>,"<event label>";
2756
2757This command requests the guild data from the char server and merrily continues
2758with the execution. Whenever the guild information becomes available (which
2759happens instantly if the guild information is already in memory, or later, if it
2760isn't and the map server has to wait for the char server to reply) it will run
2761the specified event as in a 'doevent' call.
2762
2763---------------------------------------
2764
2765*getmapguildusers <mapname>,<guild id>;
2766
2767Returns the amount of persons from the given guild that are on the given map.
2768Example(s):
2769
2770//Will set the @persons variable to the amount of persons from the guild
2771//which ID's = 10 and are at prontera.
2772
2773        set @persons,getMapGuildUsers "prontera",10;
2774
2775---------------------------------------
2776//
27772,2.- End of guild-related commands
2778//
2779---------------------------------------
2780
2781*getskilllv(<skill id>)
2782*getskilllv("<skill name>")
2783
2784This function returns the level of the specified skill that the invoking
2785character has. If they don't have the skill, 0 will be returned. The full list
2786of character skills is available in 'db/skill_db.txt'.
2787
2788There are two main uses for this function, it can check whether the character
2789has a skill or not, and it can tell you if the level is high enough.
2790
2791Example 1:
2792
2793        f (getskilllv(152)) goto L_HasSkillThrowStone;
2794        mes "You don't have Throw Stone";
2795        close;
2796    L_HasSkillThrowStone:
2797        mes "You have got the skill Throw Stone";
2798        close;
2799
2800Example 2:
2801
2802        if (getskilllv(28) >= 5) goto L_HasSkillHeallvl5orMore;
2803        if (getskilllv(28) == 10) goto L_HasSkillHealMaxed;
2804        mes "You heal skill is below lvl 5";
2805        close;
2806    L_HasSkillHeallvl6orMore:
2807        mes "Your heal lvl is 5 or more";
2808        close;
2809    L_HasSkillHealMaxed:
2810        mes "Your heal lvl has been maxed";
2811        close;
2812
2813---------------------------------------
2814
2815*getskilllist;
2816
2817This command sets a bunch of arrays with a complete list of skills the
2818invoking character has. Here's what you get:
2819
2820@skilllist_id[]   - skill ids.
2821@skilllist_lv[]   - skill levels.
2822@skilllist_flag[] - see 'skill' for the meaning of skill flags.
2823@skilllist_count  - number of skills in the above arrays.
2824
2825While 'getskillv' is probably more useful for most situations, this is the
2826easiest way to store all the skills and make the character something else for a
2827while. Advanced job for a day? :) This could also be useful to see how many
2828skills a character has.
2829
2830---------------------------------------
2831
2832*getpetinfo(<type>)
2833
2834This function will return pet information for the pet the invoking character
2835currently has active. Valid types are:
2836
2837 0 - Unique pet ID number as stored by the char server and distinguishing it
2838     from all other pets the characters actually have. This value is currently
2839     useless, at most you can use it to tell pets apart reliably.
2840 1 - Pet class number as per 'db/pet_db.txt' - will tell you what kind of a pet it
2841     is.
2842 2 - Pet name. Will return "null" if there's no pet.
2843 3 - Pet friendly level (intimacy score). 1000 is full loyalty.
2844 4 - Pet hungry level. 100 is completely full.
2845 5 - Pet rename flag. 0 means this pet has not been named yet.
2846---------------------------------------
2847
2848*gethominfo(<type>)
2849
2850This function works as a direct counterpart of 'getpetinfo':
2851 0 - Homunculus unique ID
2852 1 - Homunculus Class
2853 2 - Name
2854 3 - Friendly level (intimacy score). 100000 is full loyalty.
2855 4 - Hungry level. 100 is completely full.
2856 5 - Rename flag. 0 means this homunculus has not been named yet.
2857 6 - Homunculus level
2858---------------------------------------
2859
2860
2861*petstat(<flag>)
2862
2863Returns current pet status, all are integers except name.
2864Returns 0 or "" if the player doesn't have pets.
2865
2866Flags usable >>
2867PET_CLASS
2868PET_NAME
2869PET_LEVEL
2870PET_HUNGRY
2871PET_INTIMATE
2872
2873Example:
2874set @i, petstat(PET_CLASS);
2875
2876
2877---------------------------------------
2878
2879*getmonsterinfo(<mob ID>,<type>)
2880
2881This function will look up the monster with the specified ID number in the
2882mob database and return the info set by TYPE argument.
2883It will return -1 if there is no such monster (or the type value is invalid),
2884or "null" if you requested the monster's name.
2885
2886Valid types are listed in const.txt:
2887        MOB_NAME        0               MOB_LV  1
2888        MOB_MAXHP       2               MOB_BASEEXP     3
2889        MOB_JOBEXP      4               MOB_ATK1        5
2890        MOB_ATK2        6               MOB_DEF 7
2891        MOB_MDEF        8               MOB_STR 9
2892        MOB_AGI         10              MOB_VIT         11
2893        MOB_INT         12              JOB_DEX         13
2894        MOB_LUK         14              MOB_RANGE       15
2895        MOB_RANGE2      16              MOB_RANGE3      17
2896        MOB_SIZE        18              MOB_RACE        19
2897        MOB_ELEMENT     20              MOB_MODE        21
2898
2899Check sample in nps\sample\getmonsterinfo.txt
2900
2901---------------------------------------
2902
2903*getmapmobs("<map name>")
2904
2905This function will return the total count of monsters currently located on the
2906specified map. If the map name is given as "this", the map the invoking
2907character is on will be used. If the map is not found, or the invoker is not a
2908character while the map is "this", it will return -1.
2909
2910---------------------------------------
2911
2912*getstrlen("<string>")
2913
2914This function will return the length of the string given as an argument. It is
2915useful to check if anything input by the player exceeds name length limits and
2916other length limits and asking them to try to input something else.
2917
2918---------------------------------------
2919
2920*skillpointcount;
2921
2922Returns the total amount of skill points a character posesses (SkillPoint+SP's used in skills)
2923This command can be used to check the currently attached characters total amount of skillpoints.
2924This means the skillpoints used in skill are counted, and added to SkillPoints (number of skill points not used).
2925
2926Example:
2927
2928//This will set the temp character variable @skillPoints to the amount of skillpoints,
2929//and then tell the player the value.
2930        set @skillPoints, skillPointCount();
2931        mes "You have "+@skillPoints+" skillpoints in total!";
2932       
2933//Self-explanatory... :P
2934        if (skillPointCount() > 20)
2935                mes "Wow, you have more then 20 Skill Points in total!";
2936
2937---------------------------------------
2938
2939*getscrate(<effect type>,<base rate>{,<target ID number>})
2940
2941This function will return the chance of a status effect affecting the invoking
2942character, in percent, modified by the their current defense against said
2943status. The 'base rate' is the base chance of the status effect being inflicted,
2944in percent.
2945
2946    if (rand(100) > getscrate(Eff_Blind, 50)) goto BlindHimNow;
2947 
2948You can see the full list of available effect types you can possibly inflict in
2949'db/const.txt' under 'Eff_'.
2950
2951It is pretty certain that addressing the target by an ID number will not
2952currently work due to a bug.
2953
2954---------------------------------------
2955
2956========================
2957|3.- Checking commands.|
2958========================
2959-------------------------
2960
2961*playerattached;
2962
2963Returns the ID of the player currently attached to the script. It will return
29640 if noone is attached, or if the attached player no longer exists on the map
2965server. It is wise to check for the attached player in script functions that
2966deal with timers as there's no guarantee the player will still be logged on
2967when the timer triggers. Note that the ID of a player is actually their
2968account ID.
2969
2970-------------------------
2971
2972*isloggedin(<account id>{,<char id>});
2973
2974This function returns 1 if the specified account is logged in and 0 if they
2975aren't. You can also pass the char_id to check for both account and char id.
2976
2977---------------------------------------
2978
2979*checkweight(<item id>,<amount>)
2980*checkweight("<item name>",<amount>)
2981
2982This function will compute and return 1 if the total weight of a specified
2983number of specific items does not exceed the invoking character's carrying
2984capacity, and 0 otherwise. It is important to see if a player can carry the
2985items you expect to give them, failing to do that may open your script up to
2986abuse or create some very unfair errors.
2987
2988This function, in addition to checking to see if the player is capable of
2989holding a set amount of items, also ensures the player has room in their
2990inventory for the item(s) they will be receciving.
2991
2992Like 'getitem', this function will also accept an 'english name' from the
2993database as an argument.
2994
2995    checkweight(502,10) // 10 apples
2996
2997        if (checkweight(502,10) == 0 ) goto L_OverWeight;
2998        getitem 502,10;
2999        close;
3000    L_OverWeight:
3001        mes "Sorry you cannot hold this ammount of apples";
3002        close;
3003
3004Or to put this another way:
3005
3006        if (checkweight("APPLE",10)) goto L_Getapples;
3007        mes "Sorry you cannot hold this ammount of apples";
3008        close;
3009    L_Getapples:
3010        getitem 502,10;
3011        close;
3012
3013Both these examples have the same effect.
3014
3015---------------------------------------
3016
3017*basicskillcheck()
3018
3019This function will return the state of the configuration option
3020'basic_skill_check' in 'battle_athena.conf'. It returns 1 if the option is
3021enabled and 0 if it isn't. If the 'basic_skill_check' option is enabled, which
3022it is by default, characters must have a certain number of basic skill levels to
3023sit, request a trade, use emoticons, etc. Making your script behave differently
3024depending on whether the characters must actually have the skill to do all these
3025things might in some cases be required.
3026
3027---------------------------------------
3028
3029*checkoption(<option number>)
3030*checkoption1(<option number>)
3031*checkoption2(<option number>)
3032*setoption <option number>{,<flag>};
3033
3034The 'setoption' series of functions check for a so-called option that is set on
3035the invoking character. 'Options' are used to store status conditions and a lot
3036of other non-permanent character data of the yes-no kind. For most common cases,
3037it is better to use 'checkcart','checkfalcon','checkpeco' and other similar
3038functions, but there are some options which you cannot get at this way. They
3039return 1 if the option is set and 0 if the option is not set.
3040
3041Option numbers valid for the first (option) version of this command are:
3042
30430x1     - Sight in effect.
30440x2     - Hide in effect.
30450x4     - Cloaking in effect.
30460x8     - Cart number 1 present.
30470x10    - Falcon present.
30480x20    - Peco Peco present.
30490x40    - GM Perfect Hide in effect.
30500x80    - Cart number 2 present.
30510x100   - Cart number 3 present.
30520x200   - Cart number 4 present.
30530x400   - Cart number 5 present.
30540x800   - Orc head present.
30550x1000  - The character is wearing a wedding sprite.
30560x2000  - Ruwach is in effect.
30570x4000  - Chasewalk in effect.
30580x8000  - Flying or Xmas suit.
30590x10000 - Sighttrasher.
3060
3061Option numbers valid for the second version (opt1) of this command are:
3062
30631 - Petrified.
30642 - Frozen.
30653 - Stunned.
30664 - Sleeping.
30676 - Petrifying (the state where you can still walk)
3068
3069Option numbers valid for the third version (opt2) of this command are:
3070
30710x1  - Poisoned.
30720x2  - Cursed.
30730x4  - Silenced.
30740x8  - Signum Crucis (plays a howl-like sound effect, but otherwise no visible effects are displayed)
30750x10 - Blinded.
30760x80 - Deadly poisoned.
3077
3078Option numbers (except for opt1) are bitmasks - you can add them up to check
3079 for several states, but the functions will return true if at least one of them
3080 is in effect.
3081
3082'setoption' will set options on the invoking character. There are no second and
3083third versions of this command, so you can only change the values in the first
3084list (cloak, cart, ruwach, etc). if flag is 1 (default when omitted),
3085the option will be added to what the character currently has; if 0, the option is removed.
3086
3087This is definitely not a complete list of available option flag numbers. Ask a
3088core developer (or read the source: src/map/status.h) for the full list.
3089
3090---------------------------------------
3091
3092*setcart {<type>};
3093*checkcart()
3094
3095If <type> is 0 this command will remove the cart from the character.
3096Otherwise it gives the invoking character a cart. The cart given will be
3097cart number <type> and will work regardless of whether the character is a
3098merchant class or not.
3099Note: the character needs to have the skill MC_PUSHCART to gain a cart
3100
3101The accompanying function will return 1 if the invoking character has a cart
3102(any kind of cart) and 0 if they don't.
3103
3104    if (checkcart()) mes "But you already have a cart!";
3105
3106---------------------------------------
3107
3108*setfalcon {<flag>};
3109*checkfalcon()
3110
3111If <flag> is 0 this command will remove the falcon from the character.
3112Otherwise it gives the invoking character a falcon. The falcon will be there
3113regardless of whether the character is a hunter or not. It will (probably) not
3114have any useful effects for non-hunters though.
3115Note: the character needs to have the skill HT_FALCON to gain a falcon
3116
3117The accompanying function will return 1 if the invoking character has a falcon
3118and 0 if they don't.
3119
3120    if (checkfalcon()) mes "But you already have a falcon!";
3121
3122---------------------------------------
3123
3124*setriding {<flag>};
3125*checkriding()
3126
3127If <flag> is 0 this command will remove the mount from the character.
3128Otherwise it give the invoking character a PecoPeco (if they are a Knight
3129series class) or a GrandPeco (if they are a Crusader seriesclass). Unlike
3130'setfalcon' and 'setcart' this will not work at all if they aren't of a class
3131which can ride.
3132Note: the character needs to have the skill KN_RIDING to gain a mount
3133
3134The accompanying function will return 1 if the invoking character is riding a
3135bird and 0 if they don't.
3136
3137    if (checkriding()) mes "PLEASE leave your bird outside! No riding birds on the floor here!";
3138
3139---------------------------------------
3140
3141*checkvending ({"<player name>"})
3142*checkchatting ({"<Player Name>"})
3143
3144If the player's name is given, this command checks for that player
3145to be online and wether he/she is chatting or vending.
3146When no name is given, the attached player is used for checking.
3147Returns true or false (1 or 0) when the player is chatting/vending or not.
3148
3149Example(s):
3150if (checkVending("Aaron")) mes "Aaron is currently vending!";   
3151        //This will check if Aaron is vending, and if so, put a message in front
3152        //of the attached player saying Aaron is vending.
3153
3154if (checkChatting()) mes "You are currently chatting!";
3155        //This will check if you're in a chat room or not
3156       
3157---------------------------------------
3158
3159*agitcheck()
3160
3161This function will let you check whether the server is currently in WoE mode.
3162It will return 1 if the War of Emperium is on and 0 if it isn't.
3163
3164---------------------------------------
3165
3166*isnight()
3167*isday()
3168
3169These functions will return 1 or 0 depending on whether the server is in night
3170mode or day mode. 'isnight' returns 1 if it's night and 0 if it isn't, 'isday'
3171the other way around. They can be used interchangeably, pick the one you like
3172more:
3173
3174    // These two are equivalent:
3175    if (isday()) mes "I only prowl in the night.";
3176    if (isnight()!=1) mes "I only prowl in the night.";
3177
3178---------------------------------------
3179\\
31803,1.- Item-related commands
3181\\
3182---------------------------------------
3183*isequipped(<id>{,<id>{,<id>{,<id>}}})
3184
3185This function will return 1 if the invoking character has all of the item
3186IDs given equipped (if card IDs are passed, then it checks if the cards are
3187inserted into slots in the equipment they are currently wearing). Theorically
3188there is no limit to the number of items that may be tested for at the same time.
3189If even one of the items given is not equipped, 0 will be returned.
3190
3191    // (Poring,Santa Poring,Poporing,Marin)
3192    if (isequipped(4001,4005,4033,4196)) mes "Wow! You're wearing a full complement of possible poring cards!";
3193    // (Poring)
3194    if (isequipped(4001)) mes "A poring card is useful, don't you think?";
3195   
3196The function was meant for item scripts to support the cards released by Gravity
3197in February 2005, but it will work just fine in normal NPC scripts.
3198
3199---------------------------------------
3200
3201*isequippedcnt(<card id>{,<card id>{,<card id>{,<card id>}}})
3202
3203This function is similar to 'isequipped', but instead of 1 or 0, it will return
3204the number of cards in the list given that were found on the invoking character.
3205
3206    if (isequippedcnt(4001,4005,4033,4196)=4) mes "Finally got all four poring cards?";
3207
3208---------------------------------------
3209
3210*checkequipedcard(<card id>)
3211
3212This function will return 1 if the card specified by it's item ID number is
3213inserted into any equipment they have in their inventory, currently equipped or
3214not.
3215
3216---------------------------------------
3217
3218*getequipisidentify(<equipment slot>)
3219
3220This function will return 1 if an item in the specified equipment slot is
3221identified and 0 if it isn't. Since you can't even equip unidentified equipment,
3222there's a question of whether it can actually end up there, and it will normally
3223return 1 all the time if there is an item in this equipment slot.
3224Which is kinda pointless.
3225For a list of equipment slots see 'getequipid'.
3226
3227---------------------------------------
3228//
32293,1.- End of item-related commands
3230//
3231---------------------------------------
3232
3233==============================
3234|4.- Player-related commands.|
3235==============================
3236-------------------------
3237
3238*attachrid(<account ID>)
3239*detachrid;
3240
3241A 'RID' is an ID of a character who caused the NPC script to run, as has been
3242explained above in the introduction section. Quite a bit of commands want a RID
3243to work, since they wouldn't know where to send information otherwise. And in
3244quite a few cases the script gets invoked with a RID of zero (like through
3245OnTime special labels). If an NPC script needs this, it can attach a specified
3246character's id to itself. by calling the 'attachrid' function.
3247
3248'attachrid' returns 1 if the character was found online and 0 if it wasn't.
3249
3250This could also be used, while running in a script invoked by a character
3251through talking to an NPC, to mess with other characters.
3252Detaching the RID will make the RID of the script zero.
3253
3254---------------------------------------
3255
3256*rid2name(<rid>)
3257
3258Converts rid to name. Note: The player/monster/NPC must be online/enabled.
3259Good for PCKillEvent where you can convert 'killedrid' to the name of the player.
3260
3261Note: rid2name may not produce correct character names since rid = account id.
3262      It will return the current online character of the account only.
3263
3264---------------------------------------
3265
3266*message "<character name>","<message>";
3267
3268That command will send a message to the chat window of the character specified
3269by name. The text will also appear above the head of that character. It will not
3270be seen by anyone else.
3271
3272---------------------------------------
3273
3274*dispbottom "<message>";
3275
3276This command will send the given message into the invoking character's chat
3277window.
3278
3279---------------------------------------
3280
3281*warp "<map name>",<x>,<y>;
3282
3283This command will take the invoking character to the specifed map, and if
3284wanted, specified coordinates too, but these can be random.
3285
3286    warp "place",50,55;
3287
3288This would take them to X 50 Y 55 on the map called "place". If your X and Y
3289coordinates land on an unwalkable map square, it will send the warped character
3290to a random place. Same will happen if they are both zero:
3291
3292    warp "place",0,0;
3293
3294Notice that while warping people to coordinates 0,0 will normally get them into
3295a random place, it's not certain to always be so. Darned if I know where this is
3296actually coded, it might be that this happens because square 0,0 is unwalkable
3297on all official maps. If you're using custom maps, beware.
3298
3299There are also three special 'map names' you can use.
3300
3301"Random" will warp the player randomly on the current map.
3302"Save" and "SavePoint" will warp the player back to their savepoint.
3303
3304---------------------------------------
3305
3306*areawarp "<from map name>",<x1>,<y1>,<x2>,<y2>,"<to map name>",<x3>,<y3>;
3307
3308This command is similar to 'warp', however, it will not refer to the invoking
3309character, but instead, all characters within a specified area, defined by the
3310x1/y1-x2/y2 square, will be warped. Nobody outside the area will be affected,
3311including the activating character, if they are outside the area.
3312
3313    areawarp "place",10,10,120,120,"place2",150,150;
3314
3315Everyone that is in the area between X 10 Y 10 and X 120 Y 120, in a square
3316shape, on the map called "place", will be affected, and warped to "place2" X 150
3317Y 150
3318
3319    areawarp "place",10,10,120,120,"place2",0,0;
3320
3321By using ,0,0; as the destination coordinates it will take all the characters in
3322the affected area to a random set of co-ordinates on "place2".
3323
3324Like 'warp', areawarp will also explicitly warp characters randomly into the
3325current map if you give the 'to map name' as "Random".
3326
3327See also 'warp'.
3328
3329---------------------------------------
3330 
3331*warpparty "<mapname>",<x>,<y>,<party_id>;
3332 
3333Warps a party to specified map and coordinate given the party ID, which you can get with
3334getcharid(1). You can also request another party id given a member's name with getcharid(1,<player_name>).
3335
3336You can use the following "map names" for special warping behaviour:
3337Random:       All party members are randomly warped in their current map (as if they
3338              all used a fly wing)
3339SavePointAll: All party members are warped to their respective save point.
3340SavePoint:    All party members are warped to the save point of the currently
3341              attached player (will fail if there's no player attached).
3342Leader:       All party members are warped to the leader's position. The leader must
3343              be online and in the current map-server for this to work.
3344
3345Example:
3346mes "[Party Warper]";
3347mes "Here you go!";
3348close2;
3349set @id,getcharid(1);
3350warpparty "prontera",150,100,@id;
3351close;
3352 
3353---------------------------------------
3354 
3355*warpchar "<mapname>",<x>,<y>,<char_id>;
3356 
3357Warps another player to specified map and coordinate given the char id, which you can get with
3358getcharid(0,<player_name>). Obviously this is useless if you want to warp the same player that
3359is executing this script, unless it's some kind of "chosen" script.
3360 
3361Example:
3362 
3363warpchar "prontera",150,100,20000001;
3364 
3365---------------------------------------
3366 
3367*warpguild "<mapname>",<x>,<y>,<guild_id>;
3368 
3369Warps a guild to specified map and coordinate given the guild id, which you can get with
3370getcharid(2). You can also request another guild id given the member's name with getcharid(2,<player_name>).
3371 
3372Example:
3373 
3374warpguild "prontera",x,y,Guild_ID;
3375
3376---------------------------------------
3377
3378*warppartner("<map name>",<x>,<y>);
3379
3380This function will find the invoking character's marriage partner, if any, and
3381warp them to the map and coordinates given. Go kidnap that spouse. :) It will
3382return 1 upon success and 0 if the partner is not online, the character is not
3383married, or if there's no invoking character (no RID). 0,0 will, as usual,
3384normally translate to random coordinates.
3385
3386---------------------------------------
3387
3388*savepoint "<map name>",<x>,<y>;
3389*save "<map name>",<x>,<y>;
3390
3391This command saves where the invoking character will return to upon
3392'return to save point', if dead or in some other cases. The two versions are
3393equivalent. Map name, X coordinate and Y coordinate should be perfectly obvious.
3394This ignores any and all map flags, and can make a character respawn where no
3395teleportation is otherwise possible.
3396
3397    savepoint "place",350,75;
3398
3399---------------------------------------
3400
3401*heal <hp>,<sp>;
3402
3403This command will heal a set amount of HP and/or SP on the invoking character.
3404
3405    heal 30000,0; // This will heal 30,000 HP
3406    heal 0,30000; // This will heal 30,000 SP
3407    heal 300,300; // This will heal 300 HP and 300 SP
3408
3409This command just alters the hit points and spell points of the invoking
3410character and produces no other output whatsoever.
3411
3412---------------------------------------
3413
3414*itemheal <hp>,<sp>;
3415
3416This command works on the invoking character like 'heal', however, it is not
3417normally used in NPC scripts and will not work as expected there, but is used
3418all over in item scripts.
3419
3420Unlike 'heal', which just alters hp/sp and doesn't do anything else at all, this
3421command also shows healing animations for potions and other stuff, checks
3422whether the potion was made by a famous alchemist and alters the amount healed,
3423etc, etc. Since which kind of effect is shown depends on what item was used,
3424using it in an NPC script will not have a desired effect.
3425
3426There is also a nice example on using this with the 'rand' function, to give you
3427a random ammount of healing.
3428
3429    // This will heal anything thing from 100 to 150 HP and no SP
3430    itemheal rand(100,150),0;
3431
3432---------------------------------------
3433
3434*percentheal <hp>,<sp>;
3435
3436This command will heal the invoking character. It heals the character, but not
3437by a set value - it adds percent of their maximum HP/SP.
3438
3439    percentheal 100,0; // This will heal 100% HP
3440    percentheal 0,100; // This will heal 100% SP
3441    percentheal 50,50; // This will heal 50% HP and 50% SP
3442
3443So the amount that this will heal will depend on the total ammount of HP or SP
3444you have maximum. Like 'heal', this will not call up any animations or effects.
3445
3446---------------------------------------
3447
3448*recovery;
3449
3450This command will revive and restore full HP and SP to all characters currently
3451connected to the server.
3452
3453---------------------------------------
3454
3455*jobchange <job number>{,<upper flag>};
3456
3457This command will change the job class of the invoking character.
3458
3459    jobchange 1; // This would change your player into a Swordman
3460    jobchange 4002; // This would change your player into a Swordman High
3461
3462This command does work with numbers, but you can also use job names. The full
3463list of job names and the numbers they correspond to can be found in
3464'db/const.txt'.
3465
3466    // This would change your player into a Swordman
3467    jobchange Job_Swordman;
3468    // This would change your player into a Swordman High
3469    jobchange Job_Swordman_High;
3470
3471'upper flag' can alternatively be used to specify the type of job one changes
3472to. For example, jobchange Job_Swordman,1; will change the character to a high
3473swordsman. The upper values are:
3474-1 (or when omitted): preserves the current job type.
34750: Normal/standard classes
34761: High/Advanced classes
34772: Baby classes
3478
3479This command will also set a permanent character-based variable
3480'jobchange_level' which will contain the job level at the time right before
3481changing jobs, which can be checked for later in scripts.
3482
3483---------------------------------------
3484
3485*jobname (<job number>)
3486
3487This command retrieves the name of the given job using the msg_athena entries 550->650.
3488
3489                mes "[Kid]";
3490                mes "I never thought I'd met a "+jobname(Class)+" here of all places.";
3491                close;
3492
3493---------------------------------------
3494
3495*eaclass ({<job number>})
3496
3497This commands returns the "eA job-number" corresponding to the given class (if none is given, it returns uses
3498the invoking player's class as argument). The eA job-number is also a class number system, but it's one that
3499comes with constants which make it easy to convert among classes. The command will return -1 if you pass it a
3500job number which doesn't has a eA Job value equivalent.
3501
3502        set @eac, eaclass();
3503        if ((@eac&EAJ_BASEMASK) == EAJ_SWORDMAN)
3504                mes "You must be a swordman, knight, crusader, paladin, high swordman, lord knight, baby swordman,";
3505                mes "baby knight or baby crusader.";
3506        if (@eac&EAJL_UPPER)
3507                mes "You are a rebirth job.";
3508        if ((@eac&EAJ_UPPERMASK) == EAJ_SWORDMAN)
3509                mes "You must be a Swordman, Baby Swordman or High Swordman.";
3510
3511For more information on the eA Job System, see the docs/ea_job_system.txt file.
3512
3513---------------------------------------
3514*roclass <job number> {,<gender>}
3515
3516Does the opposite of eaclass. That is, given a eA Job class, it returns which is the corresponding RO class number.
3517A gender is required because both Bard and Dancers share the same eA Job value (EAJ_BARDDANCER), if it isn't given, the
3518gender of the executing player is taken (if there's no player running the script, male will be used by default).
3519The command returns -1 when there isn't a valid class to represent the required job (for example, if you try to get the
3520baby version of a Taekwon class).
3521
3522        set @eac, eaclass();
3523        //Check if class is already rebirth
3524        if (@eac&EAJL_UPPER) {
3525                mes "You look strong.";
3526                close;
3527        }
3528        set @eac, roclass(@eac|EAJL_UPPER);
3529        //Check if class has a rebirth version
3530        if (@eac != -1) {
3531                mes "Bet you can't wait to become a "+jobname(@eac)+"!";
3532                close;
3533        }
3534
3535---------------------------------------
3536
3537*changebase <job ID number>;
3538
3539This will change the appearance of the invoking character to that of a specified
3540job class. Nothing but appearance will change. This command is used in item
3541scripts for "Wedding Dress" and "Tuxedo" so the character like job 22, which is
3542the job number of the wedding sprites.
3543
3544It would be entered in the equip bonus section of an item
3545
35462338,Wedding_Dress,Wedding Dress,5,43000,,500,,0,,0,119529470,7,0,16,,0,1,0,{ bonus bMdef,15; changebase 22; }
3547
3548This command only works when inside item scripts.
3549
3550---------------------------------------
3551
3552*classchange <view id>,<type>;
3553
3554This command is very ancient, it's origins are clouded in mystery.
3555It will send a 'display id change' packet to everyone in the immediate area of
3556the NPC object, which will supposedly make the NPC look like a different sprite,
3557an NPC sprite ID, or a monster ID. This effect is not stored anywhere and will
3558not persist (Which is odd, cause it would be relatively easy to make it do so)
3559and most importantly, will not work at all since this command was broken with
3560the introduction of advanced classes. The code is written with the assumption
3561that the lowest sprite IDs are the job sprites and the anything beyond them is
3562monster and NPC sprites, but since the advanced classes rolled in, they got the
3563ID numbers on the other end of the number pool where monster sprites float.
3564
3565As a result it is currently impossible to call this command with a valid view
3566id. It will do nothing whatsoever if the view ID is below 4047. Getting it to
3567run will actually just crash the client.
3568
3569It could be a real gem if it can be gotten to actually do what it's supposed to
3570do, but this will only happen in a later SVN revision.
3571
3572---------------------------------------
3573
3574*changesex;
3575
3576This command will change the gender for the attached character's account. If it
3577was male, it will become female, if it was female, it will become male. The
3578change will be written to the character server, but there is no way to send this
3579information to the client, so the player will continue to see their character as
3580the gender it previously was. What the other players will see before the
3581relogin is not clear.
3582
3583If the character currently connected when this command was invoked was a
3584Dancer/Gypsy or Bard/Clown, they will become a Swordman upon 'changesex'.
3585Whatever happens to their skills is not clear. Whatever happens if another
3586character on the same account was a gender-specific class is not clear either,
3587but it's likely that the client will have serious issues with that, since no
3588other characters on the same account will get altered.
3589
3590There's good reasons to be very careful when using this command.
3591
3592---------------------------------------
3593
3594*getexp <base xp>,<job xp>;
3595
3596This command will give the invoking character a specified number of base and job
3597experience points. Can be used as a quest reward. Negative values won't work.
3598
3599    getexp 10000,5000;
3600
3601You can also use the "set" command with the constants defined in 'db/const.txt':
3602
3603    // These 2 combined has the same effect as the above command
3604    set BaseExp,BaseExp+10000;
3605    set JobExp,JobExp+5000;
3606
3607You can also reduce the ammount of experience points:
3608
3609    set BaseExp,BaseExp-10000;
3610
3611Note that 'getexp' is now subject to the 'quest_exp_rate' config option, which
3612adjusts the gained value. If you want to bypass this, use the 'set' method.
3613
3614---------------------------------------
3615
3616*setlook <look type>,<look value>;
3617
3618This command will alter the look data for the invoking character. It is used
3619mainly for changing the palette used on hair and clothes, you specify which look
3620type you want to change, then the palette you want to use. Make sure you specify
3621a palette number that exists/is usable by the client you use.
3622
3623    // This will change your hair(6), so that it uses palette 8, what ever your
3624    // palette 8 is your hair will use that colour
3625
3626    setlook 6,8;
3627
3628    // This will change your clothes(7), so they are using palette 1, whatever
3629    // your palette 1 is, your clothes will then use that set of colours.
3630   
3631    setlook 7,1;
3632
3633Here are the possible look types:
3634 
3635 0 - Base sprite
3636 1 - Hairstyle
3637 2 - Weapon
3638 3 - Head bottom
3639 4 - Head top
3640 5 - Head mid
3641 6 - Hair color
3642 7 - Clothes color
3643 8 - Shield
3644 9 - Shoes
3645
3646Whatever 'shoes' means is anybody's guess, ask Gravity - the client does nothing
3647with this value. It still wants it from the server though, so it is kept, but
3648normally doesn't do a thing.
3649 
3650Only the look data for hairstyle, hair color and clothes color are saved to the
3651char server's database and will persist. The rest freely change as the character
3652puts on and removes equipment, changes maps, logs in and out and otherwise you
3653should not expect to set them. In fact, messing with them is generally
3654hazardous, do it at your own risk, it is not tested what will this actually do -
3655it won't cause database corruption and probably won't cause a server crash, but
3656it's easy to crash the client with just about anything unusual.
3657
3658However, it might be an easy way to quickly check for empty view IDs for
3659sprites, which is essential for making custom headgear.
3660
3661Since a lot of people have different palettes for hair and clothes, it's
3662impossible to tell you what all the colour numbers are. If you want a serious
3663example, there is a Stylist script inside the default eAthena installation that
3664you can look at, this may help you create a Stylist of your own:
3665'custom\dye.txt'
3666
3667---------------------------------------
3668\\
36694,1.- Item-related commands
3670\\
3671---------------------------------------
3672
3673*getitem <item id>,<amount>{,<account ID>};
3674*getitem "<item name>",<amount>{,<account ID>};
3675
3676This command will give a specific amount of specified items to the target
3677character. If the character is not online, nothing will happen.
3678If <character ID> is not specified, items will be created in the invoking
3679character inventory instead.
3680
3681In the first and most commonly used version of this command, items are
3682referred to by their database ID number found inside 'db/item_db.txt'.
3683
3684    getitem 502,10 // The person will receive 10 apples
3685    getitem 617,1  // The person will receive 1 Old Violet Box
3686
3687Giving an item ID of -1 will give a specified number of random items from the
3688list of those that fall out of Old Blue Box. Unlike in all other cases, these
3689will be unidentified, if they turn out to be equipment. This is exactly what's
3690written in the Old Blue Box's item script.
3691
3692Other negative IDs also correspond to other random item generating item tables:
3693
3694Giving an item ID of -2 will produce the effects of Old Violet Box.
3695Giving an item ID of -3 will produce the effects of Old Card Album.
3696Giving an item ID of -4 will produce the effects of Gift Box.
3697Giving an item ID of -5 will produce the effects of Worn Out Scroll, which, in
3698current SVN, drops only Jellopies anyway.
3699
3700This transaction is logged if the log script generated transactions option is
3701enabled.
3702
3703You may also create an item by it's name in the 'english name' field in the
3704item database:
3705
3706    getitem "RED_POTION",10;
3707
3708Which will do what you'd expect. If it can't find that name in the database,
3709apples will be created anyway. It is often a VERY GOOD IDEA to use it like this.
3710
3711This is used in pretty much all NPC scripts that have to do with items and
3712quite a few item scripts. For more examples check just about any official script.
3713
3714---------------------------------------
3715
3716*getitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};
3717*getitem2 "<Item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};
3718
3719This command will give an amount of specified items to the invoking character.
3720If an optional character ID is specified, and that character is currently
3721online, items will be created in their inventory instead. If they are not
3722online, nothing will happen. It works essentially the same as 'getitem' (it even
3723works for negative ID numbers the same way, which is kinda silly) but is a lot
3724more flexible, since it allows you to give the player an item altered with it's
3725specific properties.
3726
3727Those parameters that are different from 'getitem' are:
3728
3729identify    - Whether you want the item to be identified or not, 0 unidentified,
3730              1 identified.
3731refine      - For how many plusses will it be refined.
3732              It will not let you refine an item higher than +10, if you
3733              specify more it'll still be 10.
3734attribute   - Whether the item is broken (1) or not (0) and NOT an elemental
3735              attribute.
3736card1,2,3,4 - If you want a card compound to it, place the card ID number into
3737              the specific card slot. Card ID numbers also found in
3738              'db/item_db.txt'
3739
3740Card1-card4 values are also used to store name information for named items, as
3741well as the elemental property of weapons and armor. You can create a named item
3742in this manner, however, if you just need a named piece of standard equipment,
3743it is much easier to the 'getnameditem' function instead.
3744
3745You will need to keep these values if you want to destroy and then perfectly
3746recreate a named item, for this see 'getinventorylist'.
3747
3748If you still want to try creating a named item with this command because
3749'getnameditem' won't do it for you cause it's too limited, you can do it like
3750this. Careful, minor magic ahead.
3751
3752    // First, let's get an ID of a character who's name will be on the item.
3753    // Only an existing character's name may be there.
3754    // Let's assume our character is 'Adam' and find his ID.
3755   
3756    set @charid,getcharid(0,"Adam");
3757
3758    // Now we split the character ID number into two portions with a binary
3759    // shift operation. If you don't understand what this does, just copy it.
3760   
3761    set @card3, @charid & 65535;
3762    set @card4, @charid >> 16;
3763
3764    // If you're inscribing non-equipment, @card1 must be 254.
3765    // Arrows are also not equipment. :)
3766    set @card1,254;
3767   
3768    // For named equipment, card2 means the Star Crumbs and elemental
3769    // crystals used to make this equipment. For everything else, it's 0.
3770     
3771    set @card2,0;
3772   
3773    // Now, let's give the character who invoked the script some
3774    // Adam's Apples:
3775   
3776    getitem2 512,1,1,0,0,@card1,@card2,@card3,@card4;
3777
3778This wasn't tested with all possible items, so I can't give any promises,
3779experiment first before relying on it.
3780
3781To create equipment, continue this example it like this:
3782
3783    // We've already have card3 and card4 loaded with correct
3784    // values so we'll just set up card1 and card2 with data
3785    // for an Ice Stiletto.
3786
3787    // If you're inscribing equipment, @card1 must be 255.
3788    set @card1,255;
3789   
3790    // That's the number of star crumbs in a weapon.
3791    set @sc,2;
3792   
3793    // That's the number of elemental property of the weapon.
3794    set @ele,1;
3795
3796    // And that's the wacky formula that makes them into
3797    // a single number.   
3798    set @card2,@ele+((@sc*5)<<8);
3799
3800    // That will make us an Adam's +2 VVS Ice Stiletto:
3801   
3802    getitem2 1216,1,1,2,0,@card1,@card2,@card3,@card4;
3803
3804Experiment with the number of star crumbs - I'm not certain just how much will
3805work most and what it depends on. The valid element numbers are:
3806
3807 1 - Ice, 2 - Earth 3 - Fire 4 - Wind.
3808   
3809You can, apparently, even create duplicates of the same pet egg with this
3810command, creating a pet which is the same, but simultaneously exists in two
3811eggs, and may hatch from either, although, I'm not sure what kind of a mess will
3812this really cause.
3813
3814---------------------------------------
3815
3816* getnameditem <item name|item id>,<Character name|character ID>;
3817
3818-Note: there's a total of 4 possible combinations of this command.
3819E.g: item name and character name, or with character id, etc...
3820
3821Create a item signed with the given character's name.
3822This is the same as using the hard(ly) explained way with getitem2.
3823
3824The command returns 1 when the item is created succesfully, or 0 when failed.
3825Failure occurs when there is:
3826- no player attached
3827- Item name or ID is not valid
3828- The given character ID/name is offline.
3829
3830Example:
3831
3832//This will give the currently attached player a Aaron's Apple (if Aaron is online).
3833        getnameditem "Apple","Aaron";
3834       
3835//Self-explanatory (I hope).
3836        if (getnameitem("Apple,"Aaron")) {
3837                mes "You now have a Aaron's Apple!";
3838        }
3839
3840---------------------------------------
3841
3842*makeitem <item id>,<amount>,"<map name>",<X>,<Y>;
3843*makeitem "<item name>",<amount>,"<map name>",<X>,<Y>;
3844
3845This command will create an item lying around on a specified map in the
3846specified location.
3847
3848 itemid   - Found in 'db/item_db.txt'
3849 amount   - Amount you want produced
3850 map name - The map name
3851 X        - The X coordinate
3852 Y        - The Y coordinate.
3853
3854This item will still disappear just like any other dropped item. Like 'getitem',
3855it also accepts an 'english name' field from the database and creates apples if
3856the name isn't found.
3857If the map name is given as "this", the map the invoking character is on will be used.
3858
3859---------------------------------------
3860
3861*delitem <item id>,<amount>{,<account ID>};
3862*delitem "<item name>",<amount>{,<account ID>};
3863
3864This command will take a specified amount of items from the invoking character.
3865As all the item commands, this one uses the ID of the item found inside
3866'db/item_db.txt'. The items are destroyed - there is no way an NPC can simply
3867own items and have an inventory of them, other as by destroying and recreating
3868them when needed.
3869
3870    delitem 502,10 // The person will lose 10 apples
3871    delitem 617,1  // The person will lose 1 Old Violet Box
3872
3873It is always a good idea to to check if the player actually has the item before
3874you take it from them, Otherwise, you could try to delete items which the
3875players don't actually have, which won't fail and won't give an error message,
3876but might open up ways to exploit your script.
3877
3878Like 'getitem' this command will also accept an 'english name' field from the
3879database. If the name is not found, nothing will be deleted.
3880
3881---------------------------------------
3882
3883*delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};
3884*delitem2 "<Item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};
3885
3886This command will take a specified amount of items from the invoking character.
3887Check 'getitem2' to understand its expanded parameters.
3888
3889---------------------------------------
3890
3891*countitem(<item id>)
3892*countitem("<item name>")
3893
3894This function will return the number of items for the specified item ID that the
3895invoking character has in the inventory.
3896
3897    mes "[Item Checker]";
3898    mes "Hmmm, it seems you have "+countitem(502)+" apples";
3899    close;
3900
3901Like 'getitem', this function will also accept an 'english name' from the
3902database as an argument.
3903
3904If you want to state the number at the end of a sentence, you can do it by
3905adding up strings:
3906
3907    mes "[Item Checker]";
3908    mes "Hmmm, the total number of apples you are holding is "+countitem("APPLE");
3909    close;
3910   
3911---------------------------------------
3912
3913*countitem2(<item id>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>)
3914*countitem2("<item name>",<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>)
3915
3916Expanded version of 'countitem' function, used for created/carded/forged items.
3917
3918This function will return the number of items for the specified item ID and
3919other parameters that the invoking character has in the inventory.
3920Check 'getitem2' to understand the arguments of the function.
3921   
3922---------------------------------------
3923
3924*groupranditem <group id>;
3925
3926Returns the item_id of a random item picked from the group specified. The
3927different groups and their group number are specified in db/item_group_db.txt
3928
3929When used in conjunction with other functions, you can get a random item. For
3930example, for a random pet lure:
3931
3932getitem groupranditem(15),1;
3933
3934---------------------------------------
3935
3936*enable_items;
3937*disable_items;
3938
3939These commands enable item usage while an npc is running. When enable_items is
3940run, items can be used during scripts until disable_items is called.
3941To avoid possible exploits, when enable_items is invoked, it will only enable
3942item usage while running that script in particular. Note that if a different
3943script also calls enable_items, it will override the last call (so you may
3944want to call this command at the start of your script without assuming the
3945effect is still in effect).
3946
3947---------------------------------------
3948
3949*itemskill <skill id>,<skill level>;
3950*itemskill "<skill name>",<skill level>;
3951
3952This is a command meant for item scripts to replicate single-use skills. It will
3953not work properly in NPC scripts a lot of the time because casting a skill is
3954not allowed when there is a message window or menu on screen. If there isn't one
3955cause you've made sure to run this when they already closed it, it should work
3956just fine and even show a targeting pointer if this is a targeting skill.
3957
3958// When you use Anodyne, you will cast Endure(8) level 1,
3959// and "Endure" will appear above your head as you use it.
3960605,Anodyne,Anodyne,11,2000,0,100,,,,,10477567,2,,,,,{ itemskill 8,1; },{}
3961
3962
3963---------------------------------------
3964
3965*produce <item level>;
3966
3967This command will open a crafting window on the client connected to the invoking
3968character. The 'item level' is a number which determines what kind of a crafting
3969window will pop-up. You can see the full list of such item levels in
3970'db/produce_db.txt' which determines what can actually be produced.
3971The window will not be empty only if the invoking character can actually produce
3972the items of that type and has the appropriate raw materials in their inventory.
3973
3974Valid item levels are:
3975
3976 1   - Level 1 Weapons
3977 2   - Level 2 Weapons
3978 3   - Level 3 Weapons
3979 16  - Blacksmith's Stones and Metals
3980 32  - Alchemist's Potions
3981 64  - Whitesmith's Coins
3982 123 - Whitesmith's Nuggets
3983 256 - Assassin Cross's Deadly Poison
3984
3985---------------------------------------
3986
3987*successremovecards <equipment slot>;
3988
3989This command will remove all cards from the item found in the specified
3990equipment slot of the invoking character, create new card items and give them to
3991the character. If any cards were removed in this manner, it will also show a
3992success effect.
3993
3994---------------------------------------
3995
3996*failedremovecards <equipment slot>,<type>;
3997
3998This command will remove all cards from the item found in the specified
3999equipment slot of the invoking character. 'type' determines what happens to the
4000item and the cards:
4001
4002 0 - will destroy both the item and the cards.
4003 1 - will keep the item, but destroy the cards.
4004 2 - will keep the cards, but destroy the item.
4005 
4006Whatever the type is, it will also show a failure effect on screen.
4007
4008---------------------------------------
4009
4010*repair <broken item number>;
4011
4012This command repairs a broken peice of equipment, using the same list of broken
4013items as available through 'getbrokenid'.
4014
4015The official scripts seem to use the repair command as a function instead:
4016'repair(<number>)' but it returns nothing on the stack. Probably only Valaris,
4017who made it, can answer why is it so.
4018
4019---------------------------------------
4020
4021*successrefitem <equipment slot>;
4022
4023This command will refine an item in the specified equipment slot of the invoking
4024character by +1. For a list of equipment slots see 'getequipid'. This command
4025will not only add the +1, but also display a 'refine success' effect on the
4026character and put appropriate messages into their chat window. It will also give
4027the character fame points if a weapon reached +10 this way, even though these
4028will only take effect for blacksmith who will later forge a weapon.
4029
4030The official scripts seem to use the 'successrefitem' command as a function
4031instead: 'successrefitem(<number>)' but it returns nothing on the stack.
4032This is since jAthena, so probably nobody knows for sure why is it so.
4033
4034---------------------------------------
4035
4036*failedrefitem <equipment slot>;
4037
4038This command will fail to refine an item in the specified equipment slot of the
4039invoking character. The item will be destroyed. This will also display a 'refine
4040failure' effect on the character and put appropriate messages into their chat
4041window.
4042
4043The official scripts seem to use the 'failedrefitem' command as a function
4044instead: 'failedrefitem(<number>)' but it returns nothing on the stack. This is
4045since jAthena, so probably nobody knows for sure why is it so.
4046
4047
4048---------------------------------------
4049
4050*unequip <equipment slot>;
4051
4052This command will unequip whatever is currently equipped in the invoking
4053character's specified equipment slot. For a full list of possible equipment
4054slots see 'getequipid'.
4055
4056If an item occupies several equipment slots, it will get unequipped from all of
4057them. (Which is a good thing.)
4058
4059---------------------------------------
4060
4061*clearitem;
4062
4063This command will destroy all items the invoking character has in their
4064inventory. (that includes equipped items) It will not affect anything else, like
4065storage or cart.
4066
4067---------------------------------------
4068
4069*equip <item id>;
4070*autoEquip <item id>,<option>;
4071
4072These commands are to equip a equipment on the attached character.
4073The equip function will equip the item ID given when the player has
4074this item in his/her inventory, while the autoequip function will
4075equip the given item ID when this is looted. The option parameter of
4076the autoequip is 1 or 0, 1 to turn it on, and 0 to turn it off.
4077
4078Example(s):
4079
4080//This will equip a 1104 (falchion) on the character if this is in the inventory.
4081        equip 1104;
4082       
4083//The invoked character will now automatically equip a falchion when it's looted.
4084        autoequip 1104,1;
4085       
4086//The invoked character will no longer automatically equip a falchion.
4087        autoequip 1104,0;
4088
4089---------------------------------------
4090//
40914,1.- End of item-related commands
4092//
4093---------------------------------------
4094
4095*openstorage;
4096
4097This will open a character's Kafra storage window on the client connected to the
4098invoking character. It does not check wherever it is run from, so you can allow
4099any feasible NPC to open a kafra storage. (It's not certain whether this works
4100in item scripts, but if it does, it could be interesting.)
4101
4102The storage window might not open if a message box or a trade deal is present on
4103screen already, so you should at least make sure the message box is closed
4104before you open storage.
4105
4106    mes "I will now open your stash for you";
4107    close2;
4108    openstorage;
4109    end;
4110---------------------------------------
4111\\
41124,2.- Guild-related commands
4113\\
4114---------------------------------------
4115
4116*guildopenstorage()
4117
4118This function works the same as 'openstorage' but will open a guild storage
4119window instead for the guild storage of the guild the invoking character belongs
4120to. This is a function because it returns a value - 0 if the guild storage was
4121opened successfully and 1 if it wasn't. (Notice, it's a ZERO upon success.)
4122Since guild storage is only accessible to one character at one time, it may fail
4123if another character is accessing the guild storage at the same time.
4124
4125This will also fail and return 2 if the character does not belong to any guild.
4126
4127---------------------------------------
4128
4129*guildchangegm(<guild id>,<new master's name>)
4130
4131This function will change the Guild Master of a guild. The ID is the guild's
4132id, and the new guildmaster's name must be passed.
4133
4134Returns 1 on success, 0 otherwise.
4135
4136---------------------------------------
4137
4138*guildgetexp <amount>;
4139
4140This will give the specified amount of guild experience points to the guild the
4141invoking character belongs to. It will silently fail if they do not belong to
4142any guild.
4143
4144---------------------------------------
4145
4146*guildskill <skill id>,<level>
4147*guildskill "<skill name>",<level>
4148
4149This command will bump up the specified guild skill by the specified number of
4150levels. This refers to the invoking character and will only work if the invoking
4151character is a member of a guild AND it's guildmaster, otherwise no failure
4152message will be given and no error will occur, but nothing will happen - same
4153about the guild skill trying to exceed the possible maximum. The full list of
4154guild skills is available in 'db/skill_db.txt', these are all the GD_ skills at
4155the end.
4156
4157The flag parameter is currently not functional and it's a mystery of what it
4158would actually do. (Though probably, like for character skills, it would allow
4159temporary bumping.) Using this command will bump the guild skill up permanently.
4160
4161// This would give your character's guild one level of Approval (GD_APPROVAL ID
4162// 10000). Notice that if you try to add two levels of Approval, or add
4163// Approval when the guild already has it, it will only have one level of
4164// Approval afterwards.
4165    guildskill 10000,1,0;
4166
4167You might want to make a quest for getting a certain guild skill, make it hard
4168enough that all the guild needs to help or something. Doing this for the Glory
4169of the Guild skill, which allows your guild to use an emblem, is a good idea for
4170a fun quest. (Wasting a level point on that is really annoying :D)
4171
4172---------------------------------------
4173//
41744,2 End of guild-related commands.
4175//
4176---------------------------------------
4177
4178*resetlvl <action type>;
4179
4180This is a character reset command, meant mostly for rebirth script supporting
4181Advanced jobs, which will reset the invoking character's stats and level
4182depending on the action type given. Valid action types are:
4183
4184 1 - Base level 1, Job level 1, 0 skill points, 0 base xp, 0 job xp, wipes the
4185     status effects, sets all stats to 1. If the new job is 'Novice High', give
4186     100 status points, give First Aid and Play Dead skills.
4187 2 - Base level 1, Job level 1, 0 skill points, 0 XP/JXP. Skills and attribute
4188     values are not altered.
4189 3 - Base level 1, base xp 0. Nothing else is changed.
4190 4 - Job level 1, job xp 0. Nothing else is changed.
4191
4192In all cases it will also unequip everything the character has on.
4193
4194Even though it doesn't return a value, it is used as a function in the official
4195rebirth scripts. Ask AppleGirl why.
4196
4197---------------------------------------
4198
4199*resetstatus;
4200
4201This is a character reset command, which will reset the stats on the invoking
4202character and give back all the stat points used to raise them previously.
4203Nothing will happen to any other numbers about the character.
4204
4205Used in reset NPC's (duh!)
4206
4207---------------------------------------
4208
4209*resetskill;
4210
4211This command takes off all the skill points on the invoking character, so they
4212only have Basic Skill blanked out (lvl 0) left, and returns the points for them
4213to spend again. Nothing else will change but the skills. Quest skills will also
4214reset if 'quest_skill_reset' option is set to Yes in 'battle_athena.conf'. If
4215the 'quest_skill_learn' option is set in there, the points in the quest skills
4216will also count towards the total.
4217
4218Used in reset NPC's (duh!)
4219
4220---------------------------------------
4221
4222*sc_start       <effect type>,<ticks>,<extra argument>{,<target ID number>};
4223*sc_start2      <effect type>,<ticks>,<extra argument>,<percent chance>{,<target ID number>};
4224*sc_start4      <effect type>,<ticks>,<value 1>,<value 2>,<value 3>,<value 4>{,<target ID number>};
4225*sc_end         <effect type>{,<target ID number>};
4226
4227These command bestow a status effect on the invoking character. This command is
4228used a lot in the item scripts.
4229
4230    // This would poison them for 10 min
4231    sc_start SC_Poison,600000,0;
4232
4233Effect type is a number of effect, 'db/const.txt' lists the common (mostly
4234negative) status effect types as constants, starting with 'SC_'. You can also
4235use this to give someone an effect of a player-cast spell:
4236
4237    // This will bless someone as if with Bless 10:
4238    sc_start 10,240000,10;
4239   
4240Extra argument's meaning differs depending on the effect type, for most effects
4241caused by a player skill the extra argument means the level of the skill that
4242would have been used to create that effect, for others it might have no meaning
4243whatsoever. You can actually bless someone with a 0 bless spell level this way,
4244which is fun, but weird.
4245
4246The target ID number, if given, will cause the status effect to appear on a
4247specified character, instead of the one attached to the running script. This has
4248not been properly tested.
4249
4250'sc_start2' is perfectly equivalent, but unlike 'sc_start', a status change
4251effect will only occur with a specified percentage chance. 10000 given as the
4252chance is equivalent to a 100% chance, 0 is a zero.
4253
4254'sc_start4' is just like sc_start, however it takes four parameters for the
4255status change instead of one. What these values are depends on the status
4256change in question. For example, elemental armor defense takes the following
4257four values:
4258- val1 is the first element, val2 is the resistance to the element val1.
4259- val3 is the second element, val4 is the resistance to said element.
4260eg: sc_start4 SC_DefEle,60000,Ele_Fire,20,Ele_Water,-15;
4261
4262'sc_end' will remove a specified status effect. If SC_All is used (-1), it will
4263do a complete removal of all statuses (although permanent ones will re-apply).
4264
4265You can see the full list of status effects caused by skills in
4266'src/map/status.h' - they are currently not fully documented, but most of that
4267should be rather obvious.
4268
4269---------------------------------------
4270
4271*skilleffect <skill id>,<number>;
4272*skilleffect "<skill name>",<number>;
4273
4274This command will display the visual and sound effects of a specified skill (see
4275'db/skill_db.txt' for a full list of skills) on the invoking character's sprite.
4276Nothing but the special effects and animation will happen. If the skill's normal
4277effect displays a floating number, the number given will float up.
4278
4279    // This will heal the character with 2000 hp, buff with
4280    // Bless 10 and Increase AGI 5, and display appropriate
4281    // effects.
4282    mes "Blessed be!";
4283    skilleffect 28,2000;
4284    heal 2000,0;
4285    skilleffect 34,0;
4286    // That's bless 10.
4287    sc_start 10,240000,10;
4288    skilleffect 29,0;
4289    // That's agi 5
4290    sc_start 12,140000,5;
4291
4292---------------------------------------
4293
4294*npcskilleffect <skill id>,<number>,<x>,<y>;
4295*npcskilleffect "<skill name>",<number>,<x>,<y>;
4296
4297This command behaves identically to 'skilleffect', however, the effect will not
4298be centered on the invoking character's sprite, nor on the NPC sprite, if any,
4299but will be centered at map coordinates given on the same map as the invoking
4300character.
4301
4302---------------------------------------
4303
4304*specialeffect <effect number>;
4305
4306This command will display special effect with the given number, centered on the
4307specified NPCs coordinates, if any. For a full list of special effect numbers
4308known see 'doc/effect_list.txt'. Some effect numbers are known not to work in
4309some client releases. (Notably, rain is absent from any client executables
4310released after April 2005.)
4311
4312---------------------------------------
4313
4314*specialeffect2 <effect number>;
4315
4316This command behaves identically to the 'specialeffect', but the effect will be
4317centered on the invoking character's sprite.
4318
4319---------------------------------------
4320
4321*statusup <stat>;
4322
4323This command will bump a specified stat of the invoking character up by one
4324permanently. Stats are to be given as number, but you can use these constants to
4325replace them:
4326
4327bStr -  Strength
4328bVit -  Vitality
4329bInt -  Intelligence
4330bAgi -  Agility
4331bDex -  Dexterity
4332bLuk -  Luck
4333
4334---------------------------------------
4335
4336*statusup2 <stat>,<amount>;
4337
4338This command will bump a specified stat of the invoking character up by the
4339specified amount permanently. The amount can be negative. See 'statusup'.
4340
4341    // This will decrease a character's Vit forever.
4342    statusup bVit,-1;
4343
4344---------------------------------------
4345
4346*bonus <bonus type>,<val1>;
4347*bonus2 <bonus type>,<val1>,<val2>;
4348*bonus3 <bonus type>,<val1>,<val2>,<val3>;
4349*bonus4 <bonus type>,<val1>,<val2>,<val3>,<val4>;
4350*bonus5 <bonus type>,<val1>,<val2>,<val3>,<val4>,<val5>;
4351
4352These commands are meant to be used in item scripts. They will probably work
4353outside item scripts, but the bonus will not persist for long. They, as
4354expected, refer only to an invoking character.
4355
4356You can find the full list of possible bonuses and which command to use for each
4357kind in 'doc/item_bonus.txt'.
4358
4359---------------------------------------
4360
4361*bonusautoscript <script>,<rate>{,<flag>}
4362*bonusautoscript2 <script>,<rate>{,<flag>}
4363
4364These commands are meant to be used in item scripts. They will probably work
4365outside item scripts, but the bonus will not persist for long. They, as
4366expected, refer only to an invoking character.
4367
4368What these commands do is 'attach' a script to the player which will get
4369executed on attack (or when attacked in the case of bonusautoscript2). Rate is
4370the trigger rate of the script (1000 = 100%). The optional argument flag is
4371used to classify the type of attack where the script can trigger (it shares
4372the same flags as the bAutoSpell bonus script):
4373
4374Range criteria:
4375        BF_SHORT: Trigger on melee attack
4376        BF_LONG: Trigger on ranged attack
4377        Default: BF_SHORT+BF_LONG
4378Attack type criteria:
4379        BF_WEAPON: Trigger on weapon skills
4380        BF_MAGIC: Trigger on magic skills
4381        BF_MISC: Trigger on misc skills
4382        Default: BF_WEAPON
4383Skill criteria:
4384        BF_NORMAL: Trigger on normal attacks
4385        BF_SKILL: Trigger on skills
4386        default: If the attack type is BF_WEAPON (only) BF_NORMAL is used, otherwise
4387                BF_SKILL+BF_NORMAL is used.
4388
4389In both cases, when the script triggers, the attached player will be the one
4390who holds the bonus. There is currently no way of knowing within this script
4391who was the other character (the attacker in autoscript2, or the target in
4392autoscript).
4393
4394//Grants a 1% chance of starting the state "all stats +10" for 10 seconds when
4395//using weapon or misc attacks (both melee and ranged skills).
4396        bonusautoscript "{ sc_start SC_INCALLSTATUS,10000,10; }",10,BF_WEAPON|BF_MISC;
4397
4398---------------------------------------
4399
4400*skill <skill id>,<level>{,<flag>};
4401*skill "<skill name>",<level>{,<flag>};
4402*addtoskill <skill id>,<level>{,<flag>};
4403*addtoskill "<skill name>",<level>{,<flag>};
4404
4405These commands will give the invoking character a specified skill. This is also
4406used for item scripts.
4407
4408Level is obvious. Skill id is the ID number of the skill in question as per
4409'db/skill_db.txt'. It is not known for certain whether this can be used to give
4410a character a monster's skill, but you're welcome to try with the numbers given
4411in 'db/mob_skill_db.txt'.
4412
4413Flag is 0 if the skill is given permanently (will get written with the character
4414data) or 1 if it is temporary (will be lost eventually, this is meant for card
4415item scripts usage.).  The flag parameter is optional, and defaults to 1 in
4416'skill' and to 2 in 'addtoskill'.
4417
4418Flag 2 means that the level parameter is to be interpreted as a stackable
4419additional bonus to the skill level. If the character did not have that skill
4420previously, they will now at 0+the level given.
4421
4422// This will permanently give the character Stone Throw (TF_THROWSTONE,152), at
4423// level 1.
4424    skill 152,1,0;
4425
4426---------------------------------------
4427
4428*nude;
4429
4430This command will unequip anything equipped on the invoking character.
4431
4432It is not required to do this when changing jobs since 'jobchange' will unequip
4433everything not equippable by the new job class anyway.
4434
4435---------------------------------------
4436
4437*disguise <Monster ID>;
4438*undisguise;
4439
4440This command disguises the current player with a monster sprite.
4441The disguise lasts until 'undisguise' is issued or the player logs out.
4442
4443Example:
4444
4445disquise 1002; //Yay! You're a Poring!!!
4446next;
4447undisquise; //Yay!!!! You're a human again!!
4448
4449---------------------------------------
4450\\
44514,3 Marriage-related commands
4452\\
4453---------------------------------------
4454*marriage("<spouse name>");
4455
4456This function will marry two characters, the invoking character and the one
4457referred to by name given, together, setting them up as each other's marriage
4458partner. No second function call has to be issued (in current SVN at least) to
4459make sure the marriage works both ways. The function returns 1 upon success, or
44600 if the marriage could not be completed, either because the other character
4461wasn't found or because one of the two characters is already married.
4462
4463This will do nothing else for the marriage except setting up the spouse ID for
4464both of these characters. No rings will be given and no effects will be shown.
4465
4466---------------------------------------
4467
4468*wedding;
4469
4470This command will call up wedding effects - the music and confetti - centered on
4471the invoking character.
4472
4473---------------------------------------
4474
4475*divorce()
4476
4477This function will un-marry the invoking character from whoever they were
4478married to. Both will no longer be each other's marriage partner, (at least in
4479current SVN, which prevents the cases of multi-spouse problems). It will return
44801 upon success or 0 if the character was not married at all.
4481
4482This function will also destroy both wedding rings and send a message to both
4483players, telling them they are now divorced.
4484
4485---------------------------------------
4486
4487*adopt "<parent name>","<parent name>","<novice name>";
4488*adopt("<parent name>","<parent name>","<novice name>")
4489
4490This command will set up a novice as a baby of a married couple. All three are
4491referred to by character name. The correct variables are set on all three
4492characters in the same call. The command will unequip anything the novice has
4493equipped and make them a Job_Baby class, as well as send them a 'your job has
4494been changed' message.
4495
4496Beware of calling this from inside a 'callfunc' function, cause upon successful
4497adoption, this command returns a zero, as if it were a function. This is likely
4498to screw up execution of a 'return' command. You may try to call it as a
4499function instead, but it doesn't return anything upon an error, which may also
4500cause script execution to throw up errors.
4501
4502Nothing will happen (and nothing will be returned either) if either future
4503parent is below base level 70 and/or if any of the three characters is not found
4504online.
4505
4506---------------------------------------
4507//
45084,3.- End of marriage-related commands
4509//
4510---------------------------------------
4511
4512*pcfollow <id>,<target id>;
4513*pcstopfollow <id>;
4514
4515Makes a character follow or stop following someone. This command does the same as the @follow command.
4516The main difference is that @follow can use character names, and this commands needs the Account ID for the target.
4517
4518Example(s):
4519
4520//This will make Aaron follow Bullah, when both of these characters are online.
4521        PCFollow getCharID(3,"Aaron"),getCharID(3,"Bullah");
4522       
4523//Makes Aaron stop following whoever he is following.
4524        PCStopFollow getCharID(3,"Aaron");
4525       
4526---------------------------------------
4527
4528* pcblockmove <id>,<option>;
4529
4530Prevents the given ID from moving when the option != 0, 0 enables the ID to move again.
4531ID should be able to be GID of a monster/npc or AID from a character.
4532
4533Example(s):
4534
4535//prevents the current char from moving away;
4536        pcblockmove getcharid(3),1;
4537       
4538//enables the current char to move again.       
4539        pcblockmove getcharid(3),0;
4540
4541---------------------------------------
4542
4543==================================
4544|5.- Mob / NPC -related commands.|
4545==================================
4546---------------------------------------
4547
4548*monster     "<map name>",<x>,<y>,"<name to show>",<mob id>,<amount>{,"<event label>"};
4549*areamonster "<map name>",<x1>,<y1>,<x2>,<y2>,"<name to show>",<mob id>,<amount>{,"<event label>"};
4550
4551This command will spawn a monster on the specified coordinates on the specified
4552map. If the script is invoked by a character, a special map name, "this", will
4553be recognised to mean the name of the map the invoking character is located at.
4554This command works fine in the item scripts.
4555
4556The same command arguments mean the same things as described above in the
4557beginning of this document when talking about permanent monster spawns. Monsters
4558spawned in this manner will not respawn upon being killed.
4559
4560Unlike the permanent monster spawns, if the mob id is -1, a random monster will
4561be picked from the entire database according to the rules configured in the
4562server for dead branches. This will work for all other kinds of non-permanent
4563monster spawns.
4564
4565The only very special thing about this command is an event label, which is an
4566optional parameter. This label is written like '<NPC object name>::<label name>'
4567and upon the monster being killed, it will execute the script inside of the
4568specified NPC object starting from the label given. The RID of the player
4569attached at this execution will be the RID of the killing character.
4570
4571    monster "place",60,100,"Poring",1002,1,"NPCNAME::OnLabel";
4572
4573If you do not specify any event label, a label in the NPC object that ran this
4574command, called 'OnMyMobDead:' will execute anyway, if present.
4575
4576The coordinates of 0,0 will spawn the monster on a random place on the map.
4577
4578The 'areamonster' command works much like the 'monster' command and is not
4579significantly different, but spawns the monsters within a square defined by
4580x1/y1-x2/y2.
4581
4582Simple monster killing script:
4583
4584        <Normal NPC object definition. Let's assume you called him NPCNAME.>
4585        mes "[Summon Man]";
4586        mes "Want to start the kill?";
4587        next;
4588        menu "Yes",L_Yes,"No",-;
4589        mes "[Summon Man]";
4590        mes "Come back later";
4591        close;
4592    L_Yes:
4593        monster "prontera",0,0,"Quest Poring",1002,10,"NPCNAME::OnPoringKilled";
4594        // By using 0,0 it will spawn them in a random place.
4595        mes "[Summon Man]";
4596        mes "Now go and kill all the Poring I summoned";
4597        // He summoned ten.
4598        close;
4599    L_PoringKilled:
4600        set $PoringKilled,$PoringKilled+1;
4601        if ($PoringKilled==10) goto L_AllDead;
4602        end;
4603    L_AllDead:
4604        announce "Summon Man: Well done all the poring are dead",3;
4605        set $PoringKilled,0;
4606        end;
4607
4608For more good examples see just about any official 2-1 or 2-2 job quest script.
4609
4610---------------------------------------
4611
4612*killmonster "<map name>","<event label>"{,<type>};
4613
4614This command will kill all monsters that were spawned with 'monster' or
4615'addmonster' and have a specified event label attached to them. Commonly used to
4616get rid of remaining quest monsters once the quest is complete.
4617
4618If the label is given as "All", all monsters which have their respawn times set
4619to -1 (like all the monsters summoned with 'monster' or 'areamonster' script
4620command, and all monsters summoned with GM commands, but no other ones - that
4621is, all non-permanent monsters) on the specified map will be killed regardless
4622of the event label value.
4623
4624As of r12876 killmonster now supports an optional argument type. Using 1 for type
4625will make the command fire "OnMyMobDead" events from any monsters that do die
4626as a result of this command.
4627
4628---------------------------------------
4629
4630*killmonsterall "<map name>"{,<type>};
4631
4632This command will kill all monsters on a specified map name, regardless of how
4633they were spawned or what they are. As of r12873, The behavior has changed slightly.
4634In light of a label behavior fix for mob spawning commands that will now allow the label to
4635trigger when there is no player, killmonsterall has also been modified to support this.
4636
4637Using this the normal/old way means labels dont trigger when a player didn't
4638attack/kill a monster. This is because it breaks compatability with older scripts if
4639forced to use the new method. However, if you wish to use the new label type with this
4640command, simply use 1 for type. Any other number won't be recognized.
4641
4642---------------------------------------
4643
4644*strmobinfo(<type>,<monster id>);
4645
4646This function will return information about a monster record in the database, as
4647per 'db/mob_db.txt'. Type is the kind of information returned. Valid types are:
4648
4649 1 - 'english name' field in the database, a string.
4650 2 - 'japanese name' field in the database, a string.
4651     All other returned values are numbers:
4652 3 - Level.
4653 4 - Maximum HP.
4654 5 - Maximum SP.
4655 6 - Experience reward.
4656 7 - Job experience reward.
4657
4658---------------------------------------
4659
4660*mobcount("<map name>","<event label>")
4661
4662This function will count all the monsters on the specified map that have a given
4663event label and return the number or 0 if it can't find any. Naturally, only
4664monsters spawned with 'monster' and 'areamonster' script commands can be like
4665this.
4666
4667However, apparently, if you pass this function an empty string for the event
4668label, it should return the total count of normal permanently respawning
4669monsters instead. With the current dynamic mobs system, where mobs are not kept
4670in memory for maps with no actual people playing on them, this will return a 0
4671for any such map.
4672
4673---------------------------------------
4674
4675*clone "<map name>",<x>,<y>,"<event>",<char id>{,<master_id>{,<mode>{,<flag>,<duration>}}}
4676
4677This command creates a monster which is a copy of another player. The first
4678four arguments serve the same purpose as in the monster script command, The
4679<char id> is the character id of the player to clone (player must be online).
4680If <master id> is given, the clone will be a 'slave/minion' of it. Master_id
4681must be a character id of another online player.
4682
4683The mode can be specified to determine the behaviour of the clone, it's
4684values are the same as the ones used for the mode field in the mob_db. The
4685default mode is aggressive, assists, can move, can attack.
4686
4687Flag can be either zero or one currently. If zero, the clone is a normal
4688monster that'll target players, if one, it is considered a summoned monster,
4689and as such, it'll target other monsters. Defaults to zero.
4690
4691The duration specifies how long the clone will live before it is auto-removed.
4692Specified in seconds, defaults to no limit (zero).
4693
4694Returned value is the monster ID of the spawned clone. If command fails,
4695returned value is zero.
4696
4697---------------------------------------
4698
4699*summon "Monster name",<monster id>{,<Time Out>{,"event label"}};
4700
4701This command will summon a monster. (see also 'monster') Unlike monsters spawned
4702with other commands, this one will set up the monster to fight to protect the
4703invoking character. Monster name and mob id obey the same rules as the one given
4704at the beginning of this document for permanent monster spawns with the
4705exceptions mentioned when describing 'monster' command.
4706
4707The effect for the skill 'Call Homonuculus' will be displayed centered on the
4708invoking character.
4709
4710Timeout is the time in milliseconds the summon lives, and is set default
4711to 60000 (1 minute). Note that also the value 0 will set the timer to default,
4712and it is not possible to create a spawn that lastst forever.
4713If an event label is given, upon the monster being killed, the event label will
4714run as if by 'donpcevent'.
4715
4716// Will summon a dead branch-style monster to fight for the character.
4717summon "--ja--",-1;
4718
4719---------------------------------------
4720
4721*homevolution;
4722
4723This command will try to evolve the current player's homunculus.
4724If it doesn't work, the /swt emoticon is shown.
4725
4726To evolve a homunculus, the invoking player must have a homunculus,
4727the homunculus must not be the last evolution and
4728the homunculus must be on at least 91000/100000 intimacy with it's owner.
4729
4730---------------------------------------
4731------------------------------------------------
4732//===========================================\\
4733||         Mob Control Suit Commands         ||
4734\\===========================================//
4735------------------------------------------------
4736
4737---------------------------------------
4738
4739* mobspawn (<monster name>,<monster ID>,<mapname>,<x>,<y>)
4740* mobRemove <GID>;
4741
4742This is used to spawn a monster and return it's Game ID, to be used
4743in the unit/mobcontrol commands.
4744
4745Note, I will use the stuff here in the examples for the unitcontrol.
4746
4747Example(s):
4748
4749//Spawns a poring named poi poi and put's it's GID in .GID.
4750        set .GID,mobspawn("Poi Poi",1002,"prontera",160,180);
4751//would kill our poring.
4752        mobRemove .GID;
4753
4754---------------------------------------
4755
4756* getmobdata (<GID>,<arrayname>)
4757* setmobdata <GID>,<parameter>,<new value>;
4758
4759This is used to get and set special data related to the monster.
4760With getmobdata, the array given will be filled with the current data. In setmobdata
4761the indexes in the array would be used to set that data on the monster.
4762Parameters (indexes) are:
4763
47640 = class (big, small, normal)                  7  = y                                          14 = hair style         21 = weapon
47651 = level                                       8  = speed                                      15 = hair color         22 = shield (again)
47662 = HP                                          9  = mode (see doc/mob_db_mode_list.txt)        16 = head gear bottom   23 = looking dir
47673 = max HP                                      10 = special AI state (?)                       17 = head gear middle   24 = killer state (1 or 0)
47684 = master ID (aid of the master, summon)       11 = SC option                                  18 = head gear top      25 = callback flag
47695 = map index                                   12 = sex                                        19 = cloth color        26 = no random walk (1 or 0)
47706 = x                                           13 = class (Monster ID, Job ID)                 20 = shield             
4771
4772Example(s):
4773
4774//this will set all the mobdata in the @array variable. (@array[1] being level, @array[13] class etc)
4775        getmobdata .GID,@array;
4776       
4777//set the max hp of our poring to 1000.
4778        setmobdata .GID,3,1000;
4779
4780---------------------------------------
4781
4782* mobassist <GID>,<target id>;
4783This will make the monster assist the Target ID as if it was a summon of it.
4784Example(s):
4785
4786/this will make our poring assist the current attached player! >:3
4787        mobassist .GID,getcharid(3);
4788
4789---------------------------------------
4790
4791* mobattach <GID>{,"<NPC Name>"};
4792
4793GID is the GID of a monster, NPC or account id. The NPC running or
4794he NPC name given is used to attach the monster.
4795
4796By attaching a monster, the NPC to which it is attached is ran on special actions by the monster.
4797The system will set specific data in the .ai_action variable array on the NPC invoked.
4798The special AI actions types are set in the .ai_action at place AI_ACTION_TAR_TYPE
4799
4800More AI_ vars are set in const.txt, and you can also look at sample/monstercontroller.cpp:
4801
4802---------------------------------------
4803
4804* unitwalk <GID>,<x>,<y>;
4805* unitwalk <GID>,<mapid>;
4806
4807This is one command, but can be used in two ways. If only the first argument is given,
4808the unit whose GID is given will start walking towards the map with the given mapid
4809(we believe these are the mapindexes found in db/map_index.txt).
4810
4811When 2 arguments are passed, the given unit will walk to the given x,y coordinates on
4812the map where the unit currently is.
4813
4814Example(s):
4815
4816//Will move/walk the poring we made to the coordinates 150,150
4817        unitwalk .GID,150,150;
4818
4819//Will move the poring towards alberta (if my assumed mapindexes are correct).
4820        unitwalk .GID,3;
4821
4822---------------------------------------
4823
4824* unitkill <GID>;
4825* unitwarp <GID>,<Mapname>,<x>,<y>;
4826* unitattack <GID>,<Target ID>;
4827* unitstop <GID>;
4828* unittalk <GID>,<Text>;
4829* unitemote <GID>,<Emote>;
4830
4831Okay, these commands should be fairly self explaining.
4832For the emotions, you can look in db/const.txt for prefixes with e_
4833
4834---------------------------------------
4835
4836------------------------------------------------
4837//===========================================\\
4838||      End of Mob Control Suit Commands     ||
4839\\===========================================//
4840------------------------------------------------
4841---------------------------------------
4842
4843*disablenpc "<NPC object name>";
4844*enablenpc "<NPC object name>";
4845
4846These two commands will disable and enable, respectively, an NPC object
4847specified by name. The disabled NPC will disappear from sight and will no longer
4848be triggerable in the normal way. It is not clear whether it will still be
4849accessible through 'donpcevent' and other triggering commands, but it probably
4850will be. You can disable even warp NPCs if you know their object names, which is
4851an easy way to make a map only accessible through walking half the time. Then
4852you 'enablenpc' them back.
4853
4854You can also use these commands to create the illusion of an NPC switching
4855between several locations, which is often better than actually moving the NPC -
4856create one NPC object with a visible and a hidden part to their name, make a few
4857copies, and then disable all except one.
4858
4859---------------------------------------
4860
4861*hideonnpc "<NPC object name>";
4862*hideoffnpc "<NPC object name>";
4863
4864These commands will make the NPC object specified display as hidden/visible,
4865even though not actually disabled per se. Hidden as in thief Hide skill, but
4866unfortunately, not detectable by Ruwach or Sight.
4867
4868As they are now, these commands are pointless, it is suggested to use
4869'disablenpc'/'enablenpc', because these two commands actually unload the NPC
4870sprite location and other accompanying data from memory when it is not used.
4871However, you can use these for some quest ideas (such as cloaking npcs talking
4872while hidden then revealing.... you can wonder around =P
4873
4874---------------------------------------
4875
4876*doevent "<NPC object name>::<event label>";
4877
4878This command will start a new execution thread in a specified NPC object at the
4879specified label. The execution of the script running this command will not stop.
4880No parameters may be passed with a doevent call.
4881
4882The script of the NPC object invoked in this manner will run as if it's been
4883invoked by the RID that was active in the script that issued a 'doevent'.
4884
4885    place,100,100,1%TAB%script%TAB%NPC%TAB%53,{
4886        mes "This is what you will see when you click me";
4887        close;
4888    Label:
4889        mes "This is what you will see if the doevent is activated";
4890        close;
4891    }
4892
4893    ....
4894
4895    doevent "NPC::Label";
4896
4897---------------------------------------
4898
4899*donpcevent "{NPC NAME}::<event label>";
4900
4901This command is kinda confusing cause it performs in two completely different
4902ways.
4903
4904If the event label is phrased like "::<label name>", all NPC objects that have a
4905specified label in them will be invoked as if by a 'doevent', but no RID
4906whatsoever will be attached while they execute.
4907
4908Otherwise, if the label is given as "<NPC name>::<label name>", a label within
4909the NPC object that runs this command will be called, but as if it was running
4910inside another, specified NPC object. No RID will be attached to it in this case
4911either.
4912
4913This can be used for making another NPC react to an action that you have done
4914with the NPC that has this command in it, i.e. show an emotion, or say
4915something.
4916
4917    place,100,100,1%TAB%script%TAB%NPC%TAB%53,{
4918        mes "Hey NPC2 copy what I do";
4919        close2;
4920        set @emo, rand(1,30);
4921        donpcevent "NPC2::Emo";
4922    Emo:
4923        emotion @emo;
4924        end;
4925    }
4926
4927    place,102,100,1%TAB%script%TAB%NPC2%TAB%53,{
4928        mes "Hey NPC copy what I do";
4929        close2;
4930        set @emo, rand(1,30);
4931        donpcevent "NPC::Emo";
4932    Emo:
4933        emotion @emo;
4934        end;
4935    }
4936
4937This will make both NPC perform the same random emotion from 1 to 30, and the
4938emotion will appear above each of their heads.
4939
4940---------------------------------------
4941
4942*cmdothernpc "<npc name>","<command>";
4943
4944This is simply "donpcevent <npc name>::OnCommand<command>".
4945It is an approximation of official server script language's 'cmdothernpc'.
4946
4947---------------------------------------
4948
4949*npctalk "<message>";
4950
4951This command will display a message to the surrounding area as if the NPC object
4952running it was a player talking - that is, above their head and in the chat
4953window. The display name of the NPC will get appended in front of the message to
4954complete the effect.
4955
4956    // This will make everyone in the area see the NPC greet the character
4957    // who just invoked it.
4958    npctalk "Hello "+strcharinfo(0)+" how are you";
4959
4960---------------------------------------
4961
4962*setnpcdisplay("<npc name>", "<display name>", <class id>, <size>)
4963*setnpcdisplay("<npc name>", "<display name>", <class id>)
4964*setnpcdisplay("<npc name>", "<display name>")
4965*setnpcdisplay("<npc name>", <class id>)
4966
4967Changes the display name and/or display class of the target npc.
4968Returns 0 is successful, 1 if the npc does not exist.
4969Size is 0 = norma 1 = small 2 = big.
4970
4971Since trunk r11779
4972
4973---------------------------------------
4974\\
49755,1.- Time-related commands
4976\\
4977---------------------------------------
4978*addtimer <ticks>,"<NPC object name>::<label>";
4979*deltimer "<NPC object name>::<event label>";
4980*addtimercount <ticks>,"<NPC object name>::<event label>";
4981
4982These commands will create, destroy, and delay a countdown timer - 'addtimer' to
4983create, 'deltimer' to destroy and 'addtimercount' to delay it by the specified
4984number of ticks. For all three cases, the event label given is the identifier of
4985that timer.
4986
4987When this timer runs out, a new execution thread will start in the specified NPC
4988object at the specified label. If no such label is found in the NPC object, it
4989will run as if clicked. In either case, the script runs with no RID attached.
4990
4991The ticks are given in 1/1000ths of a second.
4992
4993One more thing. These timers are stored as part of player data. If the player
4994logs out, all of these get immediately deleted, without executing the script.
4995If this behavior is undesirable, use some other timer mechanism (like 'sleep').
4996
4997---------------------------------------
4998
4999*initnpctimer{ "<NPC name>" {, <Attach Flag>} } |
5000             { "<NPC name>" | <Attach Flag> };
5001*stopnpctimer{ "<NPC name>" {, <Detach Flag>}  } |
5002             { "<NPC name>" | <Detach Flag> };
5003*startnpctimer{ "<NPC name>" {, <Attach Flag>} } |
5004              { "<NPC name>" | <Attach Flag> };
5005*setnpctimer <tick>{,"<NPC name>"};
5006*getnpctimer(<type of information>{,"<NPC name>"});
5007*attachnpctimer {"<character name>"};
5008*detachnpctimer {"<NPC name>"};
5009
5010This set of commands and functions will create and manage an NPC-based timer.
5011The NPC name may be omitted, in which case the calling NPC is used as target.
5012
5013Contrary to addtimer/deltimer commands which let you have many different timers
5014referencing different labels in the same NPC, each with their own countdown,
5015'initnpctimer' can only have one per NPC object. But it can trigger many labels
5016and let you know how many were triggered already and how many still remain.
5017
5018This timer is counting up from 0 in ticks of 1/1000ths of a second each. Upon
5019creating this timer, the execution will not stop, but will happily continue
5020onward. The timer will then invoke new execution threads at labels
5021"OnTimer<time>:" in the NPC object it is attached to.
5022
5023To create the timer, use the 'initnpctimer', which will start it running.
5024'stopnpctimer' will pause the timer, without clearing the current tick, while
5025'startnpctimer' will let the paused timer continue.
5026
5027By default timers do not have a RID attached, which lets them continue even
5028if the player that started them logs off. To attach a RID to a timer, you can
5029either use the optional "attach flag" when using 'initnpctimer/startnpctimer',
5030or do it manually by using 'attachnpctimer'. Likewise, the optional flag of
5031stopnpctimer lets you detach any RID after stopping the timer, and by using
5032'detachnpctimer' you can detach a RID at any time.
5033
5034Normally there is only a single timer per NPC, but as an exception, as long as
5035you attach a player to the timer, you can have multiple timers running at once,
5036because these will get stored on the players instead of the NPC.
5037NOTE: You need to attach the RID before the timer _before_ you start it to
5038get a player-attached timer. Otherwise it'll stay a NPC timer (no effect).
5039
5040If the player that is attached to the npctimer logs out, the "OnTimerQuit:"
5041event label of that npc will be triggered, so you can do the appropiate
5042cleanup (the player is still attached when this event is triggered).
5043
5044The 'setnpctimer' command will explicitly set the timer to a given tick.
5045'getnpctimer' provides timer information. Its parameter defines what type:
5046
5047 0 - Will return the current tick count of the timer.
5048 1 - Will return 1 if there are remaining "OnTimer<ticks>:" labels in the
5049     specified NPC waiting for execution.
5050 2 - Will return the number of times the timer has triggered an "OnTimer<tick>:"
5051     label in the specified NPC.
5052
5053Example 1:
5054
5055    <NPC Header> {
5056        initnpctimer;
5057        npctalk "I cant talk right now, give me 10 seconds";
5058        end;
5059    OnTimer5000:
5060        npctalk "Ok 5 seconds more";
5061        end;
5062    OnTimer6000:
5063        npctalk "4";
5064        end;
5065    OnTimer7000:
5066        npctalk "3";
5067        end;
5068    OnTimer8000:
5069        npctalk "2";
5070        end;
5071    OnTimer9000:
5072        npctalk "1";
5073        end;
5074    OnTimer10000:
5075        stopnpctimer;
5076        mes "[Man]";
5077        mes "Ok we can talk now";
5078    }
5079
5080Example 2:
5081
5082    OnTimer15000:
5083        npctalk "Another 15 seconds have passed.";
5084        setnpctimer 0;
5085        end;
5086       
5087    // This OnInit label will run when the script is loaded, so that the timer
5088    // is initialised immediately as the server starts. It is dropped back to 0
5089    // every time the NPC says something, so it will cycle continiously.
5090    OnInit:
5091        initnpctimer;
5092        end;
5093
5094Example 3:
5095
5096    mes "[Man]";
5097    mes "I have been waiting "+(getnpctimer(0)/1000)+" seconds for you";
5098    // we divide the timer returned by 1000 cause it will be displayed in
5099    // milliseconds otherwise
5100    close;
5101
5102Example 4:
5103
5104    mes "[Man]";
5105    mes "Ok I will let you have 30 sec more";
5106    close2;
5107    setnpctimer (getnpctimer(0)-30000);
5108    // Notice the 'close2'. If there were a 'next' there the timer would be
5109    // changed only after the player pressed the 'next' button.
5110    end;
5111 
5112---------------------------------------
5113 
5114*sleep {<milliseconds>};
5115*sleep2 {<milliseconds>};
5116*awake "<NPC name>";
5117
5118These commands are used to control the pause of a NPC.
5119sleep and sleep2 will pause the script for the given amount of milliseconds.
5120Awake is used to cancel a sleep. When awake is callen on a NPC it will run as
5121if the sleep timer ran out, and thus making the script continue. Sleep and sleep2
5122basically do the same, but the main difference is that sleep will not keep the rid,
5123while sleep2 does.
5124
5125Examples:
5126        sleep 10000; //pause the script for 10 seconds and ditch the RID (so no player is attached anymore)
5127        sleep2 5000; //pause the script for 5 seconds, and continue with the RID attached.
5128        awake "NPC"; //Cancels any running sleep timers on the NPC 'NPC'.
5129
5130---------------------------------------
5131//
51325,1.- End of time-related commands
5133//
5134
5135*announce "<text>",<flag>{,<color>};
5136
5137This command will broadcast a message to all or most players, similar to
5138@kami/@kamib GM commands.
5139
5140The region the broadcast is heard in and the color the message will come up as
5141will be determined by the flags:
5142
5143    announce "This will be shown to everyone at all in yellow.",0;
5144
5145The flag values are coded as constants in db/const.txt to make them easier to use:
5146- bc_all: Broadcast message is sent server-wide
5147- bc_map: Message is sent to everyone in the same map
5148- bc_area: Message is sent to players in the vecinity of the source.
5149- bc_self: Message is sent only to current player.
5150
5151- bc_npc: Broadcast source is the npc, not the player attached to the script
5152  (useful when a player is not attached or the message should be sent to those
5153  nearby the npc)
5154
5155- bc_yellow: The default is to send broadcasts in yellow color.
5156- bc_blue: Alternate broadcast is displayed in blue color.
5157
5158The optional parameter, color, allows usage of broadcasts in any custom color.
5159The color parameter is a single number which can be in hexadecimal notation.
5160For example:
5161    announce "This will be shown to everyone at all in yellow.",bc_all,0xFFFF00;
5162Will display a global announce in yellow. The color format is in RGB (0xRRGGBB).
5163
5164Using this for private messages to players is probably not that good an idea,
5165but it can be used instead in NPCs to "preview" an announce.
5166
5167    // This will be a private message to the player using the NPC that made the
5168    // annonucement
5169    announce "This is my message just for you",bc_blue|bc_self;
5170
5171    // This will be shown on everyones screen that is in sight of the NPC.
5172    announce "This is my message just for you people here",bc_area;
5173
5174---------------------------------------
5175
5176*mapannounce "<map name>","<text>",<flag>{,<color>};
5177
5178This command will work like 'announce' but will only broadcast to characters
5179currently residing on the specified map. The flag and optional color
5180parameters are the same as in 'announce', even though the only ones that make
5181sense are the color related ones.
5182
5183---------------------------------------
5184
5185*areaannounce "<map name>",<x1>,<y1>,<x2>,<y2>,"<text>",<flag>[,<color>];
5186
5187This command works like 'announce' but will only broadcast to characters
5188residing in the specified x1/y1-x2/y2 square on the map given. The flags and
5189color parameter given are the same as in 'announce', but only the color
5190related ones have effect.
5191
5192    areaannounce "prt_church",0,0,350,350,"God's in his heaven, all right with the world",0;
5193
5194---------------------------------------
5195
5196*callshop "<name>",<option>;
5197
5198These are a series of commands used to create dynamic shops.
5199The callshop function calls a invisible shop (view -1) as if the player clicked on it.
5200
5201For the options on callShop:
5202        0 = The normal window (buy, sell and cancel)
5203        1 = The buy window
5204        2 = The sell window
5205       
5206Example(s):
5207
5208callshop "DaShop",1;    //Will call the shop named DaShop and opens the buy menu.
5209
5210The shop which is called by callshop (as long as an npcshop* command is executed
5211from that NPC (see note 1)) will trigger the labels OnBuyItem and OnSellitem. These
5212labels can take over handling for relatively the buying of items from the shop
5213and selling the items to a shop. Via these labels you can customize the way an item
5214is bought or sold by a player.
5215
5216In the OnBuyItem, two arrays are set (@bought_nameid and @bough_quantity), which
5217hold information about the name id (item id) sold and the amount sold of it. Same
5218goes for the OnSellItem label, only the variables are named different
5219(@sold_nameid and @sold_quantity). An example on a shop comes with eAthena, and
5220can be found in the npc/sample/npc_dynamic_shop.txt file.
5221 
5222This example shows how to use the labels and their set variables to create a dynamic shop.
5223
5224Note 1: These labels will only be triggered if a npcshop* command is executed, this is
5225because these commands set a special data on the shop npc,named master_nd in the source.
5226The OnSellItem and OnBuyItem are triggered in the NPC whose master_nd is given in the shop.
5227This was found out thanks to 'Hondacrx', noticing the OnBuyItem wasn't triggered unless
5228npcshopitem was used. After rechecking the source, I found what caused this.
5229
5230---------------------------------------
5231
5232*npcshopitem "<name>",<item id>,<price>{,<item id>,<price>{,<item id>,<price>{,...}}}
5233
5234This command lets you override the contents of an existing npc shop. The
5235current sell list will be wiped, and only the items specified with the price
5236specified will be for sale.
5237
5238The function returns 1 if shop was updated successfully, or 0 if not found.
5239
5240Note that you cannot use -1 to specify default selling price!
5241
5242---------------------------------------
5243
5244*npcshopadditem "<name>",<item id>,<price>{,<item id>,<price>{,<item id>,<price>{,...}}}
5245
5246This command will add more items at the end of the selling list for the
5247specified npc shop. If you specify an item already for sell, that item will
5248appear twice on the sell list.
5249
5250The function returns 1 if shop was updated successfully, or 0 if not found.
5251
5252Note that you cannot use -1 to specify default selling price!
5253
5254---------------------------------------
5255
5256*npcshopdelitem "<name>",<item id>{,<item id>{,<item id>{,...}}}
5257
5258This command will remove items from the specified npc shop.
5259If the item to remove exists more than once on the shop, all instances will be
5260removed.
5261
5262Note that the function returns 1 even if no items were removed. The return
5263value is only to confirm that the shop was indeed found.
5264
5265---------------------------------------
5266
5267*npcshopattach "<name>"{,<flag>}
5268
5269This command will attach the current script to the given npc shop.
5270When a script is attached to a shop, the events "OnBuyItem" and "OnSellItem"
5271of your script will be executed whenever a player buys/sells from the shop.
5272Additionally, the arrays @bought_nameid[], @bought_quantity[] or @sold_nameid[]
5273and @sold_quantity[] will be filled up with the items and quantities
5274bought/sold.
5275
5276The optional parameter specifies whether to attach ("1") or detach ("0") from
5277the shop (the default is to attach). Note that detaching will detach any npc
5278attached to the shop, even if it's from another script, while attaching will
5279override any other script that may be already attached.
5280
5281The function returns 0 if the shop was not found, 1 otherwise.
5282
5283---------------------------------------
5284
5285*waitingroom "<chatroom name>",<limit>{,<event label>,<trigger>};
5286
5287This command will create a chat room, owned by the NPC object running this
5288script and displayed above the NPC sprite.
5289The maximum length of a chatroom name is 60 letters.
5290
5291The limit is the maximum number of people allowed to enter the chat room. If the
5292optional event and trigger parameters are given, the event label
5293("<NPC object name>::<label name>") will be invoked as if with a 'doevent' upon
5294the number of people in the chat room reaching the given triggering amount.
5295
5296It's funny, but for compatibility with jAthena, you can swap the event label and
5297the trigger parameters, and it will still work.
5298
5299// The NPC will just show a box above its head that says "Hello World", clicking
5300// it will do nothing, since the limit is zero.
5301    waitingroom "Hello World",0;
5302
5303// The NPC will have a box above its head, it will say "Disco - Waiting Room"
5304// and will have 8 waiting slots. Clicking this will enter the chat room, where
5305// the player will be able to wait until 8 people accumulate. Once this happens,
5306// it will cause the NPC "Bouncer" run the label "OnStart"
5307
5308    waitingroom "Disco - Waiting Room",8,"Bouncer::OnStart",8;
5309
5310Creating a waiting room does not stop the execution of the script and it will
5311continue to the next line.
5312
5313For more examples see the 2-1 and 2-2 job quest scripts which make extensive use
5314of waiting rooms.
5315
5316---------------------------------------
5317
5318*delwaitingroom {"<NPC object name"};
5319
5320This command will delete a waiting room. If no parameter is given, it will
5321delete a waiting room attached to the NPC object running this command, if it is,
5322it will delete a waiting room owned by another NPC object. This is the only way
5323to get rid of a waiting room, nothing else will cause it to disappear.
5324
5325It's not clear what happens to a waiting room if the NPC is disabled with
5326'disablenpc', by the way.
5327
5328---------------------------------------
5329
5330*enablewaitingroomevent {"<NPC object name>"};
5331*disablewaitingroomevent {"<NPC object name>"};
5332*enablearena;
5333*disablearena;
5334
5335This will enable and disable triggering the waiting room event (see
5336'waitingroom') respectively. Optionally giving an NPC object name will do that
5337for a specified NPC object. The chat room will not disappear when triggering is
5338disabled and enabled in this manner and players will not be kicked out of it.
5339Enabling a chat room event will also cause it to immediately check whether the
5340number of users in it exceeded the trigger amount and trigger the event
5341accordingly.
5342
5343Normally, whenever a waiting room was created to make sure that only one
5344character is, for example, trying to pass a job quest trial, and no other
5345characters are present in the room to mess up the script.
5346
5347The 'enablearena'/'disablearena' commands are just aliases with no parameter.
5348These are supposedly left here for compatibility with official server scripts,
5349but no eathena script uses these at the moment.
5350
5351---------------------------------------
5352
5353*getwaitingroomstate(<information type>{,"<NPC object name>"})
5354
5355This function will return information about the wating room state for the
5356attached waiting room or for a waiting room attached to the specified NPC if
5357any.
5358
5359The valid information types are:
5360
5361 0  - Number of users currently chatting.
5362 1  - Maximum number of users allowed.
5363 2  - Will return 1 if the waiting room has a trigger set.
5364      0 otherwise.
5365 3  - Will return 1 if the waiting room is currently disabled.
5366      0 otherwise.
5367 4  - The Title of the waiting room (string)
5368 5  - Password of the waiting room, if any. Pointless, since there is no way to
5369      set a password on a waiting room right now.
5370 16 - Event name of the waiting room (string)
5371 32 - Whether or not the waiting room is full.
5372 33 - Whether the amount of users in the waiting room is higher than the trigger
5373      number.
5374
5375---------------------------------------
5376
5377*warpwaitingpc "<map name>",<x>,<y>{,<number of people>};
5378
5379This command will warp the amount of characters equal to the trigger number of
5380the waiting room chat attached to the NPC object running this command to the
5381specified map and coordinates, kicking them out of the chat. Those waiting the
5382longest will get warped first. It can also do a random warp on the same map
5383("Random" instead of map name) and warp to the save point ("SavePoint").
5384
5385The list of characters to warp is taken from the list of the chat room members.
5386Those not in the chat room will not be considered even if they are talking to
5387the NPC in question. If the number of people is given, exactly this much people
5388will be warped.
5389
5390This command can also keep track of who just got warped. It does this by setting
5391special variables:
5392
5393$@warpwaitingpc[] is an array containing the character id numbers of the
5394                  characters who were just warped.
5395$@warpwaitingpcnum contains the number of the character it just warped.
5396
5397See also 'getpartymember' for advice on what to do with those variables.
5398
5399The obvious way of using this effectively would be to set up a waiting room for
5400two characters to be warped onto a random PVP map for a one-on-one duel, for
5401example.
5402
5403---------------------------------------
5404
5405*waitingroomkickall {"<NPC object name>"};
5406
5407This command would kick everybody out of a specified waiting room chat. IF it
5408was properly linked into the script interpreter which it isn't, even though the
5409code for it is in place. Expect this to become available in upcoming SVN
5410releases.
5411
5412---------------------------------------
5413
5414*setmapflagnosave "<map name>","<alternate map name>",<x>,<y>;
5415
5416This command sets the 'nosave' flag for the specified map and also gives an
5417alternate respawn-upon-relogin point.
5418
5419It does not make a map impossible to make a savepoint on as you would normally
5420think, 'savepoint' will still work. It will, however, make the specified map
5421kick the reconnecting players off to the alternate map given to the coordinates
5422 specified.
5423
5424---------------------------------------
5425
5426*setmapflag "<map name>",<flag>;
5427
5428This command marks a specified map with a map flag given. Map flags alter the
5429behavior of the map, you can see the list of the available ones in
5430'db/const.txt' under 'mf_'.
5431
5432The map flags alter the behavior of the map regarding teleporting (mf_nomemo,
5433mf_noteleport, mf_nowarp, mf_nogo), storing location when disconnected
5434(mf_nosave), dead branch usage (mf_nobranch), penalties upon death
5435(mf_nopenalty, mf_nozenypenalty), PVP behavior (mf_pvp, mf_pvp_noparty,
5436mf_pvp_noguild), WoE behavior (mf_gvg,mf_gvg_noparty), ability to use
5437skills or open up trade deals (mf_notrade, mf_novending, mf_noskill, mf_noicewall),
5438current weather effects (mf_snow, mf_fog, mf_sakura, mf_leaves, mf_rain, mf_clouds,
5439mf_fireworks) and whether day/night will be in effect on this map (mf_indoors).
5440
5441---------------------------------------
5442
5443*setbattleflag "<battle flag>",<value>;
5444*getbattleflag "<battle flag>";
5445
5446Sets or gets the value of the given battle flag.
5447Battle flags are the flags found in the battle/*.conf files and is also used in Lupus' variable rates script.
5448
5449Example(s):
5450
5451//will set the base experience rate to 20x (2000%)
5452        setBattleFlag "base_exp_rate",2000;
5453       
5454//will return the value of the base experience rate (when used after the above example, it would return 2000).
5455        getBattleFlag "base_exp_rate";
5456
5457---------------------------------------
5458
5459*removemapflag "<map name>",<flag>;
5460
5461This command removes a mapflag from a specified map. See 'setmapflag'.
5462
5463---------------------------------------
5464
5465*warpportal <x>,<y>,"<mapname>",<x>,<y>;
5466
5467Creates a warp Portal as if a acolyte class character did it.
5468The first x and y is the place of the warp portal on the map where the NPC is on
5469The mapname and second x and y is the target area of the warp portal.
5470
5471Example(s):
5472
5473//Will create a warp portal on the NPC's map at 150,150 leading to prontera, coords 150,180.
5474        warpPortal 150,150,"prontera",150,180;
5475
5476---------------------------------------
5477
5478*mapwarp "<from map>","<to map>",<x>,<y>;
5479
5480This command will collect all characters located on the From map and warp them
5481wholesale to the same point on the To map, or randomly distribute them there if
5482the coordinates are zero. "Random" is understood as a special To map name and
5483will mean randomly shuffling everyone on the same map.
5484
5485---------------------------------------
5486\\
54875,2.- Guild-related Commands
5488\\
5489---------------------------------------
5490
5491*maprespawnguildid "<map name>",<guild id>,<flag>;
5492
5493This command goes through the specified map and for each player and monster
5494found there does stuff.
5495
5496Flag is a bitmask (add up numbers to get effects you want)
5497 1 - warp all guild members to their savepoints.
5498 2 - warp all non-guild members to their savepoints.
5499 4 - remove all monsters which are not guardian or emperium.
5500
5501Flag 7 will, therefore, mean 'wipe all mobs but guardians and the emperium and
5502kick all characters out', which is what the official scripts do upon castle
5503surrender. Upon start of WoE, the scripts do 2 (warp all intruiders out).
5504
5505Characters not belonging to any guild will warp out regardless of the flag setting.
5506
5507For examples, check the WoE scripts in the distribution.
5508
5509---------------------------------------
5510
5511*agitstart;
5512*agitend;
5513
5514These two commands will start and end War of Emperium.
5515
5516This is a bit more complex than it sounds, since the commands themselves won't
5517actually do anything interesting, except causing all 'OnAgitStart:' and
5518'OnAgitEnd:' events to run everywhere, respectively. They are used as
5519simple triggers to run a lot of complex scripts all across the server, and they,
5520in turn, are triggered by clock with an 'OnClock<time>:' time-triggering label.
5521
5522---------------------------------------
5523
5524*gvgon "<map name>";
5525*gvgoff "<map name>";
5526
5527These commands will turn GVG mode for the specified maps on and off, setting up
5528appropriate map flags. In GVG mode, maps behave as if during the time of WoE,
5529even though WoE itself may or may not actually be in effect.
5530
5531---------------------------------------
5532
5533*flagemblem <guild id>;
5534
5535This command only works when run by the NPC objects which have sprite id 722,
5536which is a 3D guild flag sprite. If it isn't, the data will change, but nothing
5537will be seen by anyone. If it is invoked in that manner, the emblem of the
5538specified guild will appear on the flag, though, if any players are watching it
5539at this moment, they will not see the emblem change until they move out of sight
5540of the flag and return.
5541
5542This is commonly used in official guildwar scripts with a function call which
5543returns a guild id:
5544
5545// This will change the emblem on the flag to that of the guild that owns
5546// "guildcastle"
5547
5548    flagemblem GetCastleData("guildcastle",1);
5549
5550---------------------------------------
5551
5552*guardian("<map name>",<x>,<y>,"<name to show>",<mob id>,<amount>{,"<event label>"}{,<guardian index>})
5553
5554This command is roughly equivalent to 'monster', but is meant to be used with
5555castle guardian monsters and will only work with them. It will set the guardian
5556characteristics up according to the castle's investment values and otherwise
5557set the things up that only castle guardians need.
5558
5559Since trunk r12524:
5560Returns the id of the mob or 0 if an error occurred.
5561When 'guardian index' isn't supplied it produces a temporary guardian.
5562Temporary guardians are not saved with the castle and can't be accessed by guardianinfo.
5563
5564---------------------------------------
5565
5566*guardianinfo("<map name>", <guardian number>, <type>)
5567
5568This function will return various info about the specified guardian, or -1
5569if it fails for some reason. It is primarily used in the castle manager npc.
5570
5571Map name and guardian number (value between 0 and 7) define the target.
5572Type indicates what information to return:
5573 0 - visibility (whether the guardian is installed or not)
5574 1 - max. hp
5575 2 - current hp
5576
5577---------------------------------------
5578//
55795,2.- End of guild-related commands
5580//
5581---------------------------------------
5582
5583*npcspeed <speed value>;
5584*npcwalkto <x>,<y>;
5585*npcstop;
5586
5587These commands will make the NPC object in question move around the map. As they
5588currently are, they are a bit buggy and are not useful for much more than making
5589an NPC move randomly around the map. (see 'npc/custom/devnpc.txt' for an example
5590of such usage)
5591
5592'npcspeed' will set the NPCs walking speed to a specified value. As in the
5593@speed GM command, 200 is the slowest possible speed while 0 is the fastest
5594possible (instant motion). 100 is the default character walking speed.
5595'npcwalkto' will start the NPC sprite moving towards the specified coordinates
5596on the same map as it is currently on.
5597'npcstop' will stop the motion.
5598
5599While in transit, the NPC will be clickable, but invoking it will cause it to
5600stop motion, which will make it's coordinates different from what the client
5601computed based on the speed and motion coordinates. The effect is rather
5602unnerving.
5603
5604Only a few NPC sprites have walking animations, and those that do, do not get
5605the animation invoked when moving the NPC, due to the problem in the npc walking
5606code, which looks a bit silly. You might have better success by defining a job-
5607sprite based sprite id in 'db/mob-avail.txt' with this.
5608
5609---------------------------------------
5610
5611*movenpc <NPC name>,x,y;
5612
5613This command looks like the NPCWalkToxy function,but is a little different.
5614
5615While NPCWalkToXY just makes the NPC 'walk' to the coordinates given
5616(which sometimes gives problems if the path isn't a straight line without objects),
5617this command just moves the NPC. It basically warps out and in on the current and given spot.
5618
5619Example(s):
5620
5621//This will move Bugga from it's current position to the coords 100,20 (if those coords are walkable (legit)).
5622        moveNPC "Bugga",100,20;
5623       
5624---------------------------------------
5625
5626=====================
5627|6.- Other commands.|
5628=====================
5629---------------------------------------
5630
5631*debugmes "<message>";
5632
5633This command will send the message to the server console (map-server window). It
5634will not be displayed anywhere else.
5635
5636    debugmes strcharinfo(0)+" has just done this that and the other";
5637    // You would see in the map-server window "NAME has just done this that and
5638    // the other"
5639
5640---------------------------------------
5641
5642*logmes "<message>";
5643
5644This command will write the message given to the map server npc log file, as
5645specified in 'conf/log_athena.conf'. In the TXT version of the server, the log
5646file is 'log/npclog.log' by default. In the SQL version, if SQL logging is
5647enabled, the message will go to the 'npclog' table, otherwise, it will go to the
5648same log file.
5649
5650If logs are not enabled, nothing will happen.
5651
5652---------------------------------------
5653
5654*globalmes "<message>"{,"<NPC name>"};
5655
5656This command will send a message to the chat window of all currently connected
5657characters.
5658
5659If NPC name is specified, the message will be sent as if the sender would be
5660the npc with the said name.
5661
5662---------------------------------------
5663
5664*rand(<number>{,<number>});
5665
5666This function returns a number, randomly positioned between 0 and the number you
5667specify (if you only specify one) and the two numbers you specify if you give it
5668two.
5669
5670rand(10) would result in 0,1,2,3,4,5,6,7,8 or 9
5671
5672rand(2,10) would result in 2,3,4,5,6,7,8,9 or 10
5673
5674---------------------------------------
5675
5676*viewpoint <action>,<x>,<y>,<point number>,<color>;
5677
5678This command will mark places on the mini map in the client connected to the
5679invoking character. It uses the normal X and Y coordinates from the main map.
5680The colors of the marks are defined using a hexidecimal number, same as the ones
5681used to color text in 'mes' output, but are written as hexadecimal numbers in C.
5682(They look like 0x<six numbers>.)
5683
5684Action is what you want to do with a point, 1 will set it, while 2 will clear
5685it. Point number is the number of the point - you can have several. If more than
5686one point is drawn at the same coordinates, they will cycle, which can be used
5687to create flashing marks.
5688
5689    // This command will show a mark at coordinates X 30 Y 40, is mark number 1,
5690    // and will be red.
5691   
5692    viewpoint 1,30,40,1,0xFF0000;
5693
5694This will create three points:
5695
5696    viewpoint 1,30,40,1,0xFF0000;
5697    viewpoint 1,35,45,2,0xFF0000;
5698    viewpoint 1,40,50,3,0xFF0000;
5699
5700And this is how you remove them:
5701
5702    viewpoint 2,30,40,1,0xFF0000;
5703    viewpoint 2,35,45,2,0xFF0000;
5704    viewpoint 2,40,50,3,0xFF0000;
5705   
5706The client determines what it does with the points entirely, the server keeps no
5707memory of where the points are set whatsoever.
5708
5709---------------------------------------
5710
5711*cutin "<filename>",<position>;
5712
5713This command will display a picture stored in the GRF file in the client for the
5714player.
5715
5716The files are taken from '\data\texture\A_A£AII’„AI«§\illust' directory in the
5717GRF file. Also it seems that card cutins from \cardbmp will work here as well.
5718Only bitmaps (images stored in the bitmap format) will actually get displayed.
5719The '.bmp' extension is optional.
5720The client has no problem rendering huge 4096x4096 bitmaps, but usually they're
5721around 500x500. Bright magenta (color FF00FF) is considered to be transparent in
5722these pictures. You can easily add and alter them, but how to do this is outside
5723of the scope of this document.
5724
5725The position determines just where on screen the picture will appear:
5726  0 - bottom left corner
5727  1 - bottom middle
5728  2 - bottom right corner
5729  3 - middle of screen in a movable window with an empty title bar.
5730  4 - middle of screen without the window header, but still movable.
5731  255 - will remove the cutin previously displayed.
5732 
5733Giving an empty string for the filename and 255 for the position will remove all
5734cutin pictures. Any other position value will not cause a script error but will
5735cause the player's client to curl up and die. Only one cutin may be on screen at
5736any given time, any new cutins will replace it.
5737
5738    // This will display the picture of the 7th kafra,
5739    // the one in orange and the mini-skirt :P
5740    cutin "kafra_7",2;
5741
5742    // This will remove the displayed picture.
5743    cutin "Kafra_7",255;
5744
5745    // This will remove all pictures displayed.
5746    cutin "",255;
5747
5748---------------------------------------
5749
5750*pet <pet id>;
5751
5752This command is used in all the item scripts for taming items. Running this
5753command will make the pet catching cursor appear on the client connected to the
5754invoking character, usable on the monsters with the specified pet ID number. It
5755will still work outside an item script.
5756
5757A full list of pet IDs can be found inside 'db/pet_db.txt'
5758
5759---------------------------------------
5760
5761*emotion <emotion number>{, target};
5762
5763This command makes an object display an emoticon sprite above their own as
5764if they were doing that emotion. For a full list of emotion numbers,
5765see 'db/const.txt' under 'e_'. The inobvious ones are 'e_what' (a question mark)
5766and 'e_gasp' (the exclamation mark).
5767
5768The optional target parameter specifies who will get the emotion on top of
5769their head. If 0 (the default if omitted), the NPC in current use will show
5770the emotion, if 1, the player that is running the script will display it.
5771
5772---------------------------------------
5773
5774*misceffect <effect number>;
5775
5776This command, if run from an NPC object that has a sprite, will call up a
5777specified effect number, centered on the NPC sprite. If the running code does
5778not have an object ID (a 'floating' npc) or is not running from an NPC object at
5779all (an item script) the effect will be centered on the character who's RID got
5780attached to the script, if any. For usable item scripts, this command will
5781create an effect centered on the player using the item.
5782
5783A full list of known effects is found in 'doc/effect_list.txt'. The list of
5784those that actually work may differ greatly between client versions.
5785
5786---------------------------------------
5787
5788*soundeffect "<effect filename>",<type>
5789*soundeffectall "<effect filename>",<type>{,"<map name>"}{,<x0>,<y0>,<x1>,<y1>}
5790
5791These two commands will play a sound effect to either the invoking character
5792only ('soundeffect') or multiple characters ('soundeffectall'). If the running
5793code does not have an object ID (a 'floating' npc) or is not running from an NPC
5794object at all (an item script) the sound will be centered on the character who's
5795RID got attached to the script, if any. If it does, it will be centered on that
5796object. (an NPC sprite)
5797
5798Effect filename is the filename in a GRF. It must have the .wav extension.
5799
5800It's not quite certain what the 'type' actually does, it is sent to the client
5801directly. It probably determines which directory to play the effect from.
5802It's certain that giving 0 for the number will play sound files from 'data/wav',
5803but where the other numbers will read from is unclear.
5804
5805You can add your own effects this way, naturally.
5806
5807---------------------------------------
5808
5809*pvpon "<map name>";
5810*pvpoff "<map name>";
5811
5812These commands will turn PVP mode for the specified maps on and off. Beside
5813setting the flags referred to in 'setmapflag', 'pvpon' will also create a PVP
5814timer and ranking as will @pvpon GM command do.
5815
5816---------------------------------------
5817
5818*atcommand "<command line>";
5819
5820This command will run the given command line exactly as if it was typed in from
5821the keyboard by the player connected to the invoking character, and that
5822character belonged to an account which had GM level 99.
5823
5824    // This will ask the invoker for a character name and then use the '@nuke'
5825    // GM command on them, killing them mercilessly.
5826    input @player$;
5827    atcommand "@nuke "+@player$;
5828
5829This command has a lot of good uses, I am sure you can have some fun with this
5830one.
5831
5832---------------------------------------
5833
5834*charcommand <command>;
5835
5836NOTE: This command is changed a bit on newer trunk versions,
5837scroll down a bit for the new version!
5838
5839On older trunk versions and stable:
5840
5841command is the name of the current character (strcharinfo(0))
5842followed by ':' and the command and it's parameters.
5843
5844Example(s):
5845
5846//Will be executed as if a lvl 99 GM done the #option command.
5847        charCommand strcharinfo(0)+":#option 0 0 0 Roy";
5848
5849Newer Trunk version:
5850
5851The big change is that the character name is no longer needed.
5852This also enabled the commands to run without a player attached (according to Lance).
5853
5854Example(s):
5855
5856//this would do the same as above, but now doesn't need a player attached by default.
5857        charCommand "#option 0 0 0 Roy";
5858
5859---------------------------------------
5860
5861*unitskilluseid <GID>,<skill id>,<skill lvl>{,<target id>};
5862*unitskilluseid <GID>,"<skill name>",<skill lvl>{,<target id>};
5863*unitskillusepos <GID>,<skill id>,<skill lvl>,<x>,<y>;
5864*unitskillusepos <GID>,"<skill name>",<skill lvl>,<x>,<y>;
5865
5866This is the replacement of the older commands, these use the same values for
5867GID as the other unit* commands (See 'GID').
5868
5869Skill ID is the ID of the skill, skill level is the level of the skill.
5870For the position, the x and y are given in the unitSkillUsePos.
5871
5872---------------------------------------
5873
5874*day;
5875*night;
5876
5877These two commands will switch the entire server between day and night mode.
5878Depending on the configuration, it may cause differing client effects. If your
5879server is set to cycle between day and night, it will eventually return to that
5880cycle.
5881
5882This example will set the night time to start at 03 AM and end at 08 AM, and the
5883nighttime will persist if the server restarts during the night, if the automated
5884day/night switching is turned off in the configuration files. Figure it out on
5885your own:
5886
5887-%TAB%script%TAB%DayNight%TAB%-1,{
5888       
5889        end;
5890
5891OnClock0300:
5892   
5893OnClock0800:
5894   
5895OnInit:
5896
5897        set $@minutesfrommidnight, gettime(3)*60+gettime(2);
5898
5899        set $@night_start, 180; // 03:00
5900        set $@night_end, 480;   // 08:00
5901
5902        if ($@minutesfrommidnight>=$@night_start && $@minutesfrommidnight<$@night_end) goto StartNight;
5903
5904        goto StartDay;
5905        StartNight:     
5906        night;
5907        end;
5908        StartDay:
5909        day;
5910        end;    }
5911
5912---------------------------------------
5913
5914*defpattern <set number>,"<regular expression pattern>","<event label>";
5915*activatepset <set number>;
5916*deactivatepset <set number>;
5917*deletepset <set number>;
5918
5919This set of commands is only available if the server is compiled with regular
5920expressions library enabled. Default compilation and most binary distributions
5921aren't, which is probably bad, since these, while complex to use, are quite
5922fascinating.
5923
5924They will make the NPC object listen for text spoken publicly by players and
5925match it against regular expression patterns, then trigger labels associated
5926with these regular expression patterns.
5927
5928Patterns are organised into sets, which are referred to by a set number. You can
5929have multiple sets patterns, and multiple patterns may be active at once.
5930Numbers for pattern sets start at 1.
5931
5932'defpattern' will associate a given regular expression pattern with an event
5933label. This event will be triggered whenever something a player says is matched
5934by this regular expression pattern, if the pattern is currently active.
5935
5936'activatepset' will make the pattern set specified active. An active pattern
5937will enable triggering labels defined with 'defpattern', which will not happen
5938by default.
5939'deactivatepset' will deactivate a specified pattern set. Giving -1 as a pattern
5940set number in this case will deactivate all pattern sets defined.
5941
5942'deletepset' will delete a pattern set from memory, so you can create a new
5943pattern set in it's place.
5944
5945Using regular expressions is high wizardry. But with this high wizardry comes
5946unparallelled power of text manipulation. For an explanation of what a regular
5947expression pattern is, see a few web pages:
5948
5949http://www.regular-expressions.info/
5950http://www.weitz.de/regex-coach/
5951
5952For an example of this in use, see 'npc\sample\npc_pcre.txt'.
5953
5954With this you could, for example, automagically punish players for asking for
5955zeny in public places, or alternatively, automagically give them zeny instead if
5956they want it so much.
5957
5958---------------------------------------
5959
5960*pow(<number>,<power>)
5961
5962Returns the result of the calculation.
5963
5964Example:
5965set @i, pow(2,3); // @i will be 8
5966
5967---------------------------------------
5968
5969*sqrt(<number>)
5970
5971Returns square-root of number.
5972
5973Examlpe:
5974set @i, sqrt(25); // @i will be 5
5975
5976---------------------------------------
5977
5978*distance(<x0>,<y0>,<x1>,<y1>)
5979
5980Returns distance between 2 points.
5981
5982Example:
5983set @i, distance(100,200,101,202);
5984
5985---------------------------------------
5986
5987*query_sql "your MySQL query", <array variable> {,<array variable>, ...};
5988*query_logsql "your MySQL query", <array variable> {,<array variable>, ...};
5989
5990Puts up to 128 rows of values into the arrays and returns the number of rows.
5991
5992Example:
5993set @nb, query_sql("select name,fame from `char` ORDER BY fame DESC LIMIT 5", @name$, @fame);
5994mes "Hall Of Fame: TOP5";
5995mes "1."+@name$[0]+"("+@fame[0]+")"; // Will return a person with the biggest fame value.
5996mes "2."+@name$[1]+"("+@fame[1]+")";
5997mes "3."+@name$[2]+"("+@fame[2]+")";
5998mes "4."+@name$[3]+"("+@fame[3]+")";
5999mes "5."+@name$[4]+"("+@fame[4]+")";
6000
6001Note: In the TXT version it doesn't fill the array and always return -1.
6002Note: Use $ as suffix in the array to receive all data as text.
6003Note: The difference between query_sql and query_logsql is that the latter
6004uses the sql connection to the log database, and should be used when you want
6005to query the server log tables.
6006
6007---------------------------------------
6008
6009*setitemscript(<ItemID>,<"{ new item script }">);
6010
6011Set a new script bonus to the Item. Very useful for game events.
6012You can remove an item's itemscript by leaving empty the itemscript argument.
6013
6014Example:
6015
6016setitemscript 2637,"{ bonus bDamageWhenUnequip,40; if(isequipped(2236)==0)end; if(getskilllv(26)){skill 40,1;}else{skill 26,1+isequipped(2636);} }";
6017setitemscript 2639,"";
6018
6019---------------------------------------
6020
6021*atoi ("<string>")
6022*axtoi ("<string>")
6023
6024These commands are used to convert strings to numbers.
6025atoi will convert string using normal number (0,1,2,3,etc) while axtoi converts them to
6026hexadecimal numbers (0,1,11,01).
6027
6028Example:
6029
6030        mes atoi("11");                 // Will display 11 (can also be used to set a @var to 11)
6031        set @var, axtoi("FF");  // Will set the @var to 255
6032        mes axtoi("11");                // Will display 17 (1 = 1, 10 = 16,
6033                                                        // hexadecimal number set: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F})
6034
6035---------------------------------------
6036
6037*compare (<string>,<substring>)
6038
6039This command returns 1 or 0 when a the substring is in the main string (1) or not (0).
6040This command is not case sensitive.
6041
6042Example(s):
6043
6044//dothis; will be executed ('Bloody Murderer' contains 'Blood').
6045        if (compare("Bloody Murderer","Blood"))
6046                dothis;
6047//dothat; will not be executed ('Blood butterfly' does not contain 'Bloody').
6048        if (compare("Blood Butterfly","Bloody"))
6049                dothat;
6050
6051--------------------------------------
6052
6053*charisalpha("<string>",<position>)
6054
6055This function will return 1 if the character number Position in the given string
6056is a letter, 0 if it isn't a letter but a digit or a space.
6057
6058---------------------------------------
6059
6060*wedding_effect;
6061Starts the effect used when a wedding is done (music and everything else)
6062Example can be found in the wedding script.
6063
6064--------------------------------------
6065
6066* The Pet AI commands
6067
6068These commands will only work if the invoking character has a pet, and are meant
6069to be executed from pet scripts. They will modify the pet AI decision-making for
6070the current pet of the invoking character, and will NOT have any independent
6071effect by themselves, which is why only one of them each may be in effect at any
6072time for a specific pet. A pet may have 'petloot', 'petskillbonus',
6073'petskillattack' OR 'petpetskillattack2' and 'petskillsupport' OR 'petheal' at
6074the same time. 'petheal' is deprecated and is no longer used in the default pet
6075scripts.
6076
6077*petskillbonus <bonus type>,<value>,<duration>,<delay>;
6078
6079This command will make the pet give a bonus to the owner's stat (bonus type -
6080bInt,bVit,bDex,bAgi,bLuk,bStr,bSpeedRate - for a full list, see the values
6081starting with 'b' in 'db/const.txt')
6082
6083*petrecovery <status type>,<delay>;
6084
6085This command will make the pet cure a specified status condition. The curing
6086actions will occur once every Delay seconds. For a full list of status
6087conditions that can be cured, see the list of 'SC_' status condition constants
6088in 'db/const.txt'
6089
6090*petloot <max items>;
6091
6092This command will turn on pet looting, with a maximum number of items to loot
6093specified. Pet will store items and return them when the maximum is reached or
6094when pet performance is activated.
6095
6096*petskillsupport <skill id>,<skill level>,<delay>,<percent hp>,<percent sp>;
6097*petskillsupport "<skill name>",<skill level>,<delay>,<percent hp>,<percent sp>;
6098*petheal <level>,<delay>,<percent hp>,<percent sp>;
6099
6100This will make the pet use a specified support skill on the owner whenever the
6101HP and SP are below the given percent values, with a specified delay time
6102between activations. The skill numbers are as per 'db/skill_db.txt'.
6103'petheal' works the same as 'petskillsupport' but has the skill ID hardcoded to
610428 (Heal). This command is deprecated.
6105It's not quite certain who's stats will be used for the skills cast, the
6106character's or the pets. Probably, Skotlex can answer that question.
6107
6108*petskillattack <skill id>,<skill level>,<rate>,<bonusrate>;
6109*petskillattack "<skill name>",<skill level>,<rate>,<bonusrate>;
6110*petskillattack2 <skill id>,<damage>,<number of attacks>,<rate>,<bonusrate>;
6111*petskillattack2 "<skill name>",<damage>,<number of attacks>,<rate>,<bonusrate>;
6112
6113These two commands will make the pet cast an attack skill on the enemy the pet's
6114owner is currently fighting. Skill IDs and levels are as per 'petskillsupport'.
6115'petskillattack2' will make the pet cast the skill with a fixed amount of damage
6116inflicted and the specified number of attacks.
6117
6118All commands with delays and durations will only make the behavior active for
6119the specified duration of seconds, with a delay of the specified number of
6120seconds between activations. Rates are a chance of the effect occuring and are
6121given in percent. 'bonusrate' is added to the normal rate if the pet intimacy is
6122at the maximum possible.
6123
6124The behavior modified with the abovementioned commands will only be exibited if
6125the pet is loyal and appropriate configuration options are set in
6126'battle_athena.conf'.
6127
6128Pet scripts in the database normally run whenever a pet of that type hatches
6129from the egg. Other commands usable in item scripts (see 'bonus') will also
6130happily run from pet scripts. Apparently, the pet-specific commands will also
6131work in NPC scripts and modify the behavior of the current pet up until the pet
6132is hatched again. (Which will also occur when the character is logged in again
6133with the pet still out of the egg.) It is not certain for how long the effect of
6134such command running from an NPC script will eventually persist, but apparently,
6135it is possible to usefully employ them in usable item scripts to create pet
6136buffing items.
6137
6138Nobody tried this before, so you're essentially on your own here.
6139
6140--------------------------------------
6141
6142*bpet;
6143
6144This command opens up a pet hatching window on the client connected to the
6145invoking character. It is used in item script for the pet incubators and will
6146let the player hatch an owned egg. If the character has no eggs, it will just
6147open up an empty incubator window.
6148This is still usable outside item scripts.
6149
6150---------------------------------------
6151
6152*makepet <pet id>;
6153
6154This command will create a pet egg and put it in the invoking character's
6155inventory. The kind of pet is specified by pet ID numbers listed in
6156'db/pet_db.txt'. The egg is created exactly as if the character just successfuly
6157caught a pet in the normal way.
6158
6159    // This will make you a poring:
6160    makepet 1002;
6161
6162Notice that you absolutely have to create pet eggs with this command. If you try
6163to give a pet egg with 'getitem', pet data will not be created by the char
6164server and the egg will disappear when anyone tries to hatch it.
6165
6166---------------------------------------
6167
6168*openmail;
6169
6170This will open a character's Mail window on the client connected to the
6171invoking character.
6172
6173    mes "Close this window to open your mail inbox.";
6174    close2;
6175    openmail;
6176    end;
6177
6178---------------------------------------
6179
6180*homshuffle;
6181
6182This will recalculate the homunculus stats acording to its level, of the
6183current invoking character.
6184
6185---------------------------------------
6186
6187*setcell "<map name>",<x1>,<y1>,<x2>,<y2>,<type>,<flag>;
6188
6189Each map cell has several 'flags' that specify the properties of that cell.
6190These include terrain properties (walkability, shootability, presence of water),
6191skills (basilica, land protector, ...) and other (npc nearby, no vending, ...).
6192Each of these can be 'on' or 'off'. Together they define a cell's behavior.
6193
6194This command lets you alter these flags for all map cells in the specified
6195(x1,y1)-(x2,y2) rectangle. The 'flag' can be 0 or 1 (0:clear flag, 1:set flag).
6196The 'type' defines which flag to modify. Possible options include cell_walkable,
6197cell_shootable, cell_basilica. For a full list, see const.txt.
6198
6199Example:
6200
6201        setcell "arena",0,0,300,300,cell_basilica,1;
6202        setcell "arena",140,140,160,160,cell_basilica,0;
6203        setcell "arena",135,135,165,165,cell_walkable,0;
6204        setcell "arena",140,140,160,160,cell_walkable,1;
6205
6206This will add a makeshift ring into the center of the map. The ring will be
6207surrounded by a 5-cell wide 'gap' to prevent interference from outside, and
6208the rest of the map will be marked as 'basilica', preventing observers from
6209casting any offensive skills or fighting among themselves. Note that the wall
6210will not be shown nor known client-side, which may cause movement problems.
6211
6212Another example:
6213
6214OnBarricadeDeploy:
6215        setcell "schg_cas05",114,51,125,51,cell_walkable,0;
6216        end;
6217OnBarricadeBreak:
6218        setcell "schg_cas05",114,51,125,51,cell_walkable,1;
6219        end;
6220
6221This could be a part of the WoE:SE script, where attackers are not allowed
6222to proceed until all barricades are destroyed. This script would place and
6223remove a nonwalkable row of cells after the barricade mobs.
6224       
6225---------------------------------------
6226
6227*checkcell ("<map name>",<x>,<y>,<type>);
6228
6229This command will return 1 or 0, depending on whether the specified cell has
6230the 'type' flag set or not. There are various types to check, all mimicking
6231the server's cell_chk enumeration. The types can be found in db/const.txt.
6232
6233The meaning of the individual types can be confusing, so here's an overview:
6234  - cell_chkwall/water/cliff
6235    these check directly for the 'terrain component' of the specified cell
6236  - cell_chkpass/reach/nopass/noreach
6237    passable = not wall & not cliff, reachable = passable wrt. no-stacking mod
6238  - cell_chknpc/basilica/landprotector/novending/nochat
6239    these check for specific dynamic flags (their name indicates what they do)
6240
6241Example:
6242
6243        mes "Pick a destination map.";
6244        input .@map$;
6245        mes "Alright, now give me the coordinates.";
6246        input .@x;
6247        input .@y;
6248        if( !checkcell(.@map$,.@x,.@y,cell_chkpass) )
6249        {
6250                mes "Can't warp you there, sorry!";
6251                close;
6252        }
6253        else
6254        {
6255                mes "Ok, get ready...";
6256                close2;
6257                warp .@map$, .@x, .@y;
6258                end;
6259        }
6260
6261---------------------------------------
6262
6263Whew.
6264That's about all of them.
Note: See TracBrowser for help on using the browser.