Archive > AoC 0.6.x Custom/Unofficial modules

New module - Raid Relics tracker

(1/2) > >>

Xene:
Hey

This module cant be run a 0.6.9 version of the bot, i run it perfectly on a 0.6.8 version of the bot. Seems that the table construction isnt valid on the first bot mentioned.

Any ideas?

Xene

Since i couldnt make an attachment i have copied the module here:

<?php
/*
* RaidRelics.php  --- RaidRelics
* <Copyright Xene @ Crom Aoc>
*
*
*/
$version = "b1.0.0 - 2014-10-03";
// b1.0.0 First version of the module
/*
* BeBot - An Anarchy Online & Age of Conan Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stens?s, ShadowRealm Creations and the BeBot development team.
*
*/
$Relics = new RaidRelics($bot);
$Relics -> version = $version;

class RaidRelics extends BaseActiveModule
{
   var $version;
   /*
   * Defining the arrays needed for the module based on Tier and Location
   */
   var $Tier_relics_rare_name = array ('Rare','Rare','Dragon Tear');
   var $Tier_relics_name = array ('Simple I', 'Simple II', 'Simple III', 'Simple IV', 'Simple IV');
   var $Tier_name_short = array ('T1','T2','T3','T3.5','T4');
   var $Tier_name_long = array ('Tier 1','Tier 2','Tier 3','Tier 3.5', 'Tier 4');
   var $Armor_Location = array ('Head','Chest','Legs','Shoulders','Wrists','Hands','Belt','Boots');
   var $Tier_relics_simple = array ( 0 => array (6,6,6,4,4,4,4,4),
                             1 => array (10,10,10,7,7,7,7,7),
                             2 => array (60,60,60,40,40,40,40,20),
                             3 => array (40,40,40,25,25,25,25,25),
                             4 => array (60,60,60,40,40,40,40,40));
   var $Tier_relics_rare = array (0,0,1,2,1);
   var $Tier_gold = array (2,3,5,5,7);
   
