Jump to content

Command - ChangeRace


flygun

Recommended Posts

  • Former Staff

this is new gm command

 

in cmd.cpp write

ACMD(do_change_race);

and this

{ "change_race",	do_change_race,	0,	POS_DEAD,	GM_IMPLEMENTOR },

in cmd_gm.cpp

 

write this

ACMD(do_change_race)
{
	char arg1[256];
	one_argument(argument, arg1, sizeof(arg1));
	if (!*arg1)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "Usage: /change_race <Num> ");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_M	= 0");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_W = 1");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_M = 2"); 
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_W = 3");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_W = 4");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_M = 5");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_W = 6");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_M = 7");
//		ch->ChatPacket(CHAT_TYPE_INFO, "");
		return;
	}
	int race;
	str_to_number(race, arg1);
	if (race > 7 || race < 0)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "The Number must be from 0 --> 7 only");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_M	= 0");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_W = 1");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_M = 2");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_W = 3");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_W = 4");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_M = 5");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_W = 6");
		ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_M = 7");
		return;
	}
	ch->SetRace(race);
	ch->ChatPacket(CHAT_TYPE_INFO, "Race= %d", ch->GetRaceNum());
	ch->ClearSkill();
	ch->SetSkillGroup(0);
	ch->ClearSubSkill();
}

if anyone don't want to add new GM command you can make it like Zerelth™

 

down here :)

 |||

 |||

 |||

 |||

 V

Edited by flygun
  • Love 3
Link to comment
Share on other sites

  • Bronze

You have a few error about types. You don't need to use integer for race. BYTE is enough for it and you don't need to create new one.

 

const struct set_struct 
{
	const char *cmd;
	const char type;
} set_fields[] = {
	{ "gold",		NUMBER	},
	{ "race",		NUMBER	},
	{ "sex",		BINARY	},
	{ "exp",		NUMBER	},
	{ "max_hp",		NUMBER	},
	{ "max_sp",		NUMBER	},
	{ "skill",		NUMBER	},
	{ "alignment",	NUMBER	},
	{ "align",		NUMBER	},
	{ "n",		MISC	}
};
ACMD(do_set)
{
	char arg1[256], arg2[256], arg3[256];

	LPCHARACTER tch = NULL;

	int i, len;
	const char* line;

	line = two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));
	one_argument(line, arg3, sizeof(arg3));

	if (!*arg1 || !*arg2 || !*arg3)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "Usage: set <name> <field> <value>");
		return;
	}

	tch = CHARACTER_MANAGER::instance().FindPC(arg1);

	if (!tch)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "%s not exist", arg1);
		return;
	}

	len = strlen(arg2);

	for (i = 0; *(set_fields[i].cmd) != 'n'; i++)
		if (!strncmp(arg2, set_fields[i].cmd, len))
			break;

	switch (i)
	{
		case 0:	// gold
			{
				int gold = 0;
				str_to_number(gold, arg3);
				DBManager::instance().SendMoneyLog(MONEY_LOG_MISC, 3, gold);
				int before_gold = tch->GetGold();
				tch->PointChange(POINT_GOLD, gold, true);
				int after_gold = tch->GetGold();
				if (0 == after_gold && 0 != before_gold)
				{
					LogManager::instance().CharLog(tch, gold, "ZERO_GOLD", "GM");
				}
			}
			break;

		case 1: // race
			{
				BYTE bRace;
				str_to_number(bRace, arg3);
				if (bRace > 7 || bRace < 0)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, "The Number must be from 0 --> 7 only");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_M   = 0");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_W = 1");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_M = 2");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_W = 3");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_W = 4");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_M = 5");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_W = 6");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_M = 7");
					return;
				}

				ch->SetRace(bRace);
                                ch->SetSkillGroup(0);
				ch->ClearSkill();
				ch->ClearSubSkill();			
			}
			break;

		case 2: // sex
			break;

		case 3: // exp
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_EXP, amount, true);
			}
			break;

		case 4: // max_hp
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_MAX_HP, amount, true);
			}
			break;

		case 5: // max_sp
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_MAX_SP, amount, true);
			}
			break;

		case 6: // active skill point
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_SKILL, amount, true);
			}
			break;

		case 7: // alignment
		case 8: // alignment
			{
				int	amount = 0;
				str_to_number(amount, arg3);
				tch->UpdateAlignment(amount - ch->GetRealAlignment());
			}
			break;
	}

	if (set_fields[i].type == NUMBER)
	{
		int	amount = 0;
		str_to_number(amount, arg3);
		ch->ChatPacket(CHAT_TYPE_INFO, "%s's %s set to [%d]", tch->GetName(), set_fields[i].cmd, amount);
	}
}

 

