Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

Browse New Commands for the DG Script System...


Commands are dealt with in two different ways. Mob commands are parsed normally as a normal ACMD() is. They are added in much the same way that a normal command is added. Object and Room commands, however, have to go through their own parsing process. This involves not only adding the code for the command itself, but an entry in their own 'master command list' which is stored in either dg_wldcmd.c or dg_objcmd.c, depending on which command type you are referring to. This is simply a matter of adding a new line entry to either the obj_cmd_info or the wld_cmd_info (found near the end of their respective files) I won't go into detail on that, as it is a very simple process, much like adding a new command for players.

Identification of commands is a simple process. ACMD() is for mobs, OCMD() is for objects, and WCMD() is for rooms. Then, it is simply a matter of adding the command, and it's entry into it's respective command list.

New Commands


Rewarding


This system involves 3 commands, one for mobs, objects and rooms. It also has a main function. This main function should be placed in a central file, like dg_scripts.c, and a prototype in the dg_scripts.h file.

The syntax is simple:
wreward <victim> <type> <amount>
mreward <victim> <type> <amount>
oreward <victim> <type> <amount>

Current Types are:
practice
mana
move

Here are the specific commands:

OCMD(do_oreward)
{
  char arg[MAX_INPUT_LENGTH];
  char_data *victim;

  half_chop(argument, arg, buf);
  if (!*arg) {
    obj_log(obj, "oreward called with no argument");
    return;
  }

  if (!(victim = get_char_by_obj(obj, arg))) {
    obj_log(obj, "oreward: victim not found");
    return;
  }

  change_value(victim, buf);
}

WCMD(do_reward)
{
  char arg[MAX_INPUT_LENGTH];
  char_data *victim;

  half_chop(argument, arg, buf);
  if (!*arg) {
    wld_log(room, "wreward called with no argument");
    return;
  }

  if (!(victim = get_char_by_room(room, arg))) {
    wld_log(room, "wreward: victim not in room");
    return;
  }

  change_value(victim, buf);
}

ACMD(do_mreward)
{
  char arg[MAX_INPUT_LENGTH];
  char_data *victim;

  if (!IS_NPC(ch)) {
    send_to_char("Huh?!?\r\n", ch);
    return;
  }
  if (AFF_FLAGGED(ch, AFF_CHARM))
    return;
  half_chop(argument, arg, buf);
  if (!*arg) {
    mob_log(ch, "mreward called with no argument");
    return;
  }

  if (!(victim = get_char_room_vis(ch, arg))) {
    mob_log(ch, "mreward: victim not in room");
    return;
  }

  change_value(victim, buf);
}

Here is the common code. More types of rewards can be added if you wish. Note that the reward function can also be used to take away from these things.
NOTE: There was an error in the original code posted here, please make note of the changes (marked with comments)
void change_value(struct char_data *ch, char *argument)
{
  int amount;

  two_arguments(argument, buf1, buf2);
  /* This is now a two_arguments....it cleans up the extra space */

  /* Right down here     v there was a * missing */
  if (!*buf2 || !isdigit(*buf2)) {
    log("SYSERR: Invalid entry in change_value (%s)", argument);
    return;
  }
  amount = atoi(buf2);

  if (is_abbrev(buf1, "practice")) {
    GET_PRACTICES(ch) += amount;
    if (GET_PRACTICES(ch) < 0)
      GET_PRACTICES(ch) = 0;
  } else if (is_abbrev(buf1, "mana")) {
    GET_MANA(ch) += amount;
    if (GET_MANA(ch) < 0)
      GET_MANA(ch) = 0;
    if (GET_MANA(ch) > GET_MAX_MANA(ch))
      GET_MANA(ch) = GET_MAX_MANA(ch);
  } else if (is_abbrev(buf1, "move")) {
    GET_MOVE(ch) += amount;
    if (GET_MOVE(ch) < 0)
      GET_MOVE(ch) = 0;
    if (GET_MOVE(ch) > GET_MAX_MOVE(ch))
      GET_MOVE(ch) = GET_MAX_MOVE(ch);
  } else {
    log("SYSERR: Unknown change_value type (%s)", buf1);
  }
}



Reverse Damage


This small function should be placed in dg_scripts.c, with a prototype in the dg_scripts.h file. In the various damage commands, when the damage value is less than 0, it should be passed to this function. Since the damage command will send a message to the character, this will as well. In addition, it will make sure that the max hitpoints are not exceeded.
void reverse_damage(struct char_data *ch, int amount)
{
  send_to_char("A warm feeling fills your body as you are healed.\r\n", ch);

  GET_HIT(ch) += amount;
  if (GET_HIT(ch) > GET_MAX_HIT(ch))
    GET_HIT(ch) = GET_MAX_HIT(ch);

  update_pos(ch);
}



Return to the Death's Gate Script page