   function __construct (&$bot)
   {
      /* Constructor: Hands over a ref to the "Bot" class. */
      // Initialize the base module
      parent::__construct(&$bot, get_class($this));
      $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " .
         $this -> bot -> db -> define_tablename("RaidRelics", "True") . "(
         `RaidRelics_id` int(11) NOT NULL AUTO_INCREMENT,
         `RaidRelics_username` varchar(255) DEFAULT NULL,
         `RaidRelics_tier` varchar(10) DEFAULT NULL,
         `RaidRelics_item` varchar(100) DEFAULT NULL,
         `RaidRelics_rare` int(11) DEFAULT NULL,
         `RaidRelics_relics` int(11) DEFAULT NULL,
         `RaidRelics_gold`int(11) DEFAULT NULL,
         PRIMARY KEY (`RaidRelics_id`))");
      
                  
      $this -> register_command('all', 'relics', 'MEMBER');
      $this -> help['description'] = "This module helps you keep track of relics won in raids.";
      $this -> help['command']['relics '] = "Show which items you have and how many relics you need to complete the tier";
      $this -> help['command']['relics show <another char>'] = "Shows the relics for other chars that is registered.";
      $this -> help['command']['relics add <Tier> <Body part>'] = "Adds a new item to your list. \n <Body part> = Head, Chest, Legs, Shoulders, Wrists, Hands, Belt, Boots";
      $this -> help['notes'] = " (C) Module by Xene@Crom\n";
   }
   function command_handler($name, $msg, $origin)
   {
      /* Unified message handler
            $name: The origin player
            $msg: the actual message, including command prefix and all
            $origin: the channel the message arrived from. This can be either "tell" or "gc"
      */
      $com = $this -> parse_com($msg);
      switch($com['com'])
      {
         case 'relics':
            return($this->sub_handler($name,$com,1));
         break;
         default:
            return "Error 1";
         break;
      }
   }
   function sub_handler($name,$com,$type)
   {
      switch($com['sub'])
      {
         case 'add':
            return($this -> relics_add($name, $com['args']));
         break;
         case 'show':
            return($this -> relics_show($name, $com['args']));
         break;
         default:
            return($this -> relics_show($name, $com['args']));
         break;
      }
   }
   function relics_add($name,$args)
   {
      $arr = explode(" ", $args);
      $firstspace = strpos($args, ' ');
      $i = -1;
      $n = -1;
      $num = 0;
      empty($result);
      $armor_exist = FALSE;
      $higher_tier_not_exist = FALSE;
      $armor_is_in_list = FALSE;
      
      for ($i=0;$i<=4;$i++)
      {
         if ($this->Tier_name_short[$i]==$arr[0])
         {
            $tier_found = $i;
         }
      }
      for ($n=0;$n<=7;$n++)
      {
         if ($this->Armor_Location[$n]==$arr[1])
         {
            $armor_is_in_list = TRUE;
            $armor_found = $n;
         }
      }
      if (!$armor_is_in_list)
      {
         Return "Wrong item name!";
      }
      
      $RaidRelics_username = mysql_real_escape_string($name);
      $RaidRelics_tier = $arr[0];
      $RaidRelics_item = $this -> Armor_Location[$armor_found];
      $RaidRelics_gold = $this -> Tier_gold[$tier_found];
      $RaidRelics_relics = $this -> Tier_relics_simple[$tier_found][$armor_found];
      $RaidRelics_rare = $this -> Tier_relics_rare[$tier_found];
      
      // Check if the item is already in the list for this char
      
      $sql = "SELECT * FROM #___RaidRelics WHERE RaidRelics_username = '$name'";
      $result = $this -> bot -> db -> select($sql);
      
      
      if (!empty($result))
      {
         foreach ($result as $val)
         {
            $rr_tier[$num] = $val[2];
            $rr_item[$num] = $val[3];
            $rr_rare[$num] = $val[4];
            $rr_simple[$num] = $val[5];
            $rr_gold[$num] = $val[6];
            $num++;
         }
         
         $armor_exist = FALSE;
         $higher_tier_exist = TRUE;
         for ($z=0;$z<=$num-1;$z++)
         {
            if ($rr_item[$z] == $this->Armor_Location[$armor_found])
            {
               for ($x=0;$x<=4;$x++)
               {
                  if ($this->Tier_name_short[$x]==$rr_tier[$z])
                  {
                     $tier_in_database = $x;
                  }
               }
               if ($tier_in_database < $tier_found)
               {
                  $higher_tier_exist = FALSE;
               }
               $armor_exist = TRUE;
            }
         }
         if ($armor_exist)
         {
            if (!$higher_tier_exist)
            {
               $sql = "UPDATE #___RaidRelics SET RaidRelics_tier='$RaidRelics_tier',
               RaidRelics_rare='$RaidRelics_rare',RaidRelics_relics='$RaidRelics_relics',
               RaidRelics_gold='$RaidRelics_gold' WHERE RaidRelics_username='$name' AND RaidRelics_item='$arr[1]'";
            }
            else
            {
               return "Higher tier is already in the database!";
            }
         }
         else
         {
            $sql = "INSERT INTO #___RaidRelics (RaidRelics_username,RaidRelics_tier,RaidRelics_item,RaidRelics_rare,RaidRelics_relics,RaidRelics_gold)
                  VALUES ('$RaidRelics_username','$RaidRelics_tier','$RaidRelics_item','$RaidRelics_rare','$RaidRelics_relics','$RaidRelics_gold')";   
         }
         $this -> bot -> db ->  query($sql);
         
      }
      else
      {
         $sql = "INSERT INTO #___RaidRelics (RaidRelics_username,RaidRelics_tier,RaidRelics_item,RaidRelics_rare,RaidRelics_relics,RaidRelics_gold)
               VALUES ('$RaidRelics_username','$RaidRelics_tier','$RaidRelics_item','$RaidRelics_rare','$RaidRelics_relics','$RaidRelics_gold')";
         $this -> bot -> db ->  query($sql);
      }
      return $this->relics_show($name,null);
      
   }
   function relics_show($name,$args)
   {
      if (!empty($args))
      {
          $name = mysql_real_escape_string($args);
        }

      $num = 0;
      empty($result);
      
      $guide = "Raid armor for " . $name . "\n \n \n";
      $guide = $this->bot->core("colors")->colorize("fuchsia", $guide);

      $sql = "SELECT * FROM #___RaidRelics WHERE RaidRelics_username = '" . $name ."'";
      $result = $this -> bot -> db -> select($sql);
      
      if (!empty($result))
      {
         // Fetches the data from base and puts into arrays for counting
         foreach ($result as $val)
         {
            $rr_tier[$num] = $val[2];
            $rr_item[$num] = $val[3];
            $rr_rare[$num] = $val[4];
            $rr_simple[$num] = $val[5];
            $rr_gold[$num] = $val[6];
            $num++;
         }
         $guide .= $this -> bot -> core("colors")->colorize("lightfuchsia","Armor items: \n");
         
         // Adds up collected relics from items
         
         for ($z=0;$z<=$num;$z++)
         {
            for ($i=0;$i<=4;$i++)
            {
               if ($rr_tier[$z] == $this -> Tier_name_short[$i])
               {
                  for ($n=0;$n<=7;$n++)
                  {
                     if ($rr_item[$z] == $this -> Armor_Location[$n])
                     {
                        $colrare[$i] = $colrare[$i] + $this->Tier_relics_rare[$i];
                        $colsim[$i] = $colsim[$i] + $this->Tier_relics_simple[$i][$n];
                        $colgold[$i] = $colgold[$i] + $this->Tier_gold[$i];
                        if ($i>0)
                        {
                           for ($x=0;$x<$i;$x++)
                           {
                              $colrare[$x] = $colrare[$x] + $this->Tier_relics_rare[$x];
                              $colsim[$x] = $colsim[$x] + $this->Tier_relics_simple[$x][$n];
                              $colgold[$x] = $colgold[$x] + $this->Tier_gold[$x];
                           }
                        }
                     }
                  }
               }
            }
         }
         
         // Build up the report
         
         for ($n=0;$n<=7;$n++)
         {
            for ($z=0;$z<=$num;$z++)
            {
               if ($rr_item[$z] == $this -> Armor_Location[$n])
               {
                  for ($i=0;$i<=4;$i++)
                  {
                     if ($rr_tier[$z] == $this -> Tier_name_short[$i])
                     {
                        $guide .= $this -> bot -> core("colors")->colorize("bluesilver",$this -> Armor_Location[$n] . " : " . $this -> Tier_name_long[$i] . "\n");
                        $note = TRUE;
                     }
                     
                  }
               }
               
            }
            if (!$note)
            {
               $guide .= $this -> bot -> core("colors")->colorize("bluesilver", $this -> Armor_Location[$n] . " : " . "none \n");
            }
            $note = FALSE;
         }
         $guide .= $this -> bot -> core("colors")->colorize("lightfuchsia","Relics needed: \n");
         for ($n=0;$n<=4;$n++)
         {
            $i = 0;
            for ($i=0;$i<=7;$i++)
            {
               if ($i<=2)
               {
                  $simrare[$n] = $simrare[$n] + $this->Tier_relics_rare[$n];
               }
               $simrel[$n] = $simrel[$n] + $this->Tier_relics_simple[$n][$i];
               $simgold[$n] = $simgold[$n] + $this->Tier_gold[$n];
            }
            $simrare[$n] = $simrare[$n] - $colrare[$n];
            $simrel[$n] = $simrel[$n] - $colsim[$n];
            $simgold[$n] = $simgold[$n] - $colgold[$n];
            $guide .= $this->bot->core("colors")->colorize("green", $this->Tier_name_long[$n] . ": ");
            if ($simrare[$n]>0)
            {
               $guide .= $this->bot->core("colors")->colorize("lime", $simrare[$n] . " " . $this->Tier_relics_rare_name[$n-2] ." , ");
            }
            $guide .= $this->bot->core("colors")->colorize("lightteal", $simrel[$n] ." ". $this->Tier_relics_name[$n]);
            $guide .= $this->bot->core("colors")->colorize("green"," and " );
            $guide .= $this->bot->core("colors")->colorize("gold", $simgold[$n] . " gold! \n");
            $simrel[$n+1] = 0;
            $simgold[$n+1] = 0;
            $simrare[$n+1] = 0;
         }   
         empty($result);
      }
      else
      {
         $guide .= $this->bot->core("colors")->colorize("red","No items gathered! \n");
         $rarname = "";
         for ($n=0;$n<=4;$n++)
         {
            $i = 0;
            for ($i=0;$i<=7;$i++)
            {
               if ($i<=2)
               {
                  $simrare = $simrare + $this->Tier_relics_rare[$n];
               }
               $simrel = $simrel + $this->Tier_relics_simple[$n][$i];
               $simgold = $simgold + $this->Tier_gold[$n];
            }
            $guide .= $this->bot->core("colors")->colorize("green", $this->Tier_name_long[$n] . ": ");
            if ($simrare>0)
            {
               $guide .= $this->bot->core("colors")->colorize("lime", $simrare . " " . $this->Tier_relics_rare_name[$n-2] ." , ");
            }
            $guide .= $this->bot->core("colors")->colorize("lightteal", $simrel ." ". $this->Tier_relics_name[$n]);
            $guide .= $this->bot->core("colors")->colorize("green"," and " );
            $guide .= $this->bot->core("colors")->colorize("gold", $simgold . " gold! \n");
            $simrel = 0;
            $simgold = 0;
            $simrare = 0;
         }   
      }
      
      return $this -> bot -> core("tools") -> make_blob("Relics",$guide);
   }

}
?>

Getrix:
Are you using the same database or seperate for each bot version?

Is there any error output in console, when starting up or typing the commando in guild chat/msg?

Xene:
Two different databases on two seperated machines. On the machine with the 0.6.9 version it will not initialize even. I get this msg:

Fatal Error: Call-time pass-by-referance has been removed in "Referance to this module" in line 42.

When i rename it to: _module.php the bot starts fine and works fine

Getrix:
Is the filename "modules.php"? Make sure to rename it to RaidRelics.php and keep it in Botpath\custom\modules

Whats on your line nr 42 in the file?

I tried the file with 0.6.9-snapshot and it did not crash.

Xene:
Line 42:   parent::__construct(&$bot, get_class($this));

Even with the suggested changes same error.

Navigation

[0] Message Index

[#] Next page

Go to full version