PDA

View Full Version : Random NPC names with the @ Symbol


Secrets
03-03-2010, 03:38 AM
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.

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)

Akkadius
03-03-2010, 04:10 AM
So me and Secrets put this in and this is what we got


http://img.photobucket.com/albums/v450/Blade654/EQ000039.jpg

One #repop later...

http://img.photobucket.com/albums/v450/Blade654/EQ000038.jpg

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.

KLS
03-03-2010, 04:16 AM
My god the random name generator needs work =p

Akkadius
03-03-2010, 04:16 AM
That I would probably agree with

Secrets
03-03-2010, 04:17 AM
My god the random name generator needs work =p

it's copypasta from world, lol ><

I agree it does need work though.

ChaosSlayerZ
03-03-2010, 12:51 PM
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?

Secrets
03-03-2010, 03:06 PM
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.

ChaosSlayerZ
03-03-2010, 10:03 PM
I suddenly imagine a whole dungeon full of goblin_@ :D
You imagine the players frustration when they see 300+ randomly named goblins and try to figure out which one is actually NAMED? :grin: :grin: :grin:

pfyon
03-03-2010, 10:53 PM
I suddenly imagine a whole dungeon full of goblin_@ :D
You imagine the players frustration when they see 300+ randomly named goblins and try to figure out which one is actually NAMED? :grin: :grin: :grin:

That would be hilarious. I think I need to make a server designed to frustrate and confuse the player :p.

gaeorn
03-07-2010, 05:39 AM
That would be hilarious. I think I need to make a server designed to frustrate and confuse the player :p.

Sony already did that...