PS:

 ch->set_skill_group

The people can write "I got error" :)

 

Kind Regards

Zerelth ~ Ellie

Edited by Zerelth™

Do not be sorry, be better.

Link to comment
Share on other sites

  • Former Staff

mmm i actually tried to do it like this but didn't work cus i just saw it yesterday  so i didn't give this code my attention

i think i do it like you

 

 

and about this

ch->SetSkillGroup(0);

i wrote it so that the GM or the player can go and chose which type of skill that he want

 

 it's work fine i think  :)

sorry for bad english

and thank you

  FlyGun :)

Edited by flygun
Link to comment
Share on other sites

No, it's not working fine. You wrote

ch->set_skill_group

Which won't compile. Probably due to copypaste or whatever, but its there in your post and that's what Zerelth is pointing out, not the correct SetSkillGroup(0)

Link to comment
Share on other sites

  • Former Staff

No, it's not working fine. You wrote

ch->set_skill_group

Which won't compile. Probably due to copypaste or whatever, but its there in your post and that's what Zerelth is pointing out, not the correct SetSkillGroup(0)

sorry but  i didn't get what is the point ??

 

should i write it like this ?

ch->set_skill_group
Link to comment
Share on other sites

  • Former Staff

The event set_skill_group doesn't exist,that's his point.You should use instead SetSkillGroup

oh i got it .... but idk i didn't get any error with  set_skill_group but I i will check it now and I'll edit the topic ...

 

thanks denis

 

aha T_T i wrote it like this

    ch->SetRace(race);
    ch->ChatPacket(CHAT_TYPE_INFO, "Race= %d", ch->GetRaceNum());
    ch->ClearSkill();
    ch->SetSkillGroup(0);
    ch->ClearSubSkill();
    ch->set_skill_group

:huh: i wrote "set skill group" twice

i'v edited the topic and :)

Edited by flygun
Link to comment
Share on other sites

  • 3 weeks later...

You have a few error about types. You don't need to use integer for race. BYTE is enough for it and you don't need to create new one.

 

