Difference between revisions of "Talk:MERVBot Tutorial"

From ASSS Wiki
Jump to: navigation, search
(General Convo: responce to smong)
(yea.. .mem leak)
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
==hmm==
 +
Modified permanent get/setTag method = memory leak... boo
 +
telling them to beware is eh... i dunno [[User:BaK|BaK]]
 +
 
==General Convo==
 
==General Convo==
 
D1s: Anybody wanna format this int a table of contents? I'm lazy
 
D1s: Anybody wanna format this int a table of contents? I'm lazy
Line 45: Line 49:
 
Oh, OK, that's fine. Also, do remember that the wiki will automatically do your <p>ing for you as long as you leave a blank line in-between "paragraphs". --[[User:Cyan~Fire|Cyan~Fire]]
 
Oh, OK, that's fine. Also, do remember that the wiki will automatically do your <p>ing for you as long as you leave a blank line in-between "paragraphs". --[[User:Cyan~Fire|Cyan~Fire]]
  
== old toc ==
+
== Example Code commenting system ==
 +
 
 +
What's the use of it? --[[User:Cyan~Fire|Cyan~Fire]]
 +
 
 +
[[User:Smong|Smong]]: So if people don't understand the examples they can request help or a clarification. Also people that do understand an example might want to post a better/alternative solution. I suppose since you need an account to edit a page, maybe the wiki can be setup so you don't need an account to edit the discussion page so people can put comments in there.
 +
 
 +
I think I wasn't being very clear, Cypher didn't understand me either. I was talking about his <!-- EXAMPLE A: BEGIN--> stuff. Anyway, I've gotten permission from him to remove it, it was only supposed to be temporary. The idea of anonymous talk posts is a good idea, but I'm not sure if its possible. --[[User:Cyan~Fire|Cyan~Fire]]
 +
 
 +
== Make bot spectate specific coordinates Section ==
 +
--[[User:50% Packetloss|50% Packetloss]] 14:34, Feb 21, 2005 (EST)
 +
 
 +
This is what is currently there.
 +
<pre>
 +
tell(makeFollowing(false));
 +
tell(makeFlying(true));
 +
me->move(512 * 16, 600 * 16);
 +
tell(makeSendPosition(true));
 +
</pre>
 +
 
 +
Now when you tell the bot tell(makeFlying(true)); the core makes DLLFlying= true; Thus in the core's function void Host::doEvents() instead of the bot sending position packets, the job is left to the dll.
 +
<pre>
 +
//...
 +
if (DLLFlying)
 +
{
 +
Uint32 limit = settings.SendPositionDelay;
 +
 
 +
if (time - lastPosition > limit)
 +
{
 +
imports->talk(makePositionHook());
 +
}
 +
}
 +
else if (Me->ship == SHIP_Spectator)
 +
{ // Spectating
 +
Uint32 limit = settings.SendPositionDelay;
 +
 
 +
if (time - lastPosition > limit)
 +
{
 +
// Cycle player spectated
 +
if (Me->ship == SHIP_Spectator)
 +
spectateNext();
 +
 
 +
sendPosition(false);
 +
}
 +
}
 +
else if //...
 +
</pre>
 +
So in the dll, in the positionhook event, you need to add tell(sendPosition(false));. Im not sure if it will have a dramatic effect if the bot is in spec (never tested it), but if the bot is in a ship it will disappear from the screen. I don't know a lot about this wiki stuff so Ill leave it up to you ladies to edit.
 +
 
 +
== Random Number Selection ==
 +
 
 +
