Re: DG Scripts (Adding a new command)

From: Carlton Colter (carlton@COLTER.COM)
Date: 09/27/02


If anyone can make any suggestions to my code I would greatly appreciate
it.  I did this in 30 minutes... and it could be rather buggy.  Thank you
for checking it out -Carlton

The idea is I would call it with:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 2, Arg list:  teach me
Commands:
  train %actor.name% 'clone' 5 10
  say I have tought you how to clone yourself. %actor.name%, use it wisely.


I would like it to be able to check and make sure they have the propper
class, race, or even prerequisite skills using skill(skill-name) etc.


In... int script_driver(void *go, trig_data *trig, int type, int mode)
after:
      else if (!strn_cmp(cmd, "makeuid ", 8))
        makeuid_var(go, sc, trig, type, cmd);
add:
      else if (!strn_cmp(cmd, "train ", 6))
        train_char(cmd);


And add the procedure:

void train_char(char *argument)
{
  struct char_data *vict;
  char name[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH];
  char buf2[MAX_INPUT_LENGTH], skillname[MAX_STRING_LENGTH];
  int skill, value, i, qend, level;
  byte iserror=0;
  i = 0;
  argument = one_argument(argument, name);

  if (!*name) iserror=1;

  skip_spaces(&argument);
  /* If there is no chars in argument */
  if ((!*argument) || (*argument != '\'')) iserror=1;

  /* Locate the last quote and lowercase the magic words (if any) */
  for (qend = 1; argument[qend] && argument[qend] != '\''; qend++)
    argument[qend] = LOWER(argument[qend]);

  if (argument[qend] != '\'') iserror=1;

  /* If there was an error exit */
  if (iserror==1) {
    sprintf(errorbuf,
      "Trigger: %s, VNum %d. Train, invalid arguments: %s",
      GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), cmd);
    script_log(errorbuf);
    return;
  }

  if (!(vict = get_char(name))) {
    sprintf(errorbuf,
      "Trigger: %s, VNum %d. Train, Invalid name: %s",
      GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), name);
    script_log(errorbuf);
    return;
  }

  /* strcpy: OK (MAX_INPUT_LENGTH <= MAX_STRING_LENGTH) */
  strcpy(skillname, (argument + 1));

  skillname[qend - 1] = '\0';
  if ((skill = find_skill_num(skillname)) <= 0) {
    sprintf(errorbuf,
      "Trigger: %s, VNum %d. Train, Unrecognized Skill: %s",
      GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), skillname);
    script_log(errorbuf);
    return;
  }
  argument += qend + 1;         /* skip to next parameter */
  argument = two_arguments(argument, buf, buf2);

  if (!*buf) {
    sprintf(errorbuf,
      "Trigger: %s, VNum %d. Train, No Learned Value.",
      GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
    script_log(errorbuf);
    return;
  }

  value = atoi(buf);
  if (value == -1) value = GET_SKILL(ch,i);
  if ((value < 0) || (value > 100)) {
    sprintf(errorbuf,
      "Trigger: %s, VNum %d. Train, Invalid Learned Value: %d",
      GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), value);
    script_log(errorbuf);
    return;
  }
  if (IS_NPC(vict)) {
    sprintf(errorbuf,
      "Trigger: %s, VNum %d. Train, Victim can not be an NPC!",
      GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
    script_log(errorbuf);
    return;
  }

  if (!*buf2)
    level = -1;
  else
    level = atoi(buf2);

  /*
   * find_skill_num() guarantees a valid spell_info[] index, or -1, and we
   * checked for the -1 above so we are safe here.
   */
  if (GET_SKILL(vict,skill)>value) value=GET_SKILL(vict,skill);
  if (GET_SKILL_LEVEL(vict,skill)<level) level=GET_SKILL(vict,skill);
  SET_SKILL(vict, skill, value, level);
}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



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