BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => BeBot 0.2 support => Topic started by: craized on January 21, 2005, 04:57:22 am

Title: Teams
Post by: craized on January 21, 2005, 04:57:22 am
I'm trying to write a teams module and I'm having some trouble.
Code: [Select]

<?php
/*
* Teams Module for BE Bot <http://bebot.fieses.net>
* Module coded by Craized <http://www.craized.net>

/*
Add a "_" at the beginning of the file (Teams.php) if you do not want it to be loaded.
*/

$teams = new Teams($bot);
$commands["pgmsg"]["teams"] = &$teams;
$commands["pgjoin"][] = &$teams;
$commands["pgleave"][] = &$teams;

/*
The Class itself...
*/
class Teams
{
var $bot;
var $pgroup;



/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function Teams (&$bot)
{
$this -> bot = &$bot;
}


/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name$msg)
{
$msg explode(" "$msg);
$red "<font color=#FF0000>";
if ($msg[1] == "") {
$teams ceil(count($this -> pgroup)/6);
for($num=1$num<=$teams$num++) {
$result .= $red $num ": LDR ";
for($spot=1$spot<=6$spot++) {
if($this -> team -> $num[$spot]) {
if($spot == 1) {
$result .= $this -> team -> $num[$spot];
} else {
$result .= " - " $spot "." $this -> team -> $num[$spot];
}
}
}
$this -> bot -> send_pgroup($result);
}
}
if($msg[1] == "clear") {
foreach($this -> pgroup as $player) {
$this -> pgroup[$player] = "lft";
unset($this -> team);
}
$this -> bot -> send_pgroup($red "Teams cleared");
}
if(preg_match("#^[0-9]#"$msg[1], $info)) {
$team $msg[1];
$spot count($this -> team)+1;
if ($spot <= 6){
if($msg[2] == "") {
$this -> team -> $team[$spot] = $name;
$this -> bot -> send_pgroup($red $name " assigned to team " $msg[1]);
} else {
$user ucfirst($msg[2]);
if($this -> pgroup[$user]) {
$this -> team -> $team[$spot] = $user;
$this -> bot -> send_pgroup($red $user " assigned to team " $msg[1] . " in spot " $spot);
} else {
$this -> bot -> send_pgroup($red $msg[2] . " not in " $this -> bot -> botname);
}
}
} else {
$this -> bot -> send_pgroup($red "Sorry, team " $team " is currently full.");
}
}
if($msg[1] == spot) {
$team $msg[2];
$count count($this -> team)+1;
$this -> bot -> send_pgroup($count);
}
}


/*
This gets called if someone joins the privgroup
*/
function pgjoin($name)
{
$this -> pgroup[$name] = "lft";
}



/*
This gets called if someone leaves the privgroup
*/
function pgleave($name)
{
if (isset($this -> pgroup[$name])) {
unset($this -> pgroup[$name]);
}
}
}
?>



$this -> pgroup[$name] is not beign set when a person joins the channel as far as I can tell. Also, if someone wants to write the show teams part for me I'm willing to use it. Otherwise, I'll keep working.

Thank you for any help.


EDIT: I added the show teams part of the script, it probably doesn't work, but I have no way of telling without that damn variable getting set.

EDIT: I've updated the code again, this is as far as I can get on my own.

