Okay. Originally I'd taken the original function and simplified it to make it very fast and efficient, and it even let you use shortcuts to shrink the command down to one or two digits (nh for nexthelm, pt for prevtexture, etc.).
Then I saw what you were doing with your actual post, giving the option to change more fields with the #fixmob command than the existing ones, and the shortcuts and such wouldn't work out.
So, back to the original question, the main issue with with your code is that C++ does not support using the switch statement with strings (like Javascript, C#, etc, do). It only works with numbers and single chars.
Here's a reworked version of your code that runs efficiently and has plenty of room for expansion with new commands:
Code:
void command_fixmob(Client *c, const Seperator *sep)
{
Mob *target=c->GetTarget();
char* Usage = "Usage: #fixmob [gender]|[(next/prev)race|texture|helm|hairstyle|haircolor]";
if (!sep->arg[1])
c->Message(0,Usage);
else if (!target)
c->Message(0,"Error: this command requires an NPC target");
else
{
int16 Race = target->GetRace();
int8 Gender = target->GetGender();
int8 Texture = target->GetTexture();
int8 HelmTexture = target->GetHelmTexture();
int8 HairColor = target->GetHairColor();
int8 BeardColor = target->GetBeardColor();
int8 EyeColor1 = target->GetEyeColor1();
int8 EyeColor2 = target->GetEyeColor2();
int8 HairStyle = target->GetHairStyle();
int8 LuclinFace = target->GetLuclinFace();
int8 Beard = target->GetBeard();
int32 DrakkinHeritage = target->GetDrakkinHeritage();
int32 DrakkinTattoo = target->GetDrakkinTattoo();
int32 DrakkinDetails = target->GetDrakkinDetails();
char* ChangeType = NULL; // If it's still NULL after processing, they didn't send a valid command
int32 ChangeSetting;
char* command = sep->arg[1];
char codeMove;
char codeType;
codeMove = (command[0] | 0x20); // First character, lower-cased
if (strlen(command) > 4)
{
codeType = command[4] | 0x20; // Fifth character, lower-cased
}
else
{
codeType = NULL;
}
if (codeMove == 'g')
{
// Gender doesn't start with next/prev, so the first char is actually the type
codeType = codeMove;
}
switch (codeType)
{
case 'g': // Gender
if (strcasecmp(command, "gender") == 0)
{
Gender = (Gender == 2) ? 0 : Gender + 1; // 0 - 2
ChangeType = "Gender";
ChangeSetting = Gender;
}
break;
case 'r': // Race
switch (codeMove)
{
case 'n': // Next
if (strcasecmp(command, "nextrace") == 0)
{
Race = (Race == 586) ? 0 : Race + 1; // 0 - 586
ChangeType = "Race";
ChangeSetting = Race;
}
break;
case 'p': // Prev
if (strcasecmp(command, "prevrace") == 0)
{
Race = (Race == 0) ? 586 : Race - 1; // 0 - 586
ChangeType = "Race";
ChangeSetting = Race;
}
break;
}
break;
case 't': // Texture
switch (codeMove)
{
case 'n': // Next
if (strcasecmp(command, "nexttexture") == 0)
{
Texture = (Texture == 25) ? 0 : Texture + 1; // 0 - 25
ChangeType = "Texture";
ChangeSetting = Texture;
}
break;
case 'p': // Prev
if (strcasecmp(command, "prevtexture") == 0)
{
Texture = (Texture == 0) ? 25 : Texture - 1; // 0 - 25
ChangeType = "Texture";
ChangeSetting = Texture;
}
break;
}
break;
case 'h': // HelmTexture, HairStyle, HairColor
switch (codeMove)
{
case 'n': // Next
if (strcasecmp(command, "nexthelm") == 0)
{
HelmTexture = (HelmTexture == 25) ? 0 : HelmTexture + 1; // 0 - 25
ChangeType = "HelmTexture";
ChangeSetting = HelmTexture;
}
else if (strcasecmp(command, "nexthaircolor") == 0)
{
HairColor = (HairColor == 15) ? 0 : HairColor + 1; // 0 - 15
ChangeType = "HairColor";
ChangeSetting = HairColor;
}
else if (strcasecmp(command, "nexthairstyle") == 0)
{
HairStyle = (HairStyle == 7) ? 0 : HairStyle + 1; // 0 - 7
ChangeType = "HairStyle";
ChangeSetting = HairStyle;
}
break;
case 'p': // Prev
if (strcasecmp(command, "prevhelm") == 0)
{
HelmTexture = (HelmTexture == 0) ? 25 : HelmTexture - 1; // 0 - 25
ChangeType = "HelmTexture";
ChangeSetting = HelmTexture;
}
else if (strcasecmp(command, "prevhaircolor") == 0)
{
HairColor = (HairColor == 0) ? 15 : HairColor - 1; // 0 - 15
ChangeType = "HairColor";
ChangeSetting = HairColor;
}
else if (strcasecmp(command, "prevhairstyle") == 0)
{
HairStyle = (HairStyle == 0) ? 7 : HairStyle - 1; // 0 - 7
ChangeType = "HairStyle";
ChangeSetting = HairStyle;
}
break;
}
break;
default:
break;
}
if (ChangeType == NULL)
{
c->Message(0,Usage);
}
else
{
target->SendIllusionPacket(Race, Gender, Texture, HelmTexture, HairColor, BeardColor,
EyeColor1, EyeColor2, HairStyle, LuclinFace, Beard, 0xFF,
DrakkinHeritage, DrakkinTattoo, DrakkinDetails);
c->Message(0, "%s=%i", ChangeType, ChangeSetting);
}
}
}
I tested adding haircolor and hairstyle options.
Of course, options won't work if the illusion struct fields haven't been figured out.
I'll leave messing around with that one to you. Don't want to double up on your work. :P
- Shendare