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 Greven   Canada  (835 posts)  Bio
Date Reply #45 on Fri 13 Feb 2004 07:05 AM (UTC)

Amended on Fri 13 Feb 2004 07:12 AM (UTC) by Greven

Message
Also, for ease of reading, you may want to declar amount as
 int amount = 0;
Just to make sure it starts at 0

P.S. Heh, forums codes == Good

Nobody ever expects the spanish inquisition!

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #46 on Fri 13 Feb 2004 07:08 AM (UTC)
Message
Greven, don't forget to check the "forum codes" check box on the forum when you are using things like [code].

- Nick Gammon

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

Posted by Toy   (206 posts)  Bio
Date Reply #47 on Fri 13 Feb 2004 03:22 PM (UTC)
Message
Alrighty, after much stress and grief, I've gone through with the debugger and I've narrowed down to 2 last problems/ the first problem is this:

  	if ( !str_cmp( arg1, "all" ) )
	{
    		amount = ch->silver/100;
            change = ch->silver%100;
	}
  	else
	{    	
	amount = ch->silver/100;
	change = ch->silver%100;
  	}


The check for change all works fine. Just not sure how to set it up otherwise. The check for change without the all argument I need help on. Would it be something like

change = ch->silver - amount

and the other problem I've gotten is this one:

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


It still NULLS whenever I do any type of change for copper. I used the debugger and the first check it did was this:

Breakpoint 1, do_change (ch=0xa2577e8, argument=0x22f8d7 "all copper")
at bank.c:404
404 if ( !( banker = find_banker( ch ) ) )
(gdb) n
410 if ( IS_NPC( ch ) )
(gdb) n
417 if ( argument[0] == '\0' )
(gdb) n
423 argument = one_argument( argument, arg1 );
(gdb) n
424 argument = one_argument( argument, arg2 );
(gdb) n
435 if ( !str_cmp( arg2, "silver" ) )
(gdb) n
512 }

-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 #48 on Fri 13 Feb 2004 04:11 PM (UTC)

Amended on Fri 13 Feb 2004 04:12 PM (UTC) by Greven

Message
I think the problem if you don't choose silver here is that your using ch->silver, not what they entered, so that may be why its no working, but:

silver = amount/100;
change += amount%100;

if ( change > 100 )
{
//If you have over 100 silver after you get your change,
//convert the other extra silver to gold, and get the difference
	change -=100;
	silver++;
}

I beleive that will work.

As for the second part, when you say its null, its not detecting that you entered copper, that you entered all, that you entered a number, or all of the above?

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #49 on Fri 13 Feb 2004 04:30 PM (UTC)
Message
I added the code you suggested Greven, and it didn't work. Instead of changing 2000 silver, it made gold and silver 0, gave this message:

"You exchanged you silver for 0 gold."

And then when I tried to change all silver, it worked fine, yet set both gold and silver to 20.

And about copper going to a NULL, when ever you put in either change all copper or change amt copper, nothing happens. It'd be the same as just hitting enter.

-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 #50 on Fri 13 Feb 2004 04:41 PM (UTC)
Message
Do you have a return after the silver part? That might be whats just stopping it. That might be why your not getting to copper. I dunno, I can't see the code.

As for the change stuff, it should have been something like this, I'm really tired, and not so good with math:

  	if ( !str_cmp( arg1, "all" ) )
	{
    		amount = ch->silver/100;
            change = ch->silver%100;
	}
  	else
	{    	
	amount = atoi( arg1 )/100;
	change = atoi( arg1 )%100;

		if ( change > 100 )
		{
//If you have over 100 silver after you get your change,
//convert the other extra silver to gold, and get the difference
			change -=100;
			silver
		}
	}
  	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;
    	}


I beleive that should work, sorry, I was using the wrong variables.

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #51 on Fri 13 Feb 2004 07:09 PM (UTC)
Message
Thanks for the help with the changing of silver, its all working right now. Now to the copper issue, I used the debugger after using "change all copper" and it fed me this:

Breakpoint 1, do_change (ch=0xa2577e8, argument=0x22f8d7 "all copper")
at bank.c:406
406 if ( !( banker = find_banker( ch ) ) )
(gdb) n
412 if ( IS_NPC( ch ) )
(gdb) n
419 if ( argument[0] == '\0' )
(gdb) n
425 argument = one_argument( argument, arg1 );
(gdb) n
426 argument = one_argument( argument, arg2 );
(gdb) n
437 if ( !str_cmp( arg2, "silver" ) )
(gdb) n
532 }
(gdb) n
interpret (ch=0xa2577e8, argument=0x22f8d7 "all copper") at interp.c:731
731 end_timer(&time_used);
(gdb) n
735 update_userec(&time_used, &cmd->userec);

