Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, DotBot, Yandex, Bing

Members: 0
Guests: 7
Stats
Files
Topics
Posts
Members
Newest Member
481
3,734
19,366
618
Micheal64X
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » GOLD SHORTCUTS
Forum Rules | Mark all | Recent Posts

GOLD SHORTCUTS
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Oct 27, 2004, 11:27 am
Go to the top of the page
Go to the bottom of the page

paradox

GroupMembers
Posts15
JoinedOct 25, 2004

I've been searching for a way to add shortcuts when dealing with gold coins.

Though the more complex the better, I'm just trying to get it to do this basically:

"give 1m coin paradox" to be the same as "give 1000000 coin paradox"

similar for k = 1000, b is 1000000000.

If anyone knows where a snippet can be found, or where I'd start snooping through .c files
for a solution, it'd be great

-Paradox
       
Post is unread #2 Oct 27, 2004, 3:03 pm   Last edited Nov 18, 2007, 4:13 pm by Samson
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

#include 


/*
  util function, converts an 'advanced' ASCII-number-string into a number.
  Used by parsebet() but could also be used by do_give or do_wimpy.

  Advanced strings can contain 'k' (or 'K') and 'm' ('M') in them, not just
  numbers. The letters multiply whatever is left of them by 1,000 and
  1,000,000 respectively. Example:

  14k = 14 * 1,000 = 14,000
  23m = 23 * 1,000,0000 = 23,000,000

  If any digits follow the 'k' or 'm', the are also added, but the number
  which they are multiplied is divided by ten, each time we get one left. This
  is best illustrated in an example :)

  14k42 = 14 * 1000 + 14 * 100 + 2 * 10 = 14420

  Of course, it only pays off to use that notation when you can skip many 0's.
  There is not much point in writing 66k666 instead of 66666, except maybe
  when you want to make sure that you get 66,666.

  More than 3 (in case of 'k') or 6 ('m') digits after 'k'/'m' are automatically
  disregarded. Example:

  14k1234 = 14,123

  If the number contains any other characters than digits, 'k' or 'm', the
  function returns 0. It also returns 0 if 'k' or 'm' appear more than
  once.
*/

int advatoi(char *s)
{
        int       number = 0;   /* number to be returned */
        int       multiplier = 0;   /* multiplier used to get the extra digits right */

        /*
         * as long as the current character is a digit add to current number
         */
        while (isdigit(s[0]))
                number = (number * 10) + (*s++ - '0');

        switch (UPPER(s[0]))
        {
        case 'K':
                number *= (multiplier = 1000);
                ++s;
                break;
        case 'M':
                number *= (multiplier = 1000000);
                ++s;
                break;
        case 'B':
                number *= (multiplier = 1000000000);
                ++s;
                break;
        case '�':
                break;
        default:
                return 0;   /* not k nor m nor NULL - return 0! */
        }

        /*
         * if any digits follow k/m, add those too 
         */
        while (isdigit(s[0]) && (multiplier > 1))
        {
                /*
                 * the further we get to right, the less the digit 'worth' 
                 */
                multiplier /= 10;
                number = number + ((*s++ - '0') * multiplier);
        }

        /*
         * return 0 if non-digit character was found, other than NULL 
         */
        if (s[0] != '�' && !isdigit(s[0]))
                return 0;

        /*
         * anything left is likely extra digits (ie: 14k4443  -> 3 is extra) 
         */

        return number;
}


/*
  This function allows the following kinds of bets to be made:

  Absolute bet
  ============

  bet 14k, bet 50m66, bet 100k

  Relative bet
  ============

  These bets are calculated relative to the current bet. The '+' symbol adds
  a certain number of percent to the current bet. The default is 25, so
  with a current bet of 1000, bet + gives 1250, bet +50 gives 1500 etc.
  Please note that the number must follow exactly after the +, without any
  spaces!

  The '*' or 'x' bet multiplies the current bet by the number specified,
  defaulting to 2. If the current bet is 1000, bet x  gives 2000, bet x10
  gives 10,000 etc.

*/
int parsebet(const int currentbet, char *s)
{
        /*
         * check to make sure it's not blank 
         */
        if (s[0] != '�')
        {
                /*
                 * if first char is a digit, use advatoi 
                 */
                if (isdigit(s[0]))
                        return (advatoi(s));
                if (s[0] == '+')    /* add percent (default 25%) */
                {
                        if (s[1] == '�')
                                return (currentbet * 125) / 100;
                        return (currentbet * (100 + atoi(s + 1))) / 100;
                }
                if (s[0] == '*' || s[0] == 'x') /* multiply (default is by 2) */
                {
                        if (s[1] == '�')
                                return (currentbet * 2);
                        return (currentbet * atoi(s + 1));
                }
        }
        return 0;
}
I assume this is what your talking about.

Please note: Since you specified billion, I added it in for the case.
       
Post is unread #3 Oct 27, 2004, 8:53 pm
Go to the top of the page
Go to the bottom of the page

paradox

GroupMembers
Posts15
JoinedOct 25, 2004

sweet.. just wondering where I put that

(include is in mud.h I believe, and then just make the rest it's won c file? and add references in Makefile?)
       
Post is unread #4 Oct 28, 2004, 1:20 am
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

Should probably put it in whatever file you need it for, or its own, its from the auction code in swr.
       
Post is unread #5 Oct 28, 2004, 9:14 am
Go to the top of the page
Go to the bottom of the page

paradox

GroupMembers
Posts15
JoinedOct 25, 2004

Hey, thanks a bunch for all the help, but I'm still not really sure where to put it.

If you could be a little more indepth, it'd go a long way. I'm not afraid of reading/fiddling.. but I can't seem to get it working on my own yet, so any help would still be greatly appreciated..

thx

-Paradox
       
Post is unread #6 Oct 28, 2004, 10:20 am
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

Pick any file, lets say act_obj.c, sinc we're dealing with gold, or even shops.c. Take the include, and if its not already at the top of that file, then add it in. Then, go to the botton of the file, and added the 2 functions. Then, if your going to be using them in another file, make the function prototypes in mud.h, and you can call it from anywhere.
       
Post is unread #7 Oct 29, 2004, 7:55 am
Go to the top of the page
Go to the bottom of the page

paradox

GroupMembers
Posts15
JoinedOct 25, 2004

I actually just noticed that that exact snippet is in bet.h in stock 1.4a... thing is

it won't work.. so I'm thinking either it's disabled on purpose somewhere, or isn't configured properly.
I checked the act_obj.c and at the top it is included. (BTW the file name is bet.h)
so.. I'm not super sure.. tell me if there's any more info you need

-Paradox
       
Post is unread #8 Oct 29, 2004, 9:23 pm
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

It is from bet.h, indeed, but HOW is it not working? Are the calls not producing any results, or are you getting compile errors?
       
Post is unread #9 Oct 29, 2004, 9:26 pm
Go to the top of the page
Go to the bottom of the page

paradox

GroupMembers
Posts15
JoinedOct 25, 2004

I actually got it working..

what was wrong was twofold..

first, there was an ifcheck to see if arg1 was a number or not, which I had to change to only look at it's first digit.

second, it wasn't calling the parse code from bet.h because it was using

amount = atoi(arg1)
where I needed it to do
amount - advatoi(arg1)

now it works fine.. I just gotta fix the msg sent to chars to my liking.. cuz right now it keeps the #'s parsed, so you'll see something like "Paradox gives you 10k coins." .. which should be easy unough to fix given the code I have to work with now.. thx a LOT for all your help, I realize I've been kinda nnoying on this one

-Paradox
       
Pages:<< prev 1 next >>