22 Feb, 2009, boblinski wrote in the 1st comment:
Votes: 0
I've added in this snippet:

Quote
Put the ignore.c file in your /rom/src directory.

– Makefile
Add ignore.o to the O_FILES section.

– act_comm.c
Somewhere up towards the top, add the line:
extern bool is_ignoring(CHAR_DATA *ch, CHAR_DATA *victim);

In the do_tell function, before the lines:
act( "&rYou tell $N '$t'&x", ch, argument, victim, TO_CHAR );
act_new("&r$n tells you '$t'&x",ch,argument,victim,TO_VICT,POS_DEAD);
victim->reply = ch;

Add:
if (is_ignoring(victim, ch))
{
sprintf(buf, "%s is ignoring you.\n\r", victim->name);
send_to_char(buf, ch);
return;
}

– save.c
Before the line:
/* write alias */

Add:
for (pos = 0; pos < MAX_IGNORE; pos++)
{
if (ch->pcdata->ignore[pos] == NULL)
break;

fprintf(fp, "Ignore %s~\n", ch->pcdata->ignore[pos]);
}

Before the line:
KEY( "Id", ch->id, fread_number( fp ) );

Add:
if (!str_cmp( word, "Ignore"))
{
if (count >= MAX_IGNORE)
{
fread_to_eol(fp);
fMatch = TRUE;
break;
}

ch->pcdata->ignore[count] = fread_string(fp);
count++;
fMatch = TRUE;
break;
}

– interp.c
Before the line:
{ "inventory", do_inventory, POS_DEAD, 0, LOG_NORMAL, 1 },

Add:
{ "ignore", do_ignore, POS_DEAD, 0, LOG_NORMAL, 1 },

– interp.h
Before the line:
DECLARE_DO_FUN( do_imotd );

Add:
DECLARE_DO_FUN( do_ignore );

– merc.h
Before the line:
#define MAX_CLASS 4

Add:
#define MAX_IGNORE 4
Before the lines:
char * alias[MAX_ALIAS];
char * alias_sub[MAX_ALIAS];

Add:
char * ignore[MAX_IGNORE];


What I'm hoping to do.. is display the people that I'm ignoring in 'score'..

right now I've got:

sprintf (buf, "/ Ignoring: %s\n\r",
ch->pcdata->ignore);
send_to_char(buf, ch);


This displays the following Warning:
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_score':
act_info.c:1834: warning: char format, pointer arg (arg 3)
act_info.c:1834: warning: char format, pointer arg (arg 3)
rm -f rom


So I tried adding this into merc.h:
Quote
char * ignore;


but that just displays:
$ make
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_comm.o act_comm.c
In file included from act_comm.c:42:
merc.h:1660: error: duplicate member 'ignore'
make: *** [obj/act_comm.o] Error 1
22 Feb, 2009, Kline wrote in the 2nd comment:
Votes: 0
You can remove the following, you already added it as part of the snippet:
char * ignore;


As to what you are doing in score, here is something you can modify to suit your needs :)
send_to_char("Ignoring:",ch);
for( short i = 0; i < MAX_IGNORE, i++ )
{
char buf[256];
sprintf(buf," %s",ch->pcdata->ignore[i]);
send_to_char(buf,ch);
}
send_to_char("\r\n",ch);


You have an array of char* pointers as your ch->pcdata->ignore. So to look at any of the values, such with your sprintf paste, you need to access an array position, ie, 0, 1, … MAX_IGNORE. So ch->pcdata->ignore[0] will be the first person ignored, ch->pcdata->ignore[1] the second, and so on, up to your MAX_IGNORE.

edit: To explain things.
22 Feb, 2009, boblinski wrote in the 3rd comment:
Votes: 0
I added:
send_to_char("Ignoring:",ch);
for( short i = 0; i < MAX_IGNORE, i++ )
{
char buf[256];
sprintf(buf," %s",
ch->pcdata->ignore[i]);
send_to_char(buf, ch);
}
send_to_char("\r\n",ch);


I got a lot of problems:

gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_score':
act_info.c:1838: error: 'for' loop initial declaration used outside C99 mode
act_info.c:1838: warning: left-hand operand of comma expression has no effect
act_info.c:1838: error: parse error before ')' token
act_info.c: At top level:
act_info.c:1845: error: parse error before string constant
act_info.c:1845: warning: type defaults to `int' in declaration of `send_to_char
'
act_info.c:1845: error: conflicting types for 'send_to_char'
merc.h:2398: error: previous declaration of 'send_to_char' was here
act_info.c:1845: error: conflicting types for 'send_to_char'
merc.h:2398: error: previous declaration of 'send_to_char' was here
act_info.c:1845: warning: data definition has no type or storage class
act_info.c:1847: error: parse error before string constant
act_info.c:1847: warning: type defaults to `int' in declaration of `sprintf'
act_info.c:1847: error: conflicting types for 'sprintf'
act_info.c:1847: note: a parameter list with an ellipsis can't match an empty pa
rameter name list declaration
act_info.c:1847: error: conflicting types for 'sprintf'
act_info.c:1847: note: a parameter list with an ellipsis can't match an empty pa
rameter name list declaration
act_info.c:1847: warning: data definition has no type or storage class
act_info.c:1848: warning: type defaults to `int' in declaration of `send_to_char
'
act_info.c:1848: warning: parameter names (without types) in function declaratio
n
act_info.c:1848: warning: data definition has no type or storage class
act_info.c:1850: error: parse error before string constant
act_info.c:1850: warning: type defaults to `int' in declaration of `sprintf'
act_info.c:1850: warning: data definition has no type or storage class
act_info.c:1851: warning: type defaults to `int' in declaration of `send_to_char
'
act_info.c:1851: warning: parameter names (without types) in function declaratio
n
act_info.c:1851: warning: data definition has no type or storage class
act_info.c:1853: error: parse error before string constant
act_info.c:1853: warning: type defaults to `int' in declaration of `send_to_char
'
act_info.c:1853: warning: data definition has no type or storage class
make: *** [obj/act_info.o] Error 1
22 Feb, 2009, Stormy wrote in the 4th comment:
Votes: 0
for( short i = 0; i < MAX_IGNORE, i++ )


You have a typo after MAX_IGNORE – it should be a semicolon, not a comma.
22 Feb, 2009, Kline wrote in the 5th comment:
Votes: 0
Ooo good catch and bad on my part, typos are evil!
22 Feb, 2009, boblinski wrote in the 6th comment:
Votes: 0
Fixed that one, now am getting this:

Quote
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_score':
act_info.c:1838: error: 'for' loop initial declaration used outside C99 mode
make: *** [obj/act_info.o] Error 1
22 Feb, 2009, Kline wrote in the 7th comment:
Votes: 0
I declared i inside the loop. Remove short and declare i at the top of your do_score function instead. What works on my box may not work on others :)
22 Feb, 2009, boblinski wrote in the 8th comment:
Votes: 0
Alright, it's working really well now..

However, currently, if you're not ignoring anyone, it shows:

Quote
Ignoring: (null) (null) (null) (null)


How might I simply make it show:
Quote
Ignoring:
22 Feb, 2009, Kline wrote in the 9th comment:
Votes: 0
Check ch->pcdata-ignore!= NULL && strlen > 0
22 Feb, 2009, boblinski wrote in the 10th comment:
Votes: 0
check? how do you mean, sorry?
22 Feb, 2009, Kline wrote in the 11th comment:
Votes: 0
if( ch->pcdata->ignore[i] != NULL && strlen(ch->pcdata->ignore[i]) > 0)
prior to sprintf
22 Feb, 2009, boblinski wrote in the 12th comment:
Votes: 0
It now displays:
Quote
Ignoring:„¢€|È.$„¢€|È.$„¢€|È.$„¢€|È.$


And if I type: "ignore bob" it says:
Quote
Ignoring:Bob ignores you.
22 Feb, 2009, Sharmair wrote in the 13th comment:
Votes: 0
OK, I am not really clear on what code you now have in score with all the hacking
you have been doing, but it looks like you are sending a buffer that has not been
initialized. If might try adding the line:
*buf = 0;

Or any other version of the same thing right after the:
char buf[256];

line.

I am also unclear if the 2nd output you showed was right or in error (do you intend
to have it print the 'ignores you.' at the end, or is that another error?).
22 Feb, 2009, boblinski wrote in the 14th comment:
Votes: 0
Quote
I am also unclear if the 2nd output you showed was right or in error (do you intend
to have it print the 'ignores you.' at the end, or is that another error?).

It's an error.

The code I now have is:
send_to_char("/ Ignoring:",ch);
for (i = 0; i < MAX_IGNORE; i++)
{
*buf = 0;
char buf[256];
if( ch->pcdata->ignore[i] != NULL && strlen(ch->pcdata->ignore[i]) > 0)
sprintf(buf," %s",
ch->pcdata->ignore[i]);
send_to_char(buf, ch);
}
send_to_char("\r\n",ch);


and it compiles fine, but shows:
Quote
Ignoring:„¢€|È.$„¢€|È.$„¢€|È.$„¢€|È.$

when it should show:
Quote
Ignoring:


and it shows:
Quote
Ignoring: bob bob bob bob

when it should show:
Quote
Ignoring: bob
22 Feb, 2009, Sharmair wrote in the 15th comment:
Votes: 0
I did say right after didn't I?
Though the fact that you did not get an error from using an undefined
variable tells me that this buf is hiding a buf in an enclosing scope. The
output with the four bobs was what I would have expected with the
code if it was what I thought you might have done, but did not want
to assume and tell you of another solution.

You probably should put both the sprintf and the send_to_char in the if.
You then would really not have to set buf to an empty string (this is what
that new line I told you before does) as you would only try to output it
if you set it (if you do move the line I said before, it should work but is
calling send_to_char with an empty string on the nonexistent entries).
Also, if the code is not in the middle of using the outer buf, you could just
remove your local one here, and if your code has some ch_printf type
function, you could send the ignore name directly and not sprintf at all.

