On Sun, 5 May 2002, Mike wrote:
> Earlier last month, I sent in a question about the who list. In my mud, I
> have corperations and gangs (2 copies of the former clan code). Right now,
> I have it so it looks like:
>
> [110 Asian IMP Citizen (NoCorp) ] Tarian.
>
> You can't be in a gang or a corp at the same time, so I wanted to make more
> room for titles by having it show either a gang name or a corp name, but not
> both. Sortof like:
>
> [110 Asian IMP Ashton ] Tarian
>
> Or:
>
> [110 Asian IMP Citizen ] Tarian
>
> So I posted the question and some people wanted to see the code. So here it
> is:
>
> /*
> * Format it up.
> */
> sprintf( buf, "[%2d %6s %s %s%s%s%s%s%s%s%s%s\n\r",
First change:
You want one less argument to sprintf, so you'll have to take out a %s
from the format string. The clan & corp are currently the 4th and 5th
%s in the string above, so take out one of those.
> wch->level,
> wch->race < MAX_PC_RACE ? pc_race_table[wch->race].who_name
> : " ",
> class,
> clan_table[wch->clan].who_name,
> corp_table[wch->corp].who_name,
Second change:
Change these last two arguments above to sprintf into one.
There are two ways of doing this:
Method 1:
Declare a variable such as "char * clan_or_corp;" at the top of the function.
Put this code in front of the sprintf:
if ( wch->clan != 0 )
clan_or_corp = clan_table[wch->clan].who_name;
else if ( wch->corp != 0 )
clan_or_corp = corp_table[wch->corp].who_name;
else
clan_or_corp = "None";
Replace the last two lines quoted above with:
clan_or_corp,
Method 2:
Replace the last two lines quoted above with:
(wch->clan != 0) ? clan_table[wch->clan].who_name :
(wch->corp != 0) ? corp_table[wch->corp].who_name : "None",
Both methods are logically equivalent and will give the same results.
Just pick whichever one you like better.
The main idea is that you only want to send one argument to sprintf instead
of two, and you have to figure out what that argument will be depending on
whether they are in a clan or corporation.
> The clan table is identicle to the corp table. And one more question. I
> want to have it so that if someone is less then level 10, then there are two
> spaces between the opening bracet ( [ --1 .....), greater than or equal to
> 10 but less than 100, to only have 1 space: ( [ -10....) and greater than
> 100 to have no spaces ( [ 100 .....). Thats so that you don't get stuff
> like:
>
> [ 1 Asian IMP Citizen Ashton ] Tarian is tired.
> [10 Asian IMP Citizen Ashton ] Tarian
> [110 Asian IMP Citizen Ashton ] Tarian
Change the %2d in the sprintf to %3d. %2d tells sprintf that the next
argument is an integer, and it should be printed with at least 2 characters,
with spaces added to pad it if it isn't long enough. %3d tells it to pad
it to three spaces.
Dennis