EDIT: Highlighted text (http://www.craized.net/junk/bebot/highlight.php?Teams), dynamically updated.
Title: Teams
Post by: komives on January 21, 2005, 07:48:50 am
notice the defect:

in ($msge[2]), the extra E


if(preg_match("#[0-9]#", $msg[1], $info)) {
         if($msge[2] == "") {
Title: Teams
Post by: craized on January 21, 2005, 08:15:26 am
Thank you, noted and changed, however it made no difference, just something I would have had to deal with later  :x
Title: Teams
Post by: craized on January 22, 2005, 12:19:11 am
Well, I found why the variable wasn't being set, I manage to completely space putting $command["pgjoin"][] = &$teams; up when defining commands, things are moving along, and I'm hoping to finish the module today.

I updated the code up top if anyone wants to give suggestions, its what I'm currently working on.
Title: Teams
Post by: craized on January 26, 2005, 11:30:28 am
I figured its hard enough to read someone else's code, but plain text makes it even worse. I have a highlighted version here (http://www.craized.net/junk/bebot/highlight.php?Teams). I'll try and keep this updated.
Title: Teams
Post by: craized on January 28, 2005, 12:05:19 pm
Well, I finished the teams module, so theres no more use in this thread. I was hoping to get more help for this, but because I didn't I get to take all the credit for it myself. The link up at the top is still completely up to date. It takes the code straight from my bot folder, so if you want exactly what I have, it will always be there. Big thanks to komives for contributing.
Title: here is my implementation been using for some time now
Post by: komives on February 03, 2005, 07:40:44 am
<?php

$teams = new Teams($bot);
$commands["pgmsg"]["teams"] = &$teams;
$commands["pgjoin"][] = &$teams;
$commands["pgleave"][] = &$teams;

class Teams
{
   var $bot;
   var $pgroup;


   function Teams (&$bot)
   {
      $this -> bot = &$bot;
      $this -> pgroup = array();
   }

   function pgmsg($name, $msg)
   {
      if (preg_match("/^" . $this -> bot -> commpre . "teams$/i", $msg))
      {
         $this -> bot -> send_pgroup("<font color=#FF0000>Teams setup for " . $this -> bot -> botname . "\n");

         for($index = 1; $index <= 4; $index++)
         {
            $found = 0;
   
            $result = $index . ": LDR ";

            foreach($this -> pgroup as $player => $team)
            {
               if ($team == $index)
               {
                  $result .= $player . " ";
                  $found += 1;
               }
            }


            if ($found > 0)
               $this -> bot -> send_pgroup($result);
         }

         $found = 0;
         $result = "Unteamed: ";

         foreach($this -> pgroup as $player => $team)
         {
            if ($team == 0)
            {
               $result .= $player . " ";
               $found += 1;
            }
         }

         if ($found > 0)
            $this -> bot -> send_pgroup($result);
      }
      else if (preg_match("/^" . $this -> bot -> commpre . "teams clear$/i", $msg))
      {
         if ($this -> bot -> leader == $name)
         {
            foreach($this -> pgroup as $player => $team)
            {
               $this -> pgroup[$player] = 0;
            }
            $this -> bot -> send_pgroup("Teams cleared");
         }
         else
         {
            $this -> bot -> send_pgroup("You have to be leader to clear team setup.");
         }
      }
      else if (preg_match("/^" . $this -> bot -> commpre . "teams ([0-4])$/i", $msg, $info))
      {
         $found = 0;
   
         $this -> pgroup[$name] = 0;

         foreach($this -> pgroup as $player => $team)
         {
            if ($team == $info[1])
               $found += 1;
         }

         if ($info[1] == 0)
         {
            $this -> bot -> send_pgroup($name . " removed from team setup");
         }
         else if ($found > 5)
         {
            $this -> bot -> send_pgroup($name . " cannot be added to full team " . $info[1]);
         }
         else
         {
            $this -> pgroup[$name] = $info[1];
            $this -> bot -> send_pgroup($name . " assigned to team " . $info[1]);
         }
      }
   }


   function pgjoin($name)
   {
      $this -> pgroup[$name] = 0;
   }

   function pgleave($name)
   {
      if (isset($this -> pgroup[$name]))
      {
         unset($this -> pgroup[$name]);
      }
   }
}

?>
Title: Teams
Post by: craized on February 03, 2005, 10:28:14 am
:shock:  Wish you would have posted this before I spent the time to make mine. But I like mine better anyway, bugs and all.
Title: Teams
Post by: komives on February 03, 2005, 01:52:53 pm
this is based on your work! just modified abit! thanks again
Title: Teams
Post by: craized on February 04, 2005, 02:27:11 am
Hehe didn't recognize it, I'm gonna take yours for a test run and see how things go.

also, quick bug fix:

Code: [Select]

function pgjoin($name) {
if(!$this -> pgroup[$name]) {
$this -> pgroup[$name] = "lft";
$this -> teams = ceil(count($this -> pgroup)/6);
}
}



/*
This gets called if someone leaves the privgroup
*/
function pgleave($name) {
if ($this -> pgroup[$name] == "lft") {
unset($this -> pgroup[$name]);
}
}


This will prevent the bot from displaying a user in a team and in the unteamed list.
SimplePortal 2.3.7 © 2008-2024, SimplePortal