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: nebhyper on December 06, 2006, 06:04:14 am
-
Tokens Calculator Module
Basically you tell it your level, goal tokens, current tokens and it tells you the number of bags and token (discs) you need to reach that goal.
!tokens 205 2500 1319
CHANGE
4 Feb 2007
- Fixed so you can not enter 0 for goal.
- Fixed tell responses to not send blobs.
3 Feb 2007
- !tokens no longer needs your level. The code finds your level. You can still eneter your level just in case your character info has not been added to the members table or the whois cache table.
- Changed the output to be a link displaying your stats on the top and the bottom has what you need to achieve your goal.
- Included upcoming Tokens for VP.
EDIT: Added Change log and files to first post
-
Excellent plugin, moved to the official custom modules section.
-jj-
-
function tell($name, $msg)
{
if (preg_match("/^".$this -> bot -> commpre."tokens ([0-9]+) ([0-9]+) ([0-9]+)$/i", $msg, $info)) {
$this -> bot -> send_tell($this -> ShowTokens($info[1], $info[2], $info[3]));
}
}
send_tell needs a $name, change to:
$this -> bot -> send_tell($name,$this -> ShowTokens($info[1], $info[2], $info[3]));
-
Actually I forgot to update this post.
I've attached my current module.
EDIT: Changed first post to have changes and files
-
Changed the posts around to be more clear.
Changes and files added to first post.
Help file and php file have been changed and added to first post.
-
You might want to add the following sanity check:
if ($need < 1)
{
return "Current tokens must be less than token goal!";
}
Otherwise ppl can enter a negative value.
Also, you can't make a blob link in a tell, so this help link won't work.
Cheers for the VP addition :-)
-jj-
-
Good points.
Currently as it is if Goal is > 0 and Current > Goal it switches the values.
But if Goal is 0, yes you can get a negative $need.
I can either enter your sanity check for $need or remove Goal > 0.
Either one should fix it, I think.
As for blob in tells are you talking about
$this -> bot -> send_tell($name, "Unknown command. <a href='chatcmd:///tell <botname> <pre>help tokens'>[Help on Tokens commands]</a>");
Because I just tried it and it worked for me.
-
Aye the blob works fine, AFAIK u can't click it tho...
-jj-
-
Ok, I'll fix it and update the first post.
-
Moved to official modules.
Will be included in 0.4 branch and trunk soon.
Updated and adapted module for BeBot 0.4, added security, help and new command handler. Cleaned up the main function some and altered the old style font tags. Also added veteran tokens calculation and added detection for the rounding issue at level 50/51 for clan.
<?php
/*
* Tokens.php - Determines how many tokens and token bags you need based on your level, current tokens, and goal tokens.
* Developed by Siocuffin (RK1), adapted for BeBot 0.4 by Khalem (RK1)
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stensås, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (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; Version 2 of the License.
*
* 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$
* Revision: $Id$
*
*/
$tokens = new tokens($bot);
$commands["pgmsg"]["tokens"] = &$tokens;
$commands["tell"]["tokens"] = &$tokens;
$commands["gc"]["tokens"] = &$tokens;
/*
The Class itself...
*/
class tokens
{
var $bot;
function tokens (&$bot)
{
$this -> bot = &$bot;
$this -> bot -> accesscontrol -> create("all", "tokens", "GUEST");
$this -> help['description'] = "Token calculator";
$this -> help['command']['tokens <target> <current>']= "Calculates the amount of tokens, token bags or VP tokens (and price) based on your current level, <target> and <current> tokens";
$this -> help['command']['tokens <level > <target> <current>'] = "Calculates the amount of tokens, token bags or VP tokens (and price) based on your <level>, <target> and <current> tokens";
}
/*
Unified message handler
*/
function handler($source, $msg, $type)
{
$return = false;
$clan = false;
/*
This should really be moved to the bot core.. but until i get the time to modify every single module... :\
*/
$vars = explode(' ', strtolower($msg));
if (!empty($this -> bot -> commpre))
{
$vars[0] = substr($vars[0], 1);
}
$command = $vars[0];
switch($command)
{
case 'tokens':
$count = count($vars);
if ($count == 3)
{
if (!ctype_digit($vars[1]) || !ctype_digit($vars[2]))
{
$return["error"] = true;
$return["errordesc"] = "Values given are not numerical";
}
else
{
$who = $this -> bot -> whois -> lookup($source);
$level = $who["level"];
if ($who["faction"] == 'Clan')
{
$clan = true;
}
$return = $this -> ShowTokens($level, $vars[1], $vars[2], $clan);
}
}
else if ($count == 4)
{
if (!ctype_digit($vars[1]) || !ctype_digit($vars[2]) || !ctype_digit($vars[3]))
{
$return["error"] = true;
$return["errordesc"] = "Values given are not numerical";
}
else
{
$who = $this -> bot -> whois -> lookup($source);
if ($who["faction"] == 'Clan')
{
$clan = true;
}
$return = $this -> ShowTokens($vars[1], $vars[2], $vars[3], $clan);
}
}
else
{
$return["error"] = true;
$return["errordesc"] = "##highlight##$msg##end## is not valid input. Please see <pre>help tokens ";
}
if ($return["error"] == true)
{
$this -> bot -> send_output($source, $return["errordesc"], $type);
}
else
{
$this -> bot -> send_output($source, $return["content"], $type);
}
break;
default:
$this -> bot -> send_tell($source, "Broken plugin, recieved unhandled command: $command");
}
}
/*
Just pass off to the unified handler
*/
function tell($source, $msg)
{
$this -> handler ($source, $msg, 1);
}
function pgmsg($source, $msg)
{
$this -> handler ($source, $msg, 2);
}
function gc($source, $msg)
{
$this -> handler ($source, $msg, 3);
}
function ShowTokens($level, $goal, $current, $clan)
{
$return = false;
// Make sure our goal is larger than our current tokens
if ($goal <= $current)
{
$return["error"] = true;
$return["errordesc"] = "Your goal tokens can not be the same or less than your current tokens!";
return $return;
}
// Make sure we have a legal level range
if (($level < 1) || ($level > 220))
{
$return["error"] = true;
$return["errordesc"] = "Enter a level between ##highlight##1##end## and ##highlight##220##end##!";
return $return;
}
// Make sure we have a sane token count for both goal and current
if (!is_finite($goal) || !is_finite($current))
{
$return["error"] = true;
$return["errordesc"] = "Please enter sane values for both goal and current tokens!";
return $return;
}
if ($level > 189)
{
$tpl = 9;
}
else if ($level > 174)
{
$tpl = 8;
}
else if ($level > 149)
{
$tpl = 7;
}
else if ($level > 124)
{
$tpl = 6;
}
else if ($level > 99)
{
$tpl = 5;
}
else if ($level > 74)
{
$tpl = 4;
}
// Heres the odd one out. According to amongst others http://wiki.aodevs.com/wiki/Token_and_Tokenboards, Omni will get 3 TPL from level 50, but clan will only get from level 51. Rounding error anyone?
else if ($level > 49)
{
if (!$clan)
{
$tpl = 3;
}
else
{
if ($level > 50)
{
$tpl = 3;
}
else
{
$tpl = 2;
}
}
}
else if ($level > 14)
{
$tpl = 2;
}
else
{
$tpl = 1;
}
$need = $goal - $current;
$Step1 = $need / $tpl;
$Step2 = $Step1 / 7;
$bags = ceil(4 * $Step2);
$Step1 = ceil($Step1);
$VPtoke = ceil($need / 10);
$VP = $VPtoke * 1000;
$VP2 = $VPtoke * 10;
$VetToke = ceil($need / 50);
$Vet = $VetToke * 7;
$Vet2 = $VetToke * 50;
$inside = "##normal##::: ##highlight##Token calculator results##end## :::\n\n";
$inside .= "::: ##highlight##Your status##end## :::\n";
$inside .= "Your level: ##highlight##". $level . "##end##\n";
$inside .= "Current # of tokens: ##highlight##". number_format($current) ."##end##\n";
$inside .= "Goal # of Tokens: ##highlight##". number_format($goal) ."##end##\n";
$inside .= "Tokens needed: ##highlight##". number_format($need) ."##end##\n";
$inside .= "Tokens per token disk: ##highlight##". number_format($tpl) ."##end##\n\n";
$inside .= "::: ##highlight## Your Calculated Token Options##end## :::\n";
$inside .= "Token bags needed: ##highlight##". number_format($bags) ."##end##\n";
$inside .= "Token discs needed: ##highlight##". number_format($Step1) ."##end##\n";
$inside .= "Veteran tokens(##highlight##*##end##): ##highlight##" . number_format($VetToke) . "##end## for ##highlight##" . number_format($Vet) . "##end## veteran points.\n";
$inside .= "OFAB tokens(##highlight##**##end##): ##highlight##". number_format($VPtoke) ."##end## for ##highlight##" . number_format($VP) . "##end## victory points.\n\n";
$inside .= "##highlight##*##end## One veteran token is a set of 50 tokens, thus ##highlight##". number_format($VetToke) ."##end## will equal ##highlight##". number_format($Vet2) ." tokens.##end##\n";
$inside .= "##highlight##**##end## OFAB tokens listed are the set of 10, thus ##highlight##". number_format($VPtoke) ."##end## will equal ##highlight##". number_format($VP2) ." tokens.##end###end##";
$info = "Token calculator ::: " . $this -> bot -> make_blob('Click for results', $inside);
$return["content"] = $info;
return $return;
}
}
?>
-
When I try using this I get
Fatal error: Call to undefined function ctype_digit() in /bot/modules/Tokens.php on line 89
-
According to the php site (http://de3.php.net/manual/en/ref.ctype.php) the ctype functions are enabled per default in all php versions from 4.2 on.
So in any current installation they should be available.
-
That worked.... for some reason my php is compiling with nothing at all in it and I have to manually add everything in (really really irritating).
Thanks Already!!
-
Updated module in SVN.
Please see the apropriate SVN branch/trunk for changes or wait for 0.4.1
-
Yesterday i decided to modify this module
so you could do any order
!tokens 300 1000
!tokens 1000 300
result would be same
it simple uses highest as target and lowest as current
but in doing so i noticed 2 bugs
1. the !tokens
command is broken as count of words used was set to 4 when it should of been 1
2. the output of the !tokens main info was not in a Blob and Very Spammy.
-
Commited to SVN
-
As of patch 17.5, Clans get 3 tokens at level 50 also.
-
Changed in SVN