diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 212ad25d6f..8dc6cf8e51 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -9,7 +9,7 @@ //= Maeki Rika - A section on general concepts and lots of //= other updates and additions. //===== Version =========================================== -//= 2.11.20070109 +//= 3.00.20070208 //========================================================= //= 1.0 - First release, filled will as much info as I could //= remember or figure out, most likely there are errors, @@ -45,10 +45,19 @@ //= [FlavioJS] //= 2.12.20070201 - Added npcshopitem, npcshopadditem, npcshopdelitem and //= npcshopattach [Skotlex] +//= 3.00.20070208 +//= - Explained Logical Bitwise Operators. +//= Dj-Yhn contributed to AND (&) operator, rest by myself. [erKURITA] +//= - Added a resume of allowed variable and arrays scopes. [erKURITA] +//= - Re-organized the script commands, and grouped them depending +//= on what they do. [erKURITA] +//= - Added a packload of commands that were missing, +//= and corrected some of the wrong ones [Dj-Yhn, erKURITA & Trancid] //===== Compatible With =================================== //= LOL, can be used by anyone hopefully //===== Description ======================================= -//= A reference manual for the eAthena scripting language +//= A reference manual for the eAthena scripting language, +//= sorted out depending on their functionality. //========================================================= This document is a reference manual for all the scripting commands and functions @@ -61,16 +70,6 @@ and lots of them don't speak English and never left any notes - or are otherwise not available for comments. As such, anything written in here might not be correct, it is only correct to the best of our knowledge, which is limited. -This document is poorly structured and rather messy in general. In fact, further -cleaning up and reordering this document is probably pointless, due to upcoming -switch to Lua scripting language, which will rid us of most of the problems -mentioned herein and make a new manual necessary. But while we have this one, we -should make the most of it, and it might be helpful in making sure the new Lua -engine can actually do everything useful that the old engine could. -Note: The change to lua isn't going to happen because we are switching to eApp. - eApp has it's own scripting language and a converter to convert scripts - from the current script language. - This is not a place to teach you basic programming. This document will not teach you basic programming by itself. It's more of a reference for those who have at least a vague idea of what they want to do and want to know what tools they have @@ -344,7 +343,7 @@ prices for items in different shops. ** Define a function object -function%TAB%%TAB%{} +function%TAB%script%TAB%%TAB%{} This will define a function object, callable with the 'callfunc' command (see below). This object will load on every map server separately, so you can get at @@ -370,6 +369,8 @@ valid and mean what exactly is pending. Once an object is defined which has a 'code' field to it's definition, it contains script commands which can actually be triggered and executed. +~ RID? GID? ~ + What a RID is and why do you need to know ----------------------------------------- @@ -396,6 +397,17 @@ used to check which is the currently attached player to the script (it will return 0 if the there is no player attached or the attached player no longer is logged on to the map-server). +But what about GID? +--- ---- ----- ---- + +GID stands for the Game ID of something, this can either be the GID obtained +through mobspawn (mob control commands) or the account ID of a character. +Another way would be to right click on a mob, +NPC or char as GM sprited char to view the GID. + +This is mostly used for the new version of skill and the mob control commmands +implemented (but NEVER documented by Lance. Shame on you...). + Item and pet scripts -------------------- @@ -594,6 +606,41 @@ Arrays can naturaly store strings: the '$', normally denoting a string variable, before the square brackets that denotes an array index. +Resume of the allowed variable and array scopes +------ -- --- ------- -------- --- ----- ------ + ++==========+======+=======+ +|VarType | Norm | Array | ++==========+======+=======+ +|$Str$ | OK! | OK! | ++----------+------+-------+ +|$@Str$ | OK! | OK! | ++----------+------+-------+ +|@Str$ | OK! | OK! | ++----------+------+-------+ +|#Str$ | OK! | FAIL! | ++----------+------+-------+ +|Str$ | OK! | FAIL! | ++----------+------+-------+ +|$Int | OK! | OK! | ++----------+------+-------+ +|$@Int | OK! | OK! | ++----------+------+-------+ +|@Int | OK! | OK! | ++----------+------+-------+ +|#Int | OK! | FAIL! | ++----------+------+-------+ +|Int | OK! | FAIL! | ++----------+------+-------+ +|.Str$ | OK! | OK! | ++----------+------+-------+ +|.Int | OK! | OK! | ++----------+------+-------+ +|.@Str$ | OK! | OK! | ++----------+------+-------+ +|.@Int | OK! | OK! | ++----------+------+-------+ + Operators --------- @@ -645,15 +692,71 @@ Comparisons can be stacked in the same condition: 1=1 && 2=1 is False. 1=1 || 2=1 is True. -Logical operators work only on numbers: +Logical bitwise operators work only on numbers, and they are the following: << - Left shift. >> - Right shift. + Left shift moves the binary 1(s) of a number n positions to the left, + which is the same as multiplying by 2, n times. + In the other hand, Right shift moves the binary 1(s) of a number n positions + to the right, which is the same as dividing by 2, n times. + Example: + set b,2; + set a, b << 3; + mes a; + set a, a >> 2; + mes a; + The first mes command would display 16, which is the same as 2 x (2 x 2 x 2) = 16. + The second mes command would display 4, which is the same as 16 / 2 = 8. 8 / 2 = 4. & - And. | - Or. - ^ - Xor. + The bitwise operator AND (&) is used to test two values against eachother, + and results in setting bits which are active in both arguments. This can + be used for a few things, but in eAthena this operator is usually used to + create bitmasks in scripts. + + The bitwise operator OR (|)sets to 1 a binary position if the binary position + of one of the numbers is 1. This way a variable can hold several values we can check, + known as bitmaks. A variable currently can hold up to 32 bitmasks (from position 0 + to position 1). This is a cheap(skate) and easy way to avoid using arrays to store several checks + that a player can have. + + A bitmask basically is (ab)using the variables bits to set various options in + one variable. With the current limit if variables it is possible to store 32 + different options in one variable (by using the bits on position 0 to 31). -If you don't know what these five mean, don't bother, you don't need them. + Example(s): + - Basic example of the & operator, bit example: + 10 & 2 = 2 + Why? : + 10 = 2^1 + 2^3 (2 + 8), so in bits, it would be 1010 + 2 = 2^1 (2), so in bits (same size) it would be 0010 + The & (AND) operator sets bits which are active (1) in both arguments, so in the + example 1010 & 0010, only the 2^1 bit is active (1) in both. Resulting in the bit + 0010, which is 2. + - Basic example of creating and using a bit mask: + set @options,2|4|16; //(note: this is the same as 2+4+16, or 22) + if (@options & 1) mes "Option 1 is activated"; + if (@options & 2) mes "Option 2 is activated"; + if (@options & 4) mes "Option 3 is activated"; + if (@options & 8) mes "Option 4 is activated"; + if (@options & 16) mes "Options 5 is activated"; + This would return the messages about option 2, 3 and 5 being shown (since we've set + the 2,4 and 16 bit to 1). + ^ - Xor. + The bitwise operator XOR (eXclusive OR) sets to 0 a binary position if both numbers have a 1 + in the said position. On the other hand, it sets to 1 if there's a 1 in any of the number in + the said binary position. + This is the counter-part of the OR operator, the opposite if you like. This is used to remove a + bitmask, which is the same as substracting it. + + Example: + - We set the variable first: + set a,2|4|8|16; // this would be the same as 2+4+8+16 = 30 + - After some checks, we find he didn't do the third quest, which we asigned the 3rd value (8) + so now we have to remove it: + set a,a^8; //this would be the same as 30-8 = 22. 22 = 16+4+2, which are the flags left. + Labels ------ @@ -720,6 +823,14 @@ altering the configuration options in 'script_athena.conf'. It's pretty obvious when those will get triggered. For more information, see 'npc/sample/PCLoginEvent.txt' +OnPCLoadMapEvent: + +This special label will trigger once a player steps in a map marked with the +'loadmap' mapflag and attach its RID. The fact that this label requires a +mapflag for it to work is because, otherwise, it'd be server-wide and trigger +everytime a player would change maps. Imagine the server load with 1,000 players +(oh the pain...) + Only the special labels which are not associated with any script command are listed here. There are other kinds of labels which may be triggered in a similar manner, but they are described with their associated commands. @@ -764,16 +875,20 @@ behave nicely if you do. ------------------------- -*playerattached; -Returns the ID of the player currently attached to the script. It will return -0 if noone is attached, or if the attached player no longer exists on the map -server. It is wise to check for the attached player in script functions that -deal with timers as there's no guarantee the player will still be logged on -when the timer triggers. Note that the ID of a player is actually their -account ID. +From here on, we will have the commands sorted as follow: -------------------------- +1.- Basic commands. +2.- Information-retrieving commands. +3.- Checking commands. +4.- Player-related commands. +5.- Mob / NPC -related commands. +6.- Other commands. + +===================== +|1.- Basic commands.| +===================== +--------------------------------------- *mes ""; @@ -805,177 +920,6 @@ either side solves the problem. --------------------------------------- -*goto