Difference between revisions of "MERVBot Tutorial"

From ASSS Wiki
Jump to: navigation, search
(Player Commands - (command.cpp): better headings)
m (fixed tutorial link)
 
(109 intermediate revisions by 9 users not shown)
Line 1: Line 1:
Here is the ever-popular MERVBot Tutorial by Underlord:
+
This tutorial is based on the ever-popular MERVBot Tutorial by Underlord. It has since been updated to reflect new changes with MervBot. To see examples of how to use this instruction, see [[MERVBot Example Code]].
  
<div id="merv_toc" style="font-size: 12px; margin: 2em;">
+
This tutorial also assumes that you have a basic knowledge of C++. If you don't, check out cplusplus.com's great [http://www.cplusplus.com/doc documentation].
Setup a MERVBot bot and project in visual c++<br />
 
0) <a href="#0">Setting up a MERVBot bot</a><br />
 
<br />
 
Command.cpp<br />
 
&nbsp;1) <a href="#1">Player commands</a> (!play, !squadA vs squadB)<br />
 
<br />
 
Spawn.cpp<br />
 
&nbsp;2) <a href="#2">Event descriptions</a> (describe events in spawn.cpp)<br />
 
&nbsp;2) <a href="#2">Messaging </a>(&quot;*arena hi&quot;, &quot;:player:*scorereset)<br />
 
&nbsp;3) <a href="#3">MervBot Timer</a> (do this in 10 seconds)(countdown[n])<br />
 
&nbsp;4) <a href="#4">Writing Functions</a> (bool IsInCenter(Player *p))<br />
 
<br />
 
Useful operations<br />
 
&nbsp;6) <a href="#6">Cycling players</a><br />
 
&nbsp;7) <a href="#7">Check if pilot is in safe zone</a><br />
 
&nbsp;8) <a href="#8">Random numbers</a><br />
 
&nbsp;9) <a href="#9">Time without using countdown[n]</a><br />
 
10) <a href="#10">Storing data for pilots</a><br />
 
11) <a href="#11">Output data in messages</a><br />
 
12) <a href="#12">Input/Output to files</a><br />
 
13) <a href="#13">Programming commands</a><br />
 
14) <a href="#14">Useful player data</a><br />
 
15) <a href="#15">Bot built in functions</a><br />
 
<br />
 
Example Code<br />
 
<div style="margin-left: 2em">
 
a) <a href="#15a">No antiwarp in center of map</a><br />
 
b) <a href="#15b">Setting freq size depending on how many pilots in game</a><br />
 
c) <a href="#15c">Tracking kills and announcing when pilot gets 10 kills in a row without dying </a><br />
 
d) <a href="#15d">Warp pilot to coord when they are in a certain region</a><br />
 
e) <a href="#15e">Structures within structures</a><br />
 
f) <a href="#15f">Tracking flag data</a><br />
 
g) <a href="#15g">Way to do simple /!spam feature</a><br />
 
h) <a href="#15h">Implementing a simple stack to do &quot;next in line for several 'boxes' at once&quot;</a><br />
 
i) <a href="#15i">Reading any text from a .txt and printing it to pilot line by line</a><br />
 
j) <a href="#15j">Example of printing player stats grid</a><br />
 
k) <a href="#15k">Example of checking if any pilots are within a region</a><br />
 
l) <a href="#15l">Example of functions to get a pilot's struct id info from a name or *player info</a><br />
 
m) <a href="#15m">Example of creating a logfile name using date and squad names</a><br />
 
n) <a href="#15n">Sending messages to playing freqs or public and logging depending on status</a><br />
 
o) <a href="#15o">Example of reading in all player/freqs to struct data</a><br />
 
p) <a href="#15p">Example of finding MVP from struct data</a><br />
 
q) <a href="#15q">Print time stamp of event</a><br />
 
r) <a href="#15r">Simple way to track player bomb/bullet damage stats</a><br />
 
s) <a href="#15s">Simple way to print those stats</a><br />
 
t) <a href="#15t">Make bot spectate specific coordinates</a>
 
</div>
 
</div>
 
  
 
==Setting up a MERVBot (plugin)==
 
==Setting up a MERVBot (plugin)==
  
