Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Expanding on Alias snippet - adding system level aliases

Expanding on Alias snippet - adding system level aliases

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Gdub   (40 posts)  Bio
Date Fri 03 May 2024 07:54 PM (UTC)

Amended on Sat 04 May 2024 07:55 PM (UTC) by Nick Gammon

Message
expands on the existing alias snippet.

at the top of alias.c - add the following block of code


// system level aliases - based on spells given in class files
// Voodoo - 2024
#define MAX_SYSTEM_ALIASES 6

struct alias_struct
{
	char* aliasName;
	char* spellName;
};

// Declaration and initialization of _system_aliases
struct alias_struct _system_aliases[MAX_SYSTEM_ALIASES] =
{
	{ "crli", "cure light"},
	{ "crse", "cure serious"},
	{ "stsk", "stone skin"},
	{ "bles", "bless"},
	{ "cali", "cause light"},
	{ "curs", "curse"},
	//... add more here
};

void loadSystemAliases(CHAR_DATA* ch)
{
	char arg[MAX_INPUT_LENGTH] = "";
	char buf[MAX_STRING_LENGTH] = "";

	if (!ch)
		return; // bad

	char* spells[100] = { NULL }; // Initialize array with NULL pointers

	int sn = 0;

	// loop through class file of character
	// make a list of skills
	// if any of them match, add an alias
    int count = 0;
	for (sn = 0; sn < top_sn; sn++)
	{
		if (skill_table[sn]->skill_level[ch->class] != 0)
		{
			if (skill_table[sn]->type == SKILL_SPELL)
			{
				if (ch->pcdata->learned[sn] >= 1)
				{
					spells[count] = skill_table[sn]->name;
					sprintf(buf, "loadSystemAliases. Found %s's %s", ch->name, spells[count]);
					to_channel(buf, CHANNEL_MONITOR, "Debug", LEVEL_IMMORTAL);
                    count++;
				}

			}
		}
	}

	int size = sizeof(spells) / sizeof(spells[0]); // Assuming spells is the array of spell names
	int i = 0;
	while (i < size)
	{
		if (spells[i] != NULL)
		{
			int j = 0;
			while (j < MAX_SYSTEM_ALIASES)
			{
				if (_system_aliases[j].aliasName != NULL && _system_aliases[j].spellName != NULL)
				{
					// Debugging output
// 					sprintf(buf, "spell name: %s, command name: %s", spells[i], _system_aliases[j].spellName);
// 					to_channel(buf, CHANNEL_MONITOR, "Debug", LEVEL_IMMORTAL);

					// Compare spell name with alias name
					if (strcmp(spells[i], _system_aliases[j].spellName) == 0)
					{
						// Construct the alias argument
						sprintf(arg, "%s cast '%s'", _system_aliases[j].aliasName, _system_aliases[j].spellName);
						// Call the do_alias function with the constructed alias argument
						do_alias(ch, arg);
					,//	sprintf(buf, "loadSystemAliases. Making alias: %s.", arg);
					//	to_channel(buf, CHANNEL_MONITOR, "Debug", LEVEL_IMMORTAL);
					}
				}
				j++;
			}
		}
		i++;
	}

}




in comm.c, inside the nanny function where new characters are created. find this section


if (ch->level == 1)
{
	OBJ_DATA* obj;
...



add this new function call above the language checks:



loadSystemAliases(ch); // load em up! -Voodoo

if ((iLang = skill_lookup("common")) < 0)
	bug("Nanny: cannot find common language.");
else
	ch->pcdata->learned[iLang] = 100;


make clean, make smaug and good luck!
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 04 May 2024 07:57 PM (UTC)
Message
Whenever I see code suddenly turning into italics I know someone has forgotten to "escape" square brackets. I fixed it up for you.

Template:codetag To make your code more readable please use [code] tags as described here.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gdub   (40 posts)  Bio
Date Reply #2 on Sat 04 May 2024 11:25 PM (UTC)
Message
I will learn eventually :)

Nick Gammon said:

Whenever I see code suddenly turning into italics I know someone has forgotten to "escape" square brackets. I fixed it up for you.

(codetag)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,672 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.