Archive > BeBot 0.3 support
City Cloak Issue
wsbsteven:
parse error: syntax error, unexpected ';', expecting t_function in alienattack_guild.php on line 351
Parfet:
got it working, great idea for random raids or missed messages, but it wasn't very complete :) this one works:
AlienAttack_GUILD.php
--- Code: ---<?php
/*
* TowerAttack.php - Handle Alien attack events.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005 Thomas J. Stens� and ShadowRealm Creations
*
* Developed by:
* - Blondengy (RK1)
* - Khalem (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; either version 2 of the License, or
* (at your option) any later version.
*
* 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: 2007-07-18 05:51:08 -0700 (Wed, 18 Jul 2007) $
* Revision: $Id: AlienAttack_GUILD.php 785 2007-07-18 12:51:08Z alreadythere $
*/
/*
Prepare MySQL database
*/
$db->query("CREATE TABLE IF NOT EXISTS " . $db -> define_tablename("org_city", "true") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time INT,
action VARCHAR(10),
player VARCHAR(15))");
$alienAttack = new AlienAttack($bot);
$commands["tell"]["city"] = &$alienAttack;
$commands["tell"]["cloak"] = &$alienAttack;
$commands["tell"]["cloakset"] = &$alienAttack;
$commands["pgmsg"]["city"] = &$alienAttack;
$commands["pgmsg"]["cloak"] = &$alienAttack;
$commands["pgmsg"]["cloakset"] = &$alienAttack;
$commands["gc"]["city"] = &$alienAttack;
$commands["gc"]["cloak"] = &$alienAttack;
$commands["gc"]["cloakset"] = &$alienAttack;
$commands["buddy"][] = &$alienAttack;
$commands["gmsg"][$guild_name][] = &$alienAttack;
/*
The Class itself...
*/
class AlienAttack
{
var $bot;
var $type;
var $time;
var $action;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function AlienAttack (&$bot)
{
$this -> bot = &$bot;
$this -> bot -> accesscontrol -> create('tell', 'city', 'GUEST');
$this -> bot -> accesscontrol -> create('gc', 'city', 'GUEST');
$this -> bot -> accesscontrol -> create('pgmsg', 'city', 'GUEST');
$this -> bot -> accesscontrol -> create('tell', 'cloak', 'GUEST');
$this -> bot -> accesscontrol -> create('gc', 'cloak', 'GUEST');
$this -> bot -> accesscontrol -> create('pgmsg', 'cloak', 'GUEST');
$this -> bot -> accesscontrol -> create('tell', 'cloakset', 'ADMIN');
$this -> bot -> accesscontrol -> create('gc', 'cloakset', 'ADMIN');
$this -> bot -> accesscontrol -> create('pgmsg', 'cloakset', 'ADMIN');
$this -> bot -> settings -> create ("Cityinfo", "Spamgc", True, "Should we spam messages to GC when they occur?");
$this -> bot -> settings -> create ("Cityinfo", "SpamMembers", True, "Should we spam messages to members when they login?");
$this -> help['description'] = "Shows information and history pertaining to the city and city controller.";
$this -> help['command']['city'] = "- See description";
$this -> help['command']['cloak'] = "- See description";
$this -> help['command']['cloakset on|off'] = "Manually forces the cloak to be on or off.";
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "cloakset (.+)$/i", $msg, $info))
$this -> bot -> send_tell($name, $this -> cloakset($name, $info[1]));
else $this -> bot -> send_tell($name, $this -> city_blob($name, $msg));
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "cloakset (.+)$/i", $msg, $info))
$this -> bot -> send_pgroup($this -> cloakset($name, $info[1]));
else $this -> bot -> send_pgroup($this -> city_blob($name, $msg));
}
/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "cloakset (.+)$/i", $msg, $info))
$this -> bot -> send_gc($this -> cloakset($name, $info[1]));
else $this -> bot -> send_gc($this -> city_blob($name, $msg));
}
/*
Makes the battle results
*/
function city_blob($name, $msg)
{
$result = $this -> bot -> db -> select("SELECT time, action, player FROM #___org_city ORDER BY time DESC LIMIT 0, 12");
if (!$result)
{
return "No city events found in database.";
}
else
{
$city = "##blob_title##::::: Recent City Attacks :::::##end##\n\n";
foreach ($result as $res)
{
$city .= "##blob_text##Time:##end## " . gmdate($this -> bot -> settings -> get("Time", "FormatString"), $res[0]) . "\n";
if ($res[1] == "attack")
$city .= "City was attacked.\n";
else if ($res[1] == "on")
$city .= $res[2] . " turned cloaking ##highlight##on##end##.\n";
else if ($res[1] == "off")
$city .= $res[2] . " turned cloaking ##highlight##off##end##.\n";
else if ($res[1] == "hq")
$city .= $res[2] . " destroyed the ##highlight##HQ##end##.\n";
else if ($res[1] == "house")
$city .= $res[2] . " destroyed a ##highlight##building##end##.\n";
$city .= "\n";
}
$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 ##highlight##" . $status . "d##end##.";
$state .= $ttchange ? "" : " It is now possible to ##highlight##" . $status2 . "##end## it. ";
$state .= $ttchange ? " It will be possible to ##highlight##" . $status2 . "##end## it in ##highlight##" . $avilmin . "##end## minutes and ##highlight##" . $avilsec . "##end## seconds. " : "";
return $state . $this -> bot -> make_blob("City History", $city);
}
}
/*
This gets called on a msg in the group
*/
function gmsg($name, $group, $msg)
{
if ($name == "0")
{
$action = "none";
$player = "";
if (preg_match("/Your radar station is picking up alien activity in the area surrounding your city./i", $msg))
{
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("Alien attack incoming! Beware!");
}
else if (preg_match("/Your city in (.+) has been targeted by hostile forces./i", $msg, $info))
{
$action = "attack";
$zone = $info[1];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("Our city in ".$zone." is about to be under attack! 0MGZ RUN!!!!");
}
else if (preg_match("/(.+) turned the cloaking device in your city off./i", $msg, $info))
{
$this -> type = "off";
$this -> time = time() + (60 * 60);
$this -> bot -> cron["2sec"]["alien"] = &$this -> bot -> commands["tell"]["city"];
$action = "off";
$player = $info[1];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("##highlight##" . $player . "##end## turned the cloaking device in our city ##highlight##off##end##!");
}
else if (preg_match("/(.+) turned the cloaking device in your city on./i", $msg, $info))
{
$this -> type = "on";
$this -> time = time() + (60 * 60);
$this -> bot -> cron["2sec"]["alien"] = &$this -> bot -> commands["tell"]["city"];
$action = "on";
$player = $info[1];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("##highlight##" . $player . "##end## turned the cloaking device in our city back ##highlight##on##end##!");
}
else if (preg_match("/(.+) initiated removal of the organization headquarters in (.+)/i", $msg, $info))
{
$action = "HQ";
$player = $info[1];
$zone = $info[2];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("##highlight##" . $player . "##end## is removeing our HQ in ##highlight##".$zone."##end##! Our city... will.. *sobs* ...be destroyed!! *starts crying*");
}
else if (preg_match("/(.+) removed the organization headquarters in (.+)/i", $msg, $info))
{
$action = "HQ removed";
$player = $info[1];
$zone = $info[2];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("##highlight##" . $player . "##end## has removed our HQ in ##highlight##".$zone."##end##! We are now homeless street urchin people!! *crys even harder*");
}
else if (preg_match("/(.+) initiated removal of a (.+) in (.+)/i", $msg, $info))
{
$action = $info[2]." removal initiated";
$player = $info[1];
$zone = $info[3];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("##highlight##" . $player . "##end## is removing a ".$info[2]." at our city in ##highlight##".$zone."##end##.");
}
else if (preg_match("/(.+) removed a (.+) in (.+)/i", $msg, $info))
{
$action = $info[2]." removed";
$player = $info[1];
$zone = $info[3];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("##highlight##" . $player . "##end## removed a ".$info[2]." at our city in ##highlight##".$zone."##end##.");
}
else
{
$action = "unknown";
$player = $msg;
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc'))
$this -> bot -> send_gc("Something wierd is going on, and I don't know what it is!");
}
if ($action != "none")
{
$this -> bot -> db -> query("INSERT INTO #___org_city (time, action, player) VALUES
(" . time() . ", '" . $action . "', '" . $player . "')");
}
}
}
/*
This gets called if a buddy logs on/off
*/
function buddy($name, $msg)
{
if ($this -> last_log["on"][$name] < (time() - 5))
if ($this -> bot -> settings -> get('Cityinfo', 'SpamMembers'))
$this -> bot -> send_tell($name, $this -> city_blob($name, $msg));
}
/*
cronjob
*/
function cron()
{
if (time() > $this -> time)
{
if ($this -> type == "on")
{
$this -> bot -> send_gc("Cloaking device has be enabled one hour ago. Alien attacks can now be initiated.");
unset($this -> bot -> cron["2sec"]["alien"]);
}
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 * 15);
$this -> type = "repeat";
}
else
{
$this -> bot -> send_gc("Cloaking device is still disabled.");
$this -> time = time() + (60 * 15);
}
}
}
/*
Makes the battle results
*/
function cloakset($name, $msg)
{
if ($msg == "on")
{
$this -> type = "on";
$this -> time = time() + (60 * 60);
$this -> bot -> cron["2sec"]["alien"] = &$this -> bot -> commands["tell"]["city"];
$action = "on";
$player = $info[1];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc')) {
$this -> bot -> send_gc("##highlight##" . $name . "##end## manually set the cloaking device to ##highlight##on##end##!");
$this -> bot -> db -> query("INSERT INTO #___org_city (time, action, player) VALUES (" . time() . ", '" . $action . "', '" . $player . "')");
}
return 'Cloak setting has been toggled.';
}
else if ($msg == "off")
{
$this -> type = "off";
$this -> time = time() + (60 * 60);
$this -> bot -> cron["2sec"]["alien"] = &$this -> bot -> commands["tell"]["city"];
$action = "off";
$player = $info[1];
if ($this -> bot -> settings -> get('Cityinfo', 'Spamgc')) {
$this -> bot -> send_gc("##highlight##" . $name . "##end## manually set the cloaking device to ##highlight##off##end##!");
$this -> bot -> db -> query("INSERT INTO #___org_city (time, action, player) VALUES (" . time() . ", '" . $action . "', '" . $player . "')");
}
return 'Cloak setting has been toggled.';
}
}
}
?>
--- End code ---
Also added a feature to tell the cloak status to members on login, at the request of my org (can be toggled in the settings)
Ebag333:
You can reduce spam by going into the settings and changing Spamgc to false (under Cityinfo).
Navigation
[0] Message Index
[*] Previous page
Go to full version