I know in the bank.c file, arg1 is all and arg2 is supposed to be either copper or silver, but it appears to only call to silver.

This is the call to copper in the bank.c file:
/* Call for changing Copper */

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

		if ( change > 100 )
		{
//If you have over 1000 copper after you get your change,
//convert the other extra copper to silver, and get the difference
			change -=100;
			copper;
		}
	}
	
  	if ( amount > ch->copper )
    	{
    		sprintf( buf, "%s Sorry, but you don't have that much silver 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 exchanged your copper for %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;
}


Any thoughts?


-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 #52 on Fri 13 Feb 2004 07:32 PM (UTC)
Message
It looks like there might be a return or something after the silver portion. Perhaps your missing a set of {} thats making it go where its not supposed to, I dunno. Is there any return where there shouldn't be?

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #53 on Fri 13 Feb 2004 08:57 PM (UTC)
Message
I think I might have traced it down to this part:
Breakpoint 1, do_change (ch=0xa2577e8, argument=0x22f8d7 "2000 silver")
at bank.c:406
406 if ( !( banker = find_banker( ch ) ) )
(gdb) n
412 if ( IS_NPC( ch ) )
(gdb) n
419 if ( argument[0] == '\0' )
(gdb) n
425 argument = one_argument( argument, arg1 );
(gdb) n
426 argument = one_argument( argument, arg2 );
(gdb) n
437 if ( !str_cmp( arg2, "silver" ) )
(gdb)

it skips over these lines:
  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;
  }


could that possibly be it?

-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 #54 on Fri 13 Feb 2004 08:58 PM (UTC)
Message
void do_change (CHAR_DATA *ch, char *argument)
{
   CHAR_DATA *banker;
   int amount = 0;
   int change = 0;
   int silver;
   int copper;
   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 = one_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( arg2, "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 )/100;
	change = atoi( arg1 )%100;

		if ( change > 100 )
		{
//If you have over 100 silver after you get your change,
//convert the other extra silver to gold, and get the difference
			change -=100;
			silver++;
		}
	}
	
  	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 exchanged your silver for %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(arg1, "all") && !is_number( arg1 ) )
  	{
		sprintf( buf, "%s How much copper do you wish to change?", ch->name );
		do_tell( banker, buf );
    		return;
  	}
    
 	if ( !str_cmp( arg1, "all" ) )
	{
    		amount = ch->copper/100;
            change = ch->copper%100;
	}
  	else
	{    	
	amount = atoi( arg1 )/100;
	change = atoi( arg1 )%100;

		if ( change > 100 )
		{
//If you have over 1000 copper after you get your change,
//convert the other extra copper to silver, and get the difference
			change -=100;
			copper++;
		}
	}
	
  	if ( amount > ch->copper )
    	{
    		sprintf( buf, "%s Sorry, but you don't have that much silver 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 exchanged your copper for %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;
}
}
}
}


I posted this just in case it helps any. :)
-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 #55 on Fri 13 Feb 2004 09:00 PM (UTC)
Message
Quote:

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


This is what you said everything was worth, and this is how you are doing it ...


if ( !str_cmp( arg1, "all" ) )
  {
     amount = ch->copper/100;
     change = ch->copper%100;
  }  // end of changing all
else
  {  // not changing all     
  amount = atoi( arg1 )/100;
  change = atoi( arg1 )%100;

    if ( change > 100 )
      {
//If you have over 1000 copper after you get your change,
//convert the other extra copper to silver, and get the difference
      change -=100;
      copper;
      }  // end of change > 100

  }  // not changing all
  
if ( amount > ch->copper )
  {
  sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );
  do_tell( banker, buf );
  return;
  }  // amount > ch->copper
