Difference between revisions of "Module Creation FAQ"

From ASSS Wiki
Jump to: navigation, search
m (added at top: This is a general FAQ and there are separate tutorials on writing modules in C and writing modules in Python.)
Line 1: Line 1:
This is a general FAQ and there are separate tutorials on [[Writing_Modules_In_C|writing modules in C]] and
+
apple cows
[[Writing_Modules_In_Python|writing modules in Python]].
 
 
 
== What module and function do I use to send messages to players? ==
 
 
 
The chat interface, '''Ichat''', is defined in ''chat.h'' and is used to send messages of all kinds.
 
 
 
Most of the chat interface functions use printf like syntax in their strings.
 
 
 
NOTE: You must get the '''I_CHAT''' interface from the ASSS Module Manager before using it, just like you must on every other interface.
 
 
 
To send a green message to a single player, you should use code similar to one of the following:
 
 
 
<pre>
 
chat->SendMessage(p, "This is a message");
 
chat->SendMessage(p, "This is a message that displays an int. %i", someInt);
 
chat->SendMessage(p, "This is a message that displays a char array. %s", charArray);
 
</pre>
 
 
 
To send a message to an entire arena, one should use code similar to one of the following:
 
 
 
<pre>
 
chat->SendArenaMessage(arena, "This is an arena-wide message");
 
chat->SendArenaMessage(arena, "This is an arena-wide message that displays an int. %i", someInt);
 
chat->SendArenaMessage(arena, "This is an arena-wide message that displays a char array. %s", charArray);
 
</pre>
 
 
 
== How do I log events? ==
 
 
 
The log manager's interface, '''Ilogman''', is defined in ''logman.h'' and aids in debugging and notifying zone staff of unusual activity.
 
 
 
There are three log functions that are defined. '''Log''', '''LogP''' and '''LogA'''. All three have printf like syntaxes (just like the chat interfaces's functions) for easy addition of variable values to add in debugging.
 
 
 
There are five log levels that can be used when calling a log function.
 
 
 
<ul>
 
<li>'''L_DRIVEL''' is for meaningless log entries. Things that no sysop will ever care about. Use this level for printing out statements to help in debugging.</li>
 
<li>'''L_INFO''' is for things that people might care about.</li>
 
<li>'''L_MALICIOUS''' is for events that shouldn't happen unless someone is trying to hack/cheat. This is sent to online sysops as soon as it is logged (under default settings).</li>
 
<li>'''L_WARN''' is for things that probably shouldn't happen, but don't make a big difference.</li>
 
<li>'''L_ERROR''' is for events that are really bad. It is sent to online sysops as soon as it is logged (under default settings).</li>
 
</ul>
 
 
 
 
 
'''LogP''' is the most commonly used logging function. It should be used when you have access to a player pointer and the event relates to that player's actions.
 
 
 
<pre>
 
lm->LogP(L_DRIVEL, "my_module_name", p, "A log message attached to Player *p");
 
</pre>
 
 
 
'''LogA''' is attached to an arena rather than a player. This should be used whenever an event happens inside an arena but is tied to no specific player.
 
 
 
<pre>
 
lm->LogA(L_DRIVEL, "my_module_name", arena, "A log message attached to Arena *arena");
 
</pre>
 
 
 
'''Log''' is attached to neither an arena nor a player.
 
 
 
<pre>
 
lm->Log(L_DRIVEL, "<my_module_name> A log message");
 
</pre>
 
 
 
 
 
== How do I warp a player somewhere? ==
 
 
 
The game interface, '''Igame''' defines the function '''WarpTo''' that takes a player, an x tile and a y tile.
 
 
 
<pre>
 
game->WarpTo(p, 512, 512); //will warp a player to the center of the map
 
</pre>
 
 
 
 
 
== How do I give a player prizes? ==
 
 
 
The game interface, '''Igame''' defines the function '''GivePrize''' that takes a '''Target''', a prize type and a prize count.
 
 
 
<pre>
 
Target t;
 
t.type = T_PLAYER;
 
t.u.p = p;
 
 
 
game->GivePrize(&t, 21, 5); /* give Player p 5 repels (prize #21) */
 
</pre>
 
 
 
== How do I set a player's ship? ==
 
extract from defs.h
 
<pre>
 
/** ship names */
 
enum
 
{
 
/* pyconst: enum, "SHIP_*" */
 
SHIP_WARBIRD = 0,
 
SHIP_JAVELIN,
 
SHIP_SPIDER,
 
SHIP_LEVIATHAN,
 
SHIP_TERRIER,
 
SHIP_WEASEL,
 
SHIP_LANCASTER,
 
SHIP_SHARK,
 
SHIP_SPEC
 
};
 
</pre>
 
 
 
Replace ''ship'' with one of the enum's, fx: SHIP_WARBIRD.
 
<pre>
 
game->SetShip(p, ship);
 
</pre>
 
 
 
== How do I set a player's freq? ==
 
<pre>
 
game->SetFreq(p, freq); /* Player *p, int freq (typically in the range 0-9999) */
 
</pre>
 
See game.h
 
 
 
== How do I check when a player has entered a region? ==
 
 
 
ASSS has a callback for when an [[ASSS Region]] action(player enterence or exit) occurs. This callback is CB_REGION and the function is defined as
 
 
 
<pre>
 
local void region_cb(Player *p, Region *rgn, int x, int y, int entering)
 
</pre>
 
 
 
For information on how to write and use callbacks, see [[Writing Modules]].
 
 
 
[[Category: Module]]
 
[[Category: FAQ]]
 

Revision as of 03:47, 30 November 2005

apple cows