As far as looping through the pfiles that's not to hard just read up on how
to use scan dir and if you need some help with that i can show you some
examples of how i use it. and as for your second one here is what i use for
my tribe list. it was originally a snippet for a wizlist that auto updated
it self as you made or deimm immortals I reworked it to work for the clans.
Here's some small things to help with it, in do_delete add this around where
you unlink the pfile update_tribelist(ch, 0, 0, 0, 0); that will remove
them if they delete.
And where you have it so they are promoted guilded use
update_tribelist(victim, victim->rank, victim->clan, current_time,
victim->level);
and for deguilding use the one for deleting, should make your life a little
easier, also the command allows for you to add people using the do_tribelist
it's something only an imp can do but it helps to edit the list incase
something weird happens or for manually adding people, you can also in
comm.c add that update_tribelist(victim, victim->rank, victim->clan,
current_time, victim->level); and have it add them as they log on to maybe
save you some time. Attached to the email is my c file of the code if you
have any problems with it email me [EMAIL PROTECTED] and i'll try to help ya
out with it.
Sarix
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, July 28, 2002 7:32 AM
Subject: Clan roster
> Ok, I'm looking to make a clan roster command that will show all the
members
> of a clan and their ranks. I'm thinking that when I first implement the
> command, it should search through all the pfiles and write the names/ranks
to
> a data file for each clan, then every time someone is guilded or promoted,
it
> should add or modify the information in the data files. Then I want a
> command that will display the stored info for a given clan. The only
things
> I don't know how to do:
>
> 1) Cycle through the pfiles (I know how to load the clan data from each
> pfile, just not how to cycle through them all)
> 2) Save and Load Data to and from a clan data file.
>
> If anyone could give me some idea as to how these things can be
accomplished,
> I'd greatly appreciate it.
>
>
> Zack
>
> Drug Wars MUD,
> dwmud.ods.org 2528
> http://fly.to/dwmud
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
/***************************************************************************
* ROM 2.4 is copyright 1993-1995 Russ Taylor *
* *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor ([EMAIL PROTECTED]) *
* Gabrielle Taylor ([EMAIL PROTECTED]) *
* Brian Moore ([EMAIL PROTECTED]) *
* *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************/
/***************************************************************************
* ROT 1.4 is copyright 1996-1997 by Russ Walsh *
* *
* By using this code, you have agreed to follow the terms of the *
* ROT license, in the file doc/rot.license *
***************************************************************************/
/***************************************************************************
* This code was put in by Lucas Clav/Rico Suave/Jed/Bobo the Big fat *
* clown(joke), ported from ROT 1.4 to ROM2.4B(supposedly)... Should *
* work... har har har!!! *
****************************************************************************/
/***************************************************************************
* This code was rewriten by Dale Kingston (Sarix) for a tribal clan list
of all the
* members of a tribe for a ROM2.4B should work with no problems
* any questions or comments please email [EMAIL PROTECTED]
****************************************************************************/
#if defined(macintosh)
#include <types.h>
#include <time.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "mud.h"
#include "recycle.h"
/*extern char boot_buf[MAX_STRING_LENGTH]; */
TRIBE_DATA *tribe_list;
/*
* Local functions.
*/
void change_tribelist args( (CHAR_DATA *ch, bool add, int rank, char
*argument, int tribe));
void save_tribelist(void)
{
TRIBE_DATA *pTribe;
FILE *fp;
bool found = FALSE;
long time;
fclose( fpReserve );
if ( ( fp = fopen( TRIBE_FILE, "w" ) ) == NULL )
{
perror( TRIBE_FILE );
}
for (pTribe = tribe_list; pTribe != NULL; pTribe = pTribe->next)
{
found = TRUE;
time = pTribe->laston;
fprintf(fp, "%s %d %d %ld %d\n", pTribe->name, pTribe->rank,
pTribe->tribe, time, pTribe->level);
}
fclose(fp);
fpReserve = fopen( NULL_FILE, "r" );
if (!found)
unlink(TRIBE_FILE);
}
void load_tribelist(void)
{
FILE *fp;
TRIBE_DATA *tribe_last;
if ( ( fp = fopen( TRIBE_FILE, "r" ) ) == NULL )
{
return;
}
tribe_last = NULL;
for ( ; ; )
{
TRIBE_DATA *pTribe;
if ( feof(fp) )
{
fclose( fp );
return;
}
pTribe = new_tribe();
pTribe->name = str_dup(fread_word(fp));
pTribe->rank = fread_number(fp);
pTribe->tribe = fread_number(fp);
pTribe->laston = fread_number(fp);
pTribe->level = fread_number(fp);
fread_to_eol(fp);
if (tribe_list == NULL)
tribe_list = pTribe;
else
tribe_last->next = pTribe;
tribe_last = pTribe;
}
}
void do_tribelist(CHAR_DATA *ch, char *argument)
{
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
char arg3[MAX_INPUT_LENGTH];
char arg4[MAX_INPUT_LENGTH];
/* char buf[MAX_STRING_LENGTH]; */
int rank;
int tribe;
argument = one_argument( argument, arg1 );
argument = one_argument( argument, arg2 );
argument = one_argument( argument, arg3 );
argument = one_argument( argument, arg4 );
if ((arg1[0] != '\0') && (get_trust(ch) >= (MAX_LEVEL - 1)))
{
if ( !str_prefix( arg1, "add" ) )
{
if ( !is_number( arg2 ) || ( arg3[0] == '\0' ) )
{
send_to_char( "Syntax: tribelist add <tribe>
<name> <rank>\n\r", ch);
return;
}
tribe = atoi(arg2);
rank = atoi(arg4);
change_tribelist( ch, TRUE, rank, arg3, tribe);
return;
}
if ( !str_prefix( arg1, "delete" ) )
{
if ( arg2[0] == '\0' )
{
send_to_char( "Syntax: tribelist delete
<name>\n\r", ch );
return;
}
change_tribelist( ch, FALSE, 0, arg2, 0);
return;
}
send_to_char( "Syntax:\n\r", ch );
send_to_char( " tribelist delete <name>\n\r", ch );
send_to_char( " tribelist add <tribe> <name>\n\r", ch );
return;
}
if (tribe_list == NULL)
{
send_to_char("Their is no tribe Record at this time.\n\r",ch);
return;
}
list_tribes(ch, "all");
}
void list_tribes(CHAR_DATA *ch, char *arg)
{
int tribe = 0;
int s;
char date[MSL];
BUFFER *buffer;
char buf[MSL];
TRIBE_DATA *pTribe;
bool all = FALSE, found = FALSE;
buffer = new_buf();
if (!str_cmp(arg, "all") || !str_cmp(arg, "All"))
all = TRUE;
if(!all)
for (tribe = 1; tribe != 5; tribe++)
{
if (!str_cmp(capitalize(arg), clan_table[tribe].name))
{
found = TRUE;
break;
}
}
if (!found && !all)
{
send_to_char("No Tribe by that name.\n\r", ch);
return;
}
if(all)
for (tribe = 1; clan_table[tribe].name[0] != '\0'; tribe++)
{
if (tribe == 1)
add_buf(buffer, "The Tribe Members of Realms of the Forgotten\n\n\r");
sprintf(buf, "%s's members:\n\n\r", clan_table[tribe].name);
add_buf(buffer, buf);
for ( pTribe = tribe_list; pTribe && pTribe->name != NULL;
pTribe = pTribe->next )
{
if (pTribe->tribe != tribe)
continue;
sprintf(date, "%s", (char *) ctime(&pTribe->laston ));
for (s =0; date[s] != '\0'; s++);
date[s - 1] = '\0';
sprintf(buf, "%-3d %15s {c%-15s{w %s\n\r",
pTribe->level, strcap_color(20, clan_table[tribe].rank[pTribe->rank].rankname),
strcap_color( 15, pTribe->name), date);
add_buf(buffer, buf);
}
add_buf(buffer, "\n\r");
}
if (found && !all)
{
sprintf(buf, "%s Tribe Members:\n\n\r", clan_table[tribe].name);
add_buf(buffer, buf);
for ( pTribe = tribe_list; pTribe && pTribe->name != NULL;
pTribe = pTribe->next )
{
if (pTribe->tribe != tribe)
continue;
sprintf(date, "%s", (char *) ctime(&pTribe->laston ));
for (s =0; date[s] != '\0'; s++);
date[s - 1] = '\0';
sprintf(buf, "%-3d %15s {c%-15s{w %s\n\r",
pTribe->level, strcap_color(20, clan_table[tribe].rank[pTribe->rank].rankname),
strcap_color( 15, pTribe->name), date);
add_buf(buffer, buf);
}
add_buf(buffer, "\n\r");
}
page_to_char( buf_string(buffer), ch );
free_buf(buffer);
return;
}
void update_tribelist(CHAR_DATA *ch, int rank, int tribe, int laston, int level)
{
TRIBE_DATA *prev;
TRIBE_DATA *curr;
if (IS_NPC(ch) || IS_IMMORTAL(ch))
{
return;
}
prev = NULL;
for ( curr = tribe_list; curr != NULL; prev = curr, curr = curr->next )
{
if ( !str_cmp( ch->name, curr->name ) )
{
if ( prev == NULL )
tribe_list = tribe_list->next;
else
prev->next = curr->next;
free_tribe(curr);
save_tribelist();
}
}
if (tribe <= 0)
{
return;
}
curr = new_tribe();
curr->name = str_dup(ch->name);
curr->rank = rank;
curr->tribe = tribe;
curr->laston = laston;
curr->level = level;
curr->next = tribe_list;
tribe_list = curr;
save_tribelist();
return;
}
void change_tribelist(CHAR_DATA *ch, bool add, int rank, char *argument, int
tribe)
{
char arg[MAX_INPUT_LENGTH];
TRIBE_DATA *prev;
TRIBE_DATA *curr;
one_argument( argument, arg );
if ( !add )
{
prev = NULL;
for ( curr = tribe_list; curr != NULL; prev = curr, curr = curr->next)
{
if ( !str_cmp( capitalize( arg ), curr->name ) )
{
if ( prev == NULL )
tribe_list = tribe_list->next;
else
prev->next = curr->next;
free_tribe(curr);
save_tribelist();
}
}
} else
{
curr = new_tribe();
curr->name = str_dup( capitalize( arg ) );
curr->rank = rank;
curr->tribe = tribe;
curr->next = tribe_list;
tribe_list = curr;
save_tribelist();
}
return;
}