collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Teams  (Read 3800 times)

0 Members and 1 Guest are viewing this topic.

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« 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, dynamically updated.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline komives

  • BeBot Rookie
  • *
  • Posts: 9
  • Karma: +0/-0
Teams
« Reply #1 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] == "") {
Mage 218 NT/RK2

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« Reply #2 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
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« Reply #3 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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« Reply #4 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. I'll try and keep this updated.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« Reply #5 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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline komives

  • BeBot Rookie
  • *
  • Posts: 9
  • Karma: +0/-0
here is my implementation been using for some time now
« Reply #6 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]);
      }
   }
}

?>
Mage 218 NT/RK2

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« Reply #7 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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline komives

  • BeBot Rookie
  • *
  • Posts: 9
  • Karma: +0/-0
Teams
« Reply #8 on: February 03, 2005, 01:52:53 pm »
this is based on your work! just modified abit! thanks again
Mage 218 NT/RK2

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Teams
« Reply #9 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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 406
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal