Load Command Changes [by The Lion King]
Snippet Posted Wednesday, August 12th @ 11:30:20 PM, by George Greer in the Wizard dept.
Added Jul 6, 1998. Click the link below to read it or download it.

From: The Lion King <sdconley@pams.ncsu.edu>
Subject: Re: A better load module

Would you be interested in a piece of code that allows you to use:
   > load obj <name>
instead of just:
   > load obj <number>

Well... here it is!

----
In act.wizard.c:

/* Replace do_load with this... */

/* Extern function from db.c */

int get_vnum_from_name(char* searchname, struct char_data* ch, int do_what);


ACMD(do_load)
{
  struct char_data *mob;
  struct obj_data *obj;
  int r_num;
  int temp_num;
  int is_num=0;

  two_arguments(argument, buf, buf2);
  if (!*buf || !*buf2) {
    send_to_char("Usage: load { obj | mob } { name | vnumber }\r\n", ch);
    return;
  }
  is_num=isdigit(*buf2);
  if (is_abbrev(buf, "mob")) {
    if(!is_num){
    temp_num=get_vnum_from_name(buf2,ch,USE_MOB);
    }
    else{
        temp_num=atoi(buf2);
    }
    if ((r_num = real_mobile(temp_num)) < 0) {
      send_to_char("No such animal!\r\n", ch);
      return;
    }
    mob = read_mobile(r_num, REAL);
    char_to_room(mob, ch->in_room);

    act("$n chants some runes.  The fabric of the Universe rips open!", TRUE, c
h,0, 0, TO_ROOM);
    act("$N falls out of the hole!  The Universe re-seals!", FALSE, ch, 0, mob,
TO_ROOM);
    act("You create $N.", FALSE, ch, 0, mob, TO_CHAR);
  } else if (is_abbrev(buf, "obj")) {
    if(!isdigit(*buf2)){
    temp_num=get_vnum_from_name(buf2,ch,USE_OBJ);
    }
    else{
         temp_num=atoi(buf2);
    }
    if ((r_num = real_object(temp_num)) < 0) {
      send_to_char("What is that?\r\n", ch);
      return;
    }
    obj = read_object(r_num, REAL);
    obj_to_room(obj, ch->in_room);
    act("$n chants some magic runes!  The very fabric of the Universe rips open
!", TRUE, ch, 0, 0, TO_ROOM);
    act("$p falls out of the hole!  The Universe re-seals!", FALSE, ch, obj, 0,
 TO_ROOM);
    act("You do a cool trick and $p appears!", FALSE, ch, obj, 0, TO_CHAR);
  } else
    send_to_char("What is that?  'obj' or 'mob' please!\r\n", ch);
}

---
In db.c:

/* Add this to db.c */

/* This gets a vnum of an object or mob from a name... */

int get_vnum_from_name(char* searchname, struct char_data* ch, int do_what);

int get_vnum_from_name(char* searchname, struct char_data* ch, int do_what){
        if(do_what==USE_MOB){
        int nr,mob_number=-1;
        for(nr = 0; nr <= top_of_mobt; nr++){
                if(isname(searchname, mob_proto[nr].player.name)){
                mob_number=mob_index[nr].virtual;
        }
        }
        return mob_number;
        }
        else{
        int nr,obj_number=-1;
        for(nr =0; nr <= top_of_objt; nr++){
                if(isname(searchname, obj_proto[nr].name)){
                obj_number=obj_index[nr].virtual;
                }
        }
        return obj_number;
        }
}

---

That's all!

Steve Conley


<< Linewrapping Function, more [by Doppleganger Software] | Reply | View as text | Flattened | Load Linkdead Players [by Frollo] >>

 


Related Links
  download
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.