Server Help

Bot Questions - Help with a bot

xsp0rtsfanx - Mon Aug 08, 2005 2:35 pm
Post subject: Help with a bot
I'm probably going to use MERVBot or something like that I just need a plugin that i'm not sure how to make. It's kind of like what Mystic Kingdom does when you type .monster it says the coordinates of the monster but I want it so when people do a certain command it tells them where people are around them (since the zone has everyone cloaked). If anyone could tell me what the code is I would use I would appreciate it.
Maverick - Mon Aug 08, 2005 2:41 pm
Post subject:
Try making it on your own first, then people will be helping you into achieving your goal.
Not alot of people around here make bots by request for free.
xsp0rtsfanx - Mon Aug 08, 2005 2:48 pm
Post subject:
I've been trying to figure out how to make it on my own but I'm not exactly sure how I would do a locate on a person. I cant find a sysop command to make it easier so is it a custom code that would try finding the coords of the person (such as 512,512) and then putting them into the A1 or J5 form or would it come back in that form.
Bak - Mon Aug 08, 2005 3:03 pm
Post subject:
it's like 128 or 256 tiles per letter / number. Just take the largest Letter / number combo (bottom right), and divide that into 1024 and then it's a simple forumula. Math.
Maverick - Mon Aug 08, 2005 3:40 pm
Post subject:
The command is *where (PM to player), it will return the coordinates like:
xsp0rtsfanx: O11

in a type of an arena message. So you can have the bot filter that message, chop the first part (before the ': ') off and return the rest to the user.
xsp0rtsfanx - Mon Aug 08, 2005 3:51 pm
Post subject:
Ok thanks. I didn't know about the *where command.. I'll try figuring out the code myself from there then. Thanks for the help.
Maverick - Mon Aug 08, 2005 5:48 pm
Post subject:
no problem, good luck icon_smile.gif
Bak - Mon Aug 08, 2005 8:23 pm
Post subject:
or you the player position and divide it, rather that a hack.
Cerium - Tue Aug 09, 2005 1:33 am
Post subject:
Assuming the bot is close enough to get the position packets.
Bak - Tue Aug 09, 2005 7:35 am
Post subject:
In Mervbot.ini:

Misc:NoisySpectator=1
Maverick - Tue Aug 09, 2005 10:20 am
Post subject:
What are the downsides of that feature of mervbot anyway?
liito-orava - Tue Aug 09, 2005 11:00 am
Post subject:
Takes more bandwidth at least. It likely increases CPU usage a little too but even if so it'd be very minor.
Bak - Tue Aug 09, 2005 12:31 pm
Post subject:
nah, it doesn't seem like it would take more bandwidth
Cerium - Tue Aug 09, 2005 10:12 pm
Post subject:
How quickly does merv jump around from player to player? Not that it would have much of an effect on bandwidth or performance, but it would effect accuracy.

If its 1 player/sec, with 30 people, theres a chance youll only get a reliable update every 30 seconds. For something like this, itd be better if he set NoisySpectator to 0, and code the bot to spec the current monster or whatever.
xsp0rtsfanx - Tue Aug 09, 2005 10:29 pm
Post subject:
I'd have it so everytime a player wanted to check where a player is (max of 5 times per 30 seconds i can try) then it just says the coordinates of the people who are in the arena playing (not the spectators)
Bak - Tue Aug 09, 2005 10:32 pm
Post subject:
it doesn't do it like that cerium. It keeps tabs on the last position packet it got from a player... and when it gets too old it specs the player. So the position is guarenteed to be accurate within 1 second(by default). But don't take my word for it, look in host.cpp:

Code: Show/Hide

if (pp->ship != SHIP_Spectator && botInfo.db->noisySpectator)
{
   if (time - pp->lastPositionUpdate > 100)
   if (time - lastSpec > 20)
   {   // Request position if we've lost him
      pp->lastPositionUpdate = time;

      spectate(pp);
   }
}

50% Packetloss - Wed Aug 10, 2005 1:26 am
Post subject:
It depends on your settings, [misc]SendPositionDelay which is by default set to 10 (hundreths of a second).

Code: Show/Hide
      
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);
            }
         }

That is the code in which mervbot switches between players that it spectates. It doesn't request-extra-position data (aka pressing ctrl on a player while in spec) but just moves to thier last know coords, switching players every 100ms. Sometimes the bot misses things, but it is rare. ASSS allows the bot to get position packets from the entire arena (without switching it's position) if it wishes, so it is more reliable.

