Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Lag Plugin

 
Post new topic   Reply to topic Printable version
 View previous topic  CTF Plugin that stores stats Post :: Post Bot spawning  View next topic  
Author Message
Guest



Offline

PostPosted: Wed Sep 19, 2007 5:39 am    Post subject: Lag Plugin Reply to topic Reply with quote

Hello,

Well I was testing the Lag check plugin (made by Explody?) and wondered if there was a way to change how the string was handled after the player made the request. For example, lets say I was using the name "Deathwish" and I typed in !lagcheck Death it won't find the player "Deathwish". For the command to work a player has to type in the full name. I wanted to change this so that just by typing !lagcheck Death it would search the players in the current arena and match it to "Deathwish". Also, if there was a player named "DeathAxe" that's the player would get lag checked (alphabetical order). Basically the bot would have to check each string and compare them. I was just wondering if there was a function already created within merv to handle this. So far every plugin I've seen that allows a player to check another players' status, requires the requesting player to type in the whole name instead of just a part of it. I've rambled on for awhile, it's 4am and I'm tired. Any help would be appreciated. Please excuse any grammatical errors.


Thanks
Back to top
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Wed Sep 19, 2007 7:03 am    Post subject: Reply to topic Reply with quote

First things first, you should try to get/find the source to the plugin first - you aren't able to change anything if you haven't got the source files.

Not alot of plugins do matches with partial playernames, I'm pretty sure you have to make it yourself if you want it (not that much work though).
_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Wed Sep 19, 2007 12:46 pm    Post subject: Reply to topic Reply with quote

If you can find the code for it, you could use this method I made and use in my stuff:

Code: Show/Hide

Player* FindPlayerByName(char *name, bool exactmatch, _linkedlist <Player>* list);
int FirstDifferentCharacter(char *string1, char *string2);

Player* FindPlayerByName(char *name, bool exactmatch, _linkedlist <Player>* list)
{
   _listnode <Player> *parse = list->head;   //set to first link of the player linked list
   Player* bestmatchplayer = NULL;
   int bestmatchlength = 0;
   
   String nametofind = name;
   nametofind.lcase();

   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
      String pname = (String) p->name;
      pname.lcase();

      if (pname == nametofind)
         return p;
      if (!exactmatch)
      {
         int firstdifferent = FirstDifferentCharacter(nametofind, pname);
         if (bestmatchlength < firstdifferent)
         {
            bestmatchlength = firstdifferent;
            bestmatchplayer = p;
         }
      }
      parse = parse->next;   //set parse to the next link
   }
   
   return bestmatchplayer;
}


//Zero-based index of the first different character in both string.
//If both strings are the same, will return the length of the string.
int FirstDifferentCharacter(char *string1, char *string2)
{
   int i;
   for (i = 0 ; string1[i] != '\0' && string2[i] != '\0' && tolower(string1[i]) == tolower(string2[i]) ; i++)
   {
   }
   return i;
}

Just make sure you check that the return value != NULL before using it
_________________
(Insert a bunch of dead links here)
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Sep 19, 2007 2:51 pm    Post subject: Reply to topic Reply with quote

Hey Samapico, here's some faster code:
Code: Show/Hide
int FirstDifferentCharacter(const char *string1, const char *string2)
{
   int i;
   for (i = 0 ; *string1 != '\0' && *string2 != '\0' && tolower(*string1) == tolower(*string2) ; i++, string1++, string2++)
   {
   }
   return i;
}

Runs faster (or maybe the same after the compiler has optimized it). Just a hint for future iterative algorithms you write. icon_smile.gif
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Guest



Offline

PostPosted: Wed Sep 19, 2007 3:02 pm    Post subject: Reply to topic Reply with quote

Mav: I do have the source.

Sam: I thought I might have to write that part myself.

Cyan: Thanks, I'll try your function first.
Back to top
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Wed Sep 19, 2007 11:35 pm    Post subject: Reply to topic Reply with quote

Cyan~Fire wrote:
Hey Samapico, here's some faster code:
Code: Show/Hide
int FirstDifferentCharacter(const char *string1, const char *string2)
{
   int i;
   for (i = 0 ; *string1 != '\0' && *string2 != '\0' && tolower(*string1) == tolower(*string2) ; i++, string1++, string2++)
   {
   }
   return i;
}

Runs faster (or maybe the same after the compiler has optimized it). Just a hint for future iterative algorithms you write. icon_smile.gif

cool, thanks


and guest, I thought I'd share that tongue.gif But you can write it yourself too, it's not that complicated
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Sep 20, 2007 1:09 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide
Player* FindPlayerByName(const char *startsWith, _linkedlist <Player>* list)
{
   Player* rv = NULL;
   int len = (int)strlen(startsWith);

   for (_listnode <Player> *parse = list->head; parse; parse = parse->next)
   {
      Player* p = parse->item;

      if (strnicmp(p->name,startsWith,len) == 0)
      {
         rv = p;

         if (stricmp(p->name,startsWith) == 0)
            break;
      }
   }
   
   return rv;
}


Returns NULL if no player starts with the requested substring.
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Thu Sep 20, 2007 2:50 am    Post subject: Reply to topic Reply with quote

Guest, can you attach the source here for any future reference if people are searching for it?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Guest



Offline

PostPosted: Thu Sep 20, 2007 3:41 am    Post subject: Reply to topic Reply with quote

Done.



lagbot-src.zip - 10.27 KB
File downloaded or viewed 37 time(s)
Back to top
Guest



Offline

PostPosted: Thu Sep 20, 2007 3:58 am    Post subject: Reply to topic Reply with quote

Also for some reason when I compile the plugin right from the zip I get errors.

Error 3 error C2065: 'ifstream' : undeclared identifier c:\.....\mervbot\src\lagbot\spawn.cpp 60

Error 4 error C2146: syntax error : missing ';' before identifier 'file' c:\...\spawn.cpp 60

Error 5 error C3861: 'file': identifier not found c:\....\spawn.cpp 60

Error 6 error C2228: left of '.getline' must have class/struct/union c:\....\spawn.cpp 62

Error 7 fatal error C1903: unable to recover from previous error(s); stopping compilation c:\...\spawn.cpp 62
Back to top
Guest



Offline

PostPosted: Thu Sep 20, 2007 4:05 am    Post subject: Reply to topic Reply with quote

I forgot to add that it was using #include <fstream.h> which is outdated so I changed it to #include <fstream> and it gave me the above errors. BTW, it wasn't compiling even before I made this minor change...

Anyone know exactly why?
Back to top
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Sep 20, 2007 10:15 am    Post subject: Reply to topic Reply with quote

after you do "#include <fstream>" you might need to do "using namespace std;"
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Guest



Offline

PostPosted: Thu Sep 20, 2007 3:29 pm    Post subject: Reply to topic Reply with quote

Thanks Bak, that did the trick.
Back to top
blue monday
Novice


Joined: Nov 04 2005
Posts: 75
Offline

PostPosted: Tue Oct 30, 2007 2:13 pm    Post subject: Reply to topic Reply with quote

Would you be able to post the new one you made? I would love to only have to type half the name. icon_smile.gif
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 153 page(s) served in previous 5 minutes.

phpBB Created this page in 0.531731 seconds : 40 queries executed (92.7%): GZIP compression disabled