|
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Fri Jul 31, 2009 10:45 pm Post subject: A little confused... |
|
|
|
|
Hello everyone.
I've been spending some time on reading some tutorials on how to create simple bots. I have a few questions which I hope can be answered here, I did look at the sticky by the way.
To be exact, by bots I mean I am interested in making plugins for TWcore. I looked around this forum and other sources and read that these plugins are either written in C, python, or c++. Even java. OK, i know c++ very well, been doing it for the past couple of years.
I know that it doesn't matter which language you use to make a program, as long as it goes from point A to B, your all good. So, I was thinking of a tutorial on creating plugins for TWcore in c++ if possible (what compiler?). If not then a good direction toward a good tutorial.
Please note that I did look at D1st0rtion's site and at twcore.org. I installed the required programs and read most of it. Lots of information their but I want to make sure which information is more accurate. So, which tutorials would you guys recommend. C++ related tutorials would be great.
If you think my knowledge isn't enough then please do direct me to what I need to know. If you think there is a beginner step befor getting on making plugins then please let me know. If you think starting from bots is easier than plugins for TWcore, then please post. I want to make my summer days off a little more useful. I want to get started with simple plugins, and then maybe move on from their.
-Thanks in advance, sorry if any spelling mistakes
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:24 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Sat Aug 01, 2009 1:21 am Post subject: |
|
|
|
|
Bak wrote: | To the best of my knowledge TWCore, and therefore each of its plugins, is written in Java.
If you want to use C++ consider MervCore. |
Alright, for MervCore. Do you know any good tutorials? And which compiler would you suggest for c++. I used dev-c++ before, and thats pretty much it.
Is there a guide on this?
-Thanks
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:24 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat Aug 01, 2009 3:23 am Post subject: |
|
|
|
|
http://wiki.minegoboom.com/index.php/MERVBot_Tutorial
That guide has describes how to set up the compile environment with MS Visual Studio. If you don't have that the process is the same as creating any .dll file, although if you can't figure out how to do that let me know and I might make some sort of tutorial.
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Sun Aug 02, 2009 10:51 am Post subject: |
|
|
|
|
Bak wrote: | http://wiki.minegoboom.com/index.php/MERVBot_Tutorial
That guide has describes how to set up the compile environment with MS Visual Studio. If you don't have that the process is the same as creating any .dll file, although if you can't figure out how to do that let me know and I might make some sort of tutorial. |
Hello,
Thank you for the tutorial. I did go their and installed Microsoft Visual Studio. The only problem is that under the sub-heading "Microsoft Visual c++", It goes over an older version of Microsoft visual studios. I have the lates one so the directions are really, really off. I am having problems. If you can just create directions using Microsoft Visual Studio 9.0 (latest)) then that will be awesome.
-Thanks
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Aug 02, 2009 11:09 am Post subject: |
|
|
|
|
I don't know if someone found a solution for this, but compiling Merv plugins with MS Visual Studio 2005 often gives you plugins that cannot work on computers without VS2005 installed. I personally use VS 6.0 to compile merv plugins. _________________ (Insert a bunch of dead links here)
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Sun Aug 02, 2009 12:20 pm Post subject: |
|
|
|
|
Samapico wrote: | I don't know if someone found a solution for this, but compiling Merv plugins with MS Visual Studio 2005 often gives you plugins that cannot work on computers without VS2005 installed. I personally use VS 6.0 to compile merv plugins. |
Man I couln't find a link for version 6.0. I looked everywhere. If you can find a torrent link plz let me know. MS newer versions are a drag, even the new office. They screw up everything
-Many thanks.
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Sun Aug 02, 2009 12:23 pm Post subject: |
|
|
|
|
Man I couln't find a link for version 6.0. I looked everywhere. If you can find a torrent link plz let me know. MS newer versions are a drag, even the new office. They screw up everything
I personally use dev-c++ to compile my c++ programs. Thats what I always used. This studio thing is a huge crap. I looked at doing all this stuff in dev-c++ but no luck. Hardly any support on that at all over the net.
-Many thanks.
EDIT: Sorry for double post, my bad
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Sun Aug 02, 2009 1:22 pm Post subject: |
|
|
|
|
Hey i might be able to take a look at mervbot and update it for vs2005.
Or indeed convert it too a cross-platform system which will compile on dev++ if you give me a week or so. _________________ Rediscover online gaming. Get Subspace | STF The future...prehaps
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Mon Aug 03, 2009 1:21 am Post subject: |
|
|
|
|
Doc Flabby wrote: | Hey i might be able to take a look at mervbot and update it for vs2005.
Or indeed convert it too a cross-platform system which will compile on dev++ if you give me a week or so. |
THat would be great. In fact, if you or anyone can have some time to simply write a simple little tutorial on how to make a .dll file on dev-c++ then that would be even better.
I can make a .dll file, but I don't really know what to do from there. The current mervbot tutorial is good, but it misses some instructions. Perhaps a little more explenation on the .dll lets say would be great.
For example, i start a .dll project on dev-c++. I just donnu what to do from their. When I try to edit some files in src folder of any plugin, I can open them in dev-c++. The main problem is that their is no simple step-by-step tutorial on mervbot modules. TWcore has really good tutorials though.
-Thanks in advance
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Mon Aug 03, 2009 6:02 am Post subject: |
|
|
|
|
Ah I think i've discoved why you may have had some difficulty with the tutorial A link was broken on the page which contains the sample plugin project that contains the project files to create DLL files.
Optional Step 0
Download wxdev http://wxdsgn.sourceforge.net/
This is a more up to date version of devC++
1. Download Mervbot
Download
http://mervbot.com/files/MERVBot.rar
Unzip the src file into the Mervbot folder
So you have an extra folder caused "src" along with "get", "log", "lvl"
eg c:\mervbot\src
2. Download Sample DLL Plugin Project
Download Sample Bot File
http://www.mervbot.com/files/Tutorial.rar
Copy the "default" folder in the zip file into the src folder.
eg c:\mervbot\src\default
3. Compile and Test
Inside the default folder is a project file "default.dev" you can open with dev c++ or wxdev, there are also project files for visual studio, these are already setup to create the correct DLL file. Open this file and Compile it. Then copy the dll from the debug folder to c:\mervbot
Add the dll to spawns.txt and change NoTerminal=0 in mervbot.ini to show output. run it and see if it works./
Once you get the "Default.dll" working to create your own, copy it to a new folder eg. c:\mervbot\src\mybot rename the files and edit them to make it you own [/b][/code]
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Mon Aug 03, 2009 3:10 pm Post subject: |
|
|
|
|
OK, thanks for a quick tutorial.
Editing this post 3 times now, lol.
I installed 'wxdev'. When I try to compile 'default.dll', it give me the following error:
"No Host application was provided. You can set it in Execute | Parameters"
When I go to Execute > Parameters from top menu, it opens a box from which I can set a host application. I dunno what is a host application.
Despite this error listed above, it does creade a 'Default.dll' file in the debug folder. It also creates the following files: "command.o", "libDefault.a", and "spawn.o". What should I do with these files? Also copy them with the default.dll file or these don't really matter.
So many questions, so little time. Also wonder, is there a way to edit an existing .dll file? For example, can I edit the 'Default.dll' which I just created; using wxDev??
If you can help than many thanks.
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Mon Aug 03, 2009 3:47 pm Post subject: |
|
|
|
|
Zamin wrote: | OK, thanks for a quick tutorial.
Editing this post 3 times now, lol.
I installed 'wxdev'. When I try to compile 'default.dll', it give me the following error:
"No Host application was provided. You can set it in Execute | Parameters"
When I go to Execute > Parameters from top menu, it opens a box from which I can set a host application. I dunno what is a host application.
|
Ah its because you are trying to run the dll. A dll needs an exe "host" to run it, on its own it can't do anything. If you want to use the debugger, to step though or use breakpoints in wxdev, you should specify mervbot.exe as the host, you don't need to do this to get the bot to work.
Zamin wrote: |
Despite this error listed above, it does creade a 'Default.dll' file in the debug folder. It also creates the following files: "command.o", "libDefault.a", and "spawn.o". What should I do with these files? Also copy them with the default.dll file or these don't really matter.
|
The other files are just C++ object files and are just created as part of the compilation process. They can just be ignored
Zamin wrote: |
So many questions, so little time. Also wonder, is there a way to edit an existing .dll file? For example, can I edit the 'Default.dll' which I just created; using wxDev??
If you can help than many thanks. |
Unfortunatly a dll file (which is almost identical to a exe file) can't be edited (easily) after its been created. If you have the source code to the dll you want to change, you can simply alter the source and compile an alterered dll.
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Mon Aug 03, 2009 5:25 pm Post subject: |
|
|
|
|
OK, thanks.
OK, when my .dll file is complete, i move it to mervbot main folder; that is all right? I mean, this .dll file is the entire module right? Or do I need the entire src folder.
I mean, when I make my package of the module. Do I just need to pass on the .dll file, also the src folder, and what about the command.cpp, spawn.cpp, and spawn.h files?
Also, what do you mean by "Add the dll to spawns.txt"?? Kinda dumb question but i did look at spawn.txt, i dunno where to mention the .dll name in it. I read the same thing in other plugin readme's but didn't really understood what to change in that file.
Is this what i edit:??
# Spawns.txt Format:
# Bot name : Bot password : Arena name : Plugin names : Staff password |
Instead of 'Plugin names', i must enter for example 'Default.dll'??
EDIT: Also, another question. I was looking at the Music Lock Plugin (download: http://www.subspacedownloads.com/index.php?act=file&fid=938) and was looking at it's command.cpp and noticed that none of the variables being used were ever declared. This kind of confused me, again; how is it possible your using variables such as 'sendPrivate' and 'checkParam' and not declair them in the function itself. I am sure that the variables being used are called from other libraries in Mervbot directory.
Having said that, hope not too confusing. I was wondering if there is a list of all types of different variables which I can use along with their effect. In other words, there must be a list which tells which variable to use and what effect it has. For example, 'sendPrivate' sends a private message to the user.
-Thanks in advance
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Aug 03, 2009 10:45 pm Post subject: |
|
|
|
|
<stuff about spawns.txt>
Yes, exactly
You can also message !load default or !load default.dll to your bot after it has spawned... When doing tests I usually start my bot, then !load someplugin, try stuff, !unload 0, make changes, recompile, !load someplugin... etc.
Use !plugins to know the ID of your plugin, and !unload # to unload it.
In spawns.txt, you also don't need to write the ".dll" part of the plugin name.
Your mervbot only needs the .dll in its folder, it doesn't care about the source.
sendPrivate and checkParam are not variables, they are functions. Which is why you get parenthesis after it, with the parameters.
These functions are part of the botInfo class, which constitutes pretty much the entirety of your code. A class is just a data structure, with variables and functions related to it.
The sendPrivate and checkParam functions are declared in spawn.h and spawn.cpp, which contains the declaration of the botInfo class and all the variables and functions it has. If you want to add variables that you can access throughout your code, you'll want to declare them as members of the botInfo class. The comments in that area tell you how. Also, if you want to know other functions or variables available, they're there. You can define your own functions there if you want as well. The syntax for class functions is a bit weird, just check how the other functions are done to understand how.
You need both a declaration which defines the arguments of the function and its return type:
void sendPrivate( Player * p, char * msg); |
And the definition of the function, where the actual code of it is:
void botInfo::sendPrivate( Player *p, char * msg)
{
//code...
} |
(These are from memory, and with all the other languages I've played with lately, I could have made a few mistakes, so don't take this for granted )
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Tue Aug 04, 2009 2:09 am Post subject: |
|
|
|
|
Thanks for replying sama, i'm assuming your the same sama in HS. lol
Anyways, your techneque about loading plugin, seeing effect and unloading again to change code is very useful. But the only problem is that when I load plugin, use it. And when I unload the plugin to change the code, I need to delete the current default.dll file in order to bring int he new default.dll file right. But when I try to delete the current .dll file it says it is being used. I have to exit the Mervbot completely, then I am able to delete the .dll file. Not a big problem but if you can think of a way around that then that will make my life even more easier. lol
Anyways, I was wondering. If everything is defined in spawn.cpp and spawn.h, why have 2 files? Does it not make things a bit too complicated?
EDIT: I was playing around with the command.cpp and ran into this problem:
The following code works: (When I type !rand, this code kicks in)
else if (c->check("rand"))
{
sendPrivate(p, "asd as");
} |
But this does not work:
else if (c->check("rand"))
{
string Message;
Message = "asd as";
sendPrivate(p,Message);
} |
Any idea why not? All I am trying to do is save the text in the 'Message' string and then pming it. What harm is that? I am guessing it is not recognizing the variables. I tried to pass an integer in the message and that also didn't work. I did something like this:
else if (c->check("rand"))
{
int z = 0;
z = 2 + 2;
sendPrivate(p,z);
} |
The code above is very simple, I don't know why the function is not recognizing variables.
NOTE: the code is being used in the function:
void botInfo::gotCommand(Player *p, Command *c)
I did properly write what was necessary in the function:
void botInfo::gotHelp(Player *p, Command *c)
I played around with the code. It made a few commands which just sends you back a 'text' pm. I wanted to have a variable (containing any type of information [number/text]) being sent in the pm.
Sorry if confusing
-Thanks in Advance
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:24 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Tue Aug 04, 2009 9:09 am Post subject: |
|
|
|
|
When projects have large numbers of files people usually split them into header files (.h files) and the corresponding implementations (.cpp files). This usually speeds up compiling when only a small number of files are modified.
Pay particular attention to types when you're using functions.
void sendPrivate( Player * p, char * msg); |
Notice that msg has type char*, so you can't pass it a string or an int without doing a conversion first.
string Message;
Message = "asd as";
sendPrivate(p,Message.c_str()); |
the .c_str() converts the string to a const char* which is compatible with a char*. Alteratively, you can use Mervbot Strings (capital 'S' at the start of String).
else if (c->check("rand"))
{
int z = 0;
z = 2 + 2;
String message = z;
sendPrivate(p,message);
} |
Or, if you're more comfortable with C-style strings you can use those directly
else if (c->check("rand"))
{
int z = 0;
char buf[128];
z = 2 + 2;
snprintf(buf, sizeof(buf), "%i", z); // may need to #include the proper header for snprintf, use google
sendPrivate(p,buf);
} |
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Tue Aug 04, 2009 12:13 pm Post subject: |
|
|
|
|
Thank you for a great reply. I tried everything and it worked. I would like to thank all 3 of you for giving me excellent support on this.
OK, another problem. lol. I wanted to make my own function. Editing the same code as mentioned in my earlier post:
else if (c->check("rand"))
{
int z = 0;
z = addition(2,2);
String Message;
Message = "The number is: ";
Message += z;
sendPrivate(p, Message);
} |
Where can I add this function??:
void addition(int a, int b)
{
int z;
z = a + b;
return z
} |
It's this addition function thats giving me the problem. When I don't use the addition function and do, for example '2 + 2' in the rand section, it works. I simply don't know where to put this function. I tried all three files; command.cpp, spawn.cpp, and spawn.h. I even tried to make a seperate file, placed the function addition in it and called it in command.cpp under #include "spawn.h".
This is a very little problem, i am sure. Like the rest. Please do let me know what I am overlooking.
-Thanks in advance
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:24 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Tue Aug 04, 2009 1:03 pm Post subject: |
|
|
|
|
the compiler (thing that makes the .dlls) needs to know about the function before you use it. It reads the files from top to bottom. Thus, place the function above where it's called (at the top level, not inside another function), and it should work. Also, your function is missing a semicolon after "return z".
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Tue Aug 04, 2009 2:24 pm Post subject: |
|
|
|
|
Bak wrote: | the compiler (thing that makes the .dlls) needs to know about the function before you use it. It reads the files from top to bottom. Thus, place the function above where it's called (at the top level, not inside another function), and it should work. Also, your function is missing a semicolon after "return z". |
Yes yes, I did define addition function at the very top of command.cpp, right after #include "..\algorithms.h"
And for the semicolon after 'return z', i didn't put their because when the function is ending, you don't have to put it their. It is not mandatory, from what I learned. But it doesn't hurt to put it in so I did and tried. But still same problem.
It gives me a dozen errors on #include "..\clientprot.h" in spawn.h
I noticed that none of the files uses:
#include <iostream> and using namespace std;
I don't know if you or anyone know this syntax but thats what I learned in uni. Please let me know how I can use functions in this.
-Thanks
|
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:24 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Tue Aug 04, 2009 4:20 pm Post subject: |
|
|
|
|
#include just pastes the contents of a file at that location, so #include <iostream> will paste the iostream.h file (from somewhere on your computer, your compiler knows where it is) which includes definitions of functions related to input/output streams, which is unrelated to your error. namespace std is just the namespace dealing with input/output streams. otherwise, before you call cout, for example, you would need to do "std::cout << "hi";". By using the namespace you don't need to be explicit. Namespaces prevent conflicts with other files that might want to also use names like cout or cin for other things.
attach your command.cpp and I'll take a look
|
|
Back to top |
|
|
Zamin Newbie
Joined: Mar 03 2006 Posts: 14 Offline
|
Posted: Tue Aug 04, 2009 6:50 pm Post subject: |
|
|
|
|
Hello, thank you both for quick reply.
As for class. I am not using class or defining a function inside a class. I am making a seperate function on top of command.dll and then calling on that function inside another.
Thank you for clearing out the iostream and using namespace std; thing to me. The file is attached. The function 'addition' is defined right at the top of the file. And is being called in the void botInfo::gotCommand under the command !rand.
-Thanks to both once again
Command.cpp
command.cpp - 5.15 KB
File downloaded or viewed 43 time(s)
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:24 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Tue Aug 04, 2009 7:23 pm Post subject: |
|
|
|
|
your function is defined as returning a void (not returning any value) but it should actually return an integer. Change the return value in the signature to int:
Quote: | int addition(int a, int b)
{
int z;
z = a + b;
return z;
} |
Also, I'm fairly certain the semicolon after the return is mandatory, perhaps you're thinking of another language.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Tue Aug 04, 2009 8:40 pm Post subject: |
|
|
|
|
Zamin wrote: | Thanks for replying sama, i'm assuming your the same sama in HS. lol
Anyways, your techneque about loading plugin, seeing effect and unloading again to change code is very useful. But the only problem is that when I load plugin, use it. And when I unload the plugin to change the code, I need to delete the current default.dll file in order to bring int he new default.dll file right. But when I try to delete the current .dll file it says it is being used. |
Make sure your plugin wasn't loaded twice in the bot... also, make sure your debugger wasn't attached to it for debugging or something. Usually I can delete the dll just fine after unloading it. Also make sure you only have 1 spawn (it's possible to have multiple spawns per single .exe)
Also, I am the one and only Samapico.
|
|
Back to top |
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 671 page(s) served in previous 5 minutes.
|