Ok, some of that might be confusing, here is some code modified with
some of what I have talked about:
send_to_char("/ Ignoring:",ch);
for (i = 0; i < MAX_IGNORE; i++){
char buf[256];
if( ch->pcdata->ignore[i] != NULL && strlen(ch->pcdata->ignore[i]) > 0){
sprintf(buf," %s", ch->pcdata->ignore[i]);
send_to_char(buf, ch);
}
}
send_to_char("\r\n",ch);
22 Feb, 2009, cbunting wrote in the 16th comment:
Votes: 0
Hello,

You can take what you need from here.. I made a simple command to output the ignore list as I also had the ignore.c installed.

void do_icheck (CHAR_DATA * ch, char *argument)
{
char buf[256];
int i;

send_to_char("Ignoring:",ch);
for (i = 0; i < MAX_IGNORE && ch->pcdata->ignore[i] != NULL; i++)
{
sprintf(buf," %s",ch->pcdata->ignore[i]);
send_to_char(buf,ch);
}
send_to_char("\r\n",ch);
}


With MAX_IGNORE… If it was set to 5 and you were only ignoring 2 people, you would show bob, fred, (null) (null) (null) but you only want to list the not nulls..

My max ignore is 10.. I logged in two bogus chars, below is the output.

3074/3074hp 3183/3183m 2928/2928mv> icheck
Ignoring: poot pogo

Hope this helps,
Chris
22 Feb, 2009, boblinski wrote in the 17th comment:
Votes: 0
Thanks everyone..

I'm using this now:
send_to_char("/ Ignoring:",ch);
for (i = 0; i < MAX_IGNORE; i++)
{
char buf[256];
if( ch->pcdata->ignore[i] != NULL && strlen(ch->pcdata->ignore[i]) > 0)
{
sprintf(buf," %s", ch->pcdata->ignore[i]);
send_to_char(buf, ch);
}
}
send_to_char("\r\n",ch);


however.. I was thinking.. how could I make it say "none" if I'm not ignoring anyone?:

Quote
Ignoring: none
22 Feb, 2009, Sharmair wrote in the 18th comment:
Votes: 0
There are a few ways you could have it say none, I pretty straight forward
method would be to add a bool to track if at least one was found. You would
add something like:
bool found = FALSE;

up at the top of the score function with all the other variables, and then
the existing code block something like:
send_to_char("/ Ignoring:",ch);
for (i = 0; i < MAX_IGNORE; ++i){
char buf[256];
if( ch->pcdata->ignore[i] != NULL && strlen(ch->pcdata->ignore[i]) > 0){
sprintf(buf," %s", ch->pcdata->ignore[i]);
send_to_char(buf, ch);
found = TRUE;
}
}
if(!found)
send_to_char("none", ch);
send_to_char("\r\n",ch);
22 Feb, 2009, boblinski wrote in the 19th comment:
Votes: 0
okay, this is really coming together now..

The last thing I want to do is make it so that you can type:

"ignore none"

And it would clean all the people being ignored..

I came up with this:
if (none))
{
free_string(ignore[pos]);
rch->pcdata->ignore[pos] = NULL;
return;
}
}


I don't think this is even close as it needs to make all the ignore 'slots' null.. (between 1 and MAX_IGNORE)
22 Feb, 2009, Sharmair wrote in the 20th comment:
Votes: 0
You will have to make some kind of loop to clear all of the slots, a for loop would probably
be a good fit for that (the slots would be from 0 to MAX_IGNORE-1 though). I have not seen
the code you are working with so I am going to have to make some assumptions based on
how most commands are done and will use some of the variable names you use. In the ignore
command you have now, you should have a string that is used as a name to either look up
a character or is used to directly fill a slot when you ignore someone (I think the first use is
probably the way it works). This string is probably in a buffer (arg is a very commonly used
name) that was filled with a one_argument(argument, arg) call, though it is possible that
argument is used as is. In the code I give here, I will use arg, but replace with whatever the
code uses now for the name it parses from your input. I am going to assume your use of
'none' as in the if(none) was NOT a bool you had already set from parsing the input and is
just conceptually what you want to do. I will also assume you already have an int called pos
defined in the function. In the code you gave, you use rch for the character, I will use ch as
it is used very widely as the actor (user, self etc) in a command, if the ignore command
actually does use something else for the user of the command, replace with that. I am also
assuming that ch has been validated to be a player (not a mob).

Use something like:
if(!str_cmp(arg, "none")){
for(pos = 0; pos < MAX_IGNORE; ++pos){
if(ch->pcdata->ignore[pos]){
free_string(ch->pcdata->ignore[pos]);
ch->pcdata->ignore[pos] = NULL;
}
}
send_to_char("Ignores cleared.\r\n", ch);
return;
}

in the ignore command just before it starts looking for the victim character with the name
in arg (again, if another variable is used, use that here).
0.0/24