When picking a random number, the code for [[MERVBot_Tutorial#Picking_a_random_pilot|Picking a random pilot]] works off GetTickCount, which is very bad. GTC does not have single digit accuracy, and you can see this by running a loop for a couple of seconds and 'bucketing' the return values module X. If X is something like 25 or 50, you'll see very obvious patterns, where certain numbers are skipped completely. Even modulo something smaller like 10, and the distribution is horrible. The section right above this uses rand() correctly. In a simple tutorial, even rand() % X is much better than GTC() % X.
  
Please leave this here for now. --[[User:Cyan~Fire|Cyan~Fire]]
+
== About recent code changes ==
  
<div id="merv_toc" style="font-size: 12px; margin: 2em;">
+
[[User:Mine GO BOOM|Mine GO BOOM]] 22:42, Jun 8, 2006 (EDT): Instead of using numbers in the code, such as '9' in atoi and 256 for str, you should use sizeof. If you change the size of str in the future, makes it easier to handle, and is also less prone to errors when you are coding, as you '''know''' it won't overflow the variable (unless it doesn't tack on '\0' at the end, check documentation on that function?).
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>
 

Latest revision as of 00:43, 17 March 2008

hmm

Modified permanent get/setTag method = memory leak... boo telling them to beware is eh... i dunno BaK

General Convo

D1s: Anybody wanna format this int a table of contents? I'm lazy

Smong: That is sick. Maybe split into more pages? Says it is over 160k.

Pests: There is already pages defined. You could just split them up into that.

OK, I'm working on converting it to real HTML (using <pre>) instead of the &nbsp; crap. --Cyan~Fire

CypherJF: Should we just call this "the bot tutorial" based on the tutorial by Underlord? Then update it accordingly? -- And also, the link to MervBot w/e 37 is now 45; should we just comment that this tutorial was writen for the 37 -- or... comments! lol.

CypherJF: I'd like to say that all sections appear to have been updated for the Wiki; time to go through edit, and catch mistakes. Add to the wiki itself - perhaps more example code.

CypherJF: Cyan and I were talking about the section "Checking if pilot is in a safe zone"; whether or not to just remove it. I remarked that it's a nice section for those to the whole plugin deal. But, I was just noticing how it'd make more sense to put the "Useful Player data" before hand... So i guess the next step is to go through and try to address the logical-aspect of ordering of the content? What's your guys' take?

Smong: Uh yeah.. so why are there so many major edits to just one page? I can't see anything in recent changes but edits to the mervbot tutorial.

CypherJF: See my other notes: "CypherJF: Well I've been doing the edits from all around campus. Like yesterday I did 4-6 things from the MathLab; and the rest from the dorm, etc. lol. I don't think it really matters, since there isn't much other activity going on.. on the wiki." So, I'd make edits and just post em. It happened to be the only activity and sooo it looks worse than it is.

sscanf

Well, I'm using sscanf() for parsing player input. Yes, an advanced function, but maybe it will discourage C++ newbs from making bot plugins. Any comments? --Cyan~Fire

D1st0rt: Cool beans. I learned something new :D

Event list

Removed event list because it was redundant with dllcore.h, less descriptive, and too easy to get out-of-date. Anybody who wants it back, please post here so I can ignore you. :-D --Cyan~Fire

CypherJF: Like people are really going to read through the dllcore.h file.. on a webpage tutorial. hmm i think not. I still say keep it there.

If someone doesn't make the effort to look up events in dllcore.h, they shouldn't be making plugins. I think of this tutorial as more of a "here are the basics and intricacies of making a MERVBot plugin" more than "here is how to follow step-by-step instructions and call it programming". --Cyan~Fire

D1s: Even I look up things in dllcore.h, its a very useful resource. As long as it says to look in it, I don't think we'd need the full list here

Extra Code Samples

CypherJF: I'd like to somehow split these up better; and make them linkable, what do you guy's think?

CypherJF: I made sub-headers, and so they'll be added into the table of contents. Let me know what you guys think of it.

Alrighty, looks good. One thing I would ask is to try to save up a bunch of edits in a text editor or something, than have the myriad edits you do now. Thanks for sharing the burden with me! --Cyan~Fire

CypherJF: Well I've been doing the edits from all around campus. Like yesterday I did 4-6 things from the MathLab; and the rest from the dorm, etc. lol. I don't think it really matters, since there isn't much other activity going on.. on the wiki.

Oh, OK, that's fine. Also, do remember that the wiki will automatically do your <p>ing for you as long as you leave a blank line in-between "paragraphs". --Cyan~Fire

Example Code commenting system

What's the use of it? --Cyan~Fire

Smong: So if people don't understand the examples they can request help or a clarification. Also people that do understand an example might want to post a better/alternative solution. I suppose since you need an account to edit a page, maybe the wiki can be setup so you don't need an account to edit the discussion page so people can put comments in there.

I think I wasn't being very clear, Cypher didn't understand me either. I was talking about his <!-- EXAMPLE A: BEGIN--> stuff. Anyway, I've gotten permission from him to remove it, it was only supposed to be temporary. The idea of anonymous talk posts is a good idea, but I'm not sure if its possible. --Cyan~Fire

Make bot spectate specific coordinates Section

--50% Packetloss 14:34, Feb 21, 2005 (EST)

This is what is currently there.

tell(makeFollowing(false));
tell(makeFlying(true));
me->move(512 * 16, 600 * 16);
tell(makeSendPosition(true));

Now when you tell the bot tell(makeFlying(true)); the core makes DLLFlying= true; Thus in the core's function void Host::doEvents() instead of the bot sending position packets, the job is left to the dll.

//...
if (DLLFlying)
{
	Uint32 limit = settings.SendPositionDelay;

	if (time - lastPosition > limit)
	{
		imports->talk(makePositionHook());
	}
}
else if (Me->ship == SHIP_Spectator)
{	// Spectating
	Uint32 limit = settings.SendPositionDelay;

	if (time - lastPosition > limit)
	{
		// Cycle player spectated
		if (Me->ship == SHIP_Spectator)
			spectateNext();

			sendPosition(false);
	}
}
else if //...

So in the dll, in the positionhook event, you need to add tell(sendPosition(false));. Im not sure if it will have a dramatic effect if the bot is in spec (never tested it), but if the bot is in a ship it will disappear from the screen. I don't know a lot about this wiki stuff so Ill leave it up to you ladies to edit.

Random Number Selection

When picking a random number, the code for Picking a random pilot works off GetTickCount, which is very bad. GTC does not have single digit accuracy, and you can see this by running a loop for a couple of seconds and 'bucketing' the return values module X. If X is something like 25 or 50, you'll see very obvious patterns, where certain numbers are skipped completely. Even modulo something smaller like 10, and the distribution is horrible. The section right above this uses rand() correctly. In a simple tutorial, even rand() % X is much better than GTC() % X.

About recent code changes

Mine GO BOOM 22:42, Jun 8, 2006 (EDT): Instead of using numbers in the code, such as '9' in atoi and 256 for str, you should use sizeof. If you change the size of str in the future, makes it easier to handle, and is also less prone to errors when you are coding, as you know it won't overflow the variable (unless it doesn't tack on '\0' at the end, check documentation on that function?).