Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Need help!

Need help!

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 3  4  5  

Posted by Toy   (206 posts)  Bio
Date Reply #15 on Mon 09 Feb 2004 10:39 AM (UTC)
Message
Ok.. ran into a saving problem... whenever you save and quit, you lose your balance.. I got these bug messages

Comm: Loading player data for: Toy (7K)
Log: [*****] FILE: ../player/t/Toy LINE: 29
Log: [*****] BUG: Fread_char: no match: GoldBalance
Log: [*****] FILE: ../player/t/Toy LINE: 29
Log: [*****] BUG: Fread_char: no match: 0
Log: [*****] FILE: ../player/t/Toy LINE: 30
Log: [*****] BUG: Fread_char: no match: SilverBalance0
Log: [*****] FILE: ../player/t/Toy LINE: 31
Log: [*****] BUG: Fread_char: no match: CopperBalance0
Comm: Toy@127.0.0.1((ident not active)) has connected.

in load_char_obj:
ch->pcdata->goldbalance			= 0;


in fread_char:
KEY( "GoldBalance",     ch->pcdata>goldbalance,    fread_number( fp ) );


and in fwrite_char:
    fprintf( fp, "GoldBalance  %d\n",   ch->pcdata->goldbalance );


Ok.. I added those and amended them all to mud.h under pc_data... am I missing something?

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #16 on Mon 09 Feb 2004 03:39 PM (UTC)
Message
Hmmm, goldbalance looks ok, just make sure that it is under the 'G' case, because it is sorted by the first letter. It looks like the others are being printed into the file without a space betweem the word and the number, like:
fprintf( fp, "SilverBalance%d\n",   ch->pcdata->silverbalance );
Should be
fprintf( fp, "SilverBalance  %d\n",   ch->pcdata->silverbalance );

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Toy   (206 posts)  Bio
Date Reply #17 on Mon 09 Feb 2004 05:41 PM (UTC)
Message
Thanks Greven. All I needed was an extra space and it cleared all the bug messages up. Here's what I'm working on right now:

	/* convert cost to g/s/c */
	tmpvalue = maxgold;
	gcost = tmpvalue/10000;
	tmpvalue = tmpvalue%10000;
	scost = tmpvalue/100;
	tmpvalue = tmpvalue%100;
	ccost = tmpvalue;
	if(ch->gold < gcost || ch->silver < scost || ch->copper < ccost){
    tmpvalue = wealth - maxgold;
		conv_currency( ch, tmpvalue);
    send_to_char("You hand your coins to the shopkeeper who quickly makes change.\n\r",ch);


That is from shop.c. It allows the shop keeper to make change from what you buy. Trying to figure out how to put that into do_withdraw, do_deposit, and do_balance because at the moment, if you deposit 3000 copper, it only reads as copper. So if you want to take out the equivent of the amount in any other coin, you'd have to go to a shop and get change first. ;p

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #18 on Mon 09 Feb 2004 06:32 PM (UTC)

Amended on Mon 09 Feb 2004 06:33 PM (UTC) by Greven

Message
You could use that pretty easily to make a change command, so they don't have to be taking/giving money from/to the bank, since you will need some way in which to specify what kind of money you want back. As for the actual math formula, I'm far to tired, but you need to work out 3 thing: how much they want in what unit, how much to take out of each unit, and how much to put into each unit(if they want 99 copper but have 0, you must remove 1 silver, give the character 99 copper, and give ch->pcdata->silverbalance 1 copper.)

However, it looks like this is all done already by conv_currency, so you could very easily use that, but I don't know what maxgold or wealth is set to. If you can paste those, I might be able to help you more.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Toy   (206 posts)  Bio
Date Reply #19 on Mon 09 Feb 2004 10:03 PM (UTC)
Message
Having a hard time with this. I even went back to the original snippet. I found the conversions is this:

Mathmatics
----------
100 copper = 1 silver
100 silver = 1 gold
1 gold = 10000 copper

-side note: have to fix that so you need less copper to make silver.

And this also:

tmpvalue = money;
ch->gold = tmpvalue/10000;
tmpvalue=tmpvalue%10000;
ch->silver = tmpvalue/100;
tmpvalue=tmpvalue%100;
ch->copper = tmpvalue;

the part of the code I cut and pasted earlier was for buying pets. I found these lines for wealth and maxgold:

wealth = get_value(ch->gold, ch->silver ,ch->copper);
maxgold = 10 * pet->level * pet->level;

Not sure if this is helping or not. I'm so confused of how to go about doing this. If my help isn't working, my only idea is to look at the original snippet. There is multiple calls for wealth and maxgold, and they seem to pertain to seeing if the carrier has enough money on them.

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Toy   (206 posts)  Bio
Date Reply #20 on Wed 11 Feb 2004 05:55 AM (UTC)
Message
Ok, I'm working on the changing of currency right now. Since I'm still sorta weak at this, I'm having a crisis. I've tried to imitate the calls in the other portions of the bank.c code. Here's what I have so far:

void do_change (CHAR_DATA *ch, char *argument)
{
   int amount;
   int change;
   char buf [MAX_STRING_LENGTH];
   char arg1 [MAX_INPUT_LENGTH];
   char arg2 [MAX_INPUT_LENGTH];
  
   if ( !( banker = find_banker( ch ) ) )
  {
    send_to_char( "You're not in a bank!\n\r", ch );
    return;
  }
  
  if ( IS_NPC( ch ) )
  {
    sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
    do_say( banker, buf );
    return;
  }
  
  if ( argument[0] == '\0' )
  {
    do_say( banker, "If you need help, see HELP BANK." );
    return;
  }

         argument = one_argument( argument, arg1 );
	   argument = two_argument( argument, arg2 );

  if ( arg1 == '\0' || arg2 == '\0' )
  {
    sprintf( buf, "%s How much gold, silver, or copper do you wish to change?", ch->name );
    do_tell( banker, buf );
    return;
  }              

/* Call for changing Gold into Silver and Copper */

  if ( !str_cmp( arg2, "gold" ) )
  {
  if ( str_cmp(arg1, "all") && !is_number( arg1 ) )
  	{
		sprintf( buf, "%s How much gold do you wish to change?", ch->name );
		do_tell( banker, buf );
    		return;
  	}


But then I ran into this snag: How do I add a call to let the person choose between changing into copper or silver? I know how the rest of this code is gonna look in my head: if the player calls to silver, divide the number by 100, and if calls to copper dived by 10000, then alter the changes in all 3 of the pcdata balances.. I just need a shove in the right direction...

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #21 on Wed 11 Feb 2004 06:37 AM (UTC)
Message
The simple (low coding headache) solution is to not allow a change down from gold at all and only allow copper/silver to be upgraded to the next better value. You do realize you need to recode shop functions to account for your 3 coin types as well right?

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #22 on Wed 11 Feb 2004 06:37 AM (UTC)
Message
What you need to do is to make a function that you can specify which type you want to specify. You can probably copy and adapt convert_currency to do so, I can probably help if you can post the function.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Toy   (206 posts)  Bio
Date Reply #23 on Wed 11 Feb 2004 06:54 AM (UTC)
Message
I like the idea of not downgrading from gold, that's save some trouble.

As I mentioned before, in the shops.c file there shows a way of converting currency already from the snippet I installed.

/* convert cost to g/s/c */
tmpvalue = maxgold;
gcost = tmpvalue/10000;
tmpvalue = tmpvalue%10000;
scost = tmpvalue/100;
tmpvalue = tmpvalue%100;
ccost = tmpvalue;

more or less, that reads, from what I can tell that ccost, or copper is equal to a normal value, with silver 100x that, and gold 10000x that. So I'm trying to do is something like this:

if the player wishes to change silver into gold, it'll take the amount of the silver, subtract it from ch->silver, and add it to ch->gold by subtracting the multiple the number of silver by 100 and adding a 1 to the goldbalance per 100x the amount of silver.

so I guess it's supposed to look something like this:


  	if ( !str_cmp( arg1, "all" ) )
    		amount = ch->silver * 10;
  	else
    		amount = atoi( arg1 );

  	if ( amount > ch->silver )
    	{
    		sprintf( buf, "%s Sorry, but you don't have that much silver to convert.", ch->name );
    		do_tell( banker, buf );
    		return;
    	}
else
{  	ch->silver -= amount;
  	ch->gold += amount;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You change %d silver into %d gold.\n\r", amount );
  	sprintf( buf, "$n changes some currancy.\n\r" );
  	act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  	save_char_obj( ch );
  	return;
} 


I think I'm on the right path here, just not entirely sure.

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #24 on Wed 11 Feb 2004 10:06 AM (UTC)
Message
Actually if gold is worth 100 silver an easier way to handle that would be something like:
amount = ch->silver/100
change = ch->silver%100
ch->gold += amount
ch->silver = change

and repeat for copper to silver

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Toy   (206 posts)  Bio
Date Reply #25 on Wed 11 Feb 2004 05:23 PM (UTC)
Message
Here's what I have so far:

void do_change (CHAR_DATA *ch, char *argument)
{
   CHAR_DATA *banker;
   int amount;
   int change;
   char buf [MAX_STRING_LENGTH];
   char arg1 [MAX_INPUT_LENGTH];
//   char arg2 [MAX_INPUT_LENGTH];
  
   if ( !( banker = find_banker( ch ) ) )
  {
    send_to_char( "You're not in a bank!\n\r", ch );
    return;
  }
  
  if ( IS_NPC( ch ) )
  {
    sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
    do_say( banker, buf );
    return;
  }
  
  if ( argument[0] == '\0' )
  {
    do_say( banker, "If you need help, see HELP BANK." );
    return;
  }

         argument = one_argument( argument, arg1 );
//	   argument = two_argument( argument, arg2 );

  if ( arg1 == '\0' )
  {
    sprintf( buf, "%s How much silver or copper do you wish to change into gold?", ch->name );
    do_tell( banker, buf );
    return;
  }              

/* Call for changing Silver */

  if ( !str_cmp( arg1, "silver" ) )
  {
  if ( str_cmp(arg1, "all") && !is_number( arg1 ) )
  	{
		sprintf( buf, "%s How much silver do you wish to change?", ch->name );
		do_tell( banker, buf );
    		return;
  	}
    
  	if ( !str_cmp( arg1, "all" ) )
	{
    		amount = ch->silver/100;
            change = ch->silver%100;
	}
  	else
	{    	
	amount = atoi( arg1 );
  	}
  	if ( amount > ch->silver )
    	{
    		sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );
    		do_tell( banker, buf );
    		return;
    	}
	else
	{
  	ch->gold += amount;
  	ch->silver = change;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You change %d silver into %d gold coins.\n\r", amount );
  	sprintf( buf, "$n changes some currency.\n\r" );
  	act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  	save_char_obj( ch );
  	return;
}
}
}



I recompiled with only a
bank.c: In function `do_change':
bank.c:399: warning: `change' might be used uninitialized in this function error message

I logged in and tried to change 2000000 silver into gold... and nothing happens. Looks luck a null. If I put in "change silver" I get this:

The banker tells you 'How much silver do you wish to change?'

Also get a null for "change all silver". Did I put something in the wrong spot?

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Toy   (206 posts)  Bio
Date Reply #26 on Wed 11 Feb 2004 06:26 PM (UTC)
Message
Just realized I posted the wrong bit of code. Posted the stuff I was trying before I added the copper segment. ;p

void do_change (CHAR_DATA *ch, char *argument)
{
   CHAR_DATA *banker;
   int amount;
   int change;
   char buf [MAX_STRING_LENGTH];
   char arg1 [MAX_INPUT_LENGTH];
   char arg2 [MAX_INPUT_LENGTH];
  
   if ( !( banker = find_banker( ch ) ) )
  {
    send_to_char( "You're not in a bank!\n\r", ch );
    return;
  }
  
  if ( IS_NPC( ch ) )
  {
    sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
    do_say( banker, buf );
    return;
  }
  
  if ( argument[0] == '\0' )
  {
    do_say( banker, "If you need help, see HELP BANK." );
    return;
  }

         argument = one_argument( argument, arg1 );
	   argument = two_argument( argument, arg2 );

  if ( arg1 == '\0' || arg2 == '\0' )
  {
    sprintf( buf, "%s How much silver or copper do you wish to change into gold?", ch->name );
    do_tell( banker, buf );
    return;
  }              

/* Call for changing Silver */

  if ( !str_cmp( arg1, "silver" ) )
  {
  if ( str_cmp(arg1, "all") && !is_number( arg1 ) )
  	{
		sprintf( buf, "%s How much silver do you wish to change?", ch->name );
		do_tell( banker, buf );
    		return;
  	}
    
  	if ( !str_cmp( arg1, "all" ) )
	{
    		amount = ch->silver/100;
            change = ch->silver%100;
	}
  	else
	{    	
	amount = atoi( arg1 );
  	}
  	if ( amount > ch->silver )
    	{
    		sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );
    		do_tell( banker, buf );
    		return;
    	}
	else
	{
  	ch->gold += amount;
  	ch->silver = change;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You change %d silver into %d gold coins.\n\r", amount );
  	sprintf( buf, "$n changes some currency.\n\r" );
  	act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  	save_char_obj( ch );
  	return;
}

/* Call for changing Copper */

  if ( !str_cmp( arg2, "copper" ) )
  {
  if ( str_cmp(arg2, "all") && !is_number( arg2 ) )
  	{
		sprintf( buf, "%s How much copper do you wish to change into silver?", ch->name );
		do_tell( banker, buf );
    		return;
  	}
    
  	if ( !str_cmp( arg2, "all" ) )
	{
    		amount = ch->copper/1000;
            change = ch->copper%1000;
	}
  	else
	{    	
	amount = atoi( arg2 );
  	}
  	if ( amount > ch->copper )
    	{
    	sprintf( buf, "%s Sorry, but you don't have that much copper to change.", ch->name );
    		do_tell( banker, buf );
    		return;
    	}
	else
	{
  	ch->silver += amount;
  	ch->copper = change;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You change %d copper into %d silver coins.\n\r", amount );
  	sprintf( buf, "$n changes some currency.\n\r" );
  	act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  	save_char_obj( ch );
  	return;
}
}
}


-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #27 on Thu 12 Feb 2004 01:40 AM (UTC)

Amended on Thu 12 Feb 2004 01:42 AM (UTC) by Meerclar

Message
A large part of what has this not functioning properly is your arg1/2 handling in the code.

  if ( !str_cmp( arg2, "copper" ) )
  {
  if ( str_cmp(arg2, "all") && !is_number( arg2 ) )

should be more like

  if ( !str_cmp( arg2, "copper" ) )
  {
  if ( str_cmp(arg1, "all") && !is_number( arg1 ) )

and

  if ( !str_cmp( arg1, "silver" ) )
  {
  if ( str_cmp(arg1, "all") && !is_number( arg1 ) )

should be more like

  if ( !str_cmp( arg2, "silver" ) )
  {
  if ( str_cmp(arg1, "all") && !is_number( arg1 ) )

Also in your copper segment

amount = atoi( arg2 );

should be

amount = atoi( arg1 );


Granted, it may still not be flawless after the args are correctly called but you shouldnt be getting no results anymore.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Toy   (206 posts)  Bio
Date Reply #28 on Thu 12 Feb 2004 06:07 AM (UTC)
Message
And the fun goes on...

Attempting to change copper still nulls. Changed 2,000 silver into gold and ended up with 2,000 gold and 0 silver with this message:

"You change 2000 silver into 0 gold coins."

So after putting in the changes Meercleer suggested, I'm one step closer.. I hope.

Any other advice/suggestions to finish this monster would be great.

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #29 on Thu 12 Feb 2004 06:25 AM (UTC)
Message
See my recent post about using gdb - put a breakpoint at your function, then step through checking the contents of the variables, until you see what is going wrong.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


166,811 views.

This is page 2, subject is 5 pages long:  [Previous page]  1  2 3  4  5  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.