Welcome to the Builder Academy

Question How to manage charmies with group system?

More
11 Oct 2022 00:54 #10198 by Nero
I have integrated the new group system from TBAMud into the game which works but there are some bugs I am trying to iron out.
The main thing I would like to resolve is making it to where if the leader leaves the group, it goes to assign a random person in the group list as the new leader,
it sometimes will pick a pet from the list instead of an actual player.
Also, I would like for if the player leaves the group, it also removes all of their pets as well and maybe even if they join the group it autojoins their charmies would be pretty cool too if it's possible.
Code:
void leave_group(struct char_data *ch) {   struct group_data *group;   struct char_data *tch;   struct iterator_data Iterator;   bool found_pc = FALSE;   bool quiet = FALSE;        if ((group = ch->group) == NULL)     return;   send_to_group(NULL, group, "@C%s has left the group.\r\n@n", GET_NAME(ch));   remove_from_list(ch, group->members);   ch->group = NULL;     if (group->members->iSize) {     for (tch = (struct char_data *) merge_iterator(&Iterator, group->members);       tch; tch = next_in_list(&Iterator))         if (!IS_NPC(tch))           found_pc = TRUE;                remove_iterator(&Iterator);     }   if (!found_pc)     SET_BIT(GROUP_FLAGS(group), GROUP_NPC);     if (GROUP_LEADER(group) == ch && group->members->iSize) {     group->leader = (struct char_data *) random_from_list(group->members);     send_to_group(NULL, group, "@C%s has assumed leadership of the group.\r\n@n", GET_NAME(GROUP_LEADER(group)));   } else if (group->members->iSize == 0)     free_group(group);      }

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

More
12 Oct 2022 18:13 #10202 by Nero
For anyone else who is interested in wanting to do something similar I was able to manage this with the help of Zusuk from Luminari
I had to create a while loop
Code:
void leave_group(struct char_data *ch) {   struct group_data *group;   struct char_data *tch;   struct iterator_data Iterator;   bool found_pc = FALSE;   bool quiet = FALSE;   int loop_limit = 0;        if ((group = ch->group) == NULL)     return;   send_to_group(NULL, group, "@C%s has left the group.\r\n@n", GET_NAME(ch));   remove_from_list(ch, group->members);   ch->group = NULL;     if (group->members->iSize) {     for (tch = (struct char_data *) merge_iterator(&Iterator, group->members);       tch; tch = next_in_list(&Iterator))         if (!IS_NPC(tch))           found_pc = TRUE;                remove_iterator(&Iterator);     }   if (!found_pc)     SET_BIT(GROUP_FLAGS(group), GROUP_NPC);     if (GROUP_LEADER(group) == ch && group->members->iSize) { do {   group->leader = (struct char_data *) random_from_list(group->members);   loop_limit++; } while (IS_NPC(group->leader) && loop_limit < 100);     send_to_group(NULL, group, "@C%s has assumed leadership of the group.\r\n@n", GET_NAME(GROUP_LEADER(group)));   } else if (group->members->iSize == 0 || IS_NPC(group->leader))     free_group(group);     } void join_group(struct char_data *ch, struct group_data *group) {   struct char_data *mob = NULL;   mob_vnum mob_num = 0;   add_to_list(ch, group->members);        if (group->leader == NULL)     group->leader = ch;          ch->group = group;       if (IS_SET(group->group_flags, GROUP_NPC) && !IS_NPC(ch))     REMOVE_BIT(GROUP_FLAGS(group), GROUP_NPC);        if (group->leader == ch)     send_to_group(NULL, group, "@C%s becomes leader of the group.@n\r\n", GET_NAME(ch));   else     send_to_group(NULL, group, "@C%s joins the group.\r\n@n", GET_NAME(ch));     SET_BIT_AR(AFF_FLAGS(ch), AFF_GROUP);     }
The following user(s) said Thank You: thomas

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

Time to create page: 0.291 seconds