BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => AO 0.6.x Custom/Unofficial modules => Anarchy Online Archive => AO official modules => Topic started by: Akarah on November 28, 2005, 08:57:24 am

Title: modified AlienAttack_GUILD
Post by: Akarah on November 28, 2005, 08:57:24 am
since i hate doing math so much, i added the "time to change" in the city_blob function.

i also "aliased" !cloak to !city by simply adding the 3 commands array entries.

but mostly, the countdown stuff. it's not well done at all, just expanded what was already there really. i could probably word it differently and get away with only one conditional in the $state assignment.

anyhow, here's my change..

in function city_blob, find the line:
Code: [Select]

      $result = $this -> bot -> db -> select("SELECT time, action FROM org_city WHERE action = 'on' OR action = 'off' ORDER BY time DESC LIMIT 0, 1");


add these 2 lines after it:
Code: [Select]

      $avilmin = date("i",3600-(time()-$result[0][0]));
      $avilsec = date("s",3600-(time()-$result[0][0]));


and change the following if-else to this:
Code: [Select]

      if ($result[0][1] == "on")
      {
        $state = "The cloaking device is <font color=#ffff00>enabled</font>." . " It is currently <font color=#ffff00>" . (($result[0][0] > (time() - 3600)) ? "not " : "") . "possible</font> to disable it. " . (($result[0][0] > (time() - 3600)) ? "Change possible in <font color=#ffff00>" . $avilmin . "</font> minutes and <font color=#ffff00>" . $avilsec . "</font> seconds. " : "");
      }
      else
      {
        $state = "The cloaking device is <font color=#ffff00>disabled</font>. It is currently <font color=#ffff00>" . (($result[0][0] > (time() - 3600)) ? "not " : "") . "possible</font> to enable it. " . (($result[0][0] > (time() - 3600)) ? "Change possible in <font color=#ffff00>" . $avilmin . "</font> minutes and <font color=#ffff00>" . $avilsec . "</font> seconds. " : "");
      }
      return $state . $this -> bot -> make_blob("City History", $city);
    }


yup pretty unreadable.. and yup pretty ugly that i do 2 conditionals per assignment, but it works (and i took out the 60*60 calculation too.. unnecessary ;) )

if someone wants to rewrite it and incorporate the changes into svn, then hooray - i couldn't think of a coherent way of wording the message without making more work for myself ;)

cheers!

/Aka
Title: modified AlienAttack_GUILD
Post by: Xenixa on November 28, 2005, 09:24:47 am
Aliased !cloak? The command was always !city ... at least in the copy I have that came with the bot.

Cool idea about Displaying time left before cloak can be raised/lowered however. :)
Title: modified AlienAttack_GUILD
Post by: Akarah on November 28, 2005, 10:21:02 am
yeah, it is !city but i made it also be !cloak, because thats what my guild was used to before and i wanted to keep the transition as minor as possible (aside from the numerous amazingly good things that changed and are better now ;) )
Title: modified AlienAttack_GUILD
Post by: Khalem on November 28, 2005, 08:04:26 pm
I changed the actual code to:
Code: [Select]

      $result = $this -> bot -> db -> select("SELECT time, action FROM org_city WHERE action = 'on' OR action = 'off' ORDER BY time DESC LIMIT 0, 1");

      $avilmin = date("i",3600-(time()-$result[0][0]));
      $avilsec = date("s",3600-(time()-$result[0][0]));
     
      if ($result[0][1] == "on")
      {
        $status = "enable";
        $status2 = "disable";
      }
      else
      {
        $status = "disable";
        $status2 = "enable";
      }

      if($result[0][0] > (time() - 3600))
        $ttchange = true;
      else
        $ttchange = false;

      $state = "The cloaking device is <font color=#ffff00>" . $status . "d</font>.";
      $state .= $ttchange ? "" : " It is now possible to <font color=#ffff00>" . $status2 . "</font> it. ";
      $state .= $ttchange ? " It will be possible to <font color=#ffff00>" . $status2 . "</font> it in " . $avilmin . "</font> minutes and <font color=#ffff00>" . $avilsec . "</font> seconds. " : "";
      return $state . $this -> bot -> make_blob("City History", $city);


On a side note, i prefer readability to efficiency in this case, hence the two $ttchange checks instead of doing one. Although it could probably be split over two lines as one.
Title: modified AlienAttack_GUILD
Post by: Akarah on November 28, 2005, 08:15:41 pm
see.. i knew someone could make it look better :)

good one! thanks! updating mine now :)
Title: modified AlienAttack_GUILD
Post by: Khalem on November 29, 2005, 12:02:41 am
Whoops. Updated update with an update.

Been doing too much Ruby as of late and forgot curly braces.
Also made a small cosmetical fix.
Title: modified AlienAttack_GUILD
Post by: Xenixa on November 29, 2005, 12:16:34 am
Heheh I was gunna post something about the curly braces.
Zend Studio tosses ya Syntax errors so when I paste stuff like that I just automatically add whats missing. *shrug*

Looks good though. Made quite a few org members happy that they no long have to watch the clock or look for the bot to say it can be switched.
Title: modified AlienAttack_GUILD
Post by: Akarah on November 29, 2005, 02:15:44 am
yeah coming from primarily a perl background, i habitually use curly brackets in php even when it is apparently not necessary (like when an if (condition) only has one action) like:

Code: [Select]

if ($stuff) do_stuff();


i'd write like this:
Code: [Select]

if ($stuff) { do_stuff(); }


