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
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);
}