[Crossfire-wiki] [Crossfire Wiki] page changed: client_side_scripting:client_scripting_interface-basic_howto
no-reply_wiki at cross-fire.org
no-reply_wiki at cross-fire.org
Mon Nov 30 12:57:12 CST 2015
A page in your DokuWiki was added or changed. Here are the details:
Date : 2015/11/30 12:57
User : partmedia
Edit Summary: Update first example
@@ -6,50 +6,23 @@
===== Getting Started =====
- To run a script in the client, use the //script// command, which takes a path to the script to run. 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.
+
+ 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.
==== Hello World ====
- Here we go for the first script. We will do quite simple things. We will ask our character to say "hello world" around. The script will be written in C because we simply need to choose a language. The script is quite simple:
+ Save the following script in a file, mark it executable, and run it in the client using the ''script'' command:
- #include <stdio.h>
-
- int main() {
- puts("issue 1 1 say Hello world!\n");
- }
-
-
- Name it first.c, compile it and launch it in your command shell:
-
- tchize at Urd:~$ /home/tchize/script/first
- issue 1 1 say hello world
-
- No surprise in the output (notice the \n at the end in source file). Now we are going to run it in the client. Start the client and log in your prefered server. When it's done, type in the following command:
-
- scripts
-
- Client will say you have no running scripts. That's good. Now type:
-
- script <path_to_my_first_script>
-
- where path_to_my_first_script is the location of your first script. For example I typed:
-
- script /home/tchize/script/first
-
- and you character says hello to the world. Nice, isn't it? Now try this yourself with the following script:
-
- int main(){
- printf("issue 1 1 shout hello world!\n");
- printf("issue 1 1 shout I use scripts!\n");
- }
+ #!/usr/bin/env python
+ print("issue 1 1 say Hello, world!")
- Do you get the idea? every printf you make is a command to the client scripting interface. So now let's look at this command. It begins with issue followed by 2 integers. The command __issue__ is part of the interacting of the Client Scripting Interface. It allows a script to send any command the player could send. There are lots of them i won't explain here. Just issue the command 'help commands' to get the list. What are those 2 integers? The first one is repeat. It typically is used for dropping items, but can be used in other cases. The second integer, 1 or 0, is must send. If it is //one//, the command must be sent, if it is //zero//, command may be lost in the client-server process. Most user will set this to 1.
+ The ''issue'' interface command runs a given command as if a user typed it into the command window. It takes 3 arguments: //repeat//, the number of times to repeat the command (typically used for dropping items); //must_send//, an integer either zero or one; and //command//, the command to execute.
- ===== Second Script =====
- Spy Kids
+ ==== Monitoring ====
What to do next? As you can see, our script doesn't wait very long after issuing commands. And it doesn't get information from the client at all. In fact it just //hopes// it is really speaking to the client. We are going to write a simple script which will __issue__ a command to the client and then gets the result. We are going to spy!\\
\\
Use the following script and run it in client. Ensure you ran the client in a console or you won't see any result!
@@ -145,9 +118,11 @@
watch stats food 395
Wow! This mean we know when food is low and we can ask our script to invoke restoration (remember the __issue__ command?) when our character's food gets below 50! No starvation anymore.
- ===== What's next? =====
+
+ ===== Reference =====
+
There are two things you can still do with Script. The first is to request a bit of informations. The client then tells the script what it wants to know. The second thing is triggering an action of the script from client interface. The command scripttell allows player to say something to a script. The script will get the exact command typed by player. See below for command list.
==== Commands to client ====
@@ -246,12 +221,14 @@
issue 0 0 lookat 2 3
FIXME add a complete set of commands that work with <repeat> and another of those that work without it.
- ===== Windows-specific notes =====
+
+ ===== Platform-Specific Notes =====
+
Scripting works thanks to a patch from archaios. Known issues are:
* If you want to run a Perl script for instance, you need to issue 'perl <script_name.pl>, even if .pl is correctly seen as perl script.
* If script doesn't output anything, try turning off buffering (in perl $| = 1) or flush your pipe, or add a sleep at end of program. It seems Windows closes pipes at script termination before client gets time to grab output.
IP-Address : 136.152.142.33
Hostname : airbears2-136-152-142-33.airbears2.berkeley.edu
Old Revision: http://wiki.metalforge.net/dokuwiki/doku.php/client_side_scripting:client_scripting_interface-basic_howto?rev=1448869913
New Revision: http://wiki.metalforge.net/dokuwiki/doku.php/client_side_scripting:client_scripting_interface-basic_howto
--
This mail was generated by DokuWiki at
http://wiki.metalforge.net/dokuwiki/
More information about the crossfire-wiki
mailing list