Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2010, 03:38 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,449
Default Random NPC names with the @ Symbol

This makes it so it picks a random NPC name whenever the NPC has the symbol @ in its name. It also supports having the @ in the name where ever you want, so you could do "Guard @" and it would show up as "Guard Pyzui" for example, on a #repop of the zone. Good for completely random NPCs.

I don't know if this should be added to official SVN or not, but it shouldn't hurt because we never know if SOE will do random mob names in the future, plus it's not going to affect PEQ content (no @ symbols in the NPCs name atm, it's why I picked it)

It also adds support for a random name to be generated in MiscFunctions.cpp. Perhaps this could be ported to perl for whatever reason you may have.

Code:
Index: common/MiscFunctions.cpp
===================================================================
--- common/MiscFunctions.cpp	(revision 1272)
+++ common/MiscFunctions.cpp	(working copy)
@@ -490,3 +490,80 @@
 	return NewString;
 }
 
+char *GetRandomName()
+{
+
+// creates up to a 10 char name
+			char vowels[18]="aeiouyaeiouaeioe";
+			char cons[48]="bcdfghjklmnpqrstvwxzybcdgklmnprstvwbcdgkpstrkd";
+			char rndname[17]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+			char paircons[33]="ngrkndstshthphsktrdrbrgrfrclcr";
+			int rndnum=rand()%76,n=1;
+			bool dlc=false;
+			bool vwl=false;
+			bool dbl=false;
+			if (rndnum>63)
+			{	// rndnum is 0 - 75 where 64-75 is cons pair, 17-63 is cons, 0-16 is vowel
+				rndnum=(rndnum-61)*2;	// name can't start with "ng" "nd" or "rk"
+				rndname[0]=paircons[rndnum];
+				rndname[1]=paircons[rndnum+1];
+				n=2;
+			}
+			else if (rndnum>16)
+			{
+				rndnum-=17;
+				rndname[0]=cons[rndnum];
+			}
+			else
+			{
+				rndname[0]=vowels[rndnum];
+				vwl=true;
+			}
+			int namlen=(rand()%6)+5;
+			for (int i=n;i<namlen;i++)
+			{
+				dlc=false;
+				if (vwl)	//last char was a vowel
+				{			// so pick a cons or cons pair
+					rndnum=rand()%63;
+					if (rndnum>46)
+					{	// pick a cons pair
+						if (i>namlen-3)	// last 2 chars in name?
+						{	// name can only end in cons pair "rk" "st" "sh" "th" "ph" "sk" "nd" or "ng"
+							rndnum=(rand()%8)*2;
+						}
+						else
+						{	// pick any from the set
+							rndnum=(rndnum-47)*2;
+						}
+						rndname[i]=paircons[rndnum];
+						rndname[i+1]=paircons[rndnum+1];
+						dlc=true;	// flag keeps second letter from being doubled below
+						i+=1;
+					}
+					else
+					{	// select a single cons
+						rndname[i]=cons[rndnum];
+					}
+				}
+				else
+				{		// select a vowel
+					rndname[i]=vowels[rand()%17];
+				}
+				vwl=!vwl;
+				if (!dbl && !dlc)
+				{	// one chance at double letters in name
+					if (!(rand()%(i+10)))	// chances decrease towards end of name
+					{
+						rndname[i+1]=rndname[i];
+						dbl=true;
+						i+=1;
+					}
+				}
+			}
+			rndname[0]=toupper(rndname[0]);
+			char *NewString = new char[strlen(rndname) + 1];
+			strcpy(NewString, rndname);
+			return NewString;
+
+}
Index: common/MiscFunctions.h
===================================================================
--- common/MiscFunctions.h	(revision 1272)
+++ common/MiscFunctions.h	(working copy)
@@ -81,6 +81,7 @@
 int FloatToEQH(float d);
 void RemoveApostrophes(std::string &s);
 char *RemoveApostrophes(const char *s);
+char *GetRandomName();
 
 
 
Index: zone/mob.cpp
===================================================================
--- zone/mob.cpp	(revision 1272)
+++ zone/mob.cpp	(working copy)
@@ -141,6 +141,17 @@
 	name[0]=0;
 	clean_name[0]=0;
 	lastname[0]=0;
+
+	string findname("@");
+	string myname(in_name);
+	  string::size_type pos = 0;
+    while ( (pos = myname.find(findname, pos)) != string::npos ) {
+        myname.replace( pos, findname.size(), GetRandomName());
+        pos++;
+    }
+
+	in_name = myname.c_str();
+
 	if(in_name)
 		strncpy(name,in_name,64);
 	if(in_lastname)
Reply With Quote
  #2  
Old 03-03-2010, 04:10 AM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,072
Default

So me and Secrets put this in and this is what we got




One #repop later...



You can also use this to generate random PET names, for the makepet, which alone is enough to actually put in the official source. Thank you once again Secrets.
Reply With Quote
  #3  
Old 03-03-2010, 04:16 AM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

My god the random name generator needs work =p
Reply With Quote
  #4  
Old 03-03-2010, 04:16 AM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,072
Default

That I would probably agree with
Reply With Quote
  #5  
Old 03-03-2010, 04:17 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,449
Default

Quote:
Originally Posted by KLS View Post
My god the random name generator needs work =p
it's copypasta from world, lol ><

I agree it does need work though.
Reply With Quote
  #6  
Old 03-03-2010, 12:51 PM
ChaosSlayerZ's Avatar
ChaosSlayerZ
Demi-God
 
Join Date: Mar 2009
Location: Umm
Posts: 1,492
Default

would this code work together with npc quest scripts?

Like if I would have a guard_@.pl to run a quest scrip for all guards with random names?
Reply With Quote
  #7  
Old 03-03-2010, 03:06 PM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,449
Default

Quote:
Originally Posted by ChaosSlayerZ View Post
would this code work together with npc quest scripts?

Like if I would have a guard_@.pl to run a quest scrip for all guards with random names?
Yep. Quests work fine with them in that format.
Reply With Quote
  #8  
Old 03-03-2010, 10:03 PM
ChaosSlayerZ's Avatar
ChaosSlayerZ
Demi-God
 
Join Date: Mar 2009
Location: Umm
Posts: 1,492
Default

I suddenly imagine a whole dungeon full of goblin_@
You imagine the players frustration when they see 300+ randomly named goblins and try to figure out which one is actually NAMED?
Reply With Quote
  #9  
Old 03-03-2010, 10:53 PM
pfyon's Avatar
pfyon
Discordant
 
Join Date: Mar 2009
Location: Ottawa
Posts: 495
Default

Quote:
Originally Posted by ChaosSlayerZ View Post
I suddenly imagine a whole dungeon full of goblin_@
You imagine the players frustration when they see 300+ randomly named goblins and try to figure out which one is actually NAMED?
That would be hilarious. I think I need to make a server designed to frustrate and confuse the player :p.
Reply With Quote
  #10  
Old 03-07-2010, 05:39 AM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

Quote:
Originally Posted by pfyon View Post
That would be hilarious. I think I need to make a server designed to frustrate and confuse the player :p.
Sony already did that...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 05:12 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3