Try the following, I think part of your problem was that you were using
str_cmp for the name check instead of is_name, meaning that unless you
typed the exact name of the object (generally something like "standard
merc sub issue dagger"), the check wouldn't work right, is_name checks
one word against a name list to find a match on any of those words... I
also made it so you could transpose your name and level arguments (i.e.
you can type "checkweaps 17 dagger" or "checkweaps dagger 17"), or you
can enter either argument without having to enter the word 'null' for a
name, and it only has one loop section, which will cut down on the
number of lines in your file :) I haven't tested any of this, but in
theory it should work :D
Richard Lindsey.
void do_checkweaps(CHAR_DATA *ch, char *argument)
{
char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH],
buf[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH];
BUFFER *buffer;
OBJ_DATA *obj;
bool found;
int level = 0, number = 0;
found = FALSE;
number = 0;
name[0] = '\0';
buffer = new_buf();
argument = one_argument(argument, arg1);
argument = one_argument(argument, arg2);
if ( arg1[0] == '\0' )
{
send_to_char("Syntax: checkweaps <level or name> <level or
name>\n\r", ch);
return;
}
if ( is_number(arg1) )
level = atoi(arg1);
else sprintf(name,"%s",arg1);
if ( arg2[0] != '\0' )
{
if ( is_number(arg2) )
{
if ( level ) // User entered 2 level values
{
send_to_char("Please enter only 1 level value.\n\r",
ch);
return;
}
else level = atoi(arg2);
}
else if ( name[0] != '\0' ) // User entered 2 name values
{
send_to_char("Please enter only 1 name value.\n\r", ch);
return;
}
else sprintf(name,"%s",arg2);
}
// Now just execute 1 loop
for ( obj = object_list; obj != NULL; obj = obj->next )
{
if(obj->wear_loc == WEAR_WIELD
&& (name[0] == '\0' || is_name(name,obj->name))
&& (!level || obj->level == level))
{
number++;
sprintf(buf," %d ) [ AVG DAM: %3d ] [ LEVEL: %3d ]
%s\n\r",number,((1 + obj->value[2]) * obj->value[1] /
2),obj->level,obj->short_descr);
add_buf(buffer,buf);
}
}
if ( buf_string(buffer)[0] == '\0' )
send_to_char("No matching weapons found.\n\r", ch);
else page_to_char(buf_string(buffer),ch);
free_buf(buffer);
return;
}
-----Original Message-----
From: Tristan M [mailto:[EMAIL PROTECTED]
Sent: Friday, August 13, 2004 1:01 PM
To: [email protected]
Subject: a problem im having
i wrote this little function to list all the weapons in the game and
their
average damage, with two options, you can search for options of a
particular level, particular name, particular name and level, or just
list
all the objects. my problems are:
a) that when it tries to list by name(without level) it only shows
weapons
that are level 0
b) when it tries to list by name and level it doesnt spit anything out
heres the code, can someone find whats wrong? ive been looking at it and
just cant figure it out.
void do_checkweaps(CHAR_DATA *ch, char *argument)
{
char buf[MAX_INPUT_LENGTH];
char name[MAX_INPUT_LENGTH];
char level[MAX_INPUT_LENGTH];
BUFFER *buffer;
OBJ_DATA *obj;
bool found;
int number = 0;
found = FALSE;
number = 0;
buffer = new_buf();
argument = one_argument(argument, name);
argument = one_argument(argument, level);
if (name[0] == '\0' || ( !str_cmp( name, "null" ) && level[0] ==
'\0'))
{
log_string("1");
for ( obj = object_list; obj != NULL; obj = obj->next )
{
if(obj->wear_loc == WEAR_WIELD)
{
number++;
sprintf(buf," %d ) [ AVG DAM: %3d ] [
LEVEL: %3d ] %s\n\r",number,((1 +
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
add_buf(buffer,buf);
}
}
page_to_char(buf_string(buffer),ch);
return;
}
if (str_cmp( name, "null" ) && level[0] == '\0')
{
log_string("2");
for ( obj = object_list; obj != NULL; obj = obj->next )
{
if(str_cmp(name,obj->name))
continue;
if(obj->wear_loc == WEAR_WIELD)
{
number++;
sprintf(buf," %d ) [ AVG DAM: %3d ] [
LEVEL: %3d ] %s\n\r",number,((1 +
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
add_buf(buffer,buf);
}
}
page_to_char(buf_string(buffer),ch);
return;
}
if (!str_cmp( name, "null" ))
{
log_string("3");
for ( obj = object_list; obj != NULL; obj = obj->next )
{
if(obj->level != atoi(level))
continue;
if(obj->wear_loc == WEAR_WIELD)
{
number++;
sprintf(buf," %d ) [ AVG DAM: %3d ] [
LEVEL: %3d ] %s\n\r",number,((1 +
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
add_buf(buffer,buf);
}
}
page_to_char(buf_string(buffer),ch);
return;
}
log_string("4");
for ( obj = object_list; obj != NULL; obj = obj->next )
{
if(str_cmp(name,obj->name))
continue;
if(obj->level != atoi(level))
continue;
if(obj->wear_loc == WEAR_WIELD)
{
number++;
sprintf(buf," %d ) [ AVG DAM: %3d ] [ LEVEL: %3d
] %s\n\r",number,((1 +
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
add_buf(buffer,buf);
}
}
page_to_char(buf_string(buffer),ch);
return;
}
_________________________________________________________________
Take charge with a pop-up guard built on patented Microsoft(r)
SmartScreen
Technology
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU
=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN(r) Premium right now and get
the
first two months FREE*.
--
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom