Dave Wrote:
>> /* i add the victim to the list */
>> f = new struct consent_type ;
>I don't quite understand the above. Mind exsplaining it too me? :)
Sorry, i'm kinda tired today :)
You must allocate a new struct and i wrote it using C++.
Try instead CREATE ( f , struct consent_type , 1 ) ;
That should give :
else {
vict->consenter = ch;
/* i add the victim to the list */
CREATE ( f , struct consent_type , 1 ) ;
f->next = ch->consented ;
f->consented = vict ;
ch->consented = f ;
act("You give your consent to $N.", FALSE, ch, 0, vict, TO_CHAR);
act("$n has given you $s consent.", FALSE, ch, 0, vict, TO_VICT);
}
But it'll still not work because you mistaken the victim and the actor
several time
The right way should be :
ch->consented : the list of people that has consented you
ch->consenter : the character you have consented :
Also it seems you want to have only one consenter from the consent code ,
but several from
the view consent functions. I assume you want only one 'cause ch->conseter
is a char_data.
So:
/* we put remove the consent external 'cause we'll use it twice */
/* this function clear the consent on a character */
void clear_consent ( struct char_data * ch )
{
struct char_data * victim ;
victim = ch->consenter ;
if (!victim) return ;
for (f = victim->consented; f; f = f->next)
{
if (f->consented == ch )
/* this is the character that want to remove the consent */
{
sprintf(buf2, "%s stops consenting you.\r\n", GET_NAME(ch));
send_to_char (buf2,victim) ;
act("You stop consenting: $N.", FALSE, ch, 0, victim, TO_CHAR);
REMOVE_FROM_LIST(f,ch->consented,next);
break ;
}
}
ch->consenter = NULL ;
}
ACMD(do_consent)
{
struct char_data *vict;
struct consent_type *f, *next_fol;
one_argument(argument, buf);
if (!*buf) PrintConsent(ch);
else if (!(vict = get_char_vis(ch, buf, NULL, FIND_CHAR_WORLD)))
send_to_char(NOPERSON, ch);
else if (IS_NPC(vict)) send_to_char(NOPERSON, ch);
else if (ch->consenter == vict) act("You have already given your consent
to $M.", FALSE, ch, 0, vict, TO_CHAR)
/* until here no problem */
/* here you forgot to desalloc memory and you must look into the VICTIM
list instead of the actor */
/* i guess you use consent 'myself' to say : i don't want to consent
anyone now */
else if (vict == ch)
{
/* we clear the consent on the character */
clear_consent ( ch ) ;
send_to_char ("You consent only to yourself.\n\r",ch);
}
/* now we take care of the case you want to change the consent victim */
else
{
/* first we clear any existing consenter */
clear_consent ( ch ) ;
/* second we put the consenter on the character */
ch->consenter = vict ;
/* third we add the character to the consented list of the victim */
/* i add the victim to the list */
CREATE ( f , struct consent_type , 1 ) ;
f->next = vict->consented ;
f->consented = ch ;
vict->consented = f ;
}
}
My function should work with your PrintConsent code.
FreD.
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
| Newbie List: http://groups.yahoo.com/group/circle-newbies/ |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/25/03 PDT