07 Oct, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello:
I'm wondering if someone can help me. Let me start by saying I'm not the most experienced coder. I want to change the do_wizhelp command to sort alphabetically. I am just not sure how to do it. Right now, our commands feature has everything jumbled together. And I'd like to take what I learn here and apply it to the other commands to sort them also by starting number/letter (such as do_commands, etc…). So, I'm hopeful someone can point me in the right direction and explain it to me in layman's terms too.
void do_wizhelp( CHAR_DATA *ch, char *argument )
{
char buf[MAX_STRING_LENGTH];
int cmd;
int col;

col = 0;
for ( cmd = 0; cmd_table[cmd].name[0] != '\0'; cmd++ )
{
if ( cmd_table[cmd].level >= LEVEL_IMMORTAL
&& cmd_table[cmd].level <= get_trust( ch )
&& cmd_table[cmd].show)
{
sprintf( buf, "%-18s", cmd_table[cmd].name );
send_to_char( buf, ch );
if ( ++col % 4 == 0 )
send_to_char( "\n\r", ch );
}
}

if ( col % 4 != 0 )
send_to_char( "\n\r", ch );
return;
}

Thank you,
Arholly
07 Oct, 2011, Runter wrote in the 2nd comment:
Votes: 0
The command table is an array. So the direction you want to look in is how to sort an array in C. It's a very entry level thing taught to first year students I believe. So there should be a lot of informaton on the various ways. Alternatively you can use some code already written for you. Specifically the qsort function. If you just want the simple and ulgy way to do it, just loop through every character in the alphabit and filter the array each pass by only elements starting with that character. I don't recommend this method, though.
07 Oct, 2011, Rarva.Riendf wrote in the 3rd comment:
Votes: 0
//create an ordered skill table
struct ordered_skill_type {
SKILL_DATA *skill;
short int sn;
};

typedef struct ordered_skill_type ORDERED_SKILL_DATA;
ORDERED_SKILL_DATA* ordered_skill_table[MAX_SKILL - 2];

int compare_skill(const void *v1, const void *v2) {
ORDERED_SKILL_DATA *a1 = *(ORDERED_SKILL_DATA**)v1;
ORDERED_SKILL_DATA *a2 = *(ORDERED_SKILL_DATA**)v2;
return strcasecmp(a1->skill->name, a2->skill->name);
}

for (sn = 1;sn < MAX_SKILL -1;sn ++) {//last skill is the NULL one first the reserved…
ordered_skill_table[sn-1] = malloc(sizeof(ORDERED_SKILL_DATA));
ordered_skill_table[sn-1]->skill = (SKILL_DATA*)&skill_table[sn];
ordered_skill_table[sn-1]->sn = sn;
}
qsort(ordered_skill_table, MAX_SKILL-2, sizeof(ordered_skill_table[0]), compare_skill);


Thats what I did for my prac list, kind of the same.
Oh and there are 2 reasons the command are not ordered:
-They are grouped by thematic (example north west east or kill kick etc)
-They are ordered so some are before others so you dont have to type them fully
k will launch kill, and not kick
07 Oct, 2011, arholly wrote in the 4th comment:
Votes: 0
OK, so I get then that I shouldn't sort it for the reasons you guys mentioned. Is there a way to make it not quite so difficult to read through then or suggestions on how to do it?
07 Oct, 2011, Rarva.Riendf wrote in the 5th comment:
Votes: 0
arholly said:
OK, so I get then that I shouldn't sort it for the reasons you guys mentioned. Is there a way to make it not quite so difficult to read through then or suggestions on how to do it?

Err not what I was saying, you should keep the list as it is, but nothing prevents you from creating another just for show as I did with the skill list.
0.0/5