Archive > AO official modules

modified AlienAttack_GUILD

(1/4) > >>

Akarah:
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: ---
      $result = $this -> bot -> db -> select("SELECT time, action FROM org_city WHERE action = 'on' OR action = 'off' ORDER BY time DESC LIMIT 0, 1");

--- End code ---


add these 2 lines after it:

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

--- End code ---


and change the following if-else to this:

--- Code: ---
      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);
    }

--- End code ---


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

Xenixa:
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. :)

Akarah:
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 ;) )

Khalem:
I changed the actual code to:

--- Code: ---
      $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);

--- End code ---


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.

Akarah:
see.. i knew someone could make it look better :)

good one! thanks! updating mine now :)

Navigation

[0] Message Index

[#] Next page

Go to full version