new command help

Posted by Frobozz on Tue 23 Nov 2004 09:00 PM — 8 posts, 25,139 views.

#0
I am trying to create a command, like glance in a way, that shows just the current state of the victim (target). This is the code that I have so far (again on smaug fuss):

void do_xa( CHAR_DATA *ch, char *argument )

char arg[MAX_INPUT_LENGTH];
CHAR_DATA *victim;
char *msg;
int diff;

one_argument( argument, arg );

if ( arg[0] == '\0' )
{
send_to_char( "&wxa <&Cvictim&w>\n\r", ch );
return;
}

if ( ( victim = get_char_room( ch, arg ) ) == NULL )
{
send_to_char( "They do not seem to be here.\n\r", ch );
return;
}

percent = (( victim->hit) / victim->max_hit));


if ( percent = 100 ) msg = "&w$N(is in &Gperfect health&w)";
else if ( percent >= 90 ) msg = "&w$N(is &gslightly scratched&w)";
else if ( percent >= 80 ) msg = "&w$N(has a &Yfew bruises&w)";
else if ( percent >= 70 ) msg = "&w$N(has &Osome cuts&w)";
else if ( percent >= 60 ) msg = "&w$N(has &Rseveral wounds&w)";
else if ( percent >= 50 ) msg = "&w$N(has &Rnasty wounds&w)";
else if ( percent >= 40 ) msg = "&w$N(is &rbleeding freely&w)";
else if ( percent >= 30 ) msg = "&w$N(is &rcovered in blood&w)";
else if ( percent >= 20 ) msg = "&w$N(is &pleaking guts&w)";
else if ( percent >= 10 ) msg = "&w$N(is &palmost dead!)";
else msg = "&w$N(is &zDYING!)";
act( AT_XA, msg, ch, NULL, victim, TO_CHAR );


return;
}

do_xa has been declared in mud.h and tables.c, but these are the errors that I have sent back to me upon compile:

make -s smaug
Compiling o/act_info.o....
act_info.c: In function `do_xa':
act_info.c:3091: parse error before `one_argument'
act_info.c:3086: parm types given both in parmlist and separately
act_info.c: At top level:
act_info.c:3099: parse error before `if'
cc1: warnings being treated as errors
act_info.c:3105: warning: type defaults to `int' in declaration of `percent'
act_info.c:3105: `victim' undeclared here (not in a function)
act_info.c:3105: `victim' undeclared here (not in a function)
act_info.c:3105: parse error before `)'
act_info.c:3118: parse error before `('
make[1]: *** [o/act_info.o] Error 1
make: *** [all] Error 2

As always your help is greatly appreciated.

-Frobozz
#1
I take that back, the command is:

void do_xa( CHAR_DATA *ch, char *argument )

char arg[MAX_INPUT_LENGTH];
CHAR_DATA *victim;
char *msg;
int diff;

one_argument( argument, arg );

if ( arg[0] == '\0' )
{
send_to_char( "&wxa <&Cvictim&w>\n\r", ch );
return;
}

if ( ( victim = get_char_room( ch, arg ) ) == NULL )
{
send_to_char( "They do not seem to be here.\n\r", ch );
return;
}

percent = (100 * victim->hit) / victim->max_hit;


if ( percent = 100 ) msg = "&w$N(is in &Gperfect health&w)";
else if ( percent >= 90 ) msg = "&w$N(is &gslightly scratched&w)";
else if ( percent >= 80 ) msg = "&w$N(has a &Yfew bruises&w)";
else if ( percent >= 70 ) msg = "&w$N(has &Osome cuts&w)";
else if ( percent >= 60 ) msg = "&w$N(has &Rseveral wounds&w)";
else if ( percent >= 50 ) msg = "&w$N(has &Rnasty wounds&w)";
else if ( percent >= 40 ) msg = "&w$N(is &rbleeding freely&w)";
else if ( percent >= 30 ) msg = "&w$N(is &rcovered in blood&w)";
else if ( percent >= 20 ) msg = "&w$N(is &pleaking guts&w)";
else if ( percent >= 10 ) msg = "&w$N(is &palmost dead!)";
else msg = "&w$N(is &zDYING!)";
act( AT_XA, msg, ch, NULL, victim, TO_CHAR );


return;
}

My math was bad. But errors are still the same.
USA #2
void do_xa( CHAR_DATA *ch, char *argument )

char arg[MAX_INPUT_LENGTH];
...

You don't actually open up the first curly bracket. :-)
#3
Thanks you have been a huge help so far, Im slowly moving from absolute total newbie to... slightly above total newbie. The new error is:

make -s smaug
Compiling o/act_comm.o....
Compiling o/act_info.o....
act_info.c: In function `do_xa':
act_info.c:3105: `percent' undeclared (first use in this function)
act_info.c:3105: (Each undeclared identifier is reported only once
act_info.c:3105: for each function it appears in.)
act_info.c:3119: `AT_XA' undeclared (first use in this function)
cc1: warnings being treated as errors
act_info.c:3089: warning: unused variable `diff'
make[1]: *** [o/act_info.o] Error 1
make: *** [all] Error 2
[frobozz@bb7 src]$

#4
Ok, I slipped back to absolute newbie status and found the above errors and got rid of them. I have this now:

make -s smaug
Compiling o/act_info.o....
cc1: warnings being treated as errors
act_info.c: In function `do_xa':
act_info.c:3108: warning: suggest parentheses around assignment used as truth value
make[1]: *** [o/act_info.o] Error 1
#5
if ( percent >= 100 ) msg = "&w$N(is in &Gperfect health&w)";

I added the > rather than just having this:

if ( percent = 100 ) msg = "&w$N(is in &Gperfect health&w)";


Is there a better way to go?

Again thanks to all for the massive support so far. It's good to be back I guess!
USA #6
Quote:
act_info.c:3108: warning: suggest parentheses around assignment used as truth value
This warning is actually trying to be your friend but is pointing out a different mistake. What it's saying is that in cases like this:
if ( (foo = 1) == 1 ) {
/* do something */
}
The parentheses around foo = 1 make it quite clear that you're doing the assignment of 1 to foo, and then comparing the result of that assignment (which is the value of 'foo') to 1.

Indeed, if you look at your code here:
if ( percent = 100 ) msg = "&w$N(is in &Gperfect health&w)";
- you'll note that you have only a single equal, so you are assigning 100 to percent - and not what you probably meant, which was to see if percent equals 100, in which case you need ==, not =.
#7
Indeed, thank you very much!

Two more questions from this and Im done with this forum I swear! And I'll post the finish code for anyone that wants to use it.

1- How do I set this command to default to your opponent in combat?
---> I've looked at other skills like do_cast and it really doesnt seem to make a lot of sense to me.

2- How do I set this command to switch between different people of the same race.. the way look does with objects?
---> so xa soldier and xa soldier 2 would return the health of soldier 1 and the health of soldier 2.. so on and so on.

Thanks!