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 Sat 07 Feb 2004 11:59 PM (UTC)
Message
I found a few snippets and I installed them on my mud. One was for a banking system, the other for a new currancy system. I put the snippets in, and they worked fine. Now I'm trying to alter the bank code so it'll read gold, copper, and silver. I keep getting strange errors though. the most curious one right now is this one:

[codevoid do_balance( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *banker;
char buf [MAX_STRING_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;
}
else
{
ch_printf( ch, "You have %d gold in the bank.\n\r", ch->pcdata->balance );
}
return;
}[/code]

That's the very end of the .C file, and it gives me the message:
gcc -c -O -g3 -Wall -Wuninitialized -DNOCRYPT -
bank.c: In function `do_withdraw':
bank.c:304: error: syntax error at end of input
make[1]: *** [bank.o] Error 1
make[1]: Leaving directory `/home/Karl/smaug/dist/
make: *** [all] Error 2

Any clues?

-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 #1 on Sun 08 Feb 2004 12:42 AM (UTC)
Message
For starters, you posted the wrong function. Your error is in do_withdraw, you posted do_balance - lets see what do_withdraw looks like (and mark line 304 if you'd be so kind) and we can figure out whats wrong. My first guess from the error you got is a missing ; or " on line 304 though.

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 #2 on Sun 08 Feb 2004 06:28 AM (UTC)
Message
[code]void do_withdraw( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *banker;
char arg1[MAX_INPUT_LENGTH];
char buf [MAX_STRING_LENGTH];
int amount;

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 );
argument = one_argument( argument, arg3 );

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

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

if ( !str_cmp( arg1, "all" ) )
{
amount = ch->pcdata->balance;
}
else
{
amount = atoi( arg1 );
}

if( amount > ch->pcdata->balance )
{
sprintf( buf, "%s But you do not have that much gold in your account!", ch->name );
do_tell( banker, buf );
return;
}

if ( amount <= 0 )
{
sprintf( buf, "%s Oh I see.. you're a comedian.", ch->name );
do_tell( banker, buf );
return;
}
else
{
ch->pcdata->balance -= amount;
ch->gold += amount;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You withdraw %d gold.\n\r", amount );
sprintf( buf, "$n withdraws some coins.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}

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

if ( !str_cmp( arg2, "all" ) )
{
amount = ch->pcdata->balance;
}
else
{
amount = atoi( arg2 );
}

if( amount > ch->pcdata->balance )
{
sprintf( buf, "%s But you do not have that much silver in your account!", ch->name );
do_tell( banker, buf );
return;
}

if ( amount <= 0 )
{
sprintf( buf, "%s Oh I see.. you're a comedian.", ch->name );
do_tell( banker, buf );
return;
}
else
{
ch->pcdata->balance -= amount;
ch->silver += amount;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You withdraw %d silver.\n\r", amount );
sprintf( buf, "$n withdraws some coins.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}

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

if ( !str_cmp( arg3, "all" ) )
{
amount = ch->pcdata->balance;
}
else
{
amount = atoi( arg3 );
}

if( amount > ch->pcdata->balance )
{
sprintf( buf, "%s But you do not have that much copper in your account!", ch->name );
do_tell( banker, buf );
return;
}

if ( amount <= 0 )
{
sprintf( buf, "%s Oh I see.. you're a comedian.", ch->name );
do_tell( banker, buf );
return;
}
else
{
ch->pcdata->balance -= amount;
ch->copper += amount;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You withdraw %d copper.\n\r", amount );
sprintf( buf, "$n withdraws some coins.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}[/code]

I tried adding in some lines here and there after I posted. scapped it and started fresh. my problem is now I get the error at line 389.. which is the last line in the .c file

-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 #3 on Sun 08 Feb 2004 06:33 AM (UTC)
Message
Oh.. I forgot to mention I first posted do_balance because that's the end of the .c file. Line 304 at the time was simply this:

}

That's why I got confused to start with.

-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 #4 on Sun 08 Feb 2004 07:53 AM (UTC)
Message
Found the problem:

else
{
ch->pcdata->balance -= amount;
ch->copper += amount;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You withdraw %d copper.\n\r", amount );
sprintf( buf, "$n withdraws some coins.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}


Should be:
else
{
ch->pcdata->balance -= amount;
ch->copper += amount;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You withdraw %d copper.\n\r", amount );
sprintf( buf, "$n withdraws some coins.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}
}


You were missing a closing bracket for the function/for the else statement

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #5 on Sun 08 Feb 2004 06:56 PM (UTC)
Message
Ok, I put the } in and it helped out. Appartently I was missing one on the end of do_deposit to. Ok. Made cleaned and compiled. Everything went in through no problem. Yet, I log into the MUD and try to deposit and amount of silver or copper and it says this:

The banker tells you 'How much gold do you wish to withdraw?'

I know in do_withdraw I put three checks in, one for each coin. Here is the gold one:

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

All gives me this message:

The banker tells you 'But you do not have that much gold in your account!'

Why isn't it reading the copper or silver?

-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 #6 on Sun 08 Feb 2004 10:22 PM (UTC)
Message
Well, if its not working for copper or silver, you should post the code for copper and silver, makes it much easier. Also, if your going to use [code][/code], you have to check the box below the entry box that says "Forum codes".

Anyways, yeah, if you can post the silver/copper part( or the whole thing) we might be able to better help you.

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #7 on Mon 09 Feb 2004 03:40 AM (UTC)
Message
Once again, sorry about the forum codes.. still trying to get the hang of it.

About the silver and copper, I'm not sure what you mean. All the code I've added into the do_withdraw function I've posted already. Is there anything else you would need? I was under the assumption that what I added to that function would work the way the original snippet did. What I did was I basically copied the original part of the snippet which called for withdrawing gold, and tried making it so it would do the same for copper and silver. I'm still a novice at this, so I assumed it would work right... but it didn't.

-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 #8 on Mon 09 Feb 2004 06:09 AM (UTC)
Message
My bad, you said deposit, and I assumed thats what it was, not the withdraw code, sorry. The thing is, you are not asking at any point which they want, you have no !str_cmp if they are asking for gold, silver, or copper. Since it gets to here:

if ( str_cmp( arg1, "all" ) && !is_number( arg1 ) )
{ 
sprintf( buf, "%s How much gold do you wish to withdraw?", ch->name );
do_tell( banker, buf );
return;
}
If you put, "withdraw 100 silver", it is not all, and arg1 is not a number, so that if check is true, and so it does that code. You need something like:

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



Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #9 on Mon 09 Feb 2004 07:08 AM (UTC)
Message
OK... I added what you suggested, recompiled, and still only accepts gold. Strangly enough though, if I deposit 300 gold I get this for a balance:

You have 300 gold, 1635017078 silver, and 114 copper in the bank.

void do_deposit( CHAR_DATA *ch, char *argument )
{
  CHAR_DATA *banker;
  char arg1[MAX_INPUT_LENGTH];
  char arg2[MAX_INPUT_LENGTH];
  char arg3[MAX_INPUT_LENGTH];
  char buf [MAX_STRING_LENGTH];
  int amount;
  
  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 );
  argument = one_argument( argument, arg3 );

  if ( arg1 == '\0' || arg2 == '\0' || arg3 == '\0' )
  {
    sprintf( buf, "%s How much gold, silver, or copper do you wish to deposit?", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( !str_cmp( arg1, "gold" ) && !is_number( arg1 ) )
  {
    sprintf( buf, "%s How much gold do you wish to deposit?", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( !str_cmp( arg1, "all" ) )
    {
    amount = ch->gold;
    }
  else
    {
    amount = atoi( arg1 );
    }
  
  if ( amount > ch->gold )
    {
    sprintf( buf, "%s Sorry, but you don't have that much gold to deposit.", ch->name );
    do_tell( banker, buf );
    return;
    }
  else
  {
  ch->gold		-= amount;
  ch->pcdata->balance += amount;
  set_char_color( AT_PLAIN, ch );
  ch_printf( ch, "You deposit %d gold.\n\r", amount );
  sprintf( buf, "$n deposits some coins.\n\r" );
  act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  save_char_obj( ch );
  return;
  }

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

  if ( !str_cmp( arg3, "copper" ) && !is_number( arg3 ) )
  {
    sprintf( buf, "%s How much copper do you wish to deposit?", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( !str_cmp( arg3, "all" ) )
    {
    amount = ch->copper;
    }
  else
    {
    amount = atoi( arg3 );
    }
  
  if ( amount > ch->copper )
  {
    sprintf( buf, "%s Sorry, but you don't have that much copper to deposit.", ch->name );
    do_tell( banker, buf );
    return;
  }
    
  if ( amount <= 0 )
  {
    sprintf( buf, "%s Oh, I see.. you're a comedian.", ch->name );
    do_tell( banker, buf );
    return;
  }
  else
  {
  ch->copper	-= amount;
  ch->pcdata->balance += amount;
  set_char_color( AT_PLAIN, ch );
  ch_printf( ch, "You deposit %d copper.\n\r", amount );
  sprintf( buf, "$n deposits some coins.\n\r" );
  act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  save_char_obj( ch );
  return;
}
}


That's do_deposit. Figure that might help too. Even when u deposit 100 silver, I still get the "you don't have enough gold" message.

-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 #10 on Mon 09 Feb 2004 07:20 AM (UTC)
Message
Thats because you have it sitting all out in the open, as well as your using the wrong checks with the wrong argument. You don't need arg3, as far as I can tell. You need a section for each type, like:
// Gold section
if ( !str_cmp( arg2, "gold" ) )
{
	// Check if they entered "deposit all gold" or "deposit some gold"
	if ( str_cmp(arg1, "all") && !is_number( arg1 ) )
  	{
		sprintf( buf, "%s How much gold do you wish to deposit?", ch->name );
		do_tell( banker, buf );
    		return;
  	}
    
  	if ( !str_cmp( arg1, "all" ) )
    		amount = ch->gold;
  	else
    		amount = atoi( arg1 );
  
  	if ( amount > ch->gold )
    	{
    		sprintf( buf, "%s Sorry, but you don't have that much gold to deposit.", ch->name );
    		do_tell( banker, buf );
    		return;
    	}

  	ch->gold -= amount;
  	ch->pcdata->balance += amount;
  	set_char_color( AT_PLAIN, ch );
  	ch_printf( ch, "You deposit %d gold.\n\r", amount );
  	sprintf( buf, "$n deposits some coins.\n\r" );
  	act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
  	save_char_obj( ch );
  	return;
}


If you copy that for silver and gold, that should work as well. However, I notice that they are all deposited into ch->pcdata->balance. How does it know to differentiate the gold from silver or copper?

Hope that helps

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #11 on Mon 09 Feb 2004 08:01 AM (UTC)
Message
OK. I did what you said and it worked, with a minor flaw. If you type "deposit all" with a coin type, it looks like it just goes to a NULL call.

Just need to set up something similiar with withdraw now I guess.

And for your question about do_balance, I haven't really toyed with that yet. Not sure how to get it to read copper and silver. Gonna have to try to hunt down ch->pcdata->balance and see how to alter it abit

-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 #12 on Mon 09 Feb 2004 08:38 AM (UTC)
Message
Alrighty.. just about there... I put everything into withdraw, and got that working. Now comes do_balance.. originally, in order to check the players balance it called to this:

ch->pcdata->balance

which is all fine and dany, yet it only read gold. I went and found the original snippet and found this:

ch_printf( ch,  "You have %s gold, ", num_punct(ch->gold) );
	ch_printf( ch,"%s silver",num_punct(ch->silver));
	ch_printf(ch,", and %s copper coins.\n\r",num_punct(ch->copper) );


what that does is calls to the amount of coins you are currently carrying on you. what I'm trying to do now is get it to read from the ch->pc->balance, but the problem is I think balance only calls to the amount of gold, and I'm snagged as to how to change that. lemme put up the address where the snippet it:

http://www.afkmud.com/scripts/download.php?file=Sadiq/money.txt

that's the currency snippet I used.

-Toy is so close to getting this stupid snippet right he can taste it...

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 #13 on Mon 09 Feb 2004 09:13 AM (UTC)
Message
What you want is ch->pcdata->goldbalance, ch->pcdata->silverbalance, ch->pcdata->copperbalance. You'll wanna change do_withdraw and do_deposit, and change ch->pcdata->balance to the appropriate field. You need to also add them to pc_data in mud.h.

Nobody ever expects the spanish inquisition!

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

Posted by Toy   (206 posts)  Bio
Date Reply #14 on Mon 09 Feb 2004 09:56 AM (UTC)
Message
Cool. I got everything in and working now. Thanks alot for the help. Now, for my own personal amuzement, I'm going to see if I can get it to make change

ie if I deposit 30,000 copper, I wanna see if I can get it so it'll change into the proper amounts of gold and silver.

This should be amuzing... ;p

-Toy the Ever-amazing at Making His Life Hard

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.


156,257 views.

This is page 1, subject is 5 pages long: 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.