Archive > BeBot 0.3 support
Help with Buff-Module
Catscratch:
Hi there,
I'm developing a buff-module for bebot. But I've got a problem with the bebot buddy function.
I want that these bot is open for everyone. So a player can add his buffs. Now I want the remove this player, if he goes offline. Therefor I used the buddy function with buddy_add(...).
But in my module, the player is removed immediately after he registers his buff.
I hope someone could help me. I don't know whats wrong.
The buff module:
--- Code: ---<?
/*
* Buffs.php
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
*
*/
$buffs = new buffs($bot);
$commands["tell"]["buffs"] = &$buffs;
$commands["pgmsg"]["buffs"] = &$buffs;
/*
The Class itself...
*/
class Buffs
{
var $bot;
var $buffs;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function Buffs (&$bot)
{
$this -> bot = &$bot;
$this -> buffs = array();
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "buffs add (.+)/i", $msg, $info))
$this -> buffers_add($name, $info[1], 1);
else if (preg_match("/^" . $this -> bot -> commpre . "buffs del/i", $msg, $info))
$this -> buffers_del($name, 1);
else if (preg_match("/^" . $this -> bot -> commpre . "buffs clear/i", $msg, $info))
$this -> buffers_del_all($name, 1);
else if (preg_match("/^" . $this -> bot -> commpre . "buffs/i", $msg))
$this -> bot -> send_pgroup($this -> show_buffers());
}
function tell($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "buffs add (.+)/i", $msg, $info))
$this -> buffers_add($name, $info[1], 2);
else if (preg_match("/^" . $this -> bot -> commpre . "buffs del/i", $msg, $info))
$this -> buffers_del($name, 2);
else if (preg_match("/^" . $this -> bot -> commpre . "buffs clear/i", $msg, $info))
$this -> buffers_del_all($name, 2);
else if (preg_match("/^" . $this -> bot -> commpre . "buffs/i", $msg))
$this -> bot -> send_tell($name, $this -> show_buffers());
}
/*
Add a buffer
*/
function buffers_add($name, $buffs, $nr)
{
$name = ucfirst(strtolower($name));
if ($this -> bot -> aoc -> get_uid($name))
{
$this -> buffs[$name] = $buffs;
if($nr == 1)
$this -> bot -> send_pgroup("<font color=#ffff00>" . $name . "</font> has been added to buffers list. ($buffs) " . $this -> show_buffers());
else
$this -> bot -> send_tell($name, "<font color=#ffff00>" . $name . "</font> has been added to buffers list. ($buffs) " . $this -> show_buffers());
}
else if($nr == 1)
$this -> bot -> send_pgroup("Player <font color=#ffff00>" . $name . "</font> does not exist.");
else if($nr == 2)
$this -> bot -> send_tell($name, "Player <font color=#ffff00>" . $name . "</font> does not exist.");
}
/*
Remove a buffer
*/
function buffers_del($name, $nr)
{
$name = ucfirst(strtolower($name));
if ($name == "All")
{
$this -> buffs = array();
$this -> bot -> send_pgroup("List of buffers has been cleared.");
}
else if ($this -> bot -> aoc -> get_uid($name) != -1)
{
if (isset($this -> buffs[$name]))
{
unset($this -> buffs[$name]);
if($nr == 1)
$this -> bot -> send_pgroup("<font color=#ffff00>" . $name . "</font> has been removed from buffers list. " . $this -> show_buffers());
else
$this -> bot -> send_tell($name, "<font color=#ffff00>" . $name . "</font> has been removed from buffers list. " . $this -> show_buffers());
}
else if($nr == 1)
$this -> bot -> send_pgroup("<font color=#ffff00>" . $name . "</font> is not on list of buffers. " . $this -> show_buffers());
else
$this -> bot -> send_tell($name, "<font color=#ffff00>" . $name . "</font> is not on list of buffers. " . $this -> show_buffers());
}
else if($nr == 1)
$this -> bot -> send_pgroup("Player <font color=#ffff00>" . $name . "</font> does not exist.");
else
$this -> bot -> send_tell($name, "Player <font color=#ffff00>" . $name . "</font> does not exist.");
}
function buffers_del_all($name, $nr)
{
if ($this -> bot -> admin -> in_group($name, "admin"))
{
$this -> buffs = array();
if($nr == 1)
$this -> bot -> send_pgroup("List of buffers has been cleared.");
else
$this -> bot -> send_tell($name, "List of buffers has been cleared.");
}
else if($nr == 1)
$this -> bot -> send_pgroup("You must be an admin to access this command.");
else
$this -> bot -> send_tell($name, "You must be an admin to access this command.");
}
/*
Return the list of buffers
*/
function show_buffers()
{
$buff = array_keys($this -> buffs);
if (empty($buff))
return "No buffers on list.";
else
{
$list = "<font color=CCInfoHeadline>::: List of buffers :::</font>\n\n";
foreach ($buff as $player) {
$tempname = ucfirst(strtolower($player));
$templist .= " - <a href='chatcmd:///tell $player'>$player</a>: ".$this -> buffs[$tempname];
$uid = $this -> bot -> aoc -> get_uid($tempname);
if (!($this -> bot -> aoc -> buddy_exists($uid))) {
$this -> bot -> aoc -> buddy_add($uid);
//$templist .= " #no# ";
} else;
//$templist .= " #yes# ";
if($this -> bot -> aoc -> buddy_online($uid));
// $templist .= "- online\n";
else {
//$templist .= "- offline\n";
if (isset($this -> buffs[$tempname]))
{
unset($this -> buffs[$tempname]);
}
}
$list .= $templist;
}
return $this -> bot -> make_blob("List of Buffers", $list);
}
}
}
?>
--- End code ---
The last function (show_buffers) is this one, where this error occurs.
I do "$this -> bot -> aoc -> buddy_add($uid);" and after this I call "if($this -> bot -> aoc -> buddy_online($uid));" and thats always false at the first time. If I call this method after show_buffers was successful, it returns true. But why?
It may be helpful, if you test this module in your own bebot. :-)
Thanks for help,
(and sry for my bad english) ;)
MFG
Alreadythere:
Characters not on the notify list will be removed as buddies right away.
Which mean you'll have to add everyone that is registering to the notify list first.
$this->bot->notify->add($source, $name) is the function for this.
Catscratch:
Can you give me an example, how to register right?
I tried: $this -> bot -> notify -> add($this, $uid);
I thought, $source is the source-class, isn't it?
With this code above, the bot restarts at this point.
Thanks.
Alreadythere:
$this->bot->notify->add("Buff Module", $name);
Catscratch:
It's the same as before.
I tried:
--- Code: ---if (!($this -> bot -> aoc -> buddy_exists($uid))) {
$this -> bot -> notify -> add("Buff Module", $uid); // I also tried player's name
$this -> bot -> aoc -> buddy_add($uid);
}
--- End code ---
But at this point, the bot restarts.
Navigation
[0] Message Index
[#] Next page
Go to full version