MERVBot download site: &nbsp;http://catid.sscentral.com/
+
[http://mervbot.com MERVBot download site]
  
MERVBot Forum: &nbsp;http://www.ssforum.net/ &nbsp;(Development - MervBot forum)
 
  
 +
===Obtaining MERVBot===
  
===Download [http://catid.sscentral.com/files/MERVBot.zip MERVBot Build 37 (DLL 6.5)]===
+
* Download the [http://mervbot.com/files/MERVBot.rar latest build].
 +
* Unrar MERVBot.rar into a new folder. (example c:\program files\continuum\mervbot)
 +
* Unzip src.zip into &quot;src&quot; subfolder of that new folder (example c:\program files\continuum\mervbot\src)
  
Unzip MERVBot.zip into a new folder. (example c:\program files\continuum\mervbot)<br />
+
===Preparing to write a plugin===
Unzip src.zip into &quot;src&quot; subfolder of that new folder (example c:\program files\continuum\mervbot\src)
 
 
 
 
 
===Download [http://catid.sscentral.com/files/Tutorial.zip DLL-plugin Tutorial]===
 
  
 
''Note:'' if you only want to execute someone's premade plugin (.dll), skip to [[MERVBot Tutorial#Run your bot dll|step 4]], otherwise continue to learn how to make your own bot
 
''Note:'' if you only want to execute someone's premade plugin (.dll), skip to [[MERVBot Tutorial#Run your bot dll|step 4]], otherwise continue to learn how to make your own bot
  
Unzip Tutorial.zip (containing spawn.h, spawn.cpp, and command.cpp) into &quot;/tutorial&quot; subfolder of that new folder. (example c:\program files\continuum\mervbot\src\tutorial).
+
Download [http://www.mervbot.com/files/Tutorial.rar DLL-plugin Tutorial] and unzip Tutorial.zip (containing spawn.h, spawn.cpp, and command.cpp) into a &quot;tutorial&quot; subfolder of that new folder. (example c:\program files\continuum\mervbot\src\tutorial).
  
 
''File descriptions:''
 
''File descriptions:''
<ul>
+
* spawn.h = declare/initialize globals
<li>spawn.h = declare/initialize globals
+
* command.cpp = code for commands coming into bot (ie /!help, /!play, etc)
<li>command.cpp = code for commands coming into bot (ie /!help, /!play, etc)
+
* spawn.cpp = code that interacts with bot spawns
<li>spawn.cpp = code for main part of bot
 
</ul>
 
 
 
  
 
===Microsoft Visual c++===
 
===Microsoft Visual c++===
Line 103: Line 50:
 
===Run your bot dll===
 
===Run your bot dll===
  
To run your bot you need your DLL (mybot.dll), Commands.txt, MERVBot.exe, MERVBot.ini, Operators.txt, Spawns.txt, subspace.bin, and zlib.dll all in one folder (example c:\program files\continuum\mervbot).
+
To run your bot you need your DLL (mybot.dll), Commands.txt, MERVBot.exe, MERVBot.ini, Operators.txt, Spawns.txt, and zlib.dll all in one folder (example c:\program files\continuum\mervbot).
  
 
<ol>
 
<ol>
<li>Edit spawns.txt (only one line of text in file needed)
+
<li>Edit spawns.txt. '''Read every word of spawns.txt to find out what needs to go in there.'''
<br>
+
 
 
<br>
 
<br>
bot_name : pw_for_bot_name : arena: dll_plugin : optional_staff_password<br />
 
 
 
''Example:''
 
''Example:''
 
<pre>2v2-Bot-League : botpw : 2v2a : 2v2league : staffpw</pre>
 
<pre>2v2-Bot-League : botpw : 2v2a : 2v2league : staffpw</pre>
<ul>
+
 
<li>You should create your bot name and pw using your Continuum client as you would create any new name.
+
''Note:'' The bot will attempt to create the name if it doesn't exist already.
<li>There is no * in front of staffpw.
 
</ul>
 
  
  
Line 123: Line 66:
 
<br>
 
<br>
 
<pre>[Login]
 
<pre>[Login]
Zone=216.33.98.254:21000 // make that your zone IP:PORT available from zone.dat in Continuum dir
+
Zone=216.33.98.254:21000 // your zone IP:PORT available from zone.dat in Continuum dir
 
</pre>
 
</pre>
  
  
<li>Edit operators.txt
+
<li>Edit operators.txt. '''Read every word of operators.txt to find out what needs to go in there.'''<br />
<br>
 
<br>
 
access_level : name :<br />
 
 
          
 
          
 
''Example:''
 
''Example:''
Line 140: Line 80:
  
  
<li>Run MERVBot.exe
+
<li>Make sure the bot is on vip.txt or has smod+ access, then run MERVBot.exe.
<br>
 
<br>
 
Double click MERVBot.exe, the bot should now enter the zone. ''Note:'' Bot needs to be on vip.txt or have moderator+ access to enter a zone.
 
<br>
 
<br>
 
<li>Modify your MERVBot code
 
<br>
 
<br>
 
You can open your MERVBot project by opening &quot;mybot.dsw&quot; file with visual c++.
 
(example c:\program files\continuum\mervbot\src\mybot\mybot.dsw)
 
  
Edit the spawn.h, spawn.cpp, and command.cpp to create your plugin, then build, copy your updated DLL to your MERVBot.exe folder and then execute the bot.
+
<li>You can now edit your plugin code by opening &quot;mybot.dsw&quot; (example c:\program files\continuum\mervbot\src\mybot\mybot.dsw) in Microsoft Visual C++. Edit the spawn.h, spawn.cpp, and command.cpp to create your plugin, then build, copy your updated DLL to your MERVBot.exe folder and then execute the bot. Use the tutorial to get ideas on how to implement certain types of features into the bot.
 
 
Use the tutorial to get ideas on how to implement certain types of features into the bot.
 
  
 
</ol>
 
</ol>
Line 167: Line 95:
 
switch (p->access)
 
switch (p->access)
 
{
 
{
case OP_Player: //appropriate staff rank here. (If you want it to be a moderator command, put it under OP_Moderator.)
+
        case OP_Moderator:
 +
                {
 +
                    // handle moderator-operator commands here.
 +
                }
 +
case OP_Player: //appropriate staff rank here.
 
{
 
{
 
if (c->check("test")) //replace "test" with whatever command you want
 
if (c->check("test")) //replace "test" with whatever command you want
 
{
 
{
 
//put your command code here
 
//put your command code here
sendPrivate(p,"hi");
+
sendPrivate(p,"hi"); //example
 
}
 
}
 
}
 
}
Line 240: Line 172:
 
</pre>
 
</pre>
  
==Event Call Descriptions - in spawn.cpp==
+
==Event Calls==
  
<blockquote>MERVBot is event based, so when making a bot you need to decide what will happen at certain events. Normal plugins need to consider what happens when bot enters arena, player enters arena, player leaves arena, player events like kill, shipchange, teamchange, spec, move then any other relevent events to your bot. Just worry about events that are relevent to the tasks your bot is doing.
+
MERVBot is event based, so when making a bot you need to decide what will happen at certain events. Normal plugins need to consider what happens when bot enters arena, player enters arena, player leaves arena, player events like kill, shipchange, teamchange, spec, move then any other relevant events to your bot. Just worry about events that are relevant to the tasks your bot is doing.
<br />
 
  
===Timer===
+
MERVBot sends events to botInfo::gotEvent() in spawn.cpp. Each supported event is already present and categorized in gotEvent(), along with the paramters that MERVBot sends with the event. When a plugin wants the bot to do something, it sends tell(event) to the bot.
  
case EVENT_Tick: &nbsp;&nbsp;&nbsp; &nbsp;- called 1x/sec, decrementing each countdown[n] by 1, use for time triggered events<br />
+
See dllcore.h for a list of current events and their descriptions. Dllcore.h also contains functions (like makeFollowing) to make events to send back to the bot via tell().
  
===Arena Events===
+
<pre>tell(makeFollowing(false));</pre>
  
case EVENT_ArenaEnter: &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot enters arena<br />
+
==The Messaging System==
  
case EVENT_ArenaSettings: &nbsp;&nbsp; &nbsp;- called when bot gets arena settings<br />
+
Private message - void sendPrivate(Player *player, char *msg);
  
case EVENT_ArenaLeave:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot exits arena<br />
+
''Examples:''
  
case EVENT_ArenaListEntry: &nbsp;&nbsp; &nbsp;- called when bot gets an entry from the arena list (esc-a)<br />
+
<pre>
 +
sendPrivate(p,"hi");
  
case EVENT_ArenaListEnd: &nbsp;&nbsp; &nbsp;- called when bot reads last entry of arena list (esc-a)<br />
+
String s="test";
 +
sendPrivate(p,s);
  
===Flag Events===
+
String s="test";
 +
s += "ing";
 +
sendPrivate(p,s);
  
case EVENT_FlagGrab:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot picks up a loose flag<br />
+
char captain1[20];
 +
char captain2[20];
 +
strncpy(captain1,"",20);
 +
strncpy(captain2,"",20);
 +
sendPrivate(p,(String) captain1 + " and " + (String) captain2 + " are the captains.");
 +
</pre>
  
case EVENT_FlagDrop:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot drops a flag (timer runs out)<br />
+
Team message - void sendTeamPrivate(Uint16 team, char *msg);<br />
 +
<blockquote>Examples: <br />
 +
a) sendTeamPrivate(8025,&quot;hi spec freq&quot;);<br />
 +
b) Uint16 test=0; sendTeamPrivate(test,&quot;hi freq 0&quot;);<br />
 +
</blockquote>
  
case EVENT_FlagMove:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a flag moves<br />
+
Public message - void sendPublic(char *msg);<br />
 +
<blockquote>Example: sendPublic(&quot;*arena &quot; + (String) p-&gt;name + &quot; is now a captain&quot;);<br />
 +
</blockquote>
 +
Chat channel message - void sendChannel(char *msg);<br />
 +
<blockquote>Example: sendChannel(&quot;hi chat channel&quot;);<br />
 +
</blockquote>
 +
Remote private message - void sendRemotePrivate(char *name, char *msg);<br />
 +
<blockquote>Example: sendRemotePrivate(&quot;Player01&quot;, &quot;hi&quot;);<br />
 +
</blockquote>
  
case EVENT_FlagVictory:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a team wins flag game (gets all flags)<br />
+
Note: to have bot print several lines of text fast it needs sysop in the
 +
arena (sysop in arena bot first spawns to also) otherwise it'll print slow to avoid being
 +
kicked for spam
  
case EVENT_FlagReward:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when theres a periodic flag reward given<br />
+
===Output of data in messages===
 +
<p>An example of using normal strings to output data/messages.</p>
 +
<pre>
 +
// does *arena X pilots left in game
 +
// NOTE: variable temp needs to be defined with some value
  
===Timed Game===
+
String s = "*arena ";
 +
      s += temp;
 +
      s += " pilots left in the game.";
  
case EVENT_TimedGameOver:&nbsp;&nbsp; &nbsp;- called when a timed game is over (like speed zone game)<br />
+
sendPublic(s);
 +
</pre>
 +
Or,
 +
<pre>
 +
//NOTE: this can be considered inefficient.
  
===Soccer===
+
sendPublic("*arena " + (String)temp + " pilots left in the game");
 +
</pre>
  
case EVENT_SoccerGoal:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a soccer goal is scored<br />
+
<p>An example using sprintf to align/space data, where output data will be in this approximate format.</p>
 +
<pre>
 +
// output data will be in this approximate format (not lined up perfectly because of html)
 +
// --------------------------------------------------------------------------------------
 +
// Squad: squadname      PTS    FPTS    K    D  DMG DEALT TAKEN  F  FK    FLT
 +
// --------------------------------------------------------------------------------------
 +
// PlayerA              10000      500  116  101      9999 99999  10 150 980:55
 +
// PlayerB                500      200    7    5      9999 99999  5  3  0:04
  
case EVENT_BallMove:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a soccer ball moves<br />
+
char str[255];
 +
sendPublic("*arena--------------------------------------------------------------------------------");
  
===Receive file===
+
sprintf(str, "*arena Squad: %-20s  PTS    FPTS  K  D  DMG DEALT  TAKEN  F  FK  FLT",
 +
        freqs[freq].freqname
 +
        );
  
case EVENT_File:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a file is received (*getfile)<br />
+
sendPublic(str);
  
===Player events===
+
sendPublic("*arena--------------------------------------------------------------------------------");
  
case EVENT_PlayerEntering:&nbsp;&nbsp; &nbsp;- called when a pilot enters the arena<br />
+
            // assuming existing freqs struct with data
 +
            for (pilot=freqs[freq].playercount-1; pilot>=0; pilot--)
 +
            {
 +
                // on freq squad so print stats
 +
                char outString[255];
  
case EVENT_PlayerMove:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot's ship moves<br />
+
                sprintf(outString, "*arena %-20s %12d %8d %3d %3d %10d %6d %2d %3d %3d:%02d",
 +
                      freqs[freq].pilots[pilot].name,
 +
                      freqs[freq].pilots[pilot].points,
 +
                      freqs[freq].pilots[pilot].flagpoints,
 +
                      freqs[freq].pilots[pilot].kills,
 +
                      freqs[freq].pilots[pilot].deaths,
 +
                      freqs[freq].pilots[pilot].dmgdealt,
 +
                      freqs[freq].pilots[pilot].dmgtaken,
 +
                      freqs[freq].pilots[pilot].flags,
 +
                      freqs[freq].pilots[pilot].flagkills,
 +
                      freqs[freq].pilots[pilot].flagtime /60,
 +
                      freqs[freq].pilots[pilot].flagtime %60
 +
                      );
 +
               
 +
                sendPublic(outString);
 +
            }
  
case EVENT_PlayerWeapon:&nbsp;&nbsp; &nbsp;- called when a pilot fires a weapon<br />
+
            // Notes: sprintf format = sprintf(output char string, spacing, variables)
 +
            // Notes: s = chars, d = integer, - = left align, right align default
 +
            // Notes: doing %02d = put 0 in front if not 2 digits, %3d:%02d makes 0:04 format
 +
</pre>
  
case EVENT_WatchDamage:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot takes damage (bot must have /*watchdamage on for them)<br />
+
==Time==
  
case EVENT_PlayerDeath:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot dies<br />
+
Each time MERVBot sends an EVENT_Tick to a plugin (once a second), the default handler code decrements each value in an array of countdowns. You can modify the number of countdowns and add code to occur at a specific value for one of the countdowns.
  
case EVENT_PlayerScore:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot changes their score (?scorereset)<br />
+
Setup number of timers and initialize in spawn.h:
 +
<pre>
 +
class botInfo
 +
{
 +
#define COUNTDOWNS 10 // how many countdowns you want
 +
int countdown[COUNTDOWNS]; // this gives you 10 timers
  
case EVENT_PlayerPrize:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot gets a prize (green)<br />
+
// unrelated code
 +
 +
public:
 +
botInfo(CALL_HANDLE given)
 +
{
 +
countdown[0] = 0;
 +
countdown[1] = 60; // 60 seconds
 +
//
 +
// initialize values
 +
//
 +
countdown[9] = 5*60; // 5 minutes
 +
</pre>
 +
Using timer functions in spawn.cpp:
 +
<pre>
 +
case EVENT_Tick:
 +
{
 +
for (int i = 0; i < COUNTDOWNS; ++i) //cycles through each countdown you have
 +
--countdown[i]; //note that countdowns will continue decrementing past 0.
  
case EVENT_PlayerShip:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot ship changes<br />
+
if (countdown[1] == 2) // when timer #1 hits two seconds
 +
{
 +
// do stuff here when timer #1 hits 2 seconds
 +
// example: sendPublic("two seconds left, setting timer to 1 minute");
 +
// example: countdown[1] = 60; // change timer #1 value
 +
}
 +
</pre>
  
case EVENT_PlayerSpec:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot spectates<br />
+
You can then have events (such as EVENT_PlayerDeath) change the value of a countdown to make the bot do something a set time after an event occurs.
  
case EVENT_PlayerTeam:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when a pilot changes freqs<br />
+
=== Tracking time not using countdown[n] ===
  
case EVENT_PlayerLeaving:&nbsp;&nbsp; &nbsp;- called when a pilot exits arena (esc-q, ?go &lt;arena&gt;, or lagout)<br />
+
This is a solution to a common problem of determining the amount of time it takes for something to occur. Using basic math, we record a start-time B, and an end-time E, both in the unit of seconds, we calculate the time elapsed by E-B.
  
===Bot events===
+
Lucky for us, Windows provides a function called GetTickCount() that is a measurement of time (milliseconds) that we can use for such cases.
  
case EVENT_SelfShipReset:&nbsp;&nbsp; &nbsp;- called when bot's ship gets reset<br />
+
So:
 +
<pre>
 +
int begin = GetTickCount();
  
case EVENT_SelfPrize:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot gets a prize (green)<br />
+
// do some code here.
  
case EVENT_SelfUFO:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot toggles UFO mode<br />
+
int end = GetTickCount();
 +
 
 +
int delta = (end - begin) / 1000; // elapsed time converted to seconds from milliseconds
 +
</pre>
  
case EVENT_PositionHook:&nbsp;&nbsp; &nbsp;- called when &quot;Core is requesting the DLL to send a position packet&quot;<br />
+
=== Obtaining the current time ===
  
===Brick===
+
''Requirements:'' Include <time.h>.
  
case EVENT_BrickDropped:&nbsp;&nbsp; &nbsp;- called when a pilot uses a brick<br />
+
Use:
 +
<pre>
 +
char u[100];
 +
time_t t=time(NULL);
 +
tm *tmp = localtime(&t);
 +
strftime(u,99,"%c",tmp);
 +
sendPublic("Current date and time: " + u);
 +
</pre>
  
===Objects===
+
==Writing Functions==
 +
<!-- begin of functions. -->
 +
For this example, we will take the function called closeto, which determines
 +
if a player exists in an specific radius around a point. Now to apply this function to a MervBot plugin, you need to write it into the spawn.cpp - at the top of the file in the //////// DLL &quot;import&quot; //////// setion, as below:
 +
<pre>
 +
//////// DLL "import" ////////
  
case EVENT_ObjectToggled:&nbsp;&nbsp; &nbsp;- called when a .lvz object is toggled on/off<br />
+
bool closeto(Player *p, int x, int y, int tolerance)
 +
{
 +
// Requires the function abs() to be declared elsewhere.
 +
// Return if player p is in area of square with center x, y
 +
//  and radius = tolerance
 +
return (abs((p->tile.x) - x) - tolerance) && (abs((p->tile.y) - y) - tolerance);
 +
}
 +
</pre>
  
===Turrets===
 
  
case EVENT_CreateTurret:&nbsp;&nbsp; &nbsp;- called when a pilot attaches to another pilot (f7)<br />
+
If you want your function to have access to the data from spawn.h botInfo class, you make the function apart of it. To do this, we add the '''botInfo::''' infront of the function name, in spawn.cpp.
 +
<pre>
 +
//////// DLL "import" ////////
  
case EVENT_DeleteTurret:&nbsp;&nbsp; &nbsp;- called when a pilot detaches from a turret<br />
+
bool botInfo::closeto(Player *p, int x, int y, int tolerance)
 +
    {
 +
...
 +
    }
 +
</pre>
 +
In '''spawn.h''', add your method's prototype without botInfo::, it will look
 +
like this:
 +
<pre>
 +
//...
 +
botInfo(CALL_HANDLE given)
 +
{
 +
//  ...
 +
}
 +
  bool closeto(Player *p, int x, int y, int tolerance); // Your function prototype.
  
===Messages===
+
  void clear_objects(); //provided by Catid, and already exists.
 +
  void object_target(Player *p); //provided by Catid, and already exists.
 +
//  ...
 +
};
 +
</pre>
 +
If you're not familiar with prototypes, notice it is similar to that in your spawn.cpp, but without the botInfo::, and a trailing ;.
  
case EVENT_Chat:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot gets a chat message<br />
+
===Function notes===
  
case EVENT_LocalCommand:&nbsp;&nbsp; &nbsp;- called when bot gets a player command from arena<br />
+
Remember that you can pass variables [http://www.cplusplus.com/doc/tutorial/tut2-3.html by reference]. If variables are passed by reference, any changes a function makes to the variables will remain after the function returns.
  
case EVENT_LocalHelp:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot gets a player !help command<br />
+
From time to time you will need to pass an array to a function. An example illustrating this is:
 +
<pre>
 +
int freqs[5]; // declare our example data.
  
case EVENT_RemoteCommand:&nbsp;&nbsp; &nbsp;- called when bot gets a command from outside arena<br />
+
// call function - notice freqs and not freqs[5] or freqs[].
 +
my_function(freqs); //You're not passing the array itself, just a pointer to the array.
  
case EVENT_RemoteHelp:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when bot gets a player !help command from outside arena<br />
+
// function - notice freqs[] and not freqs[5] or freqs
 
+
void my_function(int freqs[]) {} //You're specifying that the freqs parameter is an array
case EVENT_Init:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when DLL is loaded<br />
+
</pre>
 
 
case EVENT_Term:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- called when DLL is unloaded<br />
 
              </blockquote>
 
 
 
==Messaging - How to use the messaging system==
 
  
Private message - void sendPrivate(Player *player, char *msg);
+
==Cycling through players==
  
''Examples:''
+
MERVBot stores player-related data in a linked list. A linked list is a datatype that stores its data in a series of structures linked to each other, hence the name.
  
 +
To search through the players in the arena, just start at the first link, then continue through all the following links until you reach the end:
 
<pre>
 
<pre>
sendPrivate(p,"hi");
+
_listnode <Player> *parse = playerlist->head; //set to first link of the player linked list
  
String s="test";
+
while (parse) //parse will be NULL when we reach the last link
sendPrivate(p,s);
+
{
 +
Player *p = parse->item; //item is the actual data stored in the link
  
String s="test";
+
// do functionality here
s += "ing";
+
// Example 1: sendPrivate(p,"*watchdamage"); // turns on all pilot's watchdamage
sendPrivate(p,s);
+
// Example 2: if (p->safety != 0) sendPrivate(p,"*spec"); // spec all pilots in safe zone
  
char captain1[20];
+
parse = parse->next; //set parse to the next link
char captain2[20];
+
}
strncpy(captain1,"",20);
 
strncpy(captain2,"",20);
 
sendPrivate(p,(String) captain1 + " and " + (String) captain2 + " are the captains.");
 
 
</pre>
 
</pre>
  
Team message - void sendTeamPrivate(Uint16 team, char *msg);<br />
+
For example, assuming our bot has smod+ privilages, the following code will set all non-spectator players to a specific ship. First begin by adding the following function prototype to the spawn.h in the botInfo class:
<blockquote>Examples: <br />
+
<pre>
a) sendTeamPrivate(8025,&quot;hi spec freq&quot;);<br />
+
void handleCmdSetShip(enum Ship_Types ship);
b) Uint16 test=0; sendTeamPrivate(test,&quot;hi freq 0&quot;);<br />
+
</pre>
</blockquote>
 
  
Public message - void sendPublic(char *msg);<br />
+
In spawn.cpp add:
<blockquote>Example: sendPublic(&quot;*arena &quot; + (String) p-&gt;name + &quot; is now a captain&quot;);<br />
+
<pre>
</blockquote>
+
void botInfo::handleCmdSetShip(enum Ship_Types ship)
Chat channel message - void sendChannel(char *msg);<br />
+
{
<blockquote>Example: sendChannel(&quot;hi chat channel&quot;);<br />
+
//Note that the parameter ship is of the Ship_Types enum,
</blockquote>
+
//so its value is hopefully restricted to the proper types.
Remote private message - void sendRemotePrivate(char *name, char *msg);<br />
 
<blockquote>Example: sendRemotePrivate(&quot;Player01&quot;, &quot;hi&quot;);<br />
 
</blockquote>
 
  
Note: to have bot print several lines of text fast it needs sysop in the
+
_listnode <Player> *parse = playerlist->head;
arena (sysop in arena bot first spawns to also) otherwise it'll print slow to avoid being
+
while (parse)
kicked for spam<br />
+
{
 +
Player *p = parse->item;
  
==Timer - How to use the timing function==
+
if ( p->ship != ship && p->ship != SHIP_Spectator )
                                   
+
sendPrivate(p, "*setship " + (String)ship);
                                                    <blockquote>Setup number of timers and initialize:<br />
 
                                      <blockquote>// spawn.h - specify how many timers<br />
 
                                        </blockquote>
 
&nbsp;<blockquote>class botInfo<br />
 
{<br />
 
int countdown[10];&nbsp;&nbsp; // this gives you 10 timers</blockquote>
 
&nbsp;<blockquote>&nbsp;// spawn.h - initialize timers<br />
 
&nbsp;&nbsp; &nbsp;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;public:<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;botInfo(CALL_HANDLE given)<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;countdown[0] = 0;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;countdown[1] = 60; // 60 seconds<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// initialize values<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;countdown[9] = 5*60; // 5 minutes<br />
 
                                            </blockquote>
 
                                            Using timer functions:<br />
 
                                            <blockquote>&nbsp;&nbsp; // in spawn.cpp<br />
 
                                              <br />
 
&nbsp;&nbsp; &nbsp;case EVENT_Tick:<br />
 
&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for (int i = 0; i &lt; 10; ++i)<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--countdown[i];<br />
 
                                              <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (countdown[1] == 2) // when timer #1 hits two seconds<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// do stuff here when timer #1 hits 2 seconds<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// example: sendPublic(&quot;two seconds left, setting timer to 1 minute&quot;);<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// example: countdown[1] = 60;&nbsp; // change timer #1 value<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
 
                                              </blockquote>
 
&nbsp;
 
<blockquote>&nbsp;&nbsp; &nbsp;Notes:&nbsp; - In the &quot;for&quot; loop, you want &quot;i &lt; 10&quot; to be the number of timers from spawn.h<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- The timer is in seconds. EVENT_Tick is called once per second.<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- The timers decrease by one each second down, not stopping at 0.<br />
 
                                                <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;- You can change the value of the countdown[n]'s in other parts of the program<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;(ie.&nbsp; case EVENT_PlayerDeath: { countdown[1] = 45;&nbsp; // set timer #1 to 45 sec<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;everytime someone dies)<br />
 
                                                </blockquote>
 
&nbsp;</blockquote>
 
  
                                              <br />
+
parse = parse->next;
                                                <a name="5"></a>
+
}
==Writing Functions==
+
}
<blockquote>
+
</pre>
<blockquote>Write your function in spawn.cpp at top of file in the //////// DLL &quot;import&quot; //////// section
 
                                                    <blockquote>&nbsp;&nbsp; &nbsp;//////// DLL &quot;import&quot; ////////<br />
 
          <br />
 
  
&nbsp;&nbsp; &nbsp;bool closeto(Player *p, int x, int y, int tolerance)&nbsp; // note uses abs() function declared elsewhere<br />
+
To use, just call the function with the appropriate Ship_Type from the enum in clientprot.h:
&nbsp;&nbsp;&nbsp; {<br />
+
<pre>
  &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; // return if player
+
  handleCmdSetShip(SHIP_Warbird);
p is in area of square with center x,y and radius = tolerance<br />
+
</pre>
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return (abs((p-&gt;tile.x) - x) &lt;
+
==Random numbers==
tolerance) &amp;&amp; (abs((p-&gt;tile.y) - y) &lt; tolerance);<br />
 
  
                                                       
+
===Generating a random number===
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br />
 
</blockquote>                                                        If
 
you want your function to have access to data from the spawn.h botInfo section<br />
 
                                                        <blockquote>public:<br />
 
&nbsp;&nbsp; &nbsp;botInfo(CALL_HANDLE given)<br />
 
&nbsp;&nbsp; &nbsp;{<br />
 
                                                          <br />
 
&nbsp;&nbsp; // then you need to make your spawn.cpp function in the format:<br />
 
                                                          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bool botInfo::closeto(Player *p, int x, int y, int tolerance)<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // function here<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
 
          <br />
 
Include function in spawn.h at bottom of file with the other functions<br />
 
          <blockquote>&nbsp;&nbsp; &nbsp;public:<br />
 
  
&nbsp;&nbsp; &nbsp;botInfo(CALL_HANDLE given)<br />
+
To use this method, these two includes must be used:
 +
<pre>
 +
#include "time.h"    //provides time() function.
 +
#include "stdlib.h"  //provides srand() and rand() functions.
 +
</pre>
  
&nbsp;&nbsp; &nbsp;{<br />
+
Use:
 +
<pre>
 +
    srand(time(NULL)); // seed random number generator.
  
&nbsp;&nbsp; &nbsp;}<br />
+
    rand(); // randomize.
            <br />
 
  
&nbsp;&nbsp; &nbsp;bool closeto(Player *p, int x, int y, int tolerance); <br />
+
    int temp = (int) (51 * ((float)rand()/RAND_MAX));
&nbsp; &nbsp; &nbsp;// your new function. note: w/o botInfo keyword and with a ;<br />
+
      // the above line returns a random integer between 0 and 51.
            <br />
+
      // Note: RAND_MAX is a global constant defined in stdlib.h
 +
</pre>
  
&nbsp;&nbsp; &nbsp;void clear_objects();&nbsp; // functions already there<br />
+
===Picking a random pilot===
  
&nbsp;&nbsp; &nbsp;void object_target(Player *p); // functions already there</blockquote>
+
''Note:'' A required user-defined function, getInGame(), must be created for this example to work.
  
&nbsp;</blockquote>
+
<pre>
&nbsp;</blockquote>
+
int temp = GetTickCount() % getInGame(); // getInGame() = how many pilots in arena
&nbsp;<blockquote>Pass values by reference
 
              <blockquote>bool botInfo::closeto(Player *p, int&amp; x, int y, int tolerance) &nbsp;// note the &amp;<br />
 
                <br />
 
bool is_close = closeto(p,x,y,tolerance); &nbsp;// if x is changed in closeto() its saved here <br />
 
                </blockquote>
 
&nbsp;</blockquote>
 
  
&nbsp;<blockquote>Pass array as parameter<br />
+
Player *rabbit = NULL;
                  <blockquote>int freqs[5];<br />
 
                    <br />
 
my_function(freqs); &nbsp;// call function - notice freqs and not freqs[5] or freqs[]<br />
 
                    <br />
 
void my_function(int freqs[]) {} &nbsp;// function - notice freqs[] and not freqs[5] or freqs<br />
 
                    </blockquote>
 
&nbsp;</blockquote>
 
<a name="6"></a>
 
==Cycling players- How to search through the players in the arena==
 
                                                          <blockquote>&nbsp;&nbsp; &nbsp;_listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
&nbsp;&nbsp; &nbsp;<br />
 
&nbsp;&nbsp; &nbsp;while (parse)<br />
 
&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Player *p = parse-&gt;item;<br />
 
                                                            <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// do functionality here<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Example 1: sendPrivate(p,&quot;*watchdamage&quot;); // turns on all pilot's watchdamage<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Example 2: if (p-&gt;safety != 0)
 
sendPrivate(p,&quot;*spec&quot;); // spec all pilots in safe zone<br />
 
                                                            <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parse = parse-&gt;next<br />
 
&nbsp;&nbsp;&nbsp; &nbsp; }<br />
 
                                                            </blockquote>
 
                                                            <br />
 
  
==Checking if pilot is in a safe zone==
+
_listnode <Player> *parse = playerlist->head;
                                                            <blockquote>&nbsp;&nbsp; &nbsp;if (p-&gt;safety != 0)&nbsp; // pilot is in a safe zone<br />
+
while (parse)
&nbsp;&nbsp; &nbsp;if (p-&gt;safety == 0)&nbsp; // pilot is NOT in a safe zone<br />
+
{
                                                              <br />
+
Player *p = parse->item;
&nbsp;&nbsp; &nbsp;To detect a pilot entering a safe zone do:<br />
 
                                                              <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case EVENT_PlayerMove:<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (p-&gt;safety != 0)<br />
 
                                                              </blockquote><br />
 
  
==Random number==
+
if (p->ship != SHIP_Spectator) // if player is not a spectator
                                                              <blockquote>Method 1 (completely random)<br />
+
if ( !(--temp) ) // and if we've hit the randomly-selected pilot
                                                                <blockquote>&nbsp;&nbsp; &nbsp;#include &quot;time.h&quot;<br />
+
{
                                                                  <br />
+
rabbit = p;
&nbsp;&nbsp; &nbsp;srand(time(NULL));<br />
+
break;
&nbsp;&nbsp; &nbsp;rand();<br />
+
}
&nbsp;&nbsp; &nbsp;int temp = (int) (51 * ((float)rand()/RAND_MAX));&nbsp; // returns a random integer between 0 and 51<br />
+
parse = parse->next;
                                                                  </blockquote>
+
}
                                                                  <br />
+
</pre>
Method 2 (random pilot in arena)<br />
 
                                                                  <blockquote>&nbsp;&nbsp; &nbsp;#include &lt;stdlib.h&gt;<br />
 
                                                                    <br />
 
&nbsp;&nbsp; &nbsp;int temp = GetTickCount() % getIngame();&nbsp; // getIngame() = how many pilots in arena<br />
 
                                                                    <br />
 
&nbsp;&nbsp; &nbsp;_listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
&nbsp;&nbsp; &nbsp;while (parse)<br />
 
&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Player *p = parse-&gt;item;<br />
 
                                                                    <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (p-&gt;ship != SHIP_Spectator){&nbsp; // if not in spec<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (!(--temp) {&nbsp; // decrement temp, if its 0, make this pilot rabbit<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;rabbit = p;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;break;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}}<br />
 
&nbsp;&nbsp; &nbsp;parse = parse-&gt;next;<br />
 
&nbsp;&nbsp; &nbsp;}<br />
 
                                                                    </blockquote>
 
&nbsp;</blockquote>
 
                                                                    <br />
 
                                                                    <a name="9"></a>
 
==Tracking time not using countdown[n]==
 
                                                                    <blockquote>&nbsp;&nbsp; &nbsp;#include &lt;stdlib.h&gt;<br />
 
<br />
 
&nbsp;&nbsp; &nbsp;int temp = GetTickCount(); // get time stamp<br />
 
&nbsp;&nbsp; &nbsp;// later in program<br />
 
&nbsp;&nbsp; &nbsp;temp = (GetTickCount() - temp)/1000; // how many seconds have passed<br />
 
</blockquote>
 
                                                                    <br />
 
  
 
==Storing data for pilots==
 
==Storing data for pilots==
<blockquote>There are several ways to store data for pilots (ie tracking flagtime or kills in a period of time)<br />
 
                                  <br />
 
1) get/setTag - use if you only want to track data until pilot leaves arena then its erased<br />
 
built in tags track by an ID that is reset when pilot leaves/enters arena, so loses track of data once they leave arena<br />
 
                                  <br />
 
2) modified perm get/setTag - use if you want to track all pilots even if they leave (advantage - easier to sort by player)<br />
 
also can track near unlimited amount of pilots<br />
 
                                  <br />
 
3) structs - use to track all pilots even if they leave, (advantage -
 
easier to sort by freqs), have to specify bound of players<br />
 
                                  <br />
 
note: 2 and 3 are similar in effect, mostly the difference is in how you are able to search through data<br />
 
you need to decide which method of storing data is best for each bot depending on what it does<br />
 
beware using modified perm get/setTag if bot is in an arena for long periods
 
of time, data is not reset so the linkedlist could get huge<br />
 
                                  <br />
 
  
// initialize values in spawn.h at very top<br />
+
There are several ways to store data for pilots (ie tracking flagtime or kills in a period of time). Note that these methods are all purely internal to the bot, and don't effect anything beyond the plugin in any way.
                                  <br />
 
1) Built in get/setTag method</blockquote><blockquote><blockquote>&nbsp;&nbsp; &nbsp;#define DMG_DEALT&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;0<br />
 
&nbsp;&nbsp; &nbsp;#define DMG_TAKEN&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;1<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;// in spawn.cpp initialize the values on arena-enter and player-enter<br />
 
&nbsp;&nbsp; &nbsp;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case EVENT_ArenaEnter: {<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;_listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;while (parse) // do for all pilots in arena when bot enters<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Player *p = parse-&gt;item;&nbsp; // get pilot<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_tag(p, DMG_DEALT, 0); // initialize to 0<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_tag(p, DMG_TAKEN, 0);<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPrivate(p,&quot;*watchdamage&quot;);&nbsp;
 
// optionally turn on player *watchdamage<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parse = parse-&gt;next;&nbsp; // get next pilot<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case EVENT_PlayerEntering: {<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_tag(p, DMG_DEALT, 0); // initialize to 0<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_tag(p, DMG_TAKEN, 0);<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPrivate(p,&quot;*watchdamage&quot;);<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;// then somewhere edit the tag values<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case EVENT_WatchDamage:&nbsp; {<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// sets tag for k (shooter) to be old value plus damage dealt currently<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_tag(k, DMG_BOMB_DEALT, get_tag(k, DMG_BOMB_DEALT) + damage);<br />
 
      <br />
 
&nbsp;// how to retrieve the tag values<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// as a command in spawn.h<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if (c-&gt;check(&quot;showstats&quot;)) {<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;int temp = get_tag(p, DMG_TOTAL_DEALT);<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String s = &quot;You've done &quot;;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;s += temp;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;s += &quot; damage so far!&quot;;<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPrivate(p,s);<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;// kill tags when player leaves arena<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case EVENT_PlayerLeaving: {<br />
 
      <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;killTags(p);<br />
 
      </blockquote>2) Modified permanent get/setTag method<br />
 
      <blockquote>// same as get/setTag with some modifications to the tag code, then can use tags exactly as above<br />
 
                                        <br />
 
// spawn.h, add char name[20]; into struct PlayerTag<br />
 
                                        <blockquote>struct PlayerTag<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; Player *p;<br />
 
&nbsp;&nbsp;&nbsp; char name[20];<br />
 
&nbsp;&nbsp;&nbsp; int index;<br />
 
&nbsp;&nbsp;&nbsp; int data;<br />
 
};<br />
 
                                          </blockquote>
 
// spawn.cpp, modifications<br />
 
                                          <blockquote>case EVENT_PlayerLeaving:<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; Player *p = (Player*)event.p[0];<br />
 
                                            <br />
 
&nbsp;&nbsp;&nbsp; // killTags(p); &nbsp;// remove so tag not deleted on arena exit<br />
 
                                            <br />
 
                                            </blockquote>
 
&nbsp;<blockquote>int botInfo::get_tag(Player *p, int index)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; _listnode &lt;PlayerTag&gt; *parse = taglist.head;<br />
 
&nbsp;&nbsp;&nbsp; PlayerTag *tag;<br />
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
tag = parse-&gt;item;<br />
 
                                              <br />
 
// if (tag-&gt;p == p)<br />
 
if (strcmp(tag-&gt;name,p-&gt;name)==0) &nbsp;// now tracking by player name, not ID<br />
 
if (tag-&gt;index == index)<br />
 
&nbsp;&nbsp;&nbsp; return tag-&gt;data;<br />
 
                                              <br />
 
parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; return 0;<br />
 
}<br />
 
                                              <br />
 
void botInfo::set_tag(Player *p, int index, int data)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; _listnode &lt;PlayerTag&gt; *parse = taglist.head;<br />
 
&nbsp;&nbsp;&nbsp; PlayerTag *tag;<br />
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
tag = parse-&gt;item;<br />
 
                                              <br />
 
//if (tag-&gt;p == p)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if (strcmp(tag-&gt;name,p-&gt;name)==0) // now tracking by player name, not ID<br />
 
if (tag-&gt;index == index)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; tag-&gt;data = data;<br />
 
&nbsp;&nbsp;&nbsp; return;<br />
 
}<br />
 
parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; tag = new PlayerTag;<br />
 
&nbsp;&nbsp;&nbsp; // tag-&gt;p = p; // not tracking by ID anymore<br />
 
&nbsp;&nbsp;&nbsp; strncpy(tag-&gt;name, p-&gt;name, 20); // tracking by player name<br />
 
&nbsp;&nbsp;&nbsp; tag-&gt;index = index;<br />
 
&nbsp;&nbsp;&nbsp; tag-&gt;data = data;<br />
 
&nbsp;&nbsp;&nbsp; taglist.append(tag);<br />
 
}</blockquote>
 
&nbsp;</blockquote>
 
3) Using Struct's<br />
 
      <blockquote>struct name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
 
&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
        <br />
 
  
&nbsp;&nbsp; &nbsp;// variables&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />
+
# Built-in get/setTag: Tracks data until player leaves the arena, then automatically deletes data.
 +
# Modified perm get/setTag: Tracks data until bot leaves arena, then automatically deletes data. (Advantage: easier to sort by player)
 +
# Custom Structs: Tracks data until plugin deletes it. (Advantage: easier to sort by freqs)
  
&nbsp;&nbsp; &nbsp;};<br />
+
''Note:'' 2 and 3 are similar in effect, mostly the difference is in how you are able to search through data you need to decide which method of storing data is best for each bot depending on what it does.
        <br />
 
// Example: (in spawn.h)<br />
 
        <blockquote>class botInfo<br />
 
{<br />
 
          <br />
 
struct freqdata {<br />
 
int kills;<br />
 
&nbsp;int deaths; <br />
 
};<br />
 
          <br />
 
freqdata freqs[100]; // 100 of those structs<br />
 
          <br />
 
// then access it in spawn.cpp using<br />
 
freqs[56].kills = 1;<br />
 
          </blockquote>
 
&nbsp;</blockquote>
 
          <br />
 
          </blockquote>
 
  
==Output of data/messages==
+
===Built-in get/setTag method===
          <br />
 
&nbsp;&nbsp; &nbsp;using normal Strings<br />
 
          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// does *arena X pilots left in the game.<br />
 
          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; String s = &quot;*arena &quot;;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; s += temp;&nbsp; // some variable (int)<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; s += &quot; pilots left in the game.&quot;;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; sendPublic(s)<br />             
 
                                                                       
 
                                                      <blockquote>OR<br />
 
                                                                       
 
</blockquote>
 
&nbsp;<blockquote>sendPublic(&quot;*arena &quot; + (String) temp + &quot; pilots left in the game.&quot;);<br />
 
                                                                       
 
                                                                       
 
</blockquote>
 
  
        <br />
+
Player tags simply tag a player with a number. Define the wanted values in '''spawn.h''' at the top:
&nbsp;&nbsp; &nbsp;example using sprintf to align/space data<br />
+
<pre>
          <br />
+
#define DMG_DEALT        0
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// output data
+
#define DMG_TAKEN        1
will be in this approximate format (not lined up perfectly because of html)<br />
+
</pre>
          <br />
 
            &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//
 
----------------------------------------------------------------------------------------<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Squad: squadname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
PTS&nbsp;&nbsp;&nbsp;&nbsp; FPTS&nbsp;&nbsp; &nbsp;K&nbsp;&nbsp; &nbsp;D&nbsp; DMG DEALT
 
TAKEN&nbsp; &nbsp;F&nbsp; FK&nbsp;&nbsp;&nbsp; FLT<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; &nbsp;// ----------------------------------------------------------------------------------------<br />
 
            &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//
 
PlayerA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10000 &nbsp; &nbsp; &nbsp; &nbsp;500
 
  116  101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
  9999&nbsp;  &nbsp; 99999 10 150 980:55<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;// PlayerB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 500&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
 
200&nbsp;&nbsp; &nbsp; 7&nbsp;&nbsp; &nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9999&nbsp; &nbsp; 99999&nbsp; 5&nbsp;&nbsp;
 
&nbsp; &nbsp;3&nbsp; &nbsp;&nbsp; 0:04<br />
 
          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;char str[255];<br />
 
              &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPublic(&quot;*arena----------------------------------------------------------------------------------&quot;);<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sprintf(str, &quot;*arena
 
Squad: %-20s&nbsp;&nbsp; PTS&nbsp;&nbsp;&nbsp;&nbsp; FPTS&nbsp;&nbsp; K&nbsp;&nbsp;
 
D&nbsp; DMG DEALT&nbsp; TAKEN&nbsp; F&nbsp; FK&nbsp;&nbsp;&nbsp; FLT&quot;,freqs[freq].freqname);<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPublic(str);<br />
 
              &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPublic(&quot;*arena----------------------------------------------------------------------------------&quot;);<br />
 
          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// assuming existing freqs struct with data<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for (pilot=freqs[freq].playercount-1; pilot&gt;=0; pilot--)<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// on freq squad so print stats<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;char outString[255];<br />
 
          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sprintf(outString,
 
&quot;*arena %-20s %12d %8d %3d %3d %10d %6d %2d %3d %3d:%02d&quot;,freqs[freq].pilots[pilot].name,<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;freqs[freq].pilots[pilot].points,
 
freqs[freq].pilots[pilot].flagpoints, freqs[freq].pilots[pilot].kills,<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;freqs[freq].pilots[pilot].deaths,
 
freqs[freq].pilots[pilot].dmgdealt, freqs[freq].pilots[pilot].dmgtaken,freqs[freq].pilots[pilot].flags,<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;freqs[freq].pilots[pilot].flagkills, freqs[freq].pilots[pilot].flagtime
 
/60, freqs[freq].pilots[pilot].flagtime %60);<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sendPublic(outString);<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
 
          <br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Notes: sprintf
 
format = sprintf(output char string, spacing, variables)<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Notes: s = chars, d = integer, - = left align, right align default<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Notes: doing
 
%02d = put 0 in front if not 2 digits, %3d:%02d makes 0:04 format<br />
 
          <br />
 
          <br />
 
          <a name="12"></a>
 
==Input/Output to files==
 
         
 
<blockquote>Input to file<br />
 
<blockquote>// example reading from duel.ini looking for line that starts with MaxBoxes= then taking the next char as value to store as <br />
 
// MAX_BOXES (ie duel.ini = MaxBoxes=5)<br />
 
#include &lt;fstream&gt;<br />
 
using namespace std;<br />
 
              <br />
 
ifstream file(&quot;duel.ini&quot;);<br />
 
&nbsp;&nbsp;&nbsp; char line[256];<br />
 
              <br />
 
&nbsp;&nbsp;&nbsp; // read in MaxBoxes=X<br />
 
&nbsp;&nbsp;&nbsp; while (file.getline(line, 256))<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
if (CMPSTART(&quot;MaxBoxes=&quot;, line))<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; MAX_BOXES = atoi(&amp;(line[9]));<br />
 
&nbsp;&nbsp;&nbsp; break;<br />
 
}<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
              </blockquote>
 
Output to file<br />                                                   
 
                                                                       
 
                                                                       
 
                                    <blockquote>// normal char output<br />
 
                                                                       
 
                                                                       
 
      <blockquote>#include &lt;fstream&gt;<br />
 
  
 +
In spawn.cpp, initialize the values on ArenaEnter and PlayerEnter:
 +
<pre>
 +
case EVENT_ArenaEnter:
 +
{
 +
// ...
  
using namespace std;<br />
+
// do for all pilots in arena when bot enters
 +
_listnode <Player> *parse = playerlist->head;
 +
while (parse)
 +
{
 +
  Player *p = parse->item; // get pilot
  
                <br />
+
  set_tag(p, DMG_DEALT, 0); // initialize to 0
 +
  set_tag(p, DMG_TAKEN, 0);
 +
  sendPrivate(p, "*watchdamage");  // optionally turn on player *watchdamage
  
ofstream file(&quot;duelleaguestat.inc&quot;, ios::app); &nbsp; // app = put all data at end of file<br />
+
  parse = parse->next; // get next pilot
 +
}
 +
}
 +
</pre>
 +
<pre>
 +
case EVENT_PlayerEntering:
 +
{
 +
// ...
 +
set_tag(p, DMG_DEALT, 0); // initialize to 0
 +
set_tag(p, DMG_TAKEN, 0);
 +
sendPrivate(p,"*watchdamage");
 +
}
 +
</pre>
  
                <br />
+
Then somewhere edit the tag values:
 +
<pre>
 +
case EVENT_WatchDamage:
 +
{
 +
// sets tag for k (shooter) to be old value plus damage currently dealt
  
file &lt;&lt; squad1&lt;&lt; endl; &nbsp;// squad1 = char[20]<br />
+
int old_damage = get_tag(k, DMG_BOMB_DEALT);
 +
set_tag(k, DMG_BOMB_DEALT, old_damage + damage);
 +
}
 +
</pre>
  
file &lt;&lt; &quot; vs &quot;&lt;&lt; endl;<br />
+
The following demonstrates how to retrieve the tag values as a command in command.cpp:
 +
<pre>
 +
if (c->check("showstats"))
 +
{
 +
int temp = get_tag(p, DMG_TOTAL_DEALT);
  
file &lt;&lt; squad2&lt;&lt; endl; &nbsp;// squad2 = char[20]<br />     
+
String s = "You've done ";
                                                                       
+
s += temp;
                                                                       
+
s += " damage so far!";
  </blockquote>
 
                                                                       
 
                                                      // how to output String's
 
to file (key is converting String to (char*) to file write)<br />       
 
                                                                       
 
                                                                       
 
<blockquote>
 
String str = freqs[freq].slotname[slot];<br />
 
  
str += &quot;, Repels: &quot; + (String)(int) t-&gt;repel;<br />
+
sendPrivate(p,s);
 +
}
 +
</pre>
  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
===Modified permanent get/setTag method===
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; <br />
 
  
outf &lt;&lt; endl;<br />
+
This method is the same as get/setTag with some modifications to the tag code to retain them after the player leaves. Beware of using this method if bot is in an arena for long periods of time, linkedlist could get huge.
  
outf &lt;&lt; (char*) str;<br />                                       
 
                                                                       
 
                                          </blockquote>
 
  
                                                        <br />
+
// spawn.h, add char name[20]; into struct PlayerTag
// date and time stamp<br />                                           
+
<pre>
                                                                       
+
struct PlayerTag
                                      <blockquote>#include &quot;time.h&quot;<br />
+
{
                                                                                      <br />
+
Player *p;
char u[100];<br />
+
char name[20];
time_t t=time(NULL);<br />
+
int index;
tm *tmp = localtime(&amp;t);<br />
+
int data;
strftime(u,99,&quot;%c&quot;,tmp);<br />
+
};
sendPublic(&quot;Date and time: &quot; + (String) u);<br />
+
</pre>
  
                                                                                     
+
In spawn.cpp:
                </blockquote>
+
<pre>
&nbsp;</blockquote>
+
case EVENT_PlayerLeaving:
</blockquote>
+
{
&nbsp;<blockquote>Example reading input from file using &quot;GetPrivateProfileString&quot; (from rampage plugin)<br />
+
    Player *p = (Player*)event.p[0];
                                                  <blockquote>format of rampage.ini<br />
 
        <blockquote>7=is on a killing spree! (6:0)<br />10=is opening a can of whoop-ass! (9:0)<br />
 
                                                      </blockquote>
 
read input<br />
 
                                                      <blockquote>rampageini.h<br />
 
                                                        <blockquote>#pragma once<br />
 
  
#ifndef RAMPAGEINI_H<br />
+
    // killTags(p); // remove so tag not deleted on arena exit
#define RAMPAGEINI_H<br />
 
                                                          <br />
 
#define NUM_RANKS 10<br />
 
#define BUFFER_LEN 256<br />
 
                                                          <br />
 
struct RampageSettings<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; char quotes[NUM_RANKS][BUFFER_LEN];<br />
 
};<br />
 
                                                          <br />
 
void LoadSettings(RampageSettings &amp;setts);<br />
 
                                                          <br />
 
#endif&nbsp;&nbsp;&nbsp; // RAMPAGEINI_H<br />
 
                                                          </blockquote>
 
rampageini.cpp<br />
 
                                                          <blockquote>#include &quot;rampageini.h&quot;<br />
 
static char buffer[BUFFER_LEN];<br />
 
static char path[BUFFER_LEN];<br />
 
#include &quot;../algorithms.h&quot;<br />
 
#define WIN32_LEAN_AND_MEAN<br />
 
#include &lt;windows.h&gt;<br />                                       
 
                                                                       
 
                <br />
 
char *rank_type[10] = {<br />
 
&nbsp;&nbsp; &nbsp;&quot;7&quot;,<br />
 
&nbsp;&nbsp; &nbsp;&quot;10&quot;,<br />
 
};<br />                                                               
 
                                                                <br />
 
void LoadSettings(RampageSettings &amp;setts)<br />
 
{<br />
 
&nbsp;&nbsp; &nbsp;GetCurrentDirectory(BUFFER_LEN - 64, path);<br />
 
&nbsp;&nbsp; &nbsp;strcat(path, &quot;\rampage.ini&quot;);<br />                 
 
                                                                       
 
                                      <br />
 
&nbsp;&nbsp; &nbsp;for (int i = 0; i &lt; NUM_RANKS; ++i)<br />
 
&nbsp;&nbsp; &nbsp;{<br />
 
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; GetPrivateProfileString(&quot;Comments&quot;,
 
rank_type[i], &quot;-ERROR-&quot;, setts.quotes[i], BUFFER_LEN, path);<br />
 
&nbsp;&nbsp; &nbsp;}<br />
 
}<br />                                                                 
 
                                                                </blockquote>
 
&nbsp;</blockquote>&nbsp;</blockquote>&nbsp;</blockquote>
 
  
==Simple programming commands==
+
// ...
                                                                       
+
</pre>
                                                                       
 
                                            <blockquote>simple commands &nbsp; &nbsp;<br />
 
                                                                       
 
                                                            <blockquote>
 
&nbsp;&nbsp;&nbsp; declare/initialize variables &nbsp; // example: &nbsp;int
 
temp; &nbsp;int temp2 = 1; &nbsp;temp2 = 3; &nbsp;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
// bool check = true; check = false;<br />                                                         
 
                                                                       
 
                                          <br />
 
&nbsp; &nbsp; if (condition) {}&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; &nbsp;// example: if (a &gt; b) { a++; }<br />
 
  
                  <br />
+
Locate in spawn.cpp and modify accordingly:
 +
<pre>
 +
int botInfo::get_tag(Player *p, int index)
 +
{
 +
    _listnode <PlayerTag> *parse = taglist.head;
 +
    PlayerTag *tag;
  
&nbsp;&nbsp; &nbsp;if (condition) {} else {} &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
    while (parse)
&nbsp;&nbsp;&nbsp; &nbsp;// example: if (b &lt;= 0) { b--; } else { a++;
+
    {
}<br />
+
      tag = parse->item;
  
                  <br />
+
      // if (tag->p == p)
 +
      if (strcmp(tag->name,p->name)==0)  // now tracking by player name, not pointer
 +
      if (tag->index == index)
 +
        return tag->data;
  
&nbsp;&nbsp; &nbsp;while (condition) {}&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
      parse = parse->next;
&nbsp;&nbsp;&nbsp; &nbsp;// example: while (b &gt; 0) { b--; }<br />
+
    }
 +
    return 0;
 +
}
  
                  <br />
+
void botInfo::set_tag(Player *p, int index, int data)
 +
{
 +
    _listnode <PlayerTag> *parse = taglist.head;
 +
    PlayerTag *tag;
  
&nbsp;&nbsp; &nbsp;for (initialize; condition; increment){}&nbsp;&nbsp;
+
    while (parse)
&nbsp;// example: for (a=1; a &lt; 10; a++) { a = a + b; }<br />       
+
    {
                                                                       
+
      tag = parse->item;
                                                    </blockquote>
 
  
                                                                                        array<br />
+
      //if (tag->p == p)
                                                                       
+
      if (strcmp(tag->name,p->name)==0) // now tracking by player name, not pointer
                                                              <blockquote>single dimension<br />
+
      if (tag->index == index)
                                                                       
+
      {
                                                                <blockquote>int teams[100]; &nbsp; // create 100 hundred teams 0-99<br />
+
        tag->data = data;
                                                                       
+
        return;
                                                                  <br />
+
      }
teams[50] = 1;<br />                                                   
+
      parse = parse->next;
                                                                       
+
    }
            </blockquote>
 
multi-dimensional<br />                                             
 
                                                                       
 
                  <blockquote>int teams[100][50]; &nbsp;// multidimensional arry<br />
 
                                                                       
 
                                                                    <br />
 
teams[99][49] = 2;<br />                                               
 
                                                                       
 
                  </blockquote>
 
variable size <br />                                                 
 
                                                                       
 
                <blockquote>String *list = new String[amount+1]; // string array with size amount (variable) + 1;<br />
 
                                                                       
 
<br />
 
list[amount-1] = &quot;hi&quot;;<br />                                           
 
                                                                       
 
                        </blockquote>&nbsp;</blockquote>
 
struct &nbsp; &nbsp;<br />                                           
 
                                                                       
 
                        <blockquote>&nbsp;&nbsp;&nbsp; struct name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;<br />
 
  
&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
    tag = new PlayerTag;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
    // tag->p = p; // not tracking by pointer anymore
&nbsp;<br />
+
    strncpy(tag->name, p->name, 20); // tracking by player name
 +
    tag->index = index;
 +
    tag->data = data;
 +
    taglist.append(tag);
 +
}
 +
</pre>
  
&nbsp;&nbsp; &nbsp;// variables&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
===Using structs===
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br />
 
  
 +
In '''spawn.h''':
 +
<pre>
 +
class botInfo
 +
{
 +
struct freqdata
 +
{
 +
int kills, deaths;
 +
};
 +
// ...
 +
};
 +
</pre>
  
&nbsp;&nbsp; &nbsp;};<br />                                             
+
To make use of this structure, implement accordingly:
                                                                       
+
<pre>
                        <blockquote>// example:<br />
+
freqdata freqs[100]; // 100 of those structs
struct freqdata {
+
</pre>
int kills; int deaths; };<br />                                         
+
Access the data in spawn.cpp using
                                                                       
+
<pre>
                              <br />
+
freqs[56].kills = 1;
freqdata freqs[100]; // 100 of those structs<br />                    
+
</pre>
                                                                       
 
                                                  <br />
 
freqs[56].kills =
 
1; &nbsp;// access struct<br />                                         
 
                                                                       
 
                              </blockquote>&nbsp;</blockquote>
 
  
                                                                                        switch &nbsp; &nbsp;<br />
+
See CPlusPlus.com's [http://www.cplusplus.com/doc/tutorial/tut3-5.html Structures] tutorial for a more comprehensive guide. Note that, as shown on the bottom of the page, you can have structures within structures. Thus, for example, you could have a structure for each freq with a structure for each player nested within them.
                                                                       
 
                                                                       
 
<blockquote>switch (variable)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp; <br />
 
  
&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
==Input/Output to files==
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp; <br />
 
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case n:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
For reading and/or writing to files with C++ you must have the required include statement as follows:
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; <br />
+
<pre>
 +
#include <fstream>
 +
using namespace std;
 +
</pre>
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{ } &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
===File stream input===
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
The following example will show you how to read a file, duel.ini, line by line.
&nbsp; &nbsp; <br />
 
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;break;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
<pre>#include "stdlib.h" // for atoi()</pre>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
 
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
<pre>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
  ifstream file("duel.ini");
&nbsp;&nbsp;&nbsp; &nbsp;<br />
 
  
   &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case m:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  
+
   if (!file.good()) // if there was an error opening the file
&nbsp; &nbsp;&nbsp;&nbsp; <br />
+
    sendPublic("*arena Error opening file for reading"); // or add your own error handler
 +
  else
 +
  {
 +
    char line[256];
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{&nbsp; } &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
    // read in MaxBoxes=X
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
    while (file.getline(line, 256))
&nbsp; <br />
+
    {
 +
   
 +
      if (CMPSTART("MaxBoxes=", line)) //Does the line begin with MaxBoxes= ?
 +
      {
 +
        MAX_BOXES = atoi(&(line[9])); //If so, read the value into an integer, using atoi.
 +
        break;
 +
      }
 +
    }
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;break;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+
    file.close();
&nbsp;&nbsp;&nbsp; &nbsp;<br />
+
  }
 +
</pre>
  
 +
===File stream output===
 +
The following code example will demonstrate how to append to a file, duelleaguestat.inc.
 +
<pre>
 +
ofstream file("duelleaguestat.inc", ios::app);  // app = put all data at end of file
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
+
if (!file.good()) // if there was an error opening the file
 +
  sendPublic("*arena Error opening file.");
 +
else
 +
{
 +
  file << squad1<< endl; // squad1 = char[20]
 +
  file << " vs "<< endl;
 +
  file << squad2<< endl; // squad2 = char[20]
 +
  file.close();
 +
}
 +
</pre>
  
 +
Similarly, you are able to write an output of a String to a file:
 +
<pre>
 +
// key is converting String to (char*) to file write
 +
String str = freqs[freq].slotname[slot];
 +
str += ", Repels: " + (String)(int) t->repel;
 +
file << endl;
 +
file << (char*) str;
 +
</pre>
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;default:<br />
+
===Input with GetPrivateProfileString===
  
 +
GetPrivateProfileString(), a function provided by Windows for reading INI files, will automatically find an INI key (like "MaxBoxes=") in a file for you. See the [http://msdn.microsoft.com/library MSDN Library] for help on this function. This next example will show how to read input using GetPrivateProfileString() based on the rampage plugin.
  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;break;<br />
+
The file format for rampage.ini is like this:
 +
<pre>
 +
7=is on a killing spree! (6:0)
 +
10=is opening a can of booya! (9:0)
 +
</pre>
  
 +
In '''rampageini.cpp''':
 +
<pre>
 +
#include "rampageini.h"
 +
#define WIN32_LEAN_AND_MEAN
 +
#include <windows.h>
  
&nbsp;&nbsp; &nbsp;}<br />                                             
+
#define NUM_RANKS 10
                                                                       
+
#define BUFFER_LEN 256
                            <blockquote>&nbsp;<blockquote>// Example:<br />
 
switch (p-&gt;ship) {<br />                                             
 
                                                                       
 
                                <br />
 
&nbsp;&nbsp;&nbsp; case SHIP_Warbird: &nbsp;{<br />
 
sendPrivate(p,&quot;You're in a warbird&quot;);<br />
 
} &nbsp;break;<br />             
 
                                                                       
 
                                                                <br />
 
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; default:<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; break;</blockquote>&nbsp;</blockquote>
 
  
&nbsp;</blockquote>
+
struct RampageSettings
&nbsp;</blockquote>
+
{
 +
char quotes[NUM_RANKS][BUFFER_LEN];
 +
};
 +
 +
void LoadSettings(RampageSettings &setts);
  
                  <br />
+
static char path[BUFFER_LEN];
==Useful Player data==
 
                                  <blockquote>
 
                                                                       
 
                                                        // useful data stored
 
by MervBot about each player (player.h)<br />
 
                                                                       
 
                                                          <br />
 
  
p-&gt;name = player name stored as char[20]<br />
+
char *rank_type[NUM_RANKS] = { "7", "10" };
p-&gt;squad = player squad stored as char[20]<br />
 
p-&gt;ship = ship (0-7) enumerated as SHIP_Warbird, SHIP_Spectator, etc..<br />
 
p-&gt;safety = if ship is in safety zone (boolean)<br />
 
p-&gt;bounty = player bounty<br />
 
p-&gt;energy = player energy (have bot with *energy on to get accurate readings)<br />
 
p-&gt;flagCount = how many flags player is holding<br />
 
  
p-&gt;team = player frequency<br />
+
void LoadSettings(RampageSettings &setts)
p-&gt;(burst, repel, thor, brick, decoy, rocket, portal) = how many items of that type player has<br />
+
{
p-&gt;(stealth, cloak, xradar, awarp, ufo, flash, safety, shields, supers) = if player has that item on (boolean)<br />
+
GetCurrentDirectory(BUFFER_LEN - 64, path);
 +
strcat(path, "\rampage.ini");
  
p-&gt;score.killPoints = player kill points<br />
+
for (int i = 0; i < NUM_RANKS; ++i)
p-&gt;score.flagPoints = player flag points<br />
+
{
p-&gt;score.wins = player kills from f2<br />
+
GetPrivateProfileString("Comments", rank_type[i], "-ERROR-",
p-&gt;score.losses = player deaths from f2<br />
+
setts.quotes[i], BUFFER_LEN, path);
                                    </blockquote>
+
}
                                    <br />
+
}
                                    <br />
+
</pre>
==Bot built in functions==
 
<blockquote>// useful MervBot commands to control what the bot is doing<br />
 
                                                                                                                            <br />
 
// player.cpp<br />
 
Player::move(Sint32 x, Sint32 y) &nbsp;// example &nbsp;me-&gt;move(512,512) - bot moves to coord 512 512<br />
 
Player::clone(Player *p) // example &nbsp;me-&gt;clone(p) <br />
 
                                                                                                                            <br />
 
// dllcore.cpp (descriptions of functions in dllcore.h)<br />
 
                                                                                                                            <br />
 
BotEvent makeEcho&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (char *m);<br />
 
BotEvent makeSay&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (int t, int s, int i, char *m);<br />
 
                                                                                                                            <br />
 
BotEvent makeShip&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (int s);<br />
 
BotEvent makeTeam&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (int t);<br />
 
BotEvent makeGrabFlag&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (int f);<br />
 
BotEvent makeSendPosition&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (bool reliable);<br />
 
BotEvent makeDropFlags&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ();<br />
 
                                                                                                                            <br />
 
BotEvent makeDeath&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (Player *p);<br />
 
BotEvent makeAttach&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (Player *p);<br />
 
BotEvent makeDetach&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ();<br />
 
BotEvent makeFollowing&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (bool f);<br />
 
BotEvent makeFlying&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (bool f);<br />
 
BotEvent makeBanner&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (BYTE *b);<br />
 
BotEvent makeDropBrick&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ();<br />
 
BotEvent makeFireWeapon&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (void *weapon_info);<br />
 
                                                                                                                            <br />
 
BotEvent makeToggleObjects&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (Uint16 player, Uint16 *objects, int num_objects);<br />
 
                                                                                                                            <br />
 
BotEvent makeSpawnBot&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
(char *name, char *password, char *staff, char *arena);<br />
 
BotEvent makeChangeArena&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (char *name);<br />
 
BotEvent makeChangeSettings&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (_linkedlist &lt;String&gt; *settings);<br />
 
                                                                                                                            <br />
 
// example how to use them:<br />
 
                                                                                                                            <br />
 
tell(makeFollowing(false));<br />
 
                                                      <br />
 
// look in Commands.txt , command.cpp (core), or /!help to bot to see all bot external commands (example /!go &lt;arena&gt;)<br />
 
                                                      </blockquote>
 
  
==Example Code==
+
==Player data==
  
<a name="15a"></a>
+
As stated earlier in the tutorial, MervBot stores useful player data internally as Player objects, see player.h for implementation details.
a) No antiwarp in center of map (take green away and warn)<br />     
 
                                                                       
 
                                                                       
 
  <blockquote>// using function closeto() and abs()<br /></blockquote>&nbsp;<blockquote>
 
bool closeto(Player *p, int x, int y, int tolerance) {<br />
 
&nbsp;&nbsp;&nbsp; return (abs((p-&gt;tile.x) - x) &lt; tolerance) &amp;&amp; (abs((p-&gt;tile.y) - y) &lt; tolerance); }<br /><br />
 
inline int abs(int n) {<br />
 
&nbsp;&nbsp;&nbsp; if (n &lt; 0)&nbsp;&nbsp;&nbsp; return -n;<br />
 
&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return n; }<br /><br />
 
radius = 35; &nbsp;// global variable<br /></blockquote>&nbsp;<blockquote>case EVENT_PlayerMove: {<br />
 
&nbsp;&nbsp;&nbsp; Player *p = (Player*)event.p[0];<br /><br />
 
&nbsp;&nbsp;&nbsp; // no anti in center<br />
 
&nbsp;&nbsp;&nbsp; if ((p-&gt;ship != SHIP_Spectator) &amp;&amp; (p-&gt;awarp)) {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (closeto(p, 512, 512, radius)){<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sendPrivate(p, &quot;*prize #-20&quot;);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; sendPrivate(p, &quot;*warn Antiwarp is not allowed in center.&quot;);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; }<br /></blockquote>
 
                                                                       
 
                                                                       
 
              <a name="15b"></a>
 
  
b) Setting freq size depending on how many pilots in game<br />      
+
* p->name = player name stored as char[20] (''Note:'' SubSpace protocol allows for usernames to be 19+ in length, do not rely on this for player-name comparisions.)
                                                                       
+
* p->squad = player squad stored as char[20]
                                                                       
+
* p->ship = ship (0-9) enumerated as SHIP_Warbird, SHIP_Spectator, etc..
 +
* p->safety = whether ship is in safety zone (boolean)
 +
* p->bounty = player bounty
 +
* p->energy = player energy (have bot with *energy on to get accurate readings)
 +
* p->flagCount = how many flags player is holding
 +
* p->team = player frequency
 +
* p->(burst, repel, thor, brick, decoy, rocket, portal) = how many items of that type player has
 +
* p->(stealth, cloak, xradar, awarp, ufo, flash, safety, shields, supers) = if player has that item on (boolean)
 +
* p->score.killPoints = player kill points
 +
* p->score.flagPoints = player flag points
 +
* p->score.wins = player kills from f2
 +
* p->score.losses = player deaths from f2
  
<blockquote>
+
Just access the respective member of the Player class to check the player's property.
case EVENT_Tick: &nbsp;{<br />
 
<blockquote>if (countdown[0] == 0) { &nbsp; &nbsp; // assuming countdown[0] initialized to &gt; 0&nbsp; in spawn.h, freqchange=0;<br />
 
</blockquote>
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
_listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int count = 0;<br /><br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Player *p = parse-&gt;item;<br /><br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (p-&gt;ship != SHIP_Spectator)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ++count;<br /><br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ((count &gt; 24) &amp;&amp; (freqchange != 4))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; sendPublic(&quot;?set team:maxperteam:4&quot;);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String s;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s = &quot;Max freq size 4&nbsp; (&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += count;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += &quot; pilots in game)&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sendPublic(s);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freqchange = 4;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if ((count &lt; 25) &amp;&amp; (count &gt; 14) &amp;&amp; (freqchange !=
 
3))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; sendPublic(&quot;?set team:maxperteam:3&quot;);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String s;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s = &quot;Max freq size 3&nbsp; (&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += count;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += &quot; pilots in game)&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sendPublic(s);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freqchange = 3;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><blockquote>countdown[0] = 120;<br />
 
}<br /></blockquote></blockquote>                                       
 
                                                                       
 
                                                    <a name="15c"></a>  c) Tracking kills and announcing when pilot gets 10 kills in a row without
 
dying                                                                 
 
                                                                       
 
                                                                       
 
                                                        <blockquote>case EVENT_PlayerDeath:&nbsp; {<br />
 
<blockquote>// assuming tags are setup (see storing data section)<br />
 
set_tag(p,KILLS, 0); &nbsp;// pilot died, reset to 0 kills in a row<br />
 
set_tag(k, KILLS, get_tag(k, KILLS) + 1); &nbsp;// pilot killed someone, increment kills in a row by 1<br /><br />
 
if (get_tag(k,KILLS) == 10) &nbsp;sendPublic(&quot;*arena (String) k-&gt;name + &quot; has gotten 10 kills.&quot;);</blockquote></blockquote>
 
                                                                       
 
                                                                       
 
                        <a name="15d"></a>
 
  
d) Warp pilot to coord when they are in a certain region<br />      
+
For example, in spawn.cpp, to check whether a player is in a safety zone:
                                                                       
+
<pre>
                                                                       
+
EVENT_PlayerMove:
                <blockquote>// using functions closeto() and abs()<br /><br />
+
{
bool closeto(Player *p, int x, int y, int tolerance) {<br />
+
  Player *p = (Player*)event.p[0];
  
&nbsp;&nbsp;&nbsp; return (abs((p-&gt;tile.x) - x) &lt; tolerance) &amp;&amp; (abs((p-&gt;tile.y) - y) &lt; tolerance); }<br /><br />
+
  if ( p->safety ) // player is in safe zone.
 +
    {
 +
        // do something.
 +
    }
  
inline int abs(int n) {<br />
+
  if ( !p->safety ) // player NOT in safe zone.
 +
    {
 +
        // do something.
 +
    }
 +
}
 +
</pre>
  
&nbsp;&nbsp;&nbsp; if (n &lt; 0)&nbsp;&nbsp;&nbsp; return -n;<br />
+
=== Obtaining a player pointer using name comparison ===
  
&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return n; }<br /><br />
+
Since Player pointers are internal to MERVBot, it is necessary to find a way of obtaining a Player pointer from the identifying information given by the game. One of the simpler ways is just to compare the names after converting to lowercase.
case EVENT_PlayerMove: &nbsp; &nbsp;{<br /><br />
 
if (closeto(p, 509, 509, 2)) { &nbsp;// if pilot within 2 of map coord 509,509<br />
 
&nbsp;&nbsp;&nbsp; sendPrivate(p, &quot;*warpto 509 504&quot;); &nbsp;// warp to coord 509,504<br /></blockquote>
 
                                                                       
 
                                                                       
 
                          <br />                                       
 
                                                                       
 
                                                          <a name="15e"></a>
 
  
e) Structures within structures (spawn.h botinfo)<br />             
+
''Note'': Using pilot names as vital comparisions should be used with caution. See [http://cypherjf.sscentral.com/articles/bots-as-clients/ Bot-Issues] by CypherJF.
                                                                       
 
                                                                       
 
          <blockquote>&nbsp;&nbsp;&nbsp; // Declare in spawn.h<br /><blockquote>&nbsp;&nbsp;&nbsp; struct playerstats<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
char name[20];<br /><br />
 
int kills;<br />
 
int deaths;<br />
 
Uint16 points;<br />
 
Uint16 flagpoints;<br />
 
int flagtime;<br />
 
int cflagtime;<br />
 
int flags;<br />
 
int flagkills;<br /><br />
 
int dmgdealt;<br />
 
int dmgtaken;<br /><br />
 
&nbsp;&nbsp;&nbsp; };<br /><br />
 
&nbsp;&nbsp;&nbsp; struct freqdata<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
playerstats pilots[100];<br /><br />
 
int freqpoints;<br />
 
char freqname[20];<br />
 
int freqflagpoints;<br />
 
Uint16 freqteam;<br />
 
int freqflagtime;<br /><br />
 
int flags;<br />
 
int kills;<br />
 
int deaths;<br />
 
int flagkills;<br /><br />
 
int dmgdealt;<br />
 
int dmgtaken;<br /><br />
 
int playercount;<br />
 
&nbsp;&nbsp;&nbsp; };<br /><br />
 
&nbsp;&nbsp;&nbsp; freqdata freqs[100];<br /></blockquote>
 
// Initialize in spawn.cpp<br /><blockquote>void botInfo::Clear()<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // initialize/clear struct data<br />
 
&nbsp;&nbsp;&nbsp; for (int n=99; n&gt;=0; n--)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
freqs[n].freqteam=-1;<br />
 
freqs[n].freqpoints=0;<br />
 
freqs[n].freqflagpoints=0;<br />
 
freqs[n].playercount=0;<br />
 
freqs[n].flags=0;<br />
 
freqs[n].kills=0;<br />
 
freqs[n].deaths=0;<br />
 
freqs[n].freqflagtime=0;<br />
 
freqs[n].flagkills=0;<br />
 
freqs[n].dmgdealt=0;<br />
 
freqs[n].dmgtaken=0;<br />
 
<br />
 
for (int m = 99; m&gt;=0; m--)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].deaths=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].kills=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].points=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].flagpoints=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].flagtime=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].cflagtime=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].flags=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].flagkills=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].dmgdealt=0;<br />
 
&nbsp;&nbsp;&nbsp; freqs[n].pilots[m].dmgtaken=0;<br />
 
}<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
}<br /></blockquote></blockquote>&nbsp;<blockquote>// Access data in spawn.cpp<br />
 
<blockquote>int freq = p-&gt;team;<br /><br />
 
freqs[1].pilots[2].kills++;<br /><br />
 
OR<br /><br />
 
freqs[freq].deaths++;<br /></blockquote></blockquote>                   
 
                                                                       
 
                                                                       
 
                <a name="15f"></a>
 
  
f) Tracking flag data<br />                                          
+
<pre>
                                                                       
+
// return Player* info (or NULL if not found) from p->name info
<blockquote>Example GetPilot() function &nbsp;(using structs from example e)<br /><blockquote>bool botInfo::GetPilot(Player *p)<br />
+
Player * botInfo::GetPilot(char *name)
{<br />
+
{
&nbsp;&nbsp;&nbsp; // get a pilots freq/pilot id from struct<br />
+
// get pilot from a name, return as TempPlayer
&nbsp;&nbsp;&nbsp; for (freq=freqcount-1; freq&gt;=0; freq--)<br />
+
_listnode <Player> *parse = playerlist->head;
if (p-&gt;team == freqs[freq].freqteam)<br />
 
&nbsp;&nbsp;&nbsp; for (pilot = freqs[freq].playercount-1; pilot&gt;=0; pilot--)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if (strcmp(p-&gt;name,freqs[freq].pilots[pilot].name)==0)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;<br /><br />
 
&nbsp;&nbsp;&nbsp; return false;<br />
 
}<br />
 
</blockquote></blockquote>
 
&nbsp;
 
<blockquote>Example way to track flag data using above struct/functions<br /><blockquote>
 
case EVENT_FlagGrab:<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; if (GetPilot(p)) &nbsp;// function<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freqs[freq].pilots[pilot].flags++;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freqs[freq].flags++;<br /><br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if (freqs[freq].pilots[pilot].flags &lt; 2) // didnt have a flag before,
 
first flag<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; freqs[freq].pilots[pilot].cflagtime = GetTickCount();
 
&nbsp;// time stamp when picked up flag<br />
 
&nbsp;&nbsp;&nbsp; }<br /></blockquote></blockquote>
 
&nbsp;<blockquote>Example way to track flag data using built in get/set tag (from catid flagbot)<br />
 
                                                                       
 
                                                                       
 
                                              <blockquote>
 
case EVENT_FlagGrab:<br />
 
  
 +
//convert search name to lowercase
 +
char nname[20], pname[20];
 +
strncpy(nname, name, 20);
 +
tolower(nname);
  
{<br />
+
while (parse)
 +
{
 +
Player *p = parse->item;
  
 +
// convert to lowercase to compare
 +
strncpy(pname,p->name,20);
 +
tolower(pname);
 +
if (strcmp(pname,nname)==0)
 +
return p;
 +
 +
parse = parse->next;
 +
}
  
&nbsp;&nbsp;&nbsp; set_tag(p, TAG_STAT_FS, get_tag(p, TAG_STAT_FS) + 1);<br />
+
return NULL; //player not found
 +
}
 +
</pre>
  
 +
==Bot built in functions==
  
&nbsp;&nbsp;&nbsp; set_tag(p, TAG_FLAGTIMER, GetTickCount());<br />
+
Here are some useful MervBot commands to control what the bot is doing.
 
 
 
 
}<br />                           
 
                                                                       
 
                                                                       
 
                    </blockquote>&nbsp;</blockquote>&nbsp;<blockquote>Get current flag times using struct format<br />
 
                                                                       
 
                                                                       
 
                                                  <blockquote>void botInfo::SetFlagTimes()<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // set current flagtime for pilots/freqs<br />
 
&nbsp;&nbsp;&nbsp; _listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
&nbsp;&nbsp;&nbsp; <br />
 
&nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
Player *p = parse-&gt;item;<br /> 
 
                                                                       
 
                                                                       
 
                                                  <br />
 
if (GetPilot(p))<br />
 
&nbsp;&nbsp;&nbsp; if (freqs[freq].pilots[pilot].flags &gt; 0)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (PilotOnSquad(p))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; freqs[freq].freqflagtime += (GetTickCount() - freqs[freq].pilots[pilot].cflagtime)/1000;<br />
 
                                                                       
 
                                                                       
 
                                                    <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
freqs[freq].pilots[pilot].flagtime += (GetTickCount() - freqs[freq].pilots[pilot].cflagtime)/1000;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
freqs[freq].pilots[pilot].cflagtime = GetTickCount();<br />
 
&nbsp;&nbsp;&nbsp; }<br />       
 
                                                                       
 
                                                                       
 
                                          <br />
 
parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
}<br />                                                                 
 
                                                                       
 
                                                          </blockquote>
 
// side note: &nbsp;case EVENT_FlagDrop: {} gets called anytime theres a teamkill<br />
 
                                                                       
 
                                                                       
 
                                                  </blockquote>       
 
                                                                       
 
                                                                       
 
                                          <br />                         
 
                                                                       
 
                                                                       
 
                        <a name="15g"></a>
 
g) Example way to do simple /!spam feature (allowed 1x/60s)<br />   
 
                                                                       
 
                                                                       
 
                                            <blockquote>declare and initialize variables in spawn.h<br />
 
                                                                       
 
                                                                       
 
                                                    <blockquote>class botInfo<br />
 
{<br />
 
bool spamready;<br />
 
int SPAM_TIME;<br />                                                   
 
                                                                       
 
                                                                       
 
<br />
 
public:<br />
 
&nbsp;&nbsp;&nbsp; botInfo(CALL_HANDLE given)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; spamready = true;<br />
 
&nbsp;&nbsp;&nbsp; SPAM_TIME = 60;<br />                               
 
                                                                       
 
                                                                       
 
                    </blockquote>
 
spawn.cpp - mark as spamready=true when 60 seconds up<br />         
 
                                                                       
 
                                                                       
 
                                          <blockquote>case EVENT_Tick:<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; if (countdown[0] == 1) &nbsp;{<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; spamready = true; &nbsp;// ready to spam again<br />
 
&nbsp;&nbsp;&nbsp; }<br />       
 
                                                                       
 
                                                                       
 
                                              </blockquote>           
 
                                                                       
 
                                                                       
 
                                            <br />
 
command.cpp - handle !spam command<br />                             
 
                                                                       
 
                                                                       
 
                          <blockquote>case OP_Player:<br />
 
{&nbsp;&nbsp;&nbsp; // Player-level commands<br />                     
 
                                                                       
 
                                                                       
 
                                  <br />
 
else if (c-&gt;check(&quot;spam&quot;))<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
// zone announcement &quot;Need pilots to duel in ?go arena -pilotname&quot;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (spamready == true)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String s;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; s += &quot;*zone Need pilots to duel in ?go &quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += arena;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += &quot; - &quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += p-&gt;name;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sendPublic(s);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; spamready=false;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; countdown[0] = SPAM_TIME * 60; // next spam time limit<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if (countdown[0] &lt; 0)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; sendPrivate(p,&quot;Spam ability disabled.&quot;);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String s;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += SPAM_TIME;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; s += &quot; Minute timer between announcements. &quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += countdown[0] / 60;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += &quot;:&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (countdown[0] % 60 &lt; 10)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += &quot;0&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s += countdown[0] % 60;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; s += &quot; minutes left before next spam allowed.&quot;;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sendPrivate(p, s);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; }<br />       
 
                                                                       
 
                                                                       
 
                                                </blockquote>&nbsp;</blockquote>         
 
                                                                       
 
                                                                       
 
                                              <a name="15h"></a>
 
h) Example of implementing a simple stack to do &quot;next in line for several 'boxes' at once&quot;<br />
 
                                                                       
 
                                                                       
 
                                                          <blockquote>//spawn.h declare variables<br />
 
                                                                       
 
                                                                       
 
                                                            <blockquote>class botInfo<br />
 
{<br />
 
Player *next[99][99];<br />
 
int MAX_NEXT;<br />
 
int nextcount[99];<br />                                               
 
                                                                       
 
                                                                       
 
            <br />
 
public:<br />
 
&nbsp;&nbsp;&nbsp; botInfo(CALL_HANDLE given)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; MAX_NEXT = 8; <br />                                 
 
                                                                       
 
                                                                       
 
                            </blockquote>
 
// spawn.cpp MoveUp function<br />                                     
 
                                                                       
 
                                                                       
 
                      <blockquote>void botInfo::MoveUp(int pos, int box)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // moves up the next line for that box and decrement box's nextcount<br />
 
&nbsp;&nbsp;&nbsp; if (nextcount[box] &gt; 0)<br />
 
nextcount[box]--;<br />           
 
                                                                       
 
                                                                       
 
                                                    <br />
 
&nbsp;&nbsp;&nbsp; for (pos = pos; pos &lt; MAX_NEXT - 1; pos++)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
next[box][pos] = next[box][pos + 1];<br />
 
&nbsp;&nbsp;&nbsp; }<br />                                             
 
                                                                       
 
                                                                       
 
                <br />
 
&nbsp;&nbsp;&nbsp; next[box][MAX_NEXT] = 0;<br />
 
}<br />                                                                 
 
                                                                       
 
</blockquote>
 
&nbsp;</blockquote>
 
                                                                       
 
                                                                       
 
                                                                <a name="15i"></a>
 
i) Example of reading any text from a .txt and printing it to pilot line by line<br />
 
                                                                       
 
                                                                       
 
                                                                <blockquote>#include &lt;fstream&gt;<br />
 
using namespace std;<br />                                             
 
                                                                       
 
                                                                       
 
                  <br />
 
case OP_Player:<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; if (c-&gt;check(&quot;schedule&quot;))<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // read in schedule from schedule.txt<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifstream file(&quot;schedule.txt&quot;);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char line[256];<br />
 
                                                                       
 
                                                                       
 
                                                                  <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (file.getline(line, 256))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sendPrivate(p, line);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; file.close();<br />
 
&nbsp;&nbsp;&nbsp; } <br />       
 
                                                                       
 
                                                                       
 
                                                          </blockquote>
 
                                                                       
 
                                                                       
 
                                                                <a name="15j"></a>
 
j) Example of printing player stats grid<br />                       
 
                                                                       
 
                                                                       
 
<blockquote>// spawn.cpp &nbsp; (see &quot;structures within structures&quot; example for variable declarations, varibale freqcount = # of freqs)<br />
 
                                                                       
 
                                                                       
 
                                                                    <br />
 
void botInfo::DisplayPlayers()<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // Display Match player/freq stats in this format &nbsp;(not aligned b/c of html but aligned in bot)<br />
 
&nbsp;&nbsp;&nbsp; // ---------------------------------------------------<br />
 
&nbsp;&nbsp;&nbsp; // Squad: squad_name_1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
K&nbsp; D TK DMG DEALT TAKEN<br />
 
&nbsp;&nbsp;&nbsp; // ---------------------------------------------------<br />
 
            &nbsp;&nbsp;&nbsp; // Player_1 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br /> &nbsp;&nbsp;&nbsp; // Player_2 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br /> &nbsp;&nbsp;&nbsp; // TOTAL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br />
 
&nbsp;&nbsp;&nbsp; // ---------------------------------------------------<br />
 
&nbsp;&nbsp;&nbsp; // Squad: squad_name_2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
K&nbsp; D TK DMG DEALT TAKEN<br />
 
 
 
&nbsp;&nbsp;&nbsp; // ---------------------------------------------------<br />
 
              &nbsp;&nbsp;&nbsp; // Player_3 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br /> &nbsp;&nbsp;&nbsp; // Player_4 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br /> &nbsp;&nbsp;&nbsp; // Player_5 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br />  &nbsp;&nbsp;&nbsp; // TOTAL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      0&nbsp; 0&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;
 
      0<br />
 
&nbsp;&nbsp;&nbsp; // ---------------------------------------------------<br />
 
                                                                       
 
                                                                       
 
                                                                    <br />
 
&nbsp;&nbsp;&nbsp; for (freq=freqcount-1; freq&gt;=0; freq--)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
char str[255];<br />             
 
                                                                       
 
                                                                       
 
                                                    <br />
 
sendFreqs(&quot;---------------------------------------------------&quot;);<br />
 
                                                                       
 
                                                                       
 
                                                                    <br />
 
sprintf(str, &quot;Squad: %-20s K&nbsp; D TK DMG DEALT TAKEN&quot;, freqs[freq].freqname);<br />
 
sendFreqs(str);<br />             
 
                                                                       
 
                                                                       
 
                                                      <br />
 
sendFreqs(&quot;---------------------------------------------------&quot;);<br />
 
                                                                       
 
                                                                       
 
                                                                    <br />
 
for (pilot=freqs[freq].playercount-1; pilot &gt;= 0; pilot--)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; sprintf(str, &quot;%-20s
 
%8d %2d %2d %9d %5d&quot;, freqs[freq].pilots[pilot].name, freqs[freq].pilots[pilot].kills,<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; freqs[freq].pilots[pilot].deaths, freqs[freq].pilots[pilot].teamkills,
 
freqs[freq].pilots[pilot].dmgdealt,<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; freqs[freq].pilots[pilot].dmgtaken);<br />
 
&nbsp;&nbsp;&nbsp; sendFreqs(str);<br />
 
}<br />                           
 
                                                                       
 
                                                                       
 
                                        <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
      sprintf(str, &quot;TOTAL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
      %2d %2d %2d %9d %5d&quot;, freqs[freq].kills, freqs[freq].deaths, <br />
 
&nbsp;&nbsp;&nbsp; freqs[freq].teamkills, freqs[freq].dmgdealt, freqs[freq].dmgtaken);<br />
 
sendFreqs(str);<br />
 
&nbsp;&nbsp;&nbsp; }<br />                                             
 
                                                                       
 
                                                                       
 
                    <br />
 
&nbsp;&nbsp;&nbsp; sendFreqs(&quot;---------------------------------------------------&quot;);<br />
 
}<br />                                                                 
 
                                                                       
 
                                                                       
 
  </blockquote>                                                       
 
                                                                       
 
                                                                       
 
          <a name="15k"></a> k) Example of checking if any pilots are
 
within a region                                                       
 
                                                                       
 
                                                                       
 
          <blockquote>// see GetPilotName(name) function in other example, returns *player as TempPlayer from name<br />
 
// closeto() function from several previous examples<br />             
 
                                                                       
 
                                                                       
 
                                                      <br />
 
bool botInfo::FreqAInBox()<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // return true if teamA has a pilot in the box, otherwise false<br />
 
&nbsp;&nbsp;&nbsp; for (int tempplayercount = freqs[0].playercount-1; tempplayercount &gt;= 0; tempplayercount--)<br />
 
if (GetPilotName(freqs[0].pilots[tempplayercount].name))<br />
 
&nbsp;&nbsp;&nbsp; if (closeto(TempPlayer,
 
coordX, coordY, 73) &amp;&amp; (TempPlayer-&gt;ship != SHIP_Spectator))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;<br />
 
                                                                       
 
                                                                       
 
<br />
 
&nbsp;&nbsp;&nbsp; return false;<br />
 
}<br />                                                                 
 
                                                                       
 
                                                                       
 
    </blockquote>                                                     
 
                                                                       
 
                                                                       
 
              <a name="15l"></a>
 
l) Example of functions to get a pilot's struct id info from a name or *player info<br />
 
                                                                       
 
                                                                       
 
<blockquote>// see struct examples for variable info<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
<br />
 
// return struct freq/pilot id from *player info<br />
 
bool botInfo::GetPilot(Player *p)<br />
 
 
 
{<br />
 
 
 
&nbsp;&nbsp;&nbsp; // return freq, pilot of a player p<br />
 
 
 
&nbsp;&nbsp;&nbsp; for (freq=freqcount-1; freq&gt;=0; freq--)<br />
 
 
 
if (p-&gt;team == freqs[freq].freqteam)<br />
 
 
 
&nbsp;&nbsp;&nbsp; for (pilot = freqs[freq].playercount-1; pilot&gt;=0; pilot--)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if (strcmp(p-&gt;name,freqs[freq].pilots[pilot].name)==0)<br />
 
 
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
<br />
 
 
 
&nbsp;&nbsp;&nbsp; return false;<br />
 
 
 
}<br />                                                                 
 
                                                                       
 
                                                                       
 
      <br />
 
// return *player as TempPlayer info from p-&gt;name info<br />bool botInfo::GetPilotName(char *name)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // get pilot from a name, return as TempPlayer<br />
 
&nbsp;&nbsp;&nbsp; _listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
          <br />
 
&nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
Player *p = parse-&gt;item;<br /> 
 
                                                                       
 
                                                                       
 
                                                                       
 
      <br />
 
// convert both to lowercase to compare<br />
 
char pname[20];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; <br />
 
strncpy(pname,p-&gt;name,20);<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
        <br />
 
char nname[20];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; <br />
 
strncpy(nname,name,20);<br />     
 
                                                                       
 
                                                                       
 
                                                                       
 
  <br />
 
tolower(pname);<br />
 
tolower(nname);<br />             
 
                                                                       
 
                                                                       
 
                                                                    <br />
 
if (strcmp(pname,nname)==0)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; TempPlayer = p;<br />
 
&nbsp;&nbsp;&nbsp; return true;<br />
 
}<br />                           
 
                                                                       
 
                                                                       
 
                                                      <br />
 
parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; return false;<br />
 
}<br />
 
<br />
 
// note: better to implement these functions as passing values by reference instead of using global variables<br />
 
// just easier to not have to be declaring different int freq, int pilot all the time<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
</blockquote>                                                         
 
                                                                       
 
                                                                       
 
            <a name="15m"></a>
 
m) Example of creating a logfile name using date and squad names<br />
 
                                                                       
 
                                                                       
 
<blockquote>&nbsp;&nbsp;&nbsp; // create log file name (squadA and squadB external char[20] variables)<br />
 
&nbsp;&nbsp;&nbsp; char u[100];<br />
 
&nbsp;&nbsp;&nbsp; time_t t=time(NULL);<br />
 
&nbsp;&nbsp;&nbsp; tm *tmp = localtime(&amp;t);<br />
 
&nbsp;&nbsp;&nbsp; strftime(u,99,&quot;%y&quot;,tmp);<br />
 
&nbsp;&nbsp;&nbsp; logname = &quot;c:\Program Files\Continuum\logs\&quot;;<br />
 
&nbsp;&nbsp;&nbsp; logname += u;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot;y&quot;;<br />
 
&nbsp;&nbsp;&nbsp; strftime(u,99,&quot;%m&quot;,tmp);<br />
 
&nbsp;&nbsp;&nbsp; logname += u;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot;m&quot;;<br />
 
&nbsp;&nbsp;&nbsp; strftime(u,99,&quot;%d&quot;,tmp);<br />
 
&nbsp;&nbsp;&nbsp; logname += u;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot;d&quot;;<br />
 
&nbsp;&nbsp;&nbsp; logname += squadA;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot; vs &quot;;<br />
 
&nbsp;&nbsp;&nbsp; logname += squadB;<br />
 
&nbsp;&nbsp;&nbsp; strftime(u,99,&quot;%I&quot;,tmp);<br />
 
&nbsp;&nbsp;&nbsp; logname += u;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot;h&quot;;<br />
 
&nbsp;&nbsp;&nbsp; strftime(u,99,&quot;%M&quot;,tmp);<br />
 
&nbsp;&nbsp;&nbsp; logname += u;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot;m&quot;;<br />
 
&nbsp;&nbsp;&nbsp; logname += &quot;.txt&quot;;<br />                             
 
                                                                       
 
                                                                       
 
                                            <br />
 
// example name created: &nbsp;03y01m27dBLACKDRaGON vs Integral05h08m.txt<br />
 
// format &nbsp;year, month, day, squadA vs squadB, hour, minute<br /> 
 
                                                                       
 
                                                                       
 
</blockquote>
 
                                                                       
 
                                                                       
 
                                                                       
 
  <a name="15n"></a>
 
n) Example of sending messages to playing freqs or public and logging depending on status<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
  <blockquote>// teamA, teamB, logname global variables<br />
 
void botInfo::sendFreqs(char *msg)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; char *mmsg = &quot;*arena&quot;;<br />
 
&nbsp;&nbsp;&nbsp; String s = msg;<br />
 
&nbsp;&nbsp;&nbsp; <br />
 
&nbsp;&nbsp;&nbsp; if (teammsgs == false)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
s.prepend(&quot;*arena &quot;,7);<br />
 
sendPublic(s);<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; else<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
sendTeamPrivate(8025,msg);<br />
 
sendTeamPrivate(teamA,msg);<br />
 
sendTeamPrivate(teamB,msg);<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; if (gameon == true)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
ofstream outf(logname, ios::app);<br />
 
outf &lt;&lt; msg &lt;&lt; endl;<br />
 
outf.close();<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
}<br />                                                                 
 
                                                                       
 
                                                                       
 
          </blockquote>                                               
 
                                                                       
 
                                                                       
 
                          <a name="15o"></a>
 
o) Example of reading in all player/freqs to struct data<br />       
 
                                                                       
 
                                                                       
 
                                                                    <blockquote>// see structures within structures example for freqs[] declaration<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
      <br />
 
// to get freqs in a game where there are several freqs<br />
 
void botInfo::GetFreqs()<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // read pilots into freq struct data from ingame and on playing freqs<br />                     
 
                                                                       
 
                                                                       
 
                                                        <br />
 
&nbsp;&nbsp;&nbsp; _listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
&nbsp;&nbsp;&nbsp; <br />
 
&nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
Player *p = parse-&gt;item;<br /> 
 
                                                                       
 
                                                                       
 
                                                                       
 
  <br />
 
if (p-&gt;ship != SHIP_Spectator)<br />
 
&nbsp;&nbsp;&nbsp; if (closeto(p, coordX, coordY, 73))<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // look for freq in struct<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bool foundfreq=false;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
      <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freq=freqcount-1;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
      <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while ((freq&gt;=0) &amp;&amp; (foundfreq==false))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; if (p-&gt;team == freqs[freq].freqteam)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
foundfreq=true;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
strncpy(freqs[freq].pilots[freqs[freq].playercount].name,
 
p-&gt;name, 20);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
freqs[freq].playercount++;&nbsp;&nbsp;&nbsp;
 
<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freq--;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
      <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // didnt find freq in struct so add new freq<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (foundfreq == false)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (manualsquads == false)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
strncpy(freqs[freqcount].freqname,
 
p-&gt;squad, 20);<br />                                                 
 
                                                                       
 
                                                                       
 
                            <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if (freqcount == 0)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; teamA = p-&gt;team;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; strncpy(squadA,
 
p-&gt;squad, 20);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; teamB = p-&gt;team;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; strncpy(squadB,
 
p-&gt;squad, 20);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if (p-&gt;team == teamA)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; strncpy(freqs[freqcount].freqname,squadA,20);<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
      <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
else if (p-&gt;team == teamB)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; strncpy(freqs[freqcount].freqname,squadB,20);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; freqs[freqcount].freqteam = p-&gt;team;<br />       
 
                                                                       
 
                                                                       
 
                                                                    <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; strncpy(freqs[freqcount].pilots[0].name, p-&gt;name, 20);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
                                                                       
 
                                                                       
 
                                                                       
 
    <br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freqs[freqcount].playercount++;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freqcount++;<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
}<br />                                                                 
 
                                                                       
 
                                                                       
 
                                                    <br />
 
// to get freqs in a game where there are only two teams<br />
 
void botInfo::GetFreqs()<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // read pilots into freq struct data from ingame and on playing freqs<br />
 
&nbsp;&nbsp;&nbsp; _listnode &lt;Player&gt; *parse = playerlist-&gt;head;<br />
 
&nbsp;&nbsp;&nbsp; <br />
 
&nbsp;&nbsp;&nbsp; while (parse)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
Player *p = parse-&gt;item;<br /> 
 
                                                                       
 
                                                                       
 
                                                                       
 
                                          <br />
 
if ((p-&gt;ship != SHIP_Spectator)
 
&amp;&amp; ((p-&gt;team == teamA) || (p-&gt;team == teamB)))<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; // freq 100, team A<br />
 
&nbsp;&nbsp;&nbsp; // set freq<br />
 
&nbsp;&nbsp;&nbsp; freq = 0;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
                                            <br />
 
&nbsp;&nbsp;&nbsp; if (p-&gt;team == teamB)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; freq = 1;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; // number of pilots on freq counted so far, starts 0<br />
 
&nbsp;&nbsp;&nbsp; pilot = freqs[freq].playercount;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; // pilot name<br />
 
&nbsp;&nbsp;&nbsp; strncpy(freqs[freq].pilots[pilot].name, p-&gt;name, 20);<br />
 
&nbsp;&nbsp;&nbsp; // time stamp for playing time<br />
 
&nbsp;&nbsp;&nbsp; freqs[freq].pilots[pilot].cplaying_time = GetTickCount();<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; // slot name<br />
 
&nbsp;&nbsp;&nbsp; if (freqs[freq].playercount &lt; NUMBER_PILOTS)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
strncpy(freqs[freq].slotname[pilot], p-&gt;name, 20);<br />
 
<br />
 
&nbsp;&nbsp;&nbsp; // increment freq player count<br />
 
&nbsp;&nbsp;&nbsp; freqs[freq].playercount++;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
                                              <br />
 
&nbsp;&nbsp;&nbsp; // if freq not already have name, give it player squad name<br />
 
&nbsp;&nbsp;&nbsp; if ((manualsquads == false) &amp;&amp; (strlen(p-&gt;squad) &gt; 0))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strncpy(freqs[freq].freqname, p-&gt;squad, 20);<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
                                              <br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // set player ship<br />
 
&nbsp;&nbsp;&nbsp; freqs[freq].pilots[pilot].ship = p-&gt;ship + 1;<br />
 
}<br />
 
parse = parse-&gt;next;<br />
 
&nbsp;&nbsp;&nbsp; }<br />
 
}<br />                                                       
 
                                                                       
 
                                                                       
 
                      </blockquote>                                   
 
                                                                       
 
                                                                       
 
                                        <a name="15p"></a>
 
p) Example of finding MVP from struct data (2*kills - deaths formula)<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
      <blockquote>&nbsp;&nbsp;&nbsp; int highest=-20;<br />
 
&nbsp;&nbsp;&nbsp; int mvp=0;<br />                                     
 
                                                                       
 
                                                                       
 
                                          <br />
 
&nbsp;&nbsp;&nbsp; for (pilot = freqs[mvpteam].playercount-1; pilot &gt;=0; pilot--)<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
if (((freqs[mvpteam].pilots[pilot].kills
 
* 2) - freqs[mvpteam].pilots[pilot].deaths) &gt; highest)<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; mvp = pilot;<br />
 
&nbsp;&nbsp;&nbsp; highest = (freqs[mvpteam].pilots[pilot].kills
 
* 2) - freqs[mvpteam].pilots[pilot].deaths;<br />
 
}<br />
 
&nbsp;&nbsp;&nbsp; }<br />                                             
 
                                                                       
 
                                                                       
 
                                </blockquote>                         
 
                                                                       
 
                                                                       
 
                                                      <a name="15q"></a>
 
q) Print time stamp of event<br />                                   
 
                                                                       
 
                                                                       
 
                                            <blockquote>#include &quot;time.h&quot;<br />
 
                                                                       
 
                                                                       
 
                                                                       
 
          <br />
 
char u[100];<br />
 
time_t t=time(NULL);<br />
 
tm *tmp = localtime(&amp;t);<br />
 
strftime(u,99,&quot;%c&quot;,tmp);<br />
 
sendPublic(&quot;Current date and time: &quot; + (String) u);<br />                                                   
 
                                                                       
 
                                                                       
 
                            </blockquote>                             
 
                                                                       
 
                                                                       
 
                                                    <a name="15r"></a>
 
r) Simple way to track player bomb/bullet damage stats<br />         
 
                                                                       
 
                                                                       
 
  <blockquote>// spawn.cpp (see data section for how to setup set_tag)<br />
 
// see clientprot.h for weapon information<br />
 
<br />
 
case EVENT_WatchDamage:<br />
 
{<br />
 
&nbsp;&nbsp;&nbsp; if (PLAYING) &nbsp;// if tracking stats<br />
 
&nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
if ((wi.type == PROJ_PBomb) &amp;&amp; (p-&gt;name != k-&gt;name))<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(k, DMG_BOMB_DEALT, get_tag(k, DMG_BOMB_DEALT)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(k, DMG_TOTAL_DEALT, get_tag(k, DMG_TOTAL_DEALT)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(p, DMG_BOMB_TAKEN, get_tag(p, DMG_BOMB_TAKEN)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(p, DMG_TOTAL_TAKEN, get_tag(p, DMG_TOTAL_TAKEN)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if (wi.type == PROJ_BBullet)<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(k, DMG_BULLET_DEALT, get_tag(k, DMG_BULLET_DEALT)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(k, DMG_TOTAL_DEALT, get_tag(k, DMG_TOTAL_DEALT)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(p, DMG_BULLET_TAKEN, get_tag(k, DMG_BULLET_TAKEN)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp; set_tag(p, DMG_TOTAL_TAKEN, get_tag(k, DMG_TOTAL_TAKEN)
 
+ damage);<br />
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
 
&nbsp;&nbsp;&nbsp; }<br />       
 
                                                                       
 
                                                                       
 
                                                                       
 
  </blockquote>                                                       
 
                                                                       
 
                                                                       
 
                          <a name="15s"></a>
 
s) Simple way to print those stats<br />
 
                                                                       
 
 
 
<blockquote>
 
<pre>
 
case OP_Moderator:
 
{
 
if (c-&gt;check(&quot;showstats&quot;))
 
{
 
&nbsp;&nbsp;&nbsp; sendPublic(&quot;Showing stats:&quot;);
 
                                   
 
             
 
&nbsp;&nbsp;&nbsp; _listnode &lt;Player&gt; *parse = playerlist-&gt;head;           
 
 
 
  
&nbsp;&nbsp;&nbsp; while (parse)  
+
Player.cpp:
&nbsp;&nbsp;&nbsp; {
+
* Player::move(Sint32 x, Sint32 y) moves a player to the coordinates specified by x and y
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Player *p = parse-&gt;item;
+
* Player::clone(Player *p) clones a player into a player class
  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (get_tag(p, DMG_TOTAL_DEALT) &gt; 0)
+
Look in Commands.txt , command.cpp (core), or /!help to bot to see all bot external commands (example /!go &lt;arena&gt;).
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
 
char str[256];
 
&nbsp;&nbsp;&nbsp; sprintf(str, &quot;(%-20s Dmg Dealt: Total %0004d, Bomb %0004d, Bullet %0004d&nbsp; Dmg TAKEN: Total %0004d, Bomb %0004d, Bullet %0004d)&quot;,
 
p-&gt;name, get_tag(p,DMG_TOTAL_DEALT), get_tag(p,DMG_BOMB_DEALT), get_tag(p,DMG_BULLET_DEALT),
 
get_tag(p,DMG_TOTAL_TAKEN), get_tag(p,DMG_BOMB_TAKEN), get_tag(p,DMG_BULLET_TAKEN));
 
sendPublic(str);
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parse = parse-&gt;next;
 
&nbsp;&nbsp;&nbsp; }
 
}
 
</pre>
 
    </blockquote><a name="15t"></a>
 
t) Make bot spectate specific coordinates<br />
 
  
<blockquote>
+
''LVZ Object toggling commands in plugins are to go here.''
<pre style="font-size: 11px">
 
// make bot spectate the coord 512,600
 
// possible use - capturing weapon packets in a specific region
 
  
tell(makeFollowing(false));
+
[[Category:Guides]]
tell(makeFlying(true));
 
me-&gt;move(512 * 16, 600 * 16);
 
tell(makeSendPosition(true));
 
</pre>
 
</blockquote>
 
</blockquote></blockquote>
 

Latest revision as of 04:38, 3 August 2009

This tutorial is based on the ever-popular MERVBot Tutorial by Underlord. It has since been updated to reflect new changes with MervBot. To see examples of how to use this instruction, see MERVBot Example Code.

This tutorial also assumes that you have a basic knowledge of C++. If you don't, check out cplusplus.com's great documentation.

Setting up a MERVBot (plugin)

MERVBot download site


Obtaining MERVBot

  • Download the latest build.
  • Unrar MERVBot.rar into a new folder. (example c:\program files\continuum\mervbot)
  • Unzip src.zip into "src" subfolder of that new folder (example c:\program files\continuum\mervbot\src)

Preparing to write a plugin

Note: if you only want to execute someone's premade plugin (.dll), skip to step 4, otherwise continue to learn how to make your own bot

Download DLL-plugin Tutorial and unzip Tutorial.zip (containing spawn.h, spawn.cpp, and command.cpp) into a "tutorial" subfolder of that new folder. (example c:\program files\continuum\mervbot\src\tutorial).

File descriptions:

  • spawn.h = declare/initialize globals
  • command.cpp = code for commands coming into bot (ie /!help, /!play, etc)
  • spawn.cpp = code that interacts with bot spawns

Microsoft Visual c++

  1. Start Visual Studios 6.0.
  2. Click the Drop Down Menu labeled "File" at the top left of your screen.
  3. Click "New".
  4. On the next screen that comes up, choose from the Project tab, then Win32 Dynamic-Link Library
  5. Select the "/src" folder as the base folder (example c:\program files\continuum\mervbot\src)
  6. Name your project "mybot". This will make a "mybot" subfolder in your "src" folder. Click OK. (example creates c:\program files\continuum\mervbot\src\mybot)
  7. Choose to create an "Empty DLL project".
  8. Click "Finish".
  9. Click the Drop Down Menu labbled "Project".
  10. Click "Add To Project Files"
  11. Copy only spawn.h, spawn.cpp, and command.cpp from the "tutorial" folder into the this new folder. (example from c:\program files\continuum\mervbot\src\tutorial to c:\program files\continuum\mervbot\src\mybot)
  12. Click the Drop Down Menu labelled "Build".
  13. Click "Build (dll name)" - where (dll name) is "mybot"
  14. Go into your "mybot" folder and look for a folder named "Debug" (example c:\program files\continuum\mervbot\src\mybot\debug)
  15. Your new DLL will be in that folder. (example mybot.dll)
  16. Copy mybot.dll to your base folder that has mervbot.exe in it (example c:\program files\continuum\mervbot)


Run your bot dll

To run your bot you need your DLL (mybot.dll), Commands.txt, MERVBot.exe, MERVBot.ini, Operators.txt, Spawns.txt, and zlib.dll all in one folder (example c:\program files\continuum\mervbot).

  1. Edit spawns.txt. Read every word of spawns.txt to find out what needs to go in there.
    Example:
    2v2-Bot-League : botpw : 2v2a : 2v2league : staffpw

    Note: The bot will attempt to create the name if it doesn't exist already.


  2. Edit MERVBot.ini

    [Login]
    Zone=216.33.98.254:21000	// your zone IP:PORT available from zone.dat in Continuum dir
    


  3. Edit operators.txt. Read every word of operators.txt to find out what needs to go in there.
    Example:
    4:my_name:
    4:another_sysop:
    3:other_person:
    


  4. Make sure the bot is on vip.txt or has smod+ access, then run MERVBot.exe.
  5. You can now edit your plugin code by opening "mybot.dsw" (example c:\program files\continuum\mervbot\src\mybot\mybot.dsw) in Microsoft Visual C++. Edit the spawn.h, spawn.cpp, and command.cpp to create your plugin, then build, copy your updated DLL to your MERVBot.exe folder and then execute the bot. Use the tutorial to get ideas on how to implement certain types of features into the bot.

Player Commands - (command.cpp)

This section describes how to implement player commands into your plugin. Commands are sent to the botInfo::gotCommand function in command.cpp.

Example (makes bot reply to !test with "hi"):

void botInfo::gotCommand(Player *p, Command *c) {
	switch (p->access)
	{
        case OP_Moderator:
                {
                     // handle moderator-operator commands here.
                }
	case OP_Player: //appropriate staff rank here.
		{
			if (c->check("test")) //replace "test" with whatever command you want
			{
				//put your command code here
				sendPrivate(p,"hi"); //example
			}
		}

How to have commands with numerical parameters

Example (!test #):

	if (c->check("test")) { // reads in test #, default to 1 if invalid number input
		int temp = 1;

		if (isNumeric(c->final))
			temp = atoi(c->final);

How to have player name as input

Example (!rank player):

	if (c->check("rank"))
	{
		String player_name = c->final;

		if (player_name.IsEmpty()) // default name to self if invalid name
			player_name = p->name;

How to have multi-parameter input

Use the CRT function sscanf() to scan the string for the values.

Example (!squads squadA vs squadB or !squads teamA:squadA:teamB:squadB):

else if (c->check("squads"))
{
	char squadA[20], squadB[20];
	int teamA, teamB;

	strncpy(squadA, "", 20);
	strncpy(squadB, "", 20);

	int n_found;

	//Note: %[A-Za-z ] is equivalent to %s, but allows an internal space.

	//scan the string for the two squads separated by " vs "
	n_found = sscanf(c->final, "%[A-Za-z ] vs %[A-Za-z ]", squadA, squadB);

	//if that fails, scan the string for freqA:squadA:freqB:squadB
	if (n_found < 2)
		sscanf(c->final, "%d:%[A-Za-z ]:%d:%[A-Za-z ]", &teamA, squadA, &teamB, squadB);
}

Help Menu

When a player sends !help to the bot, MERVBot calls botInfo::gotHelp() in each plugin loaded.

void botInfo::gotHelp(Player *p, Command *c)
{
	if (!*c->final)
	{
	sendPrivate(p, "4v4 Bot General Commands:");
	sendPrivate(p, "------------------------");
	sendPrivate(p, "!caps - get captain names");
	sendPrivate(p, "!roster <squad> - get roster of a squad");
	sendPrivate(p, "!schedule- get current schedule");
	sendPrivate(p, "!score - get current score");

Event Calls

MERVBot is event based, so when making a bot you need to decide what will happen at certain events. Normal plugins need to consider what happens when bot enters arena, player enters arena, player leaves arena, player events like kill, shipchange, teamchange, spec, move then any other relevant events to your bot. Just worry about events that are relevant to the tasks your bot is doing.

MERVBot sends events to botInfo::gotEvent() in spawn.cpp. Each supported event is already present and categorized in gotEvent(), along with the paramters that MERVBot sends with the event. When a plugin wants the bot to do something, it sends tell(event) to the bot.

See dllcore.h for a list of current events and their descriptions. Dllcore.h also contains functions (like makeFollowing) to make events to send back to the bot via tell().

tell(makeFollowing(false));

The Messaging System

Private message - void sendPrivate(Player *player, char *msg);

Examples:

sendPrivate(p,"hi");

String s="test";
sendPrivate(p,s);

String s="test";
s += "ing";
sendPrivate(p,s);

char captain1[20];
char captain2[20];
strncpy(captain1,"",20);
strncpy(captain2,"",20);
sendPrivate(p,(String) captain1 + " and " + (String) captain2 + " are the captains.");

Team message - void sendTeamPrivate(Uint16 team, char *msg);

Examples:

a) sendTeamPrivate(8025,"hi spec freq");
b) Uint16 test=0; sendTeamPrivate(test,"hi freq 0");

Public message - void sendPublic(char *msg);

Example: sendPublic("*arena " + (String) p->name + " is now a captain");

Chat channel message - void sendChannel(char *msg);

Example: sendChannel("hi chat channel");

Remote private message - void sendRemotePrivate(char *name, char *msg);

Example: sendRemotePrivate("Player01", "hi");

Note: to have bot print several lines of text fast it needs sysop in the arena (sysop in arena bot first spawns to also) otherwise it'll print slow to avoid being kicked for spam

Output of data in messages

An example of using normal strings to output data/messages.

 // does *arena X pilots left in game
 // NOTE: variable temp needs to be defined with some value

 String s = "*arena ";
       s += temp;
       s += " pilots left in the game.";

 sendPublic(s);

Or,

 //NOTE: this can be considered inefficient.

 sendPublic("*arena " + (String)temp + " pilots left in the game");

An example using sprintf to align/space data, where output data will be in this approximate format.

// output data will be in this approximate format (not lined up perfectly because of html)
// --------------------------------------------------------------------------------------
// Squad: squadname       PTS     FPTS    K    D  DMG DEALT TAKEN   F  FK    FLT
// --------------------------------------------------------------------------------------
// PlayerA              10000      500  116  101       9999 99999  10 150 980:55
// PlayerB                500      200    7    5       9999 99999   5   3   0:04

char str[255];
sendPublic("*arena--------------------------------------------------------------------------------");

sprintf(str, "*arena Squad: %-20s   PTS     FPTS   K   D  DMG DEALT  TAKEN  F  FK  FLT",
         freqs[freq].freqname
        );

sendPublic(str);

sendPublic("*arena--------------------------------------------------------------------------------");

            // assuming existing freqs struct with data
            for (pilot=freqs[freq].playercount-1; pilot>=0; pilot--)
            {
                // on freq squad so print stats
                char outString[255];

                sprintf(outString, "*arena %-20s %12d %8d %3d %3d %10d %6d %2d %3d %3d:%02d",
                       freqs[freq].pilots[pilot].name,
                       freqs[freq].pilots[pilot].points,
                       freqs[freq].pilots[pilot].flagpoints,
                       freqs[freq].pilots[pilot].kills,
                       freqs[freq].pilots[pilot].deaths,
                       freqs[freq].pilots[pilot].dmgdealt,
                       freqs[freq].pilots[pilot].dmgtaken,
                       freqs[freq].pilots[pilot].flags,
                       freqs[freq].pilots[pilot].flagkills,
                       freqs[freq].pilots[pilot].flagtime /60,
                       freqs[freq].pilots[pilot].flagtime %60
                       );
                
                sendPublic(outString);
            }

            // Notes: sprintf format = sprintf(output char string, spacing, variables)
            // Notes: s = chars, d = integer, - = left align, right align default
            // Notes: doing %02d = put 0 in front if not 2 digits, %3d:%02d makes 0:04 format

Time

Each time MERVBot sends an EVENT_Tick to a plugin (once a second), the default handler code decrements each value in an array of countdowns. You can modify the number of countdowns and add code to occur at a specific value for one of the countdowns.

Setup number of timers and initialize in spawn.h:

class botInfo
{
	#define COUNTDOWNS 10 		// how many countdowns you want
	int countdown[COUNTDOWNS];	// this gives you 10 timers

// unrelated code
 
	public:
	botInfo(CALL_HANDLE given)
	{
	countdown[0] = 0;
	countdown[1] = 60; // 60 seconds
	//
	// initialize values
	//
	countdown[9] = 5*60; // 5 minutes

Using timer functions in spawn.cpp:

case EVENT_Tick:
{
	for (int i = 0; i < COUNTDOWNS; ++i) //cycles through each countdown you have
		--countdown[i]; //note that countdowns will continue decrementing past 0.

	if (countdown[1] == 2) // when timer #1 hits two seconds
	{
	// do stuff here when timer #1 hits 2 seconds
	// example: sendPublic("two seconds left, setting timer to 1 minute");
	// example: countdown[1] = 60; // change timer #1 value
	}

You can then have events (such as EVENT_PlayerDeath) change the value of a countdown to make the bot do something a set time after an event occurs.

Tracking time not using countdown[n]

This is a solution to a common problem of determining the amount of time it takes for something to occur. Using basic math, we record a start-time B, and an end-time E, both in the unit of seconds, we calculate the time elapsed by E-B.

Lucky for us, Windows provides a function called GetTickCount() that is a measurement of time (milliseconds) that we can use for such cases.

So:

	int begin = GetTickCount();

	// do some code here.

	int end = GetTickCount();
  
	int delta = (end - begin) / 1000;  // elapsed time converted to seconds from milliseconds

Obtaining the current time

Requirements: Include <time.h>.

Use:

 char u[100];
 time_t t=time(NULL);
 tm *tmp = localtime(&t);
 strftime(u,99,"%c",tmp);
 sendPublic("Current date and time: " + u);

Writing Functions

For this example, we will take the function called closeto, which determines if a player exists in an specific radius around a point. Now to apply this function to a MervBot plugin, you need to write it into the spawn.cpp - at the top of the file in the //////// DLL "import" //////// setion, as below:

//////// DLL "import" ////////

bool closeto(Player *p, int x, int y, int tolerance) 
{
	// Requires the function abs() to be declared elsewhere.
	// Return if player p is in area of square with center x, y
	//   and radius = tolerance
	return (abs((p->tile.x) - x) - tolerance) && (abs((p->tile.y) - y) - tolerance);
}


If you want your function to have access to the data from spawn.h botInfo class, you make the function apart of it. To do this, we add the botInfo:: infront of the function name, in spawn.cpp.

//////// DLL "import" ////////

bool botInfo::closeto(Player *p, int x, int y, int tolerance) 
    {
	 ...
    }

In spawn.h, add your method's prototype without botInfo::, it will look like this:

//...
botInfo(CALL_HANDLE given)
 {
//  ...
 } 
  bool closeto(Player *p, int x, int y, int tolerance); // Your function prototype.

  void clear_objects(); //provided by Catid, and already exists.
  void object_target(Player *p); //provided by Catid, and already exists.
//  ...
};

If you're not familiar with prototypes, notice it is similar to that in your spawn.cpp, but without the botInfo::, and a trailing ;.

Function notes

Remember that you can pass variables by reference. If variables are passed by reference, any changes a function makes to the variables will remain after the function returns.

From time to time you will need to pass an array to a function. An example illustrating this is:

	int freqs[5]; // declare our example data.

	// call function - notice freqs and not freqs[5] or freqs[].
	my_function(freqs); //You're not passing the array itself, just a pointer to the array.

	// function - notice freqs[] and not freqs[5] or freqs
	void my_function(int freqs[]) {} //You're specifying that the freqs parameter is an array

Cycling through players

MERVBot stores player-related data in a linked list. A linked list is a datatype that stores its data in a series of structures linked to each other, hence the name.

To search through the players in the arena, just start at the first link, then continue through all the following links until you reach the end:

_listnode <Player> *parse = playerlist->head;	//set to first link of the player linked list

while (parse)	//parse will be NULL when we reach the last link
{
	Player *p = parse->item;	//item is the actual data stored in the link

	// do functionality here
	// Example 1: sendPrivate(p,"*watchdamage"); // turns on all pilot's watchdamage
	// Example 2: if (p->safety != 0) sendPrivate(p,"*spec"); // spec all pilots in safe zone

	parse = parse->next;	//set parse to the next link
}

For example, assuming our bot has smod+ privilages, the following code will set all non-spectator players to a specific ship. First begin by adding the following function prototype to the spawn.h in the botInfo class:

 void handleCmdSetShip(enum Ship_Types ship);

In spawn.cpp add:

void botInfo::handleCmdSetShip(enum Ship_Types ship)
{
	//Note that the parameter ship is of the Ship_Types enum,
	//so its value is hopefully restricted to the proper types.

	_listnode <Player> *parse = playerlist->head;
	while (parse)
	{
		Player *p = parse->item;

		if ( p->ship != ship && p->ship != SHIP_Spectator )
				sendPrivate(p, "*setship " + (String)ship);

		parse = parse->next;
	}
}

To use, just call the function with the appropriate Ship_Type from the enum in clientprot.h:

 handleCmdSetShip(SHIP_Warbird);

Random numbers

Generating a random number

To use this method, these two includes must be used:

#include "time.h"    //provides time() function.
#include "stdlib.h"  //provides srand() and rand() functions.

Use:

    srand(time(NULL)); // seed random number generator.

    rand(); // randomize.

    int temp = (int) (51 * ((float)rand()/RAND_MAX));
       // the above line returns a random integer between 0 and 51.
       // Note: RAND_MAX is a global constant defined in stdlib.h

Picking a random pilot

Note: A required user-defined function, getInGame(), must be created for this example to work.

int temp = GetTickCount() % getInGame();  // getInGame() = how many pilots in arena

Player *rabbit = NULL;

_listnode <Player> *parse = playerlist->head;
while (parse)
{
	Player *p = parse->item;

	if (p->ship != SHIP_Spectator) // if player is not a spectator
	if ( !(--temp) ) // and if we've hit the randomly-selected pilot
	{
		rabbit = p;
		break;
	}
	parse = parse->next;
}

Storing data for pilots

There are several ways to store data for pilots (ie tracking flagtime or kills in a period of time). Note that these methods are all purely internal to the bot, and don't effect anything beyond the plugin in any way.

  1. Built-in get/setTag: Tracks data until player leaves the arena, then automatically deletes data.
  2. Modified perm get/setTag: Tracks data until bot leaves arena, then automatically deletes data. (Advantage: easier to sort by player)
  3. Custom Structs: Tracks data until plugin deletes it. (Advantage: easier to sort by freqs)

Note: 2 and 3 are similar in effect, mostly the difference is in how you are able to search through data you need to decide which method of storing data is best for each bot depending on what it does.

Built-in get/setTag method

Player tags simply tag a player with a number. Define the wanted values in spawn.h at the top:

#define DMG_DEALT        0
#define DMG_TAKEN        1

In spawn.cpp, initialize the values on ArenaEnter and PlayerEnter:

case EVENT_ArenaEnter:
{
	// ...

	// do for all pilots in arena when bot enters
	_listnode <Player> *parse = playerlist->head;
	while (parse)
	{
	   Player *p = parse->item;  // get pilot

	   set_tag(p, DMG_DEALT, 0); // initialize to 0
	   set_tag(p, DMG_TAKEN, 0);
	   sendPrivate(p, "*watchdamage");  // optionally turn on player *watchdamage

	   parse = parse->next;  // get next pilot
	}
}
case EVENT_PlayerEntering:
{
//	...
	set_tag(p, DMG_DEALT, 0); // initialize to 0
	set_tag(p, DMG_TAKEN, 0);
	sendPrivate(p,"*watchdamage");
}

Then somewhere edit the tag values:

case EVENT_WatchDamage:
{
	// sets tag for k (shooter) to be old value plus damage currently dealt

	int old_damage = get_tag(k, DMG_BOMB_DEALT);
	set_tag(k, DMG_BOMB_DEALT, old_damage + damage);
}

The following demonstrates how to retrieve the tag values as a command in command.cpp:

if (c->check("showstats"))
{
	int temp = get_tag(p, DMG_TOTAL_DEALT);

	String s = "You've done ";
	s += temp;
	s += " damage so far!";

	sendPrivate(p,s);
 }

Modified permanent get/setTag method

This method is the same as get/setTag with some modifications to the tag code to retain them after the player leaves. Beware of using this method if bot is in an arena for long periods of time, linkedlist could get huge.


// spawn.h, add char name[20]; into struct PlayerTag

struct PlayerTag
{
	Player *p;
	char name[20];
	int index;
	int data;
};

In spawn.cpp:

	case EVENT_PlayerLeaving:
	{
	    Player *p = (Player*)event.p[0];

	    // killTags(p);  // remove so tag not deleted on arena exit

//	...

Locate in spawn.cpp and modify accordingly:

int botInfo::get_tag(Player *p, int index)
{
    _listnode <PlayerTag> *parse = taglist.head;
    PlayerTag *tag;

    while (parse)
    {
      tag = parse->item;

      // if (tag->p == p)
      if (strcmp(tag->name,p->name)==0)  // now tracking by player name, not pointer
      if (tag->index == index)
        return tag->data;

      parse = parse->next;
    }
    return 0;
}

void botInfo::set_tag(Player *p, int index, int data)
{
    _listnode <PlayerTag> *parse = taglist.head;
    PlayerTag *tag;

    while (parse)
    {
      tag = parse->item;

      //if (tag->p == p)
      if (strcmp(tag->name,p->name)==0) // now tracking by player name, not pointer
      if (tag->index == index)
      {
        tag->data = data;
        return;
      }
      parse = parse->next;
    }

    tag = new PlayerTag;
    // tag->p = p; // not tracking by pointer anymore
    strncpy(tag->name, p->name, 20); // tracking by player name
    tag->index = index;
    tag->data = data;
    taglist.append(tag);
}

Using structs

In spawn.h:

class botInfo
{
	struct freqdata 
	{
		int kills, deaths;
	};
// ...
};

To make use of this structure, implement accordingly:

	freqdata freqs[100]; // 100 of those structs

Access the data in spawn.cpp using

freqs[56].kills = 1;

See CPlusPlus.com's Structures tutorial for a more comprehensive guide. Note that, as shown on the bottom of the page, you can have structures within structures. Thus, for example, you could have a structure for each freq with a structure for each player nested within them.

Input/Output to files

For reading and/or writing to files with C++ you must have the required include statement as follows:

#include <fstream>
using namespace std;

File stream input

The following example will show you how to read a file, duel.ini, line by line.

#include "stdlib.h" // for atoi()
  ifstream file("duel.ini");

  if (!file.good()) // if there was an error opening the file
    sendPublic("*arena Error opening file for reading"); // or add your own error handler
  else
  {
    char line[256];

    // read in MaxBoxes=X
    while (file.getline(line, 256))
    {
     
      if (CMPSTART("MaxBoxes=", line)) //Does the line begin with MaxBoxes= ?
      {
        MAX_BOXES = atoi(&(line[9]));  //If so, read the value into an integer, using atoi.
        break;
      }
    }

    file.close();
  }

File stream output

The following code example will demonstrate how to append to a file, duelleaguestat.inc.

 ofstream file("duelleaguestat.inc", ios::app);   // app = put all data at end of file

 if (!file.good()) // if there was an error opening the file
   sendPublic("*arena Error opening file.");
 else
 {
   file << squad1<< endl;  // squad1 = char[20]
   file << " vs "<< endl;
   file << squad2<< endl;  // squad2 = char[20]
   file.close();
 }

Similarly, you are able to write an output of a String to a file:

 // key is converting String to (char*) to file write
 String str = freqs[freq].slotname[slot];
 str += ", Repels: " + (String)(int) t->repel;
 file << endl;
 file << (char*) str;

Input with GetPrivateProfileString

GetPrivateProfileString(), a function provided by Windows for reading INI files, will automatically find an INI key (like "MaxBoxes=") in a file for you. See the MSDN Library for help on this function. This next example will show how to read input using GetPrivateProfileString() based on the rampage plugin.

The file format for rampage.ini is like this:

 7=is on a killing spree! (6:0)
 10=is opening a can of booya! (9:0)

In rampageini.cpp:

#include "rampageini.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define NUM_RANKS 10
#define BUFFER_LEN 256

struct RampageSettings
{
	char quotes[NUM_RANKS][BUFFER_LEN];
};
 
void LoadSettings(RampageSettings &setts);

static char path[BUFFER_LEN];

char *rank_type[NUM_RANKS] = { "7", "10" };

void LoadSettings(RampageSettings &setts)
{
	GetCurrentDirectory(BUFFER_LEN - 64, path);
	strcat(path, "\rampage.ini");

	for (int i = 0; i < NUM_RANKS; ++i)
	{
		GetPrivateProfileString("Comments", rank_type[i], "-ERROR-",
					setts.quotes[i], BUFFER_LEN, path);
	}
}

Player data

As stated earlier in the tutorial, MervBot stores useful player data internally as Player objects, see player.h for implementation details.

  • p->name = player name stored as char[20] (Note: SubSpace protocol allows for usernames to be 19+ in length, do not rely on this for player-name comparisions.)
  • p->squad = player squad stored as char[20]
  • p->ship = ship (0-9) enumerated as SHIP_Warbird, SHIP_Spectator, etc..
  • p->safety = whether ship is in safety zone (boolean)
  • p->bounty = player bounty
  • p->energy = player energy (have bot with *energy on to get accurate readings)
  • p->flagCount = how many flags player is holding
  • p->team = player frequency
  • p->(burst, repel, thor, brick, decoy, rocket, portal) = how many items of that type player has
  • p->(stealth, cloak, xradar, awarp, ufo, flash, safety, shields, supers) = if player has that item on (boolean)
  • p->score.killPoints = player kill points
  • p->score.flagPoints = player flag points
  • p->score.wins = player kills from f2
  • p->score.losses = player deaths from f2

Just access the respective member of the Player class to check the player's property.

For example, in spawn.cpp, to check whether a player is in a safety zone:

EVENT_PlayerMove:
{
   Player *p = (Player*)event.p[0];

   if ( p->safety ) // player is in safe zone.
     {
        // do something.
     }

   if ( !p->safety ) // player NOT in safe zone.
     {
        // do something.
     }
}

Obtaining a player pointer using name comparison

Since Player pointers are internal to MERVBot, it is necessary to find a way of obtaining a Player pointer from the identifying information given by the game. One of the simpler ways is just to compare the names after converting to lowercase.

Note: Using pilot names as vital comparisions should be used with caution. See Bot-Issues by CypherJF.

// return Player* info (or NULL if not found) from p->name info
Player * botInfo::GetPilot(char *name)
{
	// get pilot from a name, return as TempPlayer
	_listnode <Player> *parse = playerlist->head;

	//convert search name to lowercase
	char nname[20], pname[20];
	strncpy(nname, name, 20);
	tolower(nname);

	while (parse)
	{
		Player *p = parse->item;

		// convert to lowercase to compare
		strncpy(pname,p->name,20);
		tolower(pname);
		if (strcmp(pname,nname)==0)
			return p;
		
		parse = parse->next;
	}

	return NULL;	//player not found
}

Bot built in functions

Here are some useful MervBot commands to control what the bot is doing.

Player.cpp:

  • Player::move(Sint32 x, Sint32 y) moves a player to the coordinates specified by x and y
  • Player::clone(Player *p) clones a player into a player class

Look in Commands.txt , command.cpp (core), or /!help to bot to see all bot external commands (example /!go <arena>).

LVZ Object toggling commands in plugins are to go here.