User Tools

Site Tools


client_side_scripting:client_scripting_interface-basic_howto

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
client_side_scripting:client_scripting_interface-basic_howto [2019/09/13 13:17]
boingman Updated monitor section to include the ncom command in JXClient RC 1.20.0
client_side_scripting:client_scripting_interface-basic_howto [2020/07/30 16:08]
boingman Added some specific information about newlines and additional watch arguments with expected results; amended version numbers with client
Line 5: Line 5:
 The script is started from the client and communicates by reading information from standard input and writing commands to standard output. A full list of commands can be found below. The script is started from the client and communicates by reading information from standard input and writing commands to standard output. A full list of commands can be found below.
  
 +
 +===== Before we start =====
 +
 +Several clients are available for this game. This page documents the scripting capabilities of version 1.71.0 GTK2 client and the JXClient of 27-Jan-2020.
 +
 +CrossFire scripting does not use carriage return (hexadecimal 0d) characters as part of newlines regardless of operating system. Only the linefeed (hexadecimal 0a) character is acceptable as a line terminator.
  
 ===== Getting Started ===== ===== Getting Started =====
  
 The ''​script''​ command starts a script at the given path. The script must be executable (''​chmod +x''​ with an appropriate shebang). For some languages, it may be necessary to write a wrapper script to execute the actual program. The ''​script''​ command starts a script at the given path. The script must be executable (''​chmod +x''​ with an appropriate shebang). For some languages, it may be necessary to write a wrapper script to execute the actual program.
 +
 +Additionally,​ on Windows systems where the shebang is not supported, the player must provide a means of running such a script. For example ''​script python <​path-to-script>''​ if you are using python.
  
 The ''​scripts''​ command lists running scripts with a numeric identifier. Scripts can be stopped using the ''​scriptkill''​ command. The ''​scripttell''​ command can be used to send arbitrary commands to a script. The ''​scripts''​ command lists running scripts with a numeric identifier. Scripts can be stopped using the ''​scriptkill''​ command. The ''​scripttell''​ command can be used to send arbitrary commands to a script.
Line 59: Line 67:
   ​   ​
   monitor -1 1 run_stop   monitor -1 1 run_stop
- 
-If you are using JXClient Release Candidate 1.12.0 (or older), monitor commands sent to the script will look like: 
- 
-  ncom XXYYYYeast 
- 
-Where XX is a 16-bit packet ID and YYYY is a 32-bit repeat indicator. Binary data is transmitted in network byte order (big endian). NOTE: Newline characters regularly occur in the packet ID field so reading this line will have to contend with that, simply reading a line will invariably end in error. It is anticipated that this issue will be fixed at some point in the future. 
  
 If you type the command __scripts__ in your client you will see our script is still running.\\ ​ If you type the command __scripts__ in your client you will see our script is still running.\\ ​
Line 92: Line 94:
 or or
   scriptkill <​number>​   scriptkill <​number>​
 +
 +the JXClient additionally supports
 +  scriptkillall
  
 Then type __scripts__ to ensure it's stopped (or to figure out the number of the script). Edit it, comment the line printf("​monitor\n"​),​ compile and run the script again. Move and look at console. You see nothing. The script didn't ask anything so the client didn't tell it anything. Your script will only get that for which it asks. Then type __scripts__ to ensure it's stopped (or to figure out the number of the script). Edit it, comment the line printf("​monitor\n"​),​ compile and run the script again. Move and look at console. You see nothing. The script didn't ask anything so the client didn't tell it anything. Your script will only get that for which it asks.
Line 136: Line 141:
  
   * //watch <command type>// - watch the given command from server-client protocol. <command type> specifies the commands we want to watch. Set to empty to get all commands.   * //watch <command type>// - watch the given command from server-client protocol. <command type> specifies the commands we want to watch. Set to empty to get all commands.
 +    * Besides what is already documented, watch also supports "​tick",​ "​drawinfo"​ (GTK2 client) and "​drawextinfo"​ (JXClient).
 +    * The "​tick"​ argument will provide the script with "watch tick <​integer>",​ as a tick of the client'​s clock.
 +    * The "​draw"​ commands are functionally equivalent in the GTK2 client and the JXClient with some minor differences. Both will provide the script with text printed in the Messages text area. The GTK2 provides the script with "watch drawinfo <​integer>​ <​message>",​ while the JXClient will provide "watch drawextinfo <​integer>​ <​integer>​ <​message>"​.
   * //unwatch <command type>// - unwatch the given command from server-client protocol. <command type> specifies the commands we want to watch. Set to empty to get all commands.   * //unwatch <command type>// - unwatch the given command from server-client protocol. <command type> specifies the commands we want to watch. Set to empty to get all commands.
   * //request <data type>// - Request a piece of informations from client memory. Following is a table of <data type> allowed:   * //request <data type>// - Request a piece of informations from client memory. Following is a table of <data type> allowed:
Line 162: Line 170:
 | spells ​     | Return a list of known spells, one per line | | spells ​     | Return a list of known spells, one per line |
 | stat paths  | Return spell paths: attuned, repelled, denied | | stat paths  | Return spell paths: attuned, repelled, denied |
-Note: player, skills, spells, stat path were added between versions 1.11 and 1.50 of the client.\\ 
-</​box>​ 
  
-FIXME \\ +Noteplayer, skills, spells, stat path were added between versions 1.11 and 1.50 of the GTK2 client.\\
-:!: In order to get the result ​of the request into your script'​s stdin you have to "watch request <data type>"​ before you do the request.\\ +
-:!: No, you do not need to watch requests (anymore?). The client will send the request to stdin of the script.+
  
   * //issue <​repeat>​ <​must_send>​ <​command>//​ - send <​command>​ to server on behalf of client. <​repeat>​ is the number of times to execute command <​must_send>​ tells whether or not the command must sent at all cost (1 or 0). <​repeat>​ and <​must_send>​ are optional parameters. See [[#The Issue Command]] for more details.   * //issue <​repeat>​ <​must_send>​ <​command>//​ - send <​command>​ to server on behalf of client. <​repeat>​ is the number of times to execute command <​must_send>​ tells whether or not the command must sent at all cost (1 or 0). <​repeat>​ and <​must_send>​ are optional parameters. See [[#The Issue Command]] for more details.
Line 179: Line 183:
 Here is an incomplete list of information strings send by client to script. Those informations are sent only because the client asked them, except for scripttell. Here is an incomplete list of information strings send by client to script. Those informations are sent only because the client asked them, except for scripttell.
  
-  * //​scripttell <yourname> <​additional data>// - user send special command to this script specifically+  * //​scripttell <scriptnumber> <​additional data>// - user send special command to this script specifically
   * //monitor <​repeat>​ <​must_send>​ <​command>//​   * //monitor <​repeat>​ <​must_send>​ <​command>//​
   * //monitor mark <​tag>//​   * //monitor mark <​tag>//​
client_side_scripting/client_scripting_interface-basic_howto.txt · Last modified: 2021/06/19 08:12 by boingman