Joy of Snippets: vdd.txt help anyone?

From: Mathew Earle Reuther (
Date: 08/02/02

After having managed to get my color woes under control (I shall hereby
declare not underlining every bloody thing to be "under control) I moved
on to a VDD snippet from the rooms section of the FTP site.  I'm including
the full text of MY version in this email, but so as not to completely
thash your mailboxes, I'm just providing a link to the original.

Basic point of the code is to take a condition and give two different room
description options depending on which one is true.  So say you're using a
day/night conditional (it's one that was included) and you come into a
room at night, it might say: The citizens of the city seem to be at home
safe in bed, only the few nightcrawlers and watchmen seem to be anywhere
around . . . while in the day you'd see something implying the activity of
the faceless masses during more active hours.

The problem is, currently it finds the very last conditional and prints
everything after that.  So if you have a 3 paragraph description and four
or five of the conditionals, you end up with a tiny fraction of your room
description.  Bummer. :)

I'm at the limit of my abilities here, and any assistance folks can
render, I'd appreciate it.  I understand what the code is doing in
general, I just can't figure out what's gone wrong with it.  Getting rid
of the 50 lines of errors, compiling it with only one warning (somewhere
after while in ProcRoomDesc it suggested brackets, anyone see why please
let me know) and having it not crash the mud seemed to be good work
already. *grin*

These are the four functions which handle workings of the string
replacement code.  I left out the other junk.

int FindOpenClose(char *buf, char** begin, char** end)
  int Level=0;

  while (*buf && *buf!='{')
  if (!(*buf))
    return 0;
  while (*buf && Level) {
    if (*buf=='{') Level++;
    else if (*buf=='}')
  if (Level)
    return 0;
  return 1;

int CheckVDD(char *TextBuf, struct char_data *ch)
  struct char_data *temp;
  int First;

  if (!strn_cmp(TextBuf,"time",4))
    else if (!strn_cmp(TextBuf,"clouds",6));
    else if (!strn_cmp(TextBuf,"rain",4))<SKY_RAINING;
    else if (!strn_cmp(TextBuf,"random00",8))
      First=rand_number(0, 1000)==0;
    else if (!strn_cmp(TextBuf,"random25",8))
      First=rand_number(0, 3)==0;
    else if (!strn_cmp(TextBuf,"random33",8))
      First=rand_number(0, 2)==0;
    else if (!strn_cmp(TextBuf,"random50",8))
      First=rand_number(0, 1)==0;
    else if (!strn_cmp(TextBuf,"god",3)) {
    for (;temp;temp=temp->next_in_room) {
      if (IS_NPC(temp))
      if (GET_LEVEL(temp)<LVL_IMMORT)
      if (GET_INVIS_LEV(temp))

    else return -1;
  return First;

int DoVDDReplace(char *Read, char *Write, char *pos, struct char_data *ch)
/*  int Level=0; */ /* Unused Var */
  char *Begin, *End;
  int First;

  First=CheckVDD(pos,ch); /* set First to val returned from CheckVVD */
    if (First==-1)
      return 0;
    if (!FindOpenClose(pos, &Begin, &End))
      return 0;
    if (!First)
      if (!FindOpenClose(pos, &Begin, &End))
        return 0;
      strncat(Write, Begin, End-Begin-1);
    if (First)
      if (!FindOpenClose(pos, &Begin, &End))
        return 0;
  return 1;

char *ProcRoomDesc(char *desc, struct char_data *ch)
  char *ReadingBuf, *WritingBuf, *pos; /* , *T; */

  while (pos=strstr(ReadingBuf,"||")) {
    if (!DoVDDReplace(ReadingBuf, WritingBuf, pos, ch))
      return desc;
    /*  T=ReadingBuf;
        WritingBuf=T; */
  return ReadingBuf;

Any assistance would be appreciated.  If this gets up and running I'll be
sure to drop the updated version over on the FTP site so folks can use it
if they please.


   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT