PDA

View Full Version : Merchant names when talking to players


Knightly
01-21-2008, 05:57 AM
When talking to players, the Merchant Name that shows up is not the version of the name with spaces so it shows up as:
Merchant_Name0 says, "Welcome to my shop!"

The fix for that is to edit zone\client_process.cpp and change the section from:
if(merch != NULL && handyitem){
char handy_id[8]={0};
int greeting=rand()%5;
int greet_id=0;
switch(greeting){
case 1:
greet_id=MERCHANT_GREETING;
break;
case 2:
greet_id=MERCHANT_HANDY_ITEM1;
break;
case 3:
greet_id=MERCHANT_HANDY_ITEM2;
break;
case 4:
greet_id=MERCHANT_HANDY_ITEM3;
break;
default:
greet_id=MERCHANT_HANDY_ITEM4;
}
sprintf(handy_id,"%i",greet_id);
char merchantname[64]={0};
strncpy(merchantname,merch->GetName(),strncpy(merchantname,merch->GetName(),strlen(merch->GetName())-2);
if(greet_id!=MERCHANT_GREETING){
Message_StringID(10,GENERIC_STRINGID_SAY,merchantn ame,handy_id,this->GetName(),handyitem->Name);

}
else
Message_StringID(10,GENERIC_STRINGID_SAY,merchantn ame,handy_id,this->GetName());

merch->CastToNPC()->FaceTarget(this->CastToMob());
}

To:
if(merch != NULL && handyitem){
char handy_id[8]={0};
int greeting=rand()%5;
int greet_id=0;
switch(greeting){
case 1:
greet_id=MERCHANT_GREETING;
break;
case 2:
greet_id=MERCHANT_HANDY_ITEM1;
break;
case 3:
greet_id=MERCHANT_HANDY_ITEM2;
break;
case 4:
greet_id=MERCHANT_HANDY_ITEM3;
break;
default:
greet_id=MERCHANT_HANDY_ITEM4;
}
sprintf(handy_id,"%i",greet_id);
char merchantname[64]={0};
strcpy(merchantname,merch->GetCleanName());
if(greet_id!=MERCHANT_GREETING){
Message_StringID(10,GENERIC_STRINGID_SAY,merchantn ame,handy_id,this->GetName(),handyitem->Name);

}
else
Message_StringID(10,GENERIC_STRINGID_SAY,merchantn ame,handy_id,this->GetName());

merch->CastToNPC()->FaceTarget(this->CastToMob());
}

Now when Merchants offer up things it will be:
Merchant Name says, "Welcome to my shop!"

There is one condition that the code above does not account for and that is the situation where a Merchant's name is longer than 64 characters. I just assumed that forcing the Merchant's name under 64 characters had to do with the size of the packet struct required to push that information which would mean that there are no merchants with names longer than 64 characters, in which case the issue is moot.

However, if you do have merchants with names longer than 64 characters then that specific merchant just won't say anything. The reason for this is because you can't copy something longer than 64 characters into something that is 64 characters, so the code doesn't work at that point, but it does continue and does not crash, so the merchant just skips what he would have said. If you're concerned about this, the way to fix it is to calculate the length of the string generated by merch->GetCleanName() and if it is longer than 64 characters use strncpy to chop it to 64 characters, otherwise use the function I've changed above. I wasn't that industrious.

cavedude
01-23-2008, 03:06 AM
Hmmm this was merged into the official code and it is working very nicely. Such a small but extremely nice change. However, certain NPCs will no longer say anything, specifically all of the Necromancer merchants in Paineel. 'Linnleu_Brackmar Necromancer Supplies' is one example. I don't think the lastname is used, but even if it is as you can see it is still under 64 characters in length.

Now, oddly in the same area the guildmasters all do work. 'Coriante_Verisue Necromancer Guildmaster' as example does use her proper text.

I went through other cities, and had no problem with their merchants and they all had a nice clean name :)

Not a big deal, as most don't even look at the text anyway I'm sure, and since it probably is a minority of NPCs anyway who really cares. I was just letting you know about it in case you can stumble upon the problem.

Knightly
01-23-2008, 09:14 PM
The guildmaster code is in a different area, so this wouldn't have affected that.

I loaded up an older version of the emu and found that I couldn't get the Paineel merchants to talk to me before the change above. I thought at first it had something to do with the handyitem, but I'm not sure now that it is the case.

I probably won't really get around to looking at it any time soon, but thank you for letting me know so that I have NPCs to test with if I happen to see the problem.