Code:
/* KaVir's plugin*/
static void msdp_update( void )
{
struct descriptor_data *d;
int PlayerCount = 0;
char buf[MAX_STRING_LENGTH];
extern const char *pc_class_types[];
int found = 0;
struct obj_data *obj, *next_obj;
for (d = descriptor_list; d; d = d->next)
{
struct char_data *ch = d->character;
if ( ch && !IS_NPC(ch) && d->connected == CON_PLAYING )
{
struct char_data *pOpponent = FIGHTING(ch);
++PlayerCount;
MSDPSetString( d, eMSDP_CHARACTER_NAME, GET_NAME(ch) );
MSDPSetNumber( d, eMSDP_ALIGNMENT, GET_ALIGNMENT(ch) );
MSDPSetNumber( d, eMSDP_EXPERIENCE, GET_EXP(ch) );
MSDPSetNumber( d, eMSDP_HEALTH, GET_HIT(ch) );
MSDPSetNumber( d, eMSDP_HEALTH_MAX, GET_MAX_HIT(ch) );
MSDPSetNumber( d, eMSDP_LEVEL, GET_LEVEL(ch) );
sprinttype( ch->player.chclass, pc_class_types, buf, sizeof(buf) );
MSDPSetString( d, eMSDP_CLASS, buf );
/* Inventory */
snprintf(buf, sizeof(buf), "");
for (obj = ch->carrying; obj; obj = next_obj) {
next_obj = obj->next_content;
found = 1;
snprintf(buf2, sizeof(buf2), "%s%s", obj->short_description, next_obj ? "," : "");
strcat(buf, buf2);
}
if (!found)
snprintf(buf, sizeof(buf), "Nothing");
MSDPSetString( d, eMSDP_INVENTORY, buf);
MSDPSetNumber( d, eMSDP_MANA, GET_MANA(ch) );
MSDPSetNumber( d, eMSDP_MANA_MAX, GET_MAX_MANA(ch) );
MSDPSetNumber( d, eMSDP_WIMPY, GET_WIMP_LEV(ch) );
MSDPSetNumber( d, eMSDP_MONEY, GET_GOLD(ch) );
MSDPSetNumber( d, eMSDP_MOVEMENT, GET_MOVE(ch) );
MSDPSetNumber( d, eMSDP_MOVEMENT_MAX, GET_MAX_MOVE(ch) );
MSDPSetNumber( d, eMSDP_AC, compute_armor_class(ch) );
/* This would be better moved elsewhere */
if ( pOpponent != NULL )
{
int hit_points = (GET_HIT(pOpponent) * 100) / GET_MAX_HIT(pOpponent);
MSDPSetNumber( d, eMSDP_OPPONENT_HEALTH, hit_points );
MSDPSetNumber( d, eMSDP_OPPONENT_HEALTH_MAX, 100 );
MSDPSetNumber( d, eMSDP_OPPONENT_LEVEL, GET_LEVEL(pOpponent) );
MSDPSetString( d, eMSDP_OPPONENT_NAME, PERS(pOpponent, ch) );
}
else /* Clear the values */
{
MSDPSetNumber( d, eMSDP_OPPONENT_HEALTH, 0 );
MSDPSetNumber( d, eMSDP_OPPONENT_LEVEL, 0 );
MSDPSetString( d, eMSDP_OPPONENT_NAME, "" );
}
MSDPUpdate( d );
}
/* Ideally this should be called once at startup, and again whenever
* someone leaves or joins the mud. But this works, and it keeps the
* snippet simple. Optimise as you see fit.
*/
MSSPSetPlayers( PlayerCount );
}
}