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

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

Author Topic: Help with Buff-Module  (Read 15853 times)

0 Members and 1 Guest are viewing this topic.

Offline Catscratch

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Help with Buff-Module
« on: July 22, 2007, 01:39:44 pm »
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: [Select]
<?
/*
* 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);
}
}

}
?>

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
« Last Edit: July 22, 2007, 06:38:31 pm by Catscratch »

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Help with Buff-Module
« Reply #1 on: July 22, 2007, 01:46:54 pm »
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.

Offline Catscratch

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Help with Buff-Module
« Reply #2 on: July 22, 2007, 03:46:03 pm »
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.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Help with Buff-Module
« Reply #3 on: July 22, 2007, 05:26:43 pm »
$this->bot->notify->add("Buff Module", $name);

Offline Catscratch

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Help with Buff-Module
« Reply #4 on: July 22, 2007, 06:36:48 pm »
It's the same as before.

I tried:
Code: [Select]
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);
}

But at this point, the bot restarts.

Offline Catscratch

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Help with Buff-Module
« Reply #5 on: July 24, 2007, 06:30:55 pm »
Ok, I thought that I'm using Bebot 0.3, but I'm using version 0.2x. May this help to find out why this buddy_add function don't work?

I also tried to add this module to the new version 0.4. But there this module isn't loaded. I think I have to tansform something to bring it up in new bebot. But at this time, I don't know exactly what.

Thanks for help.
« Last Edit: July 24, 2007, 06:32:30 pm by Catscratch »

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Help with Buff-Module
« Reply #6 on: July 24, 2007, 08:22:37 pm »
notify->add() takes the player name. But of course it won't work in 0.2, there you'll have to adapt the inc_buddy() function in Bot.php to handle notifies outside of members.

In 0.4 you just need to call the notify->add() function, it does all the ckecking and adding. No need to check the buddy list yourself there.

Just make sure you don't go over 1k buddies, or you'll most likely get disconnected from the chatserver.

Offline clashbot

  • BeBot Expert
  • ****
  • Posts: 295
  • Karma: +0/-0
    • Ascension's Home
Re: Help with Buff-Module
« Reply #7 on: January 29, 2008, 06:40:31 pm »
have we got this working so it will work with the .4 version?

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


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


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

* Who's Online
  • Dot Guests: 258
  • 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