or even more likely:
Code: [Select]

if ($stuff)
{
  do_stuff();
}


hehe
Title: modified AlienAttack_GUILD
Post by: Khalem on November 29, 2005, 02:31:38 am
Same actually Akarah, aside from i come from C, not Perl.

I favour overuse of brackets even on one line if's for the sake of readability (and less typing later if more needs to be added to the conditional check)
Title: modified AlienAttack_GUILD
Post by: mookie on November 29, 2005, 11:34:58 am
Have a console error when using this patch. I am using the 1171 aochat, and the suggested modified Bot.php with PHP 4.41.

Here is the error in the console:

Code: [Select]

[2005-11-29 09:54:55]   [TELL]  [INC]   Darkztrader: !city

Warning: Invalid argument supplied for foreach() in H:\bebot\modules\
_GUILD.php on line 100

Warning: date(): Windows does not support dates prior to midnight (00
nuary 1, 1970 in H:\bebot\modules\AlienAttack_GUILD.php on line 120

Warning: date(): Windows does not support dates prior to midnight (00
nuary 1, 1970 in H:\bebot\modules\AlienAttack_GUILD.php on line 121



Here is the code for error in line 100
Code: [Select]

Line 95]     function city_blob()
Line 96]     {
Line 97]     $city = "<font color=CCInfoHeadline>::::: Recent City activity :::::</font><font color=CCInfoText>\n\n";
Line 98]
Line 99]     $result = $this -> bot -> db -> select("SELECT time, action, player FROM org_city ORDER BY time DESC LIMIT 0, 12");
Line 100]   foreach ($result as $res)
Line 101]   {
Line 102]   $city .= "<font color=CCInfoHeader>Time:</font> <font color=CCCCHeaderColor>" . gmdate("M j, Y, G:i", $res[0]) . " GMT</font>\n";


Here is the lines for 120 and 121:
Code: [Select]

Line 120]     $avilmin = date("i",3600-(time()-$result[0][0]));
Line 121]     $avilsec = date("s",3600-(time()-$result[0][0]));


I checked placement of the { }'s and tried changing date variables. This error happens with tell, pg and Gc.
Title: modified AlienAttack_GUILD
Post by: Akarah on November 29, 2005, 12:08:35 pm
has your bot ever tracked a city controller change enable or disable? i can see if it were getting a null value for that it would be formatting based on 0 or something..

it appears $result isn't getting set right, due to something missing from the database..
Title: modified AlienAttack_GUILD
Post by: Xenixa on November 29, 2005, 12:16:17 pm
Easy enough to explain Mookie .. no Data in org_city Table. :)

Run this line as a Script in your fav MySQL Query tool:
Code: [Select]
INSERT INTO org_city (id, time, action, player) VALUES (1, 1133256000, 'on', 'Initialized');

EDIT:
Or you can add this Line just under the Query that Creates the Table:
Code: [Select]
$db->query("INSERT INTO org_city (id, time, action, player) VALUES (1, " . time() . ", 'on', 'Initialized')");
Just don't forget to Remove or Remark that line out after you run it the first time.
Title: modified AlienAttack_GUILD
Post by: mookie on November 29, 2005, 04:07:42 pm
Wow .. bingo

Well I drop the table and inserted that line Xenixa and its working. Must have had corrupt data in the table. Bot kept saying the Unknown problem statement for raids as well, but not anymore :)

thanks !!
Title: Re: modified AlienAttack_GUILD
Post by: Xenixa on April 25, 2006, 05:30:03 am
Updated:
AlienAttack_GUILD.php (ftp://xen.afraid.org/bebot_files/AlienAttack_GUILD.php)

This version is for Bebot versions 0.3.x and higher using PHP5 and AOChat v1.19
Includes all changes in this thread plus adds additional awareness to other city message types.

Enjoy

Edit: Fixed a typo, no biggie, just annoying.
Title: Re: modified AlienAttack_GUILD
Post by: tonyuh on April 17, 2007, 02:46:44 am
Sorry for necro.. but I don't know why the cron job on this module is not working for me. The text doesn't show up after one hour of turning the cloaking on/off. Also i think theres something missing in this:

else if ($this -> type != "repeat")
    {
        $this -> bot -> send_gc("Cloaking device was disabled one hour ago. It is now possible to enable it again.");
   $this -> time = time() + (60 * 60);

Shouldn't there be $this -> type = "repeat"; at the end there?

Thanks,
Tony
Title: Re: modified AlienAttack_GUILD
Post by: tonyuh on April 18, 2007, 02:28:55 pm
I think I fixed it... added $cron["1sec"][] = &$alienAttack; on top, not sure if thats the way but it seems to work.

Cheers,
Tony
Title: Re: modified AlienAttack_GUILD
Post by: Khalem on April 18, 2007, 04:00:53 pm
If you look closer at the code you will see that the cron for this module is only set when there is actually something for the cronjob to do. Ie the cloak was turned on or off.
The repeat fix is however very valid.

Committing fix for this in SVN.
Title: Re: modified AlienAttack_GUILD
Post by: Shelly on November 13, 2010, 11:54:04 am
I made a modification to this module that tracks the alien waves. Any chance of getting it into the code base?

Please see my post for the details:
http://bebot.link/ao-0-6-x-customunofficial-modules/city-alien-attack-wave-mod/ (http://bebot.link/ao-0-6-x-customunofficial-modules/city-alien-attack-wave-mod/)
SimplePortal 2.3.7 © 2008-2024, SimplePortal