User Tools

Site Tools


user:gxc:client_side_scripting:cplusplus-howto

Client Scripting Interface - C++ How To

1. Using Client Commands

To use a command normally entered in the client, use printf(“issue 1 1[output string]”) followed by fflush(stdout). printf writes the output string in stdout, which is read by the client and interpreted. fflush(stdout) flushes or clears stdout1), readying it for more data.

An explanation of “issue 1 1 ” can be found here, in an introduction to scripting overall. Essentially, the first integer is the number of times to repeat an action. For debugging and information purposes, it's generally a good idea to leave it as 1 and create a loop in C++. The second 1 should always be set as 1.

Example:

#include <cstdio>
 
int main(){
	printf("issue 1 1 use_skill praying");
	fflush(stdout);
	return 0;
}

This would make the character pray once.

2. Writing to the Screen

To write to the screen, use printf(“[output string]”) followed by fflush(stdout). printf writes the output string in stdout, which is read by the client and interpreted. fflush(stdout) flushes or clears stdout2), readying it for more data.

Example:

#include <cstdio>
 
int main(){
	printf("draw 4 Hello world\n");
	fflush(stdout);
	return 0;
}

This would return [color=#FF0000]Hello world[/color].

There are several ways to achieve this.

2.1 draw

printf("draw [number] [string]");
  • [number] - Integer between 1 and 12. See chart below for colors
  • [string] - String to output to client's window

draw allows you to output data to the client's screen in several different colors. draw should almost be used when debugging or outputting script data to the user, as the majority of the other output options use the server's chat features.

draw Colors
# color # color
1 black (#000000) 7 light green (#2E8B57)
2 dark blue (#000080) 8 very light green (#8FBC8F)
3 red (#FF0000) 9 grey (#7F7F7F)
4 dark yellow (#FFA500) 10 brown (#A0522D)
5 light blue (#1E90FF) 11 yellow (#FFD700)
6 orange (#EE7600) 12 tan (#F0E68C)

Notes & Comments

This was written on a Linux machine. I have yet to run Crossfire on Windows, but I assume the syntax for coding will be the same. Running the scripts, on the other hand, might not be.

References

1) , 2) Normally, stdout doesn't need to be cleared this often, but when scripting for Crossfire, it's good practice to flush it after each use. It ends the current output, akin to pushing enter on commands in the client.
user/gxc/client_side_scripting/cplusplus-howto.txt · Last modified: 2008/03/20 08:28 (external edit)