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

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

Author Topic: Tokens Calulator  (Read 24904 times)

0 Members and 1 Guest are viewing this topic.

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Tokens Calulator
« 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
« Last Edit: February 04, 2007, 09:11:59 pm by nebhyper »
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: !Tokens
« Reply #1 on: January 23, 2007, 02:01:47 pm »
Excellent plugin, moved to the official custom modules section.

-jj-

Offline Malosar

  • BeBot Expert
  • ****
  • Posts: 259
  • Karma: +0/-0
    • http://www.lowerdimension.com
Re: !Tokens
« Reply #2 on: January 23, 2007, 04:10:23 pm »
Code: [Select]
    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:

Code: [Select]
$this -> bot -> send_tell($name,$this -> ShowTokens($info[1], $info[2], $info[3]));
Eternalist
General of The Syndicate

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: !Tokens
« Reply #3 on: January 23, 2007, 04:55:36 pm »
Actually I forgot to update this post. 

I've attached my current module.


EDIT: Changed first post to have changes and files
« Last Edit: February 03, 2007, 07:35:06 pm by nebhyper »
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #4 on: February 03, 2007, 07:42:24 pm »
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.
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #5 on: February 04, 2007, 12:09:10 pm »
You might want to add the following sanity check:

Code: [Select]
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-

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #6 on: February 04, 2007, 08:23:39 pm »
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

Code: [Select]
$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.
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #7 on: February 04, 2007, 08:56:02 pm »
Aye the blob works fine, AFAIK u can't click it tho...

-jj-

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #8 on: February 04, 2007, 09:09:42 pm »
Ok, I'll fix it and update the first post.
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Tokens Calulator
« Reply #9 on: July 22, 2007, 03:28:41 am »
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.

Code: [Select]
<?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$msg1);
}

function pgmsg($source$msg)
{
$this -> handler ($source$msg2);
}

function gc($source$msg)
{
$this -> handler ($source$msg3);
}


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($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;
}

?>

BeBot Founder and Fixer Kingpin

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #10 on: July 22, 2007, 07:13:23 pm »
When I try using this I get
Fatal error: Call to undefined function ctype_digit() in /bot/modules/Tokens.php on line 89

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #11 on: July 22, 2007, 07:21:54 pm »
According to the php site the ctype functions are enabled per default in all php versions from 4.2 on.

So in any current installation they should be available.

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Tokens Calulator
« Reply #12 on: July 22, 2007, 08:55:20 pm »
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!!

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Tokens Calulator
« Reply #13 on: July 22, 2007, 11:30:59 pm »
Updated module in SVN.

Please see the apropriate SVN branch/trunk for changes or wait for 0.4.1
BeBot Founder and Fixer Kingpin

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Tokens Calulator
« Reply #14 on: January 19, 2008, 07:38:48 am »
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.

 

* Recent Posts
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 ]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm ]

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