Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

Coding problem

Started by Gutlan May 27, 2008 at 12:07 PM 6 replies 1.2k views
Original Post
Gutlan
Gutlan
So, i'm hookin autostance up and for some reason it wont save the autostance and also the players are saying they arn't actually ever dropping into the stance whether attacking or being attacked.. can anyone see why?

 void do_autostance(CHAR_DATA *ch, char *argument )
 {
   char arg [MAX_INPUT_LENGTH];
 
   one_argument( argument, arg, MAX_INPUT_LENGTH );
   if (IS_NPC(ch)) return;
   if (!str_cmp(arg,"none"))
   {
     send_to_char("Autostance set to None.\n\r", ch );
     ch->stance[AUTODROP] = STANCE_NONE;
   }
   else if (!str_cmp(arg, "crane"))
   {
     send_to_char("Autostance set to Crane.\n\r",ch );
     ch->stance[AUTODROP] = STANCE_CRANE;
   }
   else if (!str_cmp(arg, "bull"))
   {
     send_to_char("Autostance set to Bull.\n\r", ch );
     ch->stance[AUTODROP] = STANCE_BULL;
   }
   else if (!str_cmp(arg, "viper"))
   {
     send_to_char("Autostance set to Viper.\n\r", ch );
     ch->stance[AUTODROP] = STANCE_VIPER;
   }
   else if (!str_cmp(arg, "mongoose"))
   {
     send_to_char("Autostance set to Mongoose.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_MONGOOSE;
   }
   else if (!str_cmp(arg, "swallow") && ch->stance[STANCE_CRANE] >= 200 && ch->stance[STANCE_MONGOOSE] >= 200 )
   {
     send_to_char("Autostance set to Swallow.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_SWALLOW;
   }
   else if (!str_cmp(arg, "lion") && ch->stance[STANCE_BULL] >= 200 && ch->stance[STANCE_VIPER] >= 200 )
   {
     send_to_char("Autostance set to Lion.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_LION;
   }
   else if (!str_cmp(arg, "falcon") && ch->stance[STANCE_MONGOOSE] >= 200 && ch->stance[STANCE_BULL] >= 200 )
   {
     send_to_char("Autostance set to Falcon.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_FALCON;
   }
   else if (!str_cmp(arg, "cobra") && ch->stance[STANCE_VIPER] >= 200 && ch->stance[STANCE_CRANE] >= 200 )
   {
     send_to_char("Autostance set to Cobra.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_COBRA;
   }
   else if (!str_cmp(arg, "panther") && ch->stance[STANCE_VIPER] >= 200 && ch->stance[STANCE_MONGOOSE] >= 200 )
   {
     send_to_char("Autostance set to Panther.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_PANTHER;
   }
   else if (!str_cmp(arg, "grizzlie") && ch->stance[STANCE_BULL] >= 200 && ch->stance[STANCE_CRANE] >= 200 )
   {
     send_to_char("Autostance set to Grizzlie.\n\r", ch);
     ch->stance[AUTODROP] = STANCE_GRIZZLIE;
   }
   else send_to_char ("No such Stance.\n\r", ch);
 }
 
 void autodrop(CHAR_DATA *ch)
 {
   char buf [MAX_INPUT_LENGTH];
   char buf2 [MAX_INPUT_LENGTH];
   char stancename [10];
 
   if (IS_NPC(ch)) return;
   if (ch->stance[AUTODROP]==STANCE_NONE) return;
   else if (ch->stance[AUTODROP]==STANCE_VIPER) sprintf(stancename,"viper");
   else if (ch->stance[AUTODROP]==STANCE_CRANE) sprintf(stancename,"crane");
   else if (ch->stance[AUTODROP]==STANCE_MONGOOSE) sprintf(stancename,"mongoose");
   else if (ch->stance[AUTODROP]==STANCE_BULL) sprintf(stancename,"bull");
   else if (ch->stance[AUTODROP]==STANCE_SWALLOW) sprintf(stancename, "swallow");
   else if (ch->stance[AUTODROP]==STANCE_LION) sprintf(stancename, "lion");
   else if (ch->stance[AUTODROP]==STANCE_FALCON) sprintf(stancename, "falcon");
   else if (ch->stance[AUTODROP]==STANCE_PANTHER) sprintf(stancename, "panther");
   else if (ch->stance[AUTODROP]==STANCE_COBRA) sprintf(stancename, "cobra");
   else if (ch->stance[AUTODROP]==STANCE_GRIZZLIE) sprintf(stancename, "grizzlie");
   else return;
   if (ch->stance[0] < 1)
   {
     ch->stance[0] = ch->stance[AUTODROP];;
     sprintf(buf, "You fall into the %s stance.", stancename);
     act(buf, ch, NULL, NULL, TO_CHAR);
     sprintf(buf2, "$n falls into the %s stance.",stancename);
     act(buf2, ch, NULL, NULL, TO_ROOM);
   }
 }

Thanks:) [Edited by - Sandman on May 30, 2008 5:18:21 AM]
Sandman
Sandman
Game design is for discussion of game mechanics, rather than coding related stuff.

It might help to be a bit clearer about what the code is supposed to do, and what it actually does. If you aren't sure exactly what it is doing, then step through it in a debugger and see for yourself what the behaviour is. Also, comment how it is doing it a bit more, because there are a few things in that code that look a bit odd.

You'll probably find that the above steps will find your problem fairly quickly, and if it doesn't, we'll be better equipped to find the problem for you.

EDIT: also, [ source ] tags are best for posting code.
xanin
xanin
I answered your other post abour saving it.

Regarding dropping in to the stance, is the autodrop() function ever called? (probably needs to go somewhere in fight.c - maybe multi_hit(...) ? )
Gutlan
Gutlan
Alright in the MUD there are 10 stances viper,mongoose, ect. as read above. This code is meant to set the command do_autostance, in which you do autostance viper and when you start a fight, as long as you are not in a stance already, and have an autostance set, it will automatically make you drop into the stance you wish instead of manually typing stance viper every time before you start a fight. I fixed the autostance so that it will actually make the person automatically make you drop into the stance by making a call to autodrop in set_fighting in fight.c. What it does right now is say You autodrop into a fighting stance. I wish it to say you autodrop into the x fighting stance. It also needs to save to the player file. Which I totally have no clue how to do. In which it will save the stance you have autostance set to in the playerfile, so when you log back in you do not have to set your autostance again.
Sandman
Sandman
Quote:
Original post by Gutlan
What it does right now is say You autodrop into a fighting stance. I wish
it to say you autodrop into the x fighting stance.


This is probably because you're using sprintf() wrong in your big else if block. Specifically, you've missed out the format specifiers.

You currently have:
 else if (ch->stance[AUTODROP]==STANCE_VIPER) sprintf(stancename,"viper");   else if (ch->stance[AUTODROP]==STANCE_CRANE) sprintf(stancename,"crane");   else if (ch->stance[AUTODROP]==STANCE_MONGOOSE) sprintf(stancename,"mongoose");   else if (ch->stance[AUTODROP]==STANCE_BULL) sprintf(stancename,"bull");// ...etc


You should have something like:
 else if (ch->stance[AUTODROP]==STANCE_VIPER)  {    //             FORMAT SPECIFIER!    //                  |||||    //                  VVVVV    sprintf(stancename, "%s", "viper"); } else if (ch->stance[AUTODROP]==STANCE_CRANE)  {    sprintf(stancename, "%s", "crane"); } else if (ch->stance[AUTODROP]==STANCE_MONGOOSE)  {    sprintf(stancename, "%s", "mongoose"); } else if (ch->stance[AUTODROP]==STANCE_BULL)  {    sprintf(stancename, "%s", "bull"); }// ...etc

Alternatively, you could use strncpy() which is a bit simpler and a lot safer than sprintf and more appropriate for a case where you're just copying a string from one buffer to another, without any additional formatting.

Quote:

It also needs to save to the player file. Which I totally have no clue how to do. In which it will save the stance you have autostance set to in the playerfile, so when you log back in you do not have to set your autostance again.


You'll probably want to look into functions such as fopen(), fclose(), fread(), fwrite(), fprintf(), fscanf() and fflush() for handling file IO.
xanin
xanin
Quote:
Original post by Sandman
Quote:
Original post by Gutlan
What it does right now is say You autodrop into a fighting stance. I wish
it to say you autodrop into the x fighting stance.


This is probably because you're using sprintf() wrong in your big else if block. Specifically, you've missed out the format specifiers.


I was under the impression that that would work, its just a really bad idea?

Quote:
Original post by Sandman
Quote:

It also needs to save to the player file. Which I totally have no clue how to do. In which it will save the stance you have autostance set to in the playerfile, so when you log back in you do not have to set your autostance again.


You'll probably want to look into functions such as fopen(), fclose(), fread(), fwrite(), fprintf(), fscanf() and fflush() for handling file IO.


I covered what he'd need to do to save and load the field in one of his other threads here. No response as to if he actually tried it though.
Sandman
Sandman
Quote:
Original post by xanin
I was under the impression that that would work, its just a really bad idea?


Actually no you're right, it's fine, I'm having a stupid day. Although arguably anything with the letters 'printf' in it could be considered a really bad idea. I'm assuming the project is pure C rather than C++ though, so he's probably limited in his choices.

I'm not entirely sure what the problem is; I don't quite understand how the stance array is being used, which doesn't really help. What the hell is the significance of stance[0]?

My advice to the OP would be to step through with a debugger.
xanin
xanin
Quote:
Original post by Sandman
Quote:
Original post by xanin
I was under the impression that that would work, its just a really bad idea?


Actually no you're right, it's fine, I'm having a stupid day. Although arguably anything with the letters 'printf' in it could be considered a really bad idea. I'm assuming the project is pure C rather than C++ though, so he's probably limited in his choices.

I'm not entirely sure what the problem is; I don't quite understand how the stance array is being used, which doesn't really help. What the hell is the significance of stance[0]?

My advice to the OP would be to step through with a debugger.


It's a Godwars derivative mud, so it is (if i recall rightly) a pure C environment when stock.

I'm also not sure what the problem is because he hasn't given us any information about what doesn't work. As far as I can tell, what he posted looks like it should work - or generate compile errors. Since hes not posting about compiler errors and he's not providing any of the output from when the function is called, its sort of hard to tell. Without more information, sending him to the debugger is going to be the best bet I imagine...


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.