The reason for the switching positions is that you normally only get position packets from the players a little out of radar range (a setting aswell). Imagine if you got position packets for every player in an arena, modem users would be lagged to shit, thus this system is pretty smart from a client standpoint (a bot is a client). The bot also recieves position packets for other things other than moving, such as entering a safe-zone which is sent arena-wide (it has to because mines have to be deleted).

Noisy Spectator is a bad idea, it will lag your zone once the population reaches a certain point.
Maverick - Wed Aug 10, 2005 7:32 am
Post subject:
50% Packetloss wrote:
it will lag your zone once the population reaches a certain point.

Lag the entire zone when one client (the bot in this case) is only switching between players to get positions on them??
I can understand that the bot can't handle the load at one point if it has to get all the positions of around 100 people... but lag the entire zone?
Bak - Wed Aug 10, 2005 7:48 am
Post subject:
Hmm, after loooking further you're right in that it doesn't cycle only to player it's lost the position from, just to the next player on the playerlist (after the one it's following) and only if it's lost his position. So if you have a small map it won't need to cycle at all, but you'll have to cycle everyone in the arena to know this. This is a poor way of doing it in my opinion.

I'm going to have to agree with Maverick in that you won't lag the entire zone. I don't think you'll even lag the bot any more than normal by using noisyspectator, becase it's always recveiving packets for the area around the bot, even though that area is changing, you're never going to receive more than that area. The misc:sendpositiondelay has nothing to do with incoming packets, only with how often outgoing packets are sent (so indirectly how often you can switch players, but since noisySpectator won't switch more than every 20 ms anyway, lowering it won't make much of a difference).
50% Packetloss - Wed Aug 10, 2005 12:05 pm
Post subject:
Ok, who has been doing this longer?

Noisy spectator sends a C2S_SPECREQUEST to the server. The server in return sends a S2C_SPECDATA request to the client, which turns on extra position data (allowing the bot to see items and such). Then when the bot wants to switch to the next player, it sends out a packet and then the server has to tell one client to turn off thier SPECDATA and tell the next client to turn thier's on. Bots are fast and they will do this very quickly, spamming clients and the server with extra packets. EG tried it out once and it lagged the place to shit.
Smong - Wed Aug 10, 2005 1:59 pm
Post subject:
What about the Misc:ExtraPositionData setting and making the bot non-sysop? Surely subgame would not request the extra player data and not send such a request packet to the client.
50% Packetloss - Wed Aug 10, 2005 7:01 pm
Post subject:
Nah, I think it still does. Just that setting keeps the client from displaying the results on the screen. But I've never tested it, check out ASSS's code.
D1st0rt - Wed Aug 10, 2005 7:58 pm
Post subject:
I talked to Ekted about this a while ago and I'll pull up the log when I get a chance in a few days.
Maverick - Tue Aug 16, 2005 5:41 pm
Post subject:
So whats the solution to this (apart from residing to as3) ?
I'm making a bot that is now speccing certain areas over and over to see if people entered the areas, but its not giving the right results. (Sometimes the bot doesn't see players at all) This to avoid the NoisySpectator settings, which does give good results - but I fear of the consequences when running the bot with alot of players.

Maybe I should try to use EVENT_PositionHook instead of EVENT_Tick for a quicker cycle.
D1st0rt - Tue Aug 16, 2005 6:37 pm
Post subject:
Here be what he said, my best date estimate is around late nov 04
Code: Show/Hide
(Mr. Ekted)>shouldn't really be doing it at all, but if you have to
(Mr. Ekted)>as slowly as possible
(Mr. Ekted)>you know how much extra b/w it adds when you do that?
(Mr. Ekted)>bot sends spec, server acks, server tells client it's being specced, client acks, client sends large version of pos packet
(Mr. Ekted)>bot sends spec to another client, server acks, server tells old client to stop being specced, client acks, server tells client it's being specced, client acks, client sends large version of pos packet
:Mr. Ekted:but it is possible to get all of the weapons in an area if it sits still
:Mr. Ekted:not in spec?
(Mr. Ekted)>only if the entire map fits in bot's radar
:Mr. Ekted:do you have an idea on a minimum jump limit to have a decent refresh rate of pos?
(Mr. Ekted)>pos only gets sent every 100ms, so no faster than that, but that means with 40 players, you get updates every 4 seconds minimim
(Mr. Ekted)>junky was able to bring EG to its knees trying to spec really fast