else
  {
  ch->silver += amount;
  ch->copper = change;
  set_char_color( AT_PLAIN, ch );
  ch_printf( ch, "You exchanged your copper for %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;

  }  // enough copper


I've put in some comments and fixed up the indenting so it is easier to see the logic flow.

When you do the "next" in gdb it would be helpful to print out some values, eg. p arg1, p arg2

Also: p ch->copper, p ch->silver


Anyway, the code above doesn't make a huge amount of sense. For one thing, judging by the gdb responses it isn't being executed at all, so there must be a problem further up.

Then you have this:



  change = atoi( arg1 )%100;

    if ( change > 100 )
      {
//If you have over 1000 copper after you get your change,
//convert the other extra copper to silver, and get the difference
      change -=100;
      copper;
      }  // end of change > 100



You cannot have change > 100, because the % operator (modulus) gives the remainder after dividing by 100, it must always be in the range 0 to 99.

I know Greven suggested that, but this is wrong. Also the comment is wrong, you mention 1000 copper, but you are testing for 100.

Then this line doesn't do anything:


copper;


Moving on, you test for "if ( amount > ch->copper )" - why? This is the amount *after* dividing by 100. This is the wrong test.

If they are not changing all, you need to test before the divide.

Then you reply:


sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );


You mean *copper* to change. The whole thing is confusing to read.





- Nick Gammon

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

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #56 on Fri 13 Feb 2004 09:57 PM (UTC)

Amended on Fri 13 Feb 2004 10:15 PM (UTC) by Greven

Message
See this is where I was tired: I was working at if you had more than 100 silver on you at the time, make it one gold, not in the change, like if you have 105 pennies, make it 1 dollar and 5 cents.


However, it looks like the copper code is inside of the silver code, and that your missing a } after the return at the end of the silver code. should be:
	else
	{
  	ch->gold += amount;
  	ch->silver = change;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You exchanged your silver for %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;
	}
}


This also means you have to many } at the end of function.

Also, where your setting the gold and silver, you don't have the proper checks to see that they have that much silver.

I think the check should be:

 	if ( !str_cmp( arg1, "all" ) )
	{
    		amount = ch->silver/100;
            	change = ch->silver%100;
	}
  	else
	{    	
		amount = atoi( arg1 )/100;
		change = atoi( arg1 )%100;
// This should be checking if they have enough silver as they say they have	
		if ( atoi(arg1) > ch->silver)
		{
			send_to_char("You do not have enough silver", ch);	
			return;
		}

	}


My apoligies for the bad code, I'll try no to think so much when I'm that tired.

Nobody ever expects the spanish inquisition!

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #57 on Fri 13 Feb 2004 10:19 PM (UTC)

Amended on Sat 14 Feb 2004 12:03 AM (UTC) by Nick Gammon

Message
In the interests of this forum thread not reaching 5 pages, I've rewritten the do_change function from scratch:


void do_change( CHAR_DATA *ch, char *argument )
{
  
  // do_change snippet written by Nick Gammon
  
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    int value;

    
    if ( !find_banker ( ch ))
      {
      send_to_char( "You're not in a bank!\n", ch );
      return;
      }
  
    if ( IS_NPC( ch ) )
       return;

    

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

    if ( ! str_cmp (arg1, "") )
    {
    send_to_char( "Change what?\n\r", ch );
    send_to_char( "Usage: change (<number> | all) [ gold | silver | copper ]\n", ch );
    return;
    }

   // see if they want to change everything

  
   if (! str_cmp (arg1, "all") )
     {
     if (! str_cmp (arg2, "") ) // no argument - change everything
       {
       // change copper to silver
       ch->silver += ch->copper / 100;  // 100 coppers per silver
       ch->copper %= 100;   // remainder is change
       
       // change silver to gold
       ch->gold  += ch->silver / 100;  // 100 silvers per gold
       ch->silver %= 100;   // remainder is change      
      }
    else if (! str_cmp (arg2, "copper") )  
       {
       // change copper to silver
       ch->silver += ch->copper / 100;  // 100 coppers per silver
       ch->copper %= 100;   // remainder is change
      }
    else if (! str_cmp (arg2, "silver") )  
       {
      // change silver to gold
       ch->gold  += ch->silver / 100;  // 100 silvers per gold
       ch->silver %= 100;   // remainder is change      
      }
    else if (! str_cmp (arg2, "gold") )  
       {
      // change gold back to silver
      ch->silver += ch->gold * 100;   // each gold is 100 silvers
      ch->gold = 0;   // no gold left
      }             
    } // end of changing all
  else 
    {
    if (!is_number (arg1))
      {
      send_to_char ("You must supply a number to change (eg. \"change 22 silver\")\n", ch);
      return;
      }
    
    value = atoi (arg1);    // amount they want to change

    if (value <= 0)
      {
      send_to_char ("You can only change 1 or more\n", ch);
      return;
      }

    if (! str_cmp (arg2, "copper") )  
       {
       // change copper to silver
       
       if (ch->copper < value)
         {
        ch_printf (ch, "You only have %i copper!\n", ch->copper);
        return;          
         }
         
       ch->silver += value / 100;  // 100 coppers per silver
       ch->copper -= value;          // take away their copper
       ch->copper += value % 100;   // give back the change
      }
    else if (! str_cmp (arg2, "silver") )  
       {
       // change silver to gold
       
       if (ch->silver < value)
         {
        ch_printf (ch, "You only have %i silver!\n", ch->silver);
        return;          
         }
         
       ch->gold += value / 100;  // 100 silvers per gold
       ch->silver -= value;          // take away their silver
       ch->silver += value % 100;   // give back the change
      }
    else if (! str_cmp (arg2, "gold") )  
       {
      // change gold back to silver
             
       if (ch->gold < value)
         {
        ch_printf (ch, "You only have %i gold!\n", ch->gold);
        return;          
         }
      
      ch->silver += value * 100;   // each gold is 100 silvers
      ch->gold -= value;   // less gold
      }             
    else
      ch_printf (ch, "Change %i what? (gold, silver or copper)\n", value);
   
    } // end of changing a number
  
    
   ch_printf (ch, "You now have %i gold, %i silver, %i copper\n",
           ch->gold, ch->silver, ch->copper);
      

} // end of do_change



