summaryrefslogtreecommitdiff
path: root/doc/script_commands.txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/script_commands.txt')
-rw-r--r--doc/script_commands.txt334
1 files changed, 226 insertions, 108 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 8308f4771..9bbb65c1c 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -434,17 +434,39 @@ marked as usable in pet scripts to work in there reliably.
Numbers
-------
+The Hercules scripting engine supports 4 types of number literals:
+
+type base syntax
+----------------------------------------------
+decimal 10 255
+hexadecimal 16 0xFF
+octal 8 0o377
+binary 2 0b11111111
+
Beside the common decimal numbers, which are nothing special whatsoever
(though do not expect to use fractions, since ALL numbers are integer in
this language), the script engine also handles hexadecimal numbers, which
are otherwise identical. Writing a number like '0x<hex digits>' will make
it recognized as a hexadecimal value. Notice that 0x10 is equal to 16.
-Also notice that if you try to 'mes 0x10' it will print '16'.
+Also notice that if you try to 'mes 0x10' it will print '16'. If you wish
+to make calculations in base 8, you can also use the octal notation like
+'0o<octal digits>'. To make calculations in base 2 (binary), you can use
+the binary notation like '0b<binary digits>'.
+
+The following are all equivalent:
+ 255 == 0xFF == 0o377 == 0b11111111
Number values can't exceed the limits of an integer variable: Any number
greater than INT_MAX (2147483647) or smaller than INT_MIN (-2147483648) will
be capped to those values and will cause a warning to be reported.
+Underscores can also be used as visual separators for digit grouping purposes:
+ 2_147_483_647
+ 0x7FFF_FFFF
+
+Keep in mind that number literals cannot start or end with a separator and no
+more than one separator can be used in a row (so 12_3___456 is illegal).
+
Variables
---------
@@ -536,7 +558,9 @@ variables or an empty string ("", nothing between the quotes) for string
variables. Once you set it to that, the variable is as good as forgotten
forever, and no trace remains of it even if it was stored with character
or account data. The maximum length of variable name including prefix and
-suffix is 32.
+suffix is 32. Permanent string variables (name$, $name$, #name$, ##name$)
+can store text with a maximum length of 255 characters. All other string
+type variables have no such limitation.
Some variables are special, that is, they are already defined for you by
the scripting engine. You can see the full list somewhere in
@@ -1710,7 +1734,8 @@ The default value of 'min' and 'max' can be set with 'input_min_value' and
For numeric inputs the value is capped to the range [min, max]. Returns 1
if the value was higher than 'max', -1 if lower than 'min' and 0 otherwise.
For string inputs it returns 1 if the string was longer than 'max', -1 is
-shorter than 'min' and 0 otherwise.
+shorter than 'min' and 0 otherwise. Note that an input string has a maximum
+length of 70 characters.
---------------------------------------
@@ -1942,58 +1967,64 @@ will result in error and termination of the script.
---------------------------------------
-*function <function name>;
-*<function name>{(<argument>, ...<argument>)};
-*function <function name> {
+{public | private} *function <function name>;
+{public | private} *function <function name> {
<code>
}
-This works like callfunc(), and is used for cleaner and faster scripting.
-The function must be defined and used within a script, and works like a
-label with arguments.
-Note that the name may only contain alphanumeric characters and underscore.
+In its first form, this syntax declares a local function so it can later be
+defined. In its second form, the syntax both declares and defines a local
+function. Local functions must be defined before being used. Note that the name
+may only contain alphanumeric characters and underscore. Once defined, they can
+be called from the current script as if they were regular built-in commands, and
+can also be called from other scripts if they are marked as public. Local
+functions may be marked as public by simply adding "public" prior to the
+function definition. Functions not marked as public are private by default and
+cannot be called from another script.
Usage:
1. Declare the function.
function <function name>;
2. Call the function anywhere within the script.
- It can also return a value when used with parentheses.
- <function name>;
- 3. Define the function within the script.
+ <function name>();
+ 3. Define the function by adding its script.
<function name> {<code>}
+ Step 1 is optional if the function is defined prior to being called.
+
Example:
-prontera,154,189,4 script Item Seller 767,{
/* Function declaration */
- function SF_Selling;
+ function MyFunction;
- if (Zeny > 50) {
- mes("Welcome!");
- /* Function call */
- SF_Selling();
- } else {
- mes("You need 50z, sorry!");
- }
- close();
+ /* Function call */
+ MyFunction();
/* Function definition */
- function SF_Selling {
- mes("Would you like to buy a phracon for 50z?");
- next();
- if (select("Yes", "No, thanks") == 1) {
- Zeny -= 50;
- getitem(Phracon, 1);
- mes("Thank you!");
- }
+ function MyFunction {
+ // (do something)
return;
}
-}
+
+
+Example with public functions:
+
+ /* Function declaration + definition */
+ public function myFunction {
+ /* notice the "public" before the "function" keyword */
+ return;
+ }
+
+ /* Local call */
+ myFunction();
+
+ /* Call from another script */
+ "npc name"::myFunction();
+
Example with parameters and return value:
-prontera,150,150,0 script TestNPC 123,{
/* Function declaration */
function MyAdd;
@@ -2002,18 +2033,35 @@ prontera,150,150,0 script TestNPC 123,{
input(.@a);
input(.@b);
/* Function call */
- mes(.@a+" + "+.@b+" = "+MyAdd(.@a, .@b));
+ mesf("%i + %i = %i", .@a, .@b, MyAdd(.@a, .@b));
close();
/* Function definition */
function MyAdd {
- return(getarg(0)+getarg(1));
+ return (getarg(0) + getarg(1));
}
-}
---------------------------------------
+*<function name>({<arg>...})
+*"<npc name>"::<function name>({<arg>...})
+*callfunctionofnpc("<function name>", "<npc name>"{, <arg>...});
+
+In its first form, calls a previously defined local function. In its second
+form, calls a previously defined public local function of another NPC. If the
+name of the target NPC or the name of the local function is not known
+beforehand, callfunctionofnpc() can be used instead of the second form.
+See function() above for more details.
+
+Example:
+
+ MyFunction(arg1, arg2, arg3);
+ "MyNPC"::MyFunction(arg1, arg2, arg3);
+ callfunctionofnpc("MyNPC", "MyFunction", arg1, arg2, arg3);
+
+---------------------------------------
+
*is_function("<function name>")
This command checks whether or not a function exists and returns its type.
@@ -3147,23 +3195,24 @@ This command sets a bunch of arrays with a complete list of whatever the
invoking character has in its inventory, including all the data needed to
recreate these items perfectly if they are destroyed. Here's what you get:
-@inventorylist_id[] - array of item ids.
-@inventorylist_idx[] - array of item inventory index.
-@inventorylist_amount[] - their corresponding item amounts.
-@inventorylist_equip[] - will return the slot the item is equipped on, if at all.
-@inventorylist_refine[] - for how much it is refined.
-@inventorylist_identify[] - whether it is identified.
-@inventorylist_attribute[] - whether it is broken.
-@inventorylist_card1[] - These four arrays contain card data for the
-@inventorylist_card2[] items. These data slots are also used to store
-@inventorylist_card3[] names inscribed on the items, so you can
-@inventorylist_card4[] explicitly check if the character owns an item
- made by a specific craftsman.
-@inventorylist_expire[] - expire time (Unix time stamp). 0 means never
- expires.
-@inventorylist_bound[] - whether it is an account bounded item or not.
-@inventorylist_favorite[] - whether it is favorite (inside favorite tab) or not.
-@inventorylist_count - the number of items in these lists.
+@inventorylist_id[] - array of item ids.
+@inventorylist_idx[] - array of item inventory index.
+@inventorylist_amount[] - their corresponding item amounts.
+@inventorylist_equip[] - will return the slot the item is equipped on, if at all.
+@inventorylist_refine[] - for how much it is refined.
+@inventorylist_identify[] - whether it is identified.
+@inventorylist_attribute[] - whether it is broken.
+@inventorylist_card1[] - These four arrays contain card data for the items.
+@inventorylist_card2[] These data slots are also used to store names inscribed
+@inventorylist_card3[] on the items, so you can explicitly check if the character
+@inventorylist_card4[] owns an item made by a specific craftsman.
+@inventorylist_expire[] - expire time (Unix time stamp). 0 means never expires.
+@inventorylist_bound[] - whether it is an account bounded item or not.
+@inventorylist_favorite[] - whether it is favorite (inside favorite tab) or not.
+@inventorylist_opt_id1~5[] - array of random option id.
+@inventorylist_opt_val1~5[] - array of random option val.
+@inventorylist_opt_param1~5[] - array of random option param.
+@inventorylist_count - the number of items in these lists.
This could be handy to save/restore a character's inventory, since no
other command returns such a complete set of data, and could also be the
@@ -3191,14 +3240,15 @@ recreate these items perfectly if they are destroyed. Here's what you get:
@cartinventorylist_refine[] - for how much it is refined.
@cartinventorylist_identify[] - whether it is identified.
@cartinventorylist_attribute[] - whether it is broken.
-@cartinventorylist_card1[] - These four arrays contain card data for the
-@cartinventorylist_card2[] items. These data slots are also used to store
-@cartinventorylist_card3[] names inscribed on the items, so you can
-@cartinventorylist_card4[] explicitly check if the character owns an item
- made by a specific craftsman.
-@cartinventorylist_expire[] - expire time (Unix time stamp). 0 means never
- expires.
+@cartinventorylist_card1[] - These four arrays contain card data for the items.
+@cartinventorylist_card2[] These data slots are also used to store names inscribed on the items,
+@cartinventorylist_card3[] so you can explicitly check if the character owns an item
+@cartinventorylist_card4[] made by a specific craftsman.
+@cartinventorylist_expire[] - expire time (Unix time stamp). 0 means never expires.
@cartinventorylist_bound - whether it is an account bound item or not.
+@inventorylist_opt_id1~5[] - array of random option id.
+@inventorylist_opt_val1~5[] - array of random option val.
+@inventorylist_opt_param1~5[] - array of random option param.
@cartinventorylist_count - the number of items in these lists.
This could be handy to save/restore a character's cart_inventory, since no
@@ -3277,6 +3327,7 @@ Example:
---------------------------------------
*getiteminfo(<item ID>, <type>)
+*getiteminfo("<item name>", <type>)
*setiteminfo(<item ID>, <type>, <value>)
This function will look up the item with the specified ID number in the
@@ -3285,6 +3336,9 @@ It will return -1 if there is no such item.
Valid types are:
+ ITEMINFO_ID - Item ID (getiteminfo() only!)
+ ITEMINFO_AEGISNAME - Unique name to reference the item (getiteminfo() only!)
+ ITEMINFO_NAME - Display name (getiteminfo() only!)
ITEMINFO_BUYPRICE - Buy Price
ITEMINFO_SELLPRICE - Sell Price
ITEMINFO_TYPE - Item Type
@@ -3574,7 +3628,7 @@ If the player is not found, returns -1.
*gettimetick(<type>)
Valid types are :
- 0 - server's tick (milleseconds), unsigned int, loops every ~50 days
+ 0 - server's tick (milleseconds), unsigned int, loops every ~25 days
1 - time since the start of the current day in seconds
2 - UNIX epoch time (number of seconds elapsed since 1st of January 1970)
@@ -5273,11 +5327,11 @@ bound to the target character as specified by the bound type. All items created
in this manner cannot be dropped, sold, vended, auctioned, or mailed, and in
some cases cannot be traded or stored.
-Valid bound types are:
- 1 - Account Bound
- 2 - Guild Bound
- 3 - Party Bound
- 4 - Character Bound
+Valid item bound types are:
+ 1 - IBT_ACCOUNT - Account Bound
+ 2 - IBT_GUILD - Guild Bound
+ 3 - IBT_PARTY - Party Bound
+ 4 - IBT_CHARACTER - Character Bound
---------------------------------------
@@ -5318,12 +5372,12 @@ If a bound type is not specified or a bound type of 0 is used, it will search th
of any type, so long as the other parameters match. In all cases, this command will return the bound type of the
item found, or 0 if the specified item was not found.
-Valid bound types are:
- 0 - All Bound types.
- 1 - Account Bound
- 2 - Guild Bound
- 3 - Party Bound
- 4 - Character Bound
+Valid item bound types are:
+ 0 - IBT_ANY - Any Bound
+ 1 - IBT_ACCOUNT - Account Bound
+ 2 - IBT_GUILD - Guild Bound
+ 3 - IBT_PARTY - Party Bound
+ 4 - IBT_CHARACTER - Character Bound
Optional Parameters:
bound_type - checks to see if the item has the specified bound type.
@@ -5341,7 +5395,7 @@ Example:
close();
// This will also check if you have a bound (any type) 1205 (Cutter).
- if (checkbound(Cutter, 0)) {
+ if (checkbound(Cutter, IBT_ANY)) {
mes("You have a bound Cutter");
} else {
mes("You do not have a bound Cutter");
@@ -5356,8 +5410,8 @@ Example:
}
close();
- // This will check if the item found, has a bound type of 2 (guild_bound)
- if (checkbound(Cutter) == 2) {
+ // This will check if the item found, has a bound type of IBT_GUILD
+ if (checkbound(Cutter) == IBT_GUILD) {
mes("You have a guild_bound Cutter");
} else {
mes("You do not have a guild_bound Cutter.");
@@ -5365,7 +5419,7 @@ Example:
close();
// This will check if you have a 'guild_bound' +7 1205 (Cutter).
- if (checkbound(Cutter, 2, 7)) {
+ if (checkbound(Cutter, IBT_GUILD, 7)) {
mes("You have a +7 guild_bound Cutter.");
} else {
mes("You don't have the required item.");
@@ -5633,21 +5687,32 @@ Example:
---------------------------------------
-*enable_items()
-*disable_items()
+*enable_items({<flag>})
+*enableitemuse({<flag>})
+*disable_items({<flag>})
+*disableitemuse({<flag>})
+
+These commands enable/disable item actions while interacting with a NPC.
+When disable_items() is invoked, item actions defined by <flag> are disabled
+during scripts until enable_items() is called or the script has terminated.
+To avoid possible exploits, when disable_items() is invoked, it will only
+disable item actions while running that script in particular.
+Note that if a different script also invokes disable_items(), it will override
+the last call so you may want to call this command at the start of your
+script without assuming the effect is still in effect.
+If <flag> is omitted all item actions will be disabled.
+The enable_items() command enables item actions defined by <flag> during
+scripts until disable_items() is invoked or the script has terminated.
+If <flag> is omitted it defaults to 'item_enabled_npc' battle flag.
+For a list of supported flags have a look at the description of
+'item_enabled_npc' battle flag in 'conf/map/battle/items.conf'.
+Unless disable_items() or enable_items() is invoked the script will use
+'item_enabled_npc' battle flag by default.
+
+Example:
-These commands enable/disable changing of equipments while an NPC is
-running. When disable_items() is run, equipments cannot be changed
-during scripts until enable_items() is called or the script has
-terminated. To avoid possible exploits, when disable_items() is invoked,
-it will only disable changing equips while running that script in
-particular. Note that if a different script also calls disable_items(),
-it will override the last call (so you may want to call this command at
-the start of your script without assuming the effect is still in
-effect).
-If 'item_enabled_npc' option is set to true in 'conf/map/battle/items.conf' all
-NPC are allowing changing of equipment by default except for those have been
-set with 'disable_items'.
+ // This will disable changing equipment during this script.
+ disable_items(ITEMENABLEDNPC_EQUIP);
---------------------------------------
@@ -5659,18 +5724,20 @@ usable items. It will not work properly if there is a visible dialog
window or menu.
If the skill is self or auto-targeting, it will be used immediately.
Otherwise, a target cursor is shown.
-Optional value <flag> is a bitmask to manipulate how the skill is casted.
+By default, all skill requirements are ignored.
+Optional argument <flag> is a bitmask to manipulate how the skill is cast.
Since <flag> is a bitmask, the flags can be summed up.
Possible flags are:
- - 0x00 - ISF_NONE - Skill is casted as if has been used from skill tree.
+ - 0x00 - ISF_NONE - Skill is cast as if it has been used from skill tree.
(Same like <flag> was omitted.)
- - 0x01 - ISF_IGNORECONDITIONS - Skill requirements are ignored and not consumed
- - 0x02 - ISF_INSTANTCAST - Skill is casted instantaneously.
- - 0x04 - ISF_CASTONSELF - Skill is forcefully casted on invoking character,
+ - 0x01 - ISF_CHECKCONDITIONS - Skill requirements are checked and consumed.
+ (SP are never checked/consumed.)
+ - 0x02 - ISF_INSTANTCAST - Skill is cast instantaneously.
+ - 0x04 - ISF_CASTONSELF - Skill is forcefully cast on invoking character,
without showing the target selection cursor.
Important: Items which use itemskill() should be of type IT_USABLE.
- If the item type is IT_DELAYCONSUME and ISF_IGNORECONDITIONS is set,
+ If the item type is IT_DELAYCONSUME and ISF_CHECKCONDITIONS isn't set,
the item won't be consumed when using the item!
// When Anodyne is used, it will cast Endure, Level 1, as if the actual skill
@@ -5678,8 +5745,8 @@ Important: Items which use itemskill() should be of type IT_USABLE.
itemskill(SM_ENDURE, 1);
// Instantaneously cast Level 10 Increase Agility on invoking character,
-// without checking/consuming skill requirements.
- itemskill(AL_INCAGI, 10, ISF_IGNORECONDITIONS | ISF_INSTANTCAST | ISF_CASTONSELF);
+// with checking/consuming skill requirements (15 HP).
+ itemskill(AL_INCAGI, 10, ISF_CHECKCONDITIONS | ISF_INSTANTCAST | ISF_CASTONSELF);
// Instaed of using the constants, one could also do it like this:
itemskill(AL_INCAGI, 10, 7);
@@ -6569,17 +6636,22 @@ Examples:
---------------------------------------
-*setpcblock(<type>,<option>)
-*checkpcblock()
+*setpcblock(<type>, <option>{, <account id>})
+*checkpcblock({<account id>})
-Prevents the player from doing the following action.
+Prevents a character from doing the following action.
For setpcblock, when the <option> is true(1) will block them, and false(0)
will allow those actions again.
+The setpcblock command returns 1 on success or 0 if no character was attached.
+
The checkpcblock command returned value is a bit mask of the currently
enabled block flags (or PCBLOCK_NONE when none is set).
+Parameter <account id> is optional for both commands.
+If omitted, the currently attached character is used.
+
The <type> listed are a bit mask of the following:
PCBLOCK_NONE (only used by checkpcblock)
PCBLOCK_MOVE
@@ -6987,6 +7059,37 @@ Examples:
---------------------------------------
+*unitiswalking({<GID>})
+
+This command checks, if a unit is walking or not.
+If <GID> is omitted, the currently attached character is used.
+Returns 1 if the unit is walking, 0 if the unit is not walking and -1 on error.
+
+Note: There's no differentiation between script and client initiated walking.
+
+Example:
+
+prontera,155,185,5 script Check Walking 1_F_MARIA,{
+ mes("Enter character name.");
+ mes("");
+ input(.@name$);
+ .@GID = getcharid(CHAR_ID_ACCOUNT, .@name$);
+ if (.@GID != 0) {
+ .@iswalking = unitiswalking(.@GID);
+ if (.@iswalking == 1)
+ mesf("%s is walking.", .@name$);
+ else if (.@iswalking == 0)
+ mesf("%s is not walking.", .@name$);
+ else
+ mesf("Can't get %s's walking state.", .@name$);
+ } else {
+ mesf("%s not found!", .@name$);
+ }
+ close();
+}
+
+---------------------------------------
+
*unitkill(<GID>)
*unitwarp(<GID>, <Mapname>, <x>, <y>)
*unitattack(<GID>, <Target ID>)
@@ -7426,6 +7529,16 @@ if GID is not given use the attached player.
//=====================================
---------------------------------------
+*loudhailer("<message>"{, "<color>"})
+
+Announces a colored text in '<char_name> Shouts : <message>' format.
+<color> must be a string in "RRGGBB" format. If <color> is omitted,
+white ("FFFFFF") will be used.
+This command is specially created for the Megaphone_ item (12221),
+but will work in NPCs, too.
+
+---------------------------------------
+
*announce("<text>", <flag>{, <fontColor>{, <fontType>{, <fontSize>{, <fontAlign>{, <fontY>}}}}})
This command will broadcast a message to all or most players, similar to
@@ -7545,7 +7658,8 @@ In the OnBuyItem, two arrays are filled (@bought_nameid and
and the amount sold of it. Same goes for the OnSellItem label, only the
variables are named different (@sold_nameid, @sold_quantity, @sold_refine,
@sold_attribute, @sold_identify, @sold_card1, @sold_card2, @sold_card3,
-@sold_card4). An example on a shop comes with Hercules, and can be found
+@sold_card4, @sold_opt_id1~5, @sold_opt_val1~5, @sold_opt_param1~5).
+An example on a shop comes with Hercules, and can be found
in the doc/sample/npc_dynamic_shop.txt file.
This example shows how to use the labels and their set variables to create
@@ -9553,13 +9667,19 @@ For examples of usage, see /doc/sample/npc_rodex.txt
//=====================================
---------------------------------------
-*instance_create("<instance name>", <owner id>{, <optional owner_type>})
+*instance_create("<instance_name>", <owner_id>{, <owner_type>})
-Create an instance using the name "<instance name>" for the <owner_id> of
-owner_type (when not provided, defaults to IOT_PARTY). Most instance_*
+Creates an instance using the name "<instance_name>" for the <owner_id> of
+<owner_type> (when not provided, defaults to IOT_PARTY). Most instance_*
commands are used in conjunction with this command and depend on the
ID this command returns.
+Valid <owner_type> values:
+- IOT_NONE (0) - <owner_id> can be any arbitrary number.
+- IOT_CHAR (1) - <owner_id> is account ID.
+- IOT_PARTY (2) - <owner_id> is party ID.
+- IOT_GUILD (3) - <owner_id> is guild ID.
+
Example:
// Store the Party ID of the invoking character.
.@party_id = getcharid(CHAR_ID_PARTY);
@@ -9570,11 +9690,9 @@ Example:
// ...
} else if (.@id == -2) { // Invalid Party ID
// ...
- } else if (.@id == -3) { // No free instances (MAX_INSTANCE exceeded)
- // ...
} else if (.@id == -4) { // Already exists
// ...
- } else (.@id < 0) { // Unspecified error while queuing instance.
+ } else if (.@id < 0) { // Unspecified error while queuing instance.
// ...
}