Here is the Bid.php that I am using.
In our Guild we use a closed bidding system.
When someone bids the bot will only announce that someone has bid, it will not announce how much.
Commands:
Admin: !bid start <item>
Admin: !bid status = shows who is bidding on the item
Admin: !bid end = ends the bid
player: !bid <points>
player: !bid 0 = cancels your bid.
player: !bind info = shows info on the current item up for bid.
If someone bids for an item and then later decides he/she doesnt want it they can bid again with a 0 value to removed from the bid.
Thanks to Temar for making these changes.
<?php
/*
* Bid.php - Raid bidding.
*
* 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.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
* - Temar (RK1)
*
* See Credits file for all aknowledgements.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* File last changed at $LastChangedDate: 2008-11-30 17:09:06 -0500 (Sun, 30 Nov 2008) $
* Revision: $Id: Bid.php 1833 2008-11-30 22:09:06Z alreadythere $
*/
$bid = new Bid($bot);
/*
The Class itself...
*/
class Bid extends BaseActiveModule
{
var $help;
var $bid;
var $maxbid;
var $secondbid;
var $highestbidder;
var $announce;
var $announced;
var $end;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function __construct(&$bot)
{
parent::__construct(&$bot, get_class($this));
$this -> bid = "";
$this -> register_command('tell', 'bid', 'MEMBER');
$this -> help['description'] = "Handles auctions using raid points";
$this -> help['command']['bid start <item>'] = "Starts an auction for <item>. <item> can be text or an item ref.";
$this -> help['command']['bid end'] = "Ends the current auction.";
$this -> help['command']['bid <points>'] = "Bid <points> raid points for the item currently on auction.";
$this -> help['command']['bid info'] = "Shows information about the current auction.";
$this -> help['command']['bid status'] = "Shows bids on current/last auction.";
}
/*
This gets called on a tell with the command
*/
function command_handler($name, $msg, $origin)
{
$msg = explode(" ", $msg, 3);
Switch($msg[1])
{
case 'start':
$this -> start_bid($name, $msg[2]);
Break;
case 'info':
$this -> info_bid($name);
Break;
case 'end':
$this -> end_bid($name);
Break;
case 'bids':
case 'status':
$this -> bid_list($name);
Break;
Default:
if(is_numeric($msg[1]))
$this -> place_bid($name, $msg[1]);
else
$this -> bot -> send_help($name);
}
}
/*
Starts the bidding
*/
function start_bid($name, $item)
{
if ($this -> bot -> core("security") -> check_access($name, "leader"))
{
$this -> bid = $item;
$this -> maxbid = 1;
// $this -> secondbid = 1;
// $this -> highestbidder = "";
$this -> bidders = array();
$this -> announce = time() + 15;
$this -> announced = false;
//$this -> end = time() + 120;
//$this -> register_event("cron", "2sec");
$msg = "\n##highlight##-------------------------------------##end##\n";
$msg .= "##highlight##$name##end## started auction ";
$msg .= "on ##highlight##$item##end##! :: " . $this -> info() ."\n";
$msg .= "Note: ##red##Your MAX BID will be deducted##end##! ";
$msg .= "\n##highlight##-------------------------------------##end##";
$this -> bot -> send_output("", $msg, "both");
}
else
$this -> bot -> send_tell($name, "You must be a raidleader to do this");
}
/*
Place a bid
*/
function place_bid($name, $amount)
{
$update = true;
if (empty($this -> bid))
{
$this -> bot -> send_tell($name, "No auction in progress.");
return false;
}
else if ($amount < 30 && $amount != 0)
{
$this -> bot -> send_tell($name, "Min bid is set to ##highlight##30##end## raidpoints.");
return false;
}
$result = $this -> bot -> db -> select("SELECT points FROM #___raid_points WHERE id = " . $this -> points_to($name));
if (empty($result))
{
$this -> bot -> send_tell($name, "You appear to not have any points yet. No points table entry found.");
return false;
}
$result = $result[0][0];
//$currenthigh = (($this -> maxbid == $this -> secondbid) ? ($this -> maxbid) : ($this -> secondbid + 1));
if ($result < $amount)
{
$this -> bot -> send_tell($name, "You only have ##highlight##" . $result .
"##end## raidpoints. Please place bid again.");
return false;
}
//else if ($this -> maxbid == $amount)
//{
// $this -> secondbid = $amount;
//}
//else if ($this -> maxbid < $amount)
//{
// if ($name != $this -> highestbidder)
// {
// $this -> secondbid = $amount;
// $this -> maxbid = $amount;
// $this -> highestbidder = $name;
// }
// $this -> maxbid = $amount;
//}
//else if ($currenthigh < $amount)
//{
// if ($name != $this -> highestbidder)
// $this -> secondbid = $amount;
//}
//$highest = (($this -> maxbid == $this -> secondbid) ? ($this -> maxbid) : ($this -> secondbid + 1));
//if ($highest != $currenthigh)
//{
// $secs = $this -> end - time();
// if ($secs < 10)
// {
// $secs = 10;
// $this -> end = time() + 10;
// }
if(!isset($this -> bidders[$name]) && $amount == 0)
{
Return("Unable to Remove bid as you have not Bid!");
}
elseif(!isset($this -> bidders[$name]))
{
$this -> bidders[$name] = array($amount, time());
$this -> bot -> send_output("", "##highlight## Someone Has Bid! ##end## :: " . $this -> info(), "both");
}
elseif($this -> bidders[$name][0] < $amount)
{
$this -> bidders[$name] = array($amount, time());
$this -> bot -> send_output("", "##highlight## Someone Has Increased there Bid! ##end## :: " . $this -> info(), "both");
}
elseif($amount == 0)
{
$this -> bidders[$name] = array($amount, time());
$this -> bot -> send_output("", "##highlight## Someone Has Removed there Bid! ##end## :: " . $this -> info(), "both");
}
elseif($this -> bidders[$name][0] < $amount)
{
$this -> bidders[$name] = array($amount, time());
$this -> bot -> send_output("", "##highlight## Someone Has Decreased there Bid! ##end## :: " . $this -> info(), "both");
}
//}
}
/*
Gets called on a cronjob...
*/
function end_bid($name)
{
if ($this -> bot -> core("security") -> check_access($name, "leader"))
{
if(empty($this -> bid))
{
$this -> bot -> send_output("", "Auction is not running.", "both");
}
elseif (empty($this -> bidders))
{
$this -> bot -> send_output("", "Auction is over. No bids where placed. Item is FFA.", "both");
}
else
{
//$highest = (($this -> maxbid == $this -> secondbid) ? ($this -> maxbid) : ($this -> secondbid + 1));
$high = array(0, 0, "");
foreach($this -> bidders as $name => $bid)
{
if($bid[0] > $high[0])
$high = array($bid[0], $bid[1], $name);
elseif($bid[0] == $high[0] && $bid[1] > $high[1])
$high = array($bid[0], $bid[1], $name);
}
if($high[0] == 0)
{
$this -> bot -> send_output("", "Auction is over. No bids where placed. Item is FFA.", "both");
}
else
{
$this -> bot -> send_output("", "##highlight##".$high[2]."##end## has won the auction for ##highlight##" .
$this -> bid . "##end##. ##highlight##".$high[0]."##end## points are being deduced from his account.", "both");
$this -> bot -> db -> query("UPDATE #___raid_points SET points = points - " . $high[0] .
" WHERE id = " . $this -> points_to($high[2]));
}
}
$this -> bid = FALSE;
//$this -> unregister_event("cron", "2sec");
}
}
function bid_list($name)
{
if ($this -> bot -> core("security") -> check_access($name, "SuperAdmin"))
{
if(empty($this -> bid))
$inside = " :: Bidders for Last Auction :: \n\n";
else
$inside = " :: Current Bids :: \n\n";
if(!empty($this -> bidders))
{
foreach($this -> bidders as $user => $bid)
{
$inside .= "##highlight##$user##end## has bid ##highlight##".$bid[0]."##end##\n";
}
}
if(empty($this -> bid))
$msg = "Bidders for Last Auction :: ";
else
$msg = "Current Bids :: ";
$msg .= $this -> bot -> core("tools") -> make_blob("Click to View", $inside);
$this -> bot -> send_tell($name, $msg);
}
}
/*
Show info about bidding
*/
function info_bid($name)
{
$inside = "##blob_title##::::: Bidding info :::::##end##\n\n";
$inside .= "To place a bid write:\n";
$inside .= "##blob_text##/tell <botname> <pre>bid <points>##end##\n";
$inside .= "(Replace <points> with the number of points you would like to bid)\n\n";
$inside .= "First you may place your bids as stated above.\n";
$inside .= "but please try to bid the highest you're willing to pay right from the start to not make auctions last too long.\n\n";
$inside .= "If two people bid the same amount, the first of the two who placed a bid will get the item. ";
$inside .= "So it really does help bidding the max you're willing to spend right from the start instead of trying \n";
$inside .= "to correct later on.\n";
$this -> bot -> send_tell ($name, "Infomation about bidding :: " . $this -> bot -> core("tools") -> make_blob("click for info", $inside));
}
/*
Show info about bidding
*/
function info()
{
$inside = "##blob_title##::::: Bidding info :::::##end##\n\n";
$inside .= "To place a bid write:\n";
$inside .= "##highlight##/tell <botname> <pre>bid <points>##end##\n";
$inside .= "(Replace <points> with the number of points you would like to bid)\n";
return $this -> bot -> core("tools") -> make_blob("click for info", $inside);
}
/*
Get correct char for points
*/
function points_to($name)
{
return $this -> bot -> commands["tell"]["points"] -> points_to($name);
}
}
?>