TheSourcery | RecentChanges | Preferences | Index | RSS

Quick Snippets

This page contains small code snippets that may or not be useful to mud programmers. Consider them all to be public domain.

Counting objects in player files on a ROM type mud

$ cat offcount.c
#include <stdio.h>
#include <stdlib.h>

int offline_obj_count(int vnum)
  FILE *f;
  char cmd[160];
  int count;

    "egrep -ch \"^Vnum %d\" ../player/* | gawk \'{ s += $1 }; END { print s }\' > sum.txt", vnum);
  f = fopen ("sum.txt", "r");
  if (!f) {
    printf("offline_obj_count: Could not read sum.txt file.");
    return 0;
  fscanf(f,"%d\n", &count);
  return count;

int main(int argc, char** argv) {
  int vnum = atoi(argv[1]);
  int count = offline_obj_count(vnum);
  printf("Vnum:%d Count:%d", vnum, count);
  return 0;

$ gcc offcount.c

$ ./a 3382
Vnum:3382 Count:62

$ ./a 23008
Vnum:23008 Count:1

$ ./a 23048
Vnum:23048 Count:2

$ ./a 9999
Vnum:9999 Count:0

MPStatus command for Mobprogs

This snippet allows you to store and read state in Mobprogs.

In mob_prog.c add this define...

#define CHK_STATUS      (53)

In fn_keyword[] add this...

  "status",  /* if status $n == 1000  - checks status value on obj,room or mob */

In cmd_eval() near the end after case CHK_GRPSIZE: add...

  case CHK_STATUS:
    lval = lval_char->mprog_status;

Add the following to the CHAR_DATA structure in merc.h

  int   mprog_status;

Add an entry to mob_cmd_table[] in mob_cmds.c

  {"status", do_mpstatus},

Add this routine or similar to mob_cmds.c

void do_mpstatus (CHAR_DATA * ch, char *argument)
  char arg[MIL];
  char errbuf[MIL];

  if (ch == NULL)

  one_argument (argument, arg);
  if (!is_number (arg)) {
    sprintf (errbuf, "MpStatus: invalid arg from mob vnum %d.",
        ch->isNPC() ? ch->pIndexData->vnum : 0);
    wiznet (errbuf, NULL, NULL, WIZ_PROGS, 0, 0);
  ch->mprog_status = atoi (arg);

Get it working and now your mprogs have the capability to save and query state.

The following fight trigger is an example of usage:

if status $i == 0
  poke $n
  say You look delicious, $n.
  mob status 1
if status $i == 1
  say I have a feeling your flesh will be rather tough.
  mob echo A bolt of energy flies from $I's hand!
  mob cast 'force bolt' $n
  mob status 2
if status $i == 2
  if rand 25
    mob status 0

TheSourcery | RecentChanges | Preferences | Index | RSS
Edit text of this page | View other revisions
Last edited May 28, 2005 8:09 am by JonLambert (diff)
All material on this Wiki is the property of the contributing authors.
©2004-2006 by the contributing authors.
Ideas, requests, problems regarding this site? Send feedback.