Maverick - Wed Aug 17, 2005 3:24 am
Post subject:
Ok, how to get a Mervbot plugin to call a function every 101 ms ?
I guess you would have to create a timer (and a thread?) to do that, can someone give me an example of that?
Bak - Wed Aug 17, 2005 11:40 am
Post subject:
I'd just change the EVENT_Tick in the core to occur every 0.1 second (like powerbot's tick does).
Maverick - Thu Aug 18, 2005 3:37 pm
Post subject:
Guess that is another solution to the problem, but it would be making mervbot custom then. Hmmm, custom mervbot for my plugin icon_smile.gif
xor eax - Thu Aug 18, 2005 10:14 pm
Post subject:
I think you should use SetTimer function

Code: Show/Hide


//To start the timer:

    UINT hTimer;
    hTimer = SetTimer(NULL,0,101,TimerProc);

// (101 is the timer interval (milliseconds))
// (TimerProc is the callback that will be called when interval expires)

---------------------------------------------------------

//To stop the timer:

    KillTimer(NULL,hTimer);

---------------------------------------------------------

//The callback function

VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
   //Put your code here
   // ...

   return;
}


Maverick - Fri Aug 19, 2005 6:24 am
Post subject:
Thanks I will try that.
grav_update.gif
CypherJF - Fri Aug 19, 2005 8:06 am
Post subject:
Submit any core changes to catid to merge into the main build. icon_wink.gif I saw SOS posted his version of Merv, but doesn't it need .NET?
Maverick - Fri Aug 19, 2005 10:08 am
Post subject:
xor eax, what should be the name of the CALLBACK TimerProc() function be if I want it to be part of the botInfo:: class ? Or isn't that possible?
Smong - Fri Aug 19, 2005 1:58 pm
Post subject:
I remember going through this. You can have a static function with an extra parameter 'this' to call the member function you want.
Code: Show/Hide
class DirClient
{
protected:
   void OnDisconnected(void *clos);

   static void OnDisconnected_(void *self, void *clos);
};

...
   net->SetDisconnectFunc(OnDisconnected_, (void*)this, NULL);
...

void DirClient::OnDisconnected(void *clos)
{
...
}

void DirClient::OnDisconnected_(void *self_, void *clos)
{
   DirClient *self = (DirClient*)self_;
   self->OnDisconnected(clos);
}

Cyan~Fire - Fri Aug 19, 2005 3:46 pm
Post subject:
I'm curious. Without a message loop, how exactly does the timer notification get to your code? A separate thread? In that case, wouldn't you have to mess around with mutex's?
xor eax - Fri Aug 19, 2005 5:11 pm
Post subject:
Maverick wrote:
what should be the name of the CALLBACK TimerProc() function be if I want it to be part of the botInfo:: class ? Or isn't that possible?

TimerProc does not need to be a class member, but Smong and others know MERV and C++ much better than me, lets see what the experts say...

Cyan~Fire wrote:
Without a message loop, how exactly does the timer notification get to your code?

This is taken from the Win32API help file, SetTimer function:

"When you specify a TimerProc callback function, the DispatchMessage function simply calls the callback function instead of the window procedure. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER."

One way or the other it needs a message loop.
Maverick - Fri Aug 19, 2005 5:15 pm
Post subject:
Smong, how do I make that extra parameter 'this' use with the code xor eax posted?

Cyan~Fire thats more or less the problem I am having (was said on another forum about settimer and non-static functions)
Mr Ekted - Fri Aug 19, 2005 5:25 pm
Post subject:
Using Win API SetTimer() to handle bot timers is not good.
D1st0rt - Fri Aug 19, 2005 5:29 pm
Post subject:
Does pbot have separate timers or just really fast ticking?
Cyan~Fire - Fri Aug 19, 2005 9:34 pm
Post subject:
He said once before the pbot defines a timer interface for its plugins. This is something I will add to MERVBot, if I ever finish.
xsp0rtsfanx - Sat Aug 20, 2005 12:38 am
Post subject:
i'm glad my topic started helping out with something for mervbot although i got lost when people starting posting code lol
Mr Ekted - Sat Aug 20, 2005 2:32 am
Post subject:
Pbot has a 100ms tick event and a programmable timer event (with 100ms granularity). Even if there are 20 bots, each with 20 modules, each with 20 timers going (8000!), there's no overhead. I keep timers in a linked list sorted by trigger time, and only have to check the top one. Try calling Win API SetTimer() 8000 times.
Cerium - Sat Aug 20, 2005 6:19 am
Post subject:
Single threaded?
CypherJF - Sat Aug 20, 2005 7:17 am
Post subject:
Doubtful.
Mr Ekted - Sat Aug 20, 2005 9:57 am
Post subject:
Each bot is a single thread. Each thread manages its own timer list in the core.
Maverick - Sat Aug 20, 2005 10:48 am
Post subject:
Whats the solution for mervbot then?
Mervbot has a tick event, which goes once every second. for the rest nothing that can be really used to spec areas on a map reliable.

I need something like a timer to make function being called every 101 ms. But with a timer I have problems with non-static functions etc.

Is there a solution to making timers work in Mervbot or do I have to make a custom mervbot to have the tick event go every 101 ms?



(Can a mod split this topic into noisySpectator entitled topic please?)
xor eax - Sat Aug 20, 2005 11:03 am
Post subject:
So using 1 timer is not good because 8000 timers are an overhead?

Who is talking about calling SetTimer 8000 times? Not Maverick, not Smong, not me.

All I'm saying is that what Maverick wants can be done using SetTimer. And I haven't heard any good argument of yours against that.

Do you think a single timer per bot supose a significant overhead?

How is pbot handling the timer event? Is it using a timer or a... wheelchair?

How you're fabulous theory applies to Maverick's needs?

(and yes, Cerium, it can be single threaded, it simply does not depend on the thread model)
Mr Ekted - Sat Aug 20, 2005 11:17 am
Post subject:
Obviously my example was hyperbole. My point is that when coding, you consider scaleability. Don't do a "one time hack" that will end up being the foundation of something much more widely used.

Also, why exactly 101ms? Do you realize that, depending on the operating system, the resolution of the system timers could be as high as 16ms? Under Windows, if you are running in a worker thread (ie not a message loop), you can potentially use the multimedia timer or the high-res timer to get 1ms or even 1us accuracy. However, polling those timers has its own overhead.
Maverick - Sat Aug 20, 2005 5:29 pm
Post subject:
I don't care it has to be 101 ms, at least faster then the current EVENT_Tick of Mervbot.

icon_confused.gif

I guess I am going to continue building my bot based on noisyspectator :/
Anonymous - Sun Aug 21, 2005 12:00 pm
Post subject:
Mav, you want the bot to spec players one by one, if I understood well.

And I guess 101 msecs is the minimum time you must wait to assure that 1 position packet at least will be received from each player.

You want a non-static function to be triggered every X milliseconds... Why don't you call the non-static function from the TimerProc function?

Anyway, I think it can be done without a timer:
Why don't you make it so when a position packet arrives from the expected player then the bot switches to next player?

-You put the bot to spec the next player in list.
-When its correspondent position packet arrives the bot switches to next player.
-If a player goes to spec or leave the arena it is removed from the list of players being speced by the bot. And if the bot was specing him it switches to next player. When a player enter it is added to the list... etc.

Well... sorry Mav, I'm trying to help but maybe is better not to try it if I can't do it properly...
xor eax - Sun Aug 21, 2005 12:02 pm
Post subject:
the guest is me
Cyan~Fire - Sun Aug 21, 2005 2:11 pm
Post subject:
So, basically, you want the 101ms just to get a position packet from each player as often as possible? If so, what is wrong with NoisySpectator?
Maverick - Sun Aug 21, 2005 3:52 pm
Post subject:
I want the bot to spec certain areas on a map over time, not too quick (so it must stay speccing the area longer then 100 ms.) to get every player in that area in a reliable way.

If I try to call a non-static function with the timer the compiler complains about calling a static function from a non-static funtions (or otherway around). Someone from another forum pointed out that when using settimer the called function must have code on its own to execute - if you want to have it call functions from other classes you have to fiddle around with threads etc.

Cyan, I want to try to avoid future problems with this bot if ever the plugin encounters high pop.
Cyan~Fire - Sun Aug 21, 2005 4:54 pm
Post subject:
Quote:
Someone from another forum pointed out that when using settimer the called function must have code on its own to execute - if you want to have it call functions from other classes you have to fiddle around with threads etc.

Indeed, which is what I said before, and also why I don't think this idea of yours will work without changing the way MERV operates.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group