Archive > AO official modules

Updated Points.php

(1/5) > >>

Khalem:
This adds support to view single users points by: points <name> aswell as ability to view top25 points by: points top25 (actually, points top<anynumber>, but it will only return top 25)


--- Code: ---
<?
  /*
   * Points.php - Handles raidpoints.
   *
   * BeBot - An Anarchy Online Chat Automaton
   * Copyright (C) 2004 Jonas Jax
   *
   * Developed by Blondengy (RK1)
   * Special thanks goes out to Khalem (RK1) for his support.
   *
   * File last changed at $LastChangedDate: 2004-12-29 01:41:32 +0100 (Wed, 29 Dec 2004) $
   * Revision: $Id: Points_RAID.php 8 2004-12-29 00:41:32Z blondengy $
   */


  $points = new Points($bot);

  $commands["tell"]["points"] = &$points;


  $db -> query("CREATE TABLE IF NOT EXISTS raid_points
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
              points INT,
                                                        raiding TINYINT DEFAULT '0')");




  /*
    The Class itself...
  */
  class Points
  {
    var $bot;
    var $transfer;
    var $tomain;



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

      $result = $this -> bot -> db -> select("SELECT value FROM settings WHERE setting = 'points_transfer'");
      if (empty($result))
        $this -> transfer = 0;
      else
        $this -> transfer = $result[0][0];

      $result = $this -> bot -> db -> select("SELECT value FROM settings WHERE setting = 'points_tomain'");
      if (empty($result))
        $this -> tomain = 0;
      else
        $this -> tomain = $result[0][0];
    }



    /*
      This gets called on a tell with the command
    */
    function tell($name, $msg)
    {
                        if (preg_match("/^" . $this -> bot -> commpre . "points give (.+) ([0-9]+)$/i", $msg, $info))
                                $this -> give_points($name, $info[1], $info[2]);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points add (.+) ([0-9]+)$/i", $msg, $info))
                                $this -> add_points($name, $info[1], $info[2]);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points (del|rem) (.+) ([0-9]+)$/i", $msg, $info))
                                $this -> rem_points($name, $info[2], $info[3]);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points transfer (on|off)$/i", $msg, $info))
                                $this -> transfer_points($name, $info[1]);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points tomain (on|off)$/i", $msg, $info))
                                $this -> tomain_points($name, $info[1]);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points all$/i", $msg))
                                $this -> all_points($name);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points top([0-9]+)$/i", $msg))
                                $this -> top_points($name);
                        else if (preg_match("/^" . $this -> bot -> commpre . "points (.+)$/i", $msg, $info))
                                $this -> show_points($name, $info[1]);

                        else
                                $this -> show_points($name, false);
    }



    /*
                Shows your points
    */
    function show_points($name, $target)
    {
        if (!$target)
        {
                if (!$this -> bot -> aoc -> get_uid($target))
                {
                        $this -> bot -> send_tell ($name, "Player <font color=#ffff00>$who</font> does not exist.");
                }
                else
                {
                        $result = $this -> bot -> db -> select("SELECT points FROM raid_points WHERE id = " . $this -> points_to($name));
                        $this -> bot -> send_tell($name, "You have <font color=#ffff00>" . ($result[0][0] / 10) . "</font> raidpoints.");
                }
        }
        else
        {
                if ($this -> bot -> admin -> in_group($name, "superadmin") || $this -> bot -> admin -> in_group($name, "admin"))
                {
                        if (!$this -> bot -> aoc -> get_uid($target))
                        {
                                $this -> bot -> send_tell ($name, "Player <font color=#ffff00>$target</font> does not exist.");
                        }
                        else
                        {
                                $result = $this -> bot -> db -> select("SELECT points FROM raid_points WHERE id = " . $this -> points_to($target));
                                $this -> bot -> send_tell($name, "Player " . $target . " has <font color=#ffff00>" . ($result[0][0] / 10) . "</font> raidpoints.");
                        }
                }
                else
                {
                        $this -> bot -> send_tell($name, "You must be an admin to do this");
                }

        }
    }




    /*
                Shows your points
    */
    function all_points($name)
    {
                        if ($this -> bot -> admin -> in_group($name, "superadmin"))
                        {
        $result = $this -> bot -> db -> select("SELECT nickname, points FROM raid_points, members WHERE raid_points.id = members.id AND NOT points = 0 ORDER BY points DESC");
        $inside = "<font color=CCInfoHeadline>:::: All raidpoints ::::</font><font color=CCInfoText>\n\n";
        if (!empty($result))
        foreach ($result as $val)
        {
                $inside .= $val[0] . " <font color=CCCCTextColor>" . ($val[1] / 10) . "</font>\n";
        }

        $this -> bot -> send_tell($name, "All raidpoints :: " . $this -> bot -> make_blob("click to view", $inside));
                        }
                        else
                                $this -> bot -> send_tell($name, "You must be a superadmin to do this");
    }


    /*
                Shows top25 points
    */
    function top_points($name)
    {
        $result = $this -> bot -> db -> select("SELECT nickname, points FROM raid_points, members WHERE raid_points.id = members.id AND NOT points = 0 ORDER BY points DESC LIMIT 0,25");
        $inside = "<font color=CCInfoHeadline>:::: Top 25 raidpoints ::::</font><font color=CCInfoText>\n\n";
        if (!empty($result))
        {
                $num = 1;
                foreach ($result as $val)
                {
                        $inside .= "<font color=CCCCTextColor>" . $num . ".</font> " . $val[0] . " <font color=CCCCTextColor>" . ($val[1] / 10) . "</font>\n";
                        $num++;
                }
                $this -> bot -> send_tell($name, "Top 25 raidpoints :: " . $this -> bot -> make_blob("click to view", $inside));
        }
        else
        {
                $this -> bot -> send_tell($name, "Im sorry but there appears to be no one with raidpoints yet");
        }
    }





    /*
                Use main char's account for points...
    */
    function tomain_points($name, $toggle)
    {
                        if ($this -> bot -> admin -> in_group($name, "superadmin"))
                        {
        $this -> bot -> db -> query("DELETE FROM settings WHERE setting = 'points_tomain'");
                        $toggle == strtolower($toggle);
                                $new = (($toggle == "on") ? 1 : 0);
                                $this -> bot -> db -> query("INSERT INTO settings (setting, value) VALUES ('points_tomain', $new)");

                                $this -> tomain = $new;

                                $add = "";

                                if ($new == 1)
                                {
                                $result = $this -> bot -> db -> select("SELECT id, points FROM raid_points WHERE points != 0");
                                foreach ($result as $res)
                                {
                                        if ($res[0] != $this -> points_to($res[0]))
                                        {
                                                $this -> bot -> db -> query("UPDATE raid_points SET points = 0 WHERE id = " . $res[0]);
                                        $resu = $this -> bot -> db -> select("SELECT points FROM raid_points WHERE id = " . $this -> points_to($res[0]));
                                        if (empty($resu))
                                                $this -> bot -> db -> query("INSERT INTO raid_points (id, points, raiding) VALUES (" . $this -> points_to($res[0]) . ", " . $res[1] . ", 0)");
                                        else
                                                        $this -> bot -> db -> query("UPDATE raid_points SET points = " . ($res[1] + $resu[0][0]) . " WHERE id = " . $this -> points_to($res[0]));
                                        }
                                        }
                                $add = " All points have been transfered.";
                        }

                                $this -> bot -> send_tell($name, "Points going to the main character's account is now <font color=#ffff00>" .
                                                                        (($new == 1) ? "enabled" : "disabled") . "</font>." . $add);
                        }
                        else
                                $this -> bot -> send_tell($name, "You must be a superadmin to do this");
    }




    /*
                Enable/Disable !points give
    */
    function transfer_points($name, $toggle)
    {
                        if ($this -> bot -> admin -> in_group($name, "superadmin"))
                        {
        $this -> bot -> db -> query("DELETE FROM settings WHERE setting = 'points_transfer'");
                        $toggle == strtolower($toggle);
                                $new = (($toggle == "on") ? 1 : 0);
                                $this -> bot -> db -> query("INSERT INTO settings (setting, value) VALUES ('points_transfer', $new)");

                                $this -> transfer = $new;

                                $this -> bot -> send_tell($name, "Transfering points has been <font color=#ffff00>" .
                                                                        (($new == 1) ? "enabled" : "disabled") . "</font>.");
                        }
                        else
                                $this -> bot -> send_tell($name, "You must be a superadmin to do this");
    }




    /*
                Transfers points
    */
    function give_points($name, $who, $num)
    {
        if ($this -> transfer != 0)
        {
        $result = $this -> bot -> db -> select("SELECT points FROM raid_points WHERE id = " .
                                                                                                                                            $this -> points_to($name));

                        if ($num > ($result[0][0] / 10))
                                $this -> bot -> send_tell ($name, "You only have <font color=#ffff00>" .
                                                                                                                                        ($result[0][0] / 10) . "</font> raid points.");
                        else if (!$this -> bot -> aoc -> get_uid($who))
                                $this -> bot -> send_tell ($name, "Player <font color=#ffff00>$who</font> does not exist.");
                        else
                        {
                        $this -> bot -> db -> query("UPDATE raid_points SET points = points - " . ($num * 10) .
                                                                                                                                            " WHERE id = " . $this -> points_to($name));
                        $this -> bot -> db -> query("UPDATE raid_points SET points = points + " . ($num * 10) .
                                                                                                                                            " WHERE id = " . $this -> points_to($who));
                                $this -> bot -> send_tell($name, "You gave <font color=#ffff00>$num</font> raidpoints to <font color=#ffff00>$who</font>.");
                                $this -> bot -> send_tell($who, "You got <font color=#ffff00>$num</font> raidpoints from <font color=#ffff00>$name</font>.");
                        }
                }
                else
                        $this -> bot -> send_tell($name, "Transfering points has been <font color=#ffff00>disabled</font>.");
    }




    /*
                Adds points
    */
    function add_points($name, $who, $num)
    {
                        if ($this -> bot -> admin -> in_group($name, "superadmin"))
                        {
                        if (!$this -> bot -> aoc -> get_uid($who))
                                $this -> bot -> send_tell ($name, "Player <font color=#ffff00>$who</font> does not exist.");
                        else
                        {
                        $this -> bot -> db -> query("UPDATE raid_points SET points = points + " . ($num * 10) .
                                                                                                                                            " WHERE id = " . $this -> points_to($who));
                                $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> added <font color=#ffff00>$num</font> raidpoints to <font color=#ffff00>$who</font>'s account.");
                                $this -> bot -> send_tell($name, "You added <font color=#ffff00>$num</font> raidpoints to <font color=#ffff00>$who</font>'s account.");
                                $this -> bot -> send_tell($who, "<font color=#ffff00>$name</font> added <font color=#ffff00>$num</font> raidpoints to your account.");
                        }
                        }
                        else
                                $this -> bot -> send_tell($name, "You must be a superadmin to do this");
    }




    /*
                Remove points
    */
    function rem_points($name, $who, $num)
    {
                        if ($this -> bot -> admin -> in_group($name, "superadmin"))
                        {
                        if (!$this -> bot -> aoc -> get_uid($who))
                                $this -> bot -> send_tell ($name, "Player <font color=#ffff00>$who</font> does not exist.");
                        else
                        {
                        $this -> bot -> db -> query("UPDATE raid_points SET points = points - " . ($num * 10) .
                                                                                                                                            " WHERE id = " . $this -> points_to($who));
                                $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> removed <font color=#ffff00>$num</font> raidpoints from <font color=#ffff00>$who</font>'s account.");
                                $this -> bot -> send_tell($name, "You removed <font color=#ffff00>$num</font> raidpoints from <font color=#ffff00>$who</font>'s account.");
                                $this -> bot -> send_tell($who, "<font color=#ffff00>$name</font> removed <font color=#ffff00>$num</font> raidpoints from your account.");
                        }
                }
                        else
                                $this -> bot -> send_tell($name, "You must be a superadmin to do this");
    }



                /*
                        Get correct char for points
                */
                function points_to($name)
                {
                        if ($this -> tomain == 0)
                                return $this -> bot -> aoc -> get_uid($name);

                        $main = $this -> bot -> alts -> main($name);
                        return $this -> bot -> aoc -> get_uid($main);
                }
  }
?>

--- End code ---

jjones666:
Hi Khalem,

Had a quick play with this, 3 people have points in guild, yet only 2 showing in top 25...?

Cheers,

-jj-

Khalem:
There is an issue i discovered myself that could be the reason.

The points module was designed for standalone raidbots, and from what i can tell offhand, guild members wont be entered into the points table unless they have actually done !raid join to an active raid at least once.

In short, the points module doesnt take this into account, so it may report that points have been added to someone, but in reality it might not have actually have added them.

jjones666:
Hi Khalem,

Sorry I should have been a little more specific - it was 2AM when I wrote that =)

Basically, the points are on all three people's accounts doing !points from each person but if you do !points top25, it only shows two people in the list.  If you do !points <playername> that works fine also, showing the correct amounts.

I will try and dump SQL table Raid_points to text tonite to double check that all three people actually have points allocated in there (however, restarted bot etc and !points is still giving correct information for all three people).

Cheers,

-b-

Khalem:
Hrm. Another thought.

Are all 3 actually members of the guild?

Navigation

[0] Message Index

[#] Next page

Go to full version