const struct set_struct 
{
	const char *cmd;
	const char type;
} set_fields[] = {
	{ "gold",		NUMBER	},
	{ "race",		NUMBER	},
	{ "sex",		BINARY	},
	{ "exp",		NUMBER	},
	{ "max_hp",		NUMBER	},
	{ "max_sp",		NUMBER	},
	{ "skill",		NUMBER	},
	{ "alignment",	NUMBER	},
	{ "align",		NUMBER	},
	{ "n",		MISC	}
};
ACMD(do_set)
{
	char arg1[256], arg2[256], arg3[256];

	LPCHARACTER tch = NULL;

	int i, len;
	const char* line;

	line = two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));
	one_argument(line, arg3, sizeof(arg3));

	if (!*arg1 || !*arg2 || !*arg3)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "Usage: set <name> <field> <value>");
		return;
	}

	tch = CHARACTER_MANAGER::instance().FindPC(arg1);

	if (!tch)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "%s not exist", arg1);
		return;
	}

	len = strlen(arg2);

	for (i = 0; *(set_fields[i].cmd) != 'n'; i++)
		if (!strncmp(arg2, set_fields[i].cmd, len))
			break;

	switch (i)
	{
		case 0:	// gold
			{
				int gold = 0;
				str_to_number(gold, arg3);
				DBManager::instance().SendMoneyLog(MONEY_LOG_MISC, 3, gold);
				int before_gold = tch->GetGold();
				tch->PointChange(POINT_GOLD, gold, true);
				int after_gold = tch->GetGold();
				if (0 == after_gold && 0 != before_gold)
				{
					LogManager::instance().CharLog(tch, gold, "ZERO_GOLD", "GM");
				}
			}
			break;

		case 1: // race
			{
				BYTE bRace;
				str_to_number(bRace, arg3);
				if (bRace > 7 || bRace < 0)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, "The Number must be from 0 --> 7 only");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_M   = 0");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_W = 1");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_M = 2");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_W = 3");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_WARRIOR_W = 4");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_ASSASSIN_M = 5");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SURA_W = 6");
					ch->ChatPacket(CHAT_TYPE_INFO, "RACE_SHAMAN_M = 7");
					return;
				}

				ch->SetRace(bRace);
                                ch->SetSkillGroup(0);
				ch->ClearSkill();
				ch->ClearSubSkill();			
			}
			break;

		case 2: // sex
			break;

		case 3: // exp
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_EXP, amount, true);
			}
			break;

		case 4: // max_hp
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_MAX_HP, amount, true);
			}
			break;

		case 5: // max_sp
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_MAX_SP, amount, true);
			}
			break;

		case 6: // active skill point
			{
				int amount = 0;
				str_to_number(amount, arg3);
				tch->PointChange(POINT_SKILL, amount, true);
			}
			break;

		case 7: // alignment
		case 8: // alignment
			{
				int	amount = 0;
				str_to_number(amount, arg3);
				tch->UpdateAlignment(amount - ch->GetRealAlignment());
			}
			break;
	}

	if (set_fields[i].type == NUMBER)
	{
		int	amount = 0;
		str_to_number(amount, arg3);
		ch->ChatPacket(CHAT_TYPE_INFO, "%s's %s set to [%d]", tch->GetName(), set_fields[i].cmd, amount);
	}
}

 

PS:

 ch->set_skill_group
The people can write "I got error" :)

 

Kind Regards

Zerelth ~ Ellie

if anyone use your way he/she will be able to change only it's own race not others.

"ch->SetRace(bRace);

ch->SetSkillGroup(0);

ch->ClearSkill();

ch->ClearSubSkill();"

"ch" - means the one who's using this cmd (it doesn't matter who's name is in cmd "/set" it will change YOUR race), so if you want to change others race (eg. players), change "ch" to the 1st argument which is "tch":

tch->SetRace(bRace);

tch->SetSkillGroup(0);

tch->ClearSkill();

tch->ClearSubSkill();

Link to comment
Share on other sites

I was just practicing how to make new command so I only gave GMs (No matter gm level ) the permission to change the race

my above reply wasn't for your tutorial, it was like an adition/correction for Rize™'s answer

Link to comment
Share on other sites

  • Former Staff

 

I was just practicing how to make new command so I only gave GMs (No matter gm level ) the permission to change the race

my above reply wasn't for your tutorial, it was like an adition/correction for Rize™'s answer

 

yes i know ... :)

Link to comment
Share on other sites

  • 6 years later...
  • Premium

This don't do the same? Why so many lines for a simple code

Spoiler


ACMD(do_change_race)
{
	char arg1[256];
	int race;
	one_argument(argument, arg1, sizeof(arg1));
	if (!*arg1 || race > 7 || race < 0)	{
		ch->ChatPacket(CHAT_TYPE_INFO, "Usage: /race <Num> ");
		return;
	}
	
	str_to_number(race, arg1);
	ch->RemoveGoodAffect();
	ch->SetRace(race);
	ch->ClearSkill();
	ch->SetSkillGroup(0);
	ch->ClearSubSkill();
	ch->SetPolymorph(101);
	ch->SetPolymorph(0);
	ch->WarpSet(ch->GetX(), ch->GetY(), ch->GetMapIndex());
}

 

 

Edited by EnKor
if pc.get_sex() == true and npc.get_sex() == false then
	npc.purge()
end

 

Link to comment
Share on other sites



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.