What this lets you do is type:


change <-- get help, and show amount you have
change all <-- changes to least number of coins
change all gold <-- changes to silver
change all silver <-- changes to gold
change all copper <-- changes to silver
change 10 gold <-- change a specific amount
change 20 silver <-- change a specific amount
change 30 copper <-- change a specific amount


I'll let you add any more displays you want (eg. to the rest of the room).



- Nick Gammon

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

Posted by Toy   (206 posts)  Bio
Date Reply #58 on Fri 13 Feb 2004 10:42 PM (UTC)
Message
void do_change (CHAR_DATA *ch, char *argument)
	{
   	CHAR_DATA *banker;
   	char buf [MAX_STRING_LENGTH];
   	char arg1 [MAX_INPUT_LENGTH];
   	char arg2 [MAX_INPUT_LENGTH];
   	int amount = 0;
   	int change = 0;
   	int silver;
   	int copper;
  
   	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' )
  	{    	
      sprintf( buf, "%s How much silver or copper do you wish to exchange?", ch->name );
    	do_tell( banker, buf );
    	return;
 	}              

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

/* Call for changing Silver */
  	if ( !str_cmp( arg2, "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 )/100;
	change = atoi( arg1 )%100;
	}
  	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;
      }
	if ( change > 99 )
	{
//If you have over 100 silver after you get your change,
//convert the other extra silver to gold, and get the difference
	change -=100;
	silver++;
	}	
	else
	{
  	ch->gold += amount;
  	ch->silver = change;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You exchanged your silver for %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(arg1, "all") && !is_number( arg1 ) )
  	{
	sprintf( buf, "%s How much copper do you wish to change?", ch->name );
	do_tell( banker, buf );
    	return;
  	}
	}

 	if ( !str_cmp( arg1, "all" ) )
	{
    	amount = ch->copper/100;
      change = ch->copper%100;
	}
  	else
	{    	
	amount = atoi( arg1 )/100;
	change = atoi( arg1 )%100;
	}
  	if ( amount > ch->copper )
    	{
    	sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );
    	do_tell( banker, buf );
    	return;
      }
	if ( change > 99 )
	{
//If you have over 100 copper after you get your change,
//convert the other extra copper to silver, and get the difference
	change -=100;
	copper++;
	}	
	else
	{
  	ch->silver += amount;
  	ch->copper = change;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You exchanged your copper for %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;
	}
	}


Now that I cleaned up the types and put the amount > ch->silver check into the right spot this might be a bit easier to read. Sorry, still sorta new at this. Anyways I recompiled and tested out. All the calls for changing silver work fine cept for the "all" argument. Simply typing "change all" will now only call to silver, so I believe my issues are in the beginings argument code. Doing tests on it now.

-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 #59 on Fri 13 Feb 2004 10:44 PM (UTC)
Message
didn't see the work you did nick.. I take that last post back. ;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

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,806 views.

This is page 4, 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.