Welcome to the Builder Academy

Question Order in ADD_FOLLOWER

More
11 Jan 2021 08:01 #9775 by kogan
Order in ADD_FOLLOWER was created by kogan
Hi,
anyone can help me to order followers in ADD_FOLLOWERS to follow squence and not to reverse?
Currently last followed enters always first now.

I tried to change it but got stuck here. Only the last 2 follow now :-(

void add_follower(struct char_data *ch, struct char_data *leader)
{
  struct follow_type *k, *j;
  struct char_data *l = leader;

  if (ch->master) {
    core_dump();
    return;
  }

  ch->master = leader;

  CREATE(k, struct follow_type, 1);

  if (!l->followers) {
    k->follower = ch;
    k->next = NULL;
    leader->followers = k;
  } else {
    while (l->followers->next) {
      l->followers = l->followers->next;
    }
    k->follower = ch;
    k->next = l->followers->next;
    leader->followers->next = k;
  }

  act("You now follow $N.", FALSE, ch, 0, leader, TO_CHAR);
  if (CAN_SEE(leader, ch))
    act("$n starts following you.", TRUE, ch, 0, leader, TO_VICT);
  act("$n starts to follow $N.", TRUE, ch, 0, leader, TO_NOTVICT);
}


Thanks for your assistane.
 

Please Log in or Create an account to join the conversation.

More
12 Jan 2021 20:16 - 12 Jan 2021 20:18 #9776 by thomas
Replied by thomas on topic Order in ADD_FOLLOWER
I suggest you surround your code with [ code] tags - it makes it easier to read.

Here's an attempt at browser code for helping you out:
Code:
void add_follower(struct char_data *ch, struct char_data *leader) {   struct follow_type *k, *j;   struct char_data *l = leader;   if (ch->master) {     core_dump();     return;   }   ch->master = leader;   CREATE(k, struct follow_type, 1);   k->follower = ch;   k->next = NULL;   if (!l->followers) {     leader->followers = k;   } else {     j = l->followers;     while (j->next) {       j = j->next;     }     j->next = k;   }   act("You now follow $N.", FALSE, ch, 0, leader, TO_CHAR);   if (CAN_SEE(leader, ch))     act("$n starts following you.", TRUE, ch, 0, leader, TO_VICT);   act("$n starts to follow $N.", TRUE, ch, 0, leader, TO_NOTVICT); }
Last edit: 12 Jan 2021 20:18 by thomas. Reason: readability

Please Log in or Create an account to join the conversation.

More
07 Mar 2021 02:58 - 07 Mar 2021 02:59 #9785 by cunning
Replied by cunning on topic Order in ADD_FOLLOWER
I did this inside of handler.c - I made a change to char_from_room()
Code:
void char_from_room(struct char_data *ch) {   struct char_data *temp, *i;   if (ch == NULL || !VALID_ROOM_RNUM(IN_ROOM(ch))) {     log("SYSERR: Extracting char from room NOWHERE. (char_from_room)");     exit(1);   }   if (GET_EQ(ch, WEAR_LIGHT))     if (GET_OBJ_TYPE(GET_EQ(ch, WEAR_LIGHT)) == ITEM_LIGHT)       if (GET_OBJ_VAL(GET_EQ(ch, WEAR_LIGHT), 2)) /* Light is ON */         world[IN_ROOM(ch)].light--;    if (ch == world[IN_ROOM(ch)].people) {     world[IN_ROOM(ch)].people = ch->next_in_room;      } else {     if (world[IN_ROOM(ch)].people) {       for (i = world[IN_ROOM(ch)].people; i != NULL && i->next_in_room != ch ; i = i->next_in_room)        ; // KEEP THIS OR LOOP away! it will crash the game without it going into a loop- AP         if (i != NULL)           i->next_in_room = ch->next_in_room;     }   }   if (FIGHTING(ch)) {    if (FIGHTING(FIGHTING(ch)) == ch)      stop_fighting(FIGHTING(ch));    stop_fighting(ch);   }   REMOVE_FROM_LIST(ch, world[IN_ROOM(ch)].people, next_in_room);   IN_ROOM(ch) = NOWHERE;   ch->next_in_room = NULL; }  
Last edit: 07 Mar 2021 02:59 by cunning.

Please Log in or Create an account to join the conversation.

Time to create page: 0.195 seconds