New Triggers are actually a lot like new flags in objects, mobs and rooms.
To add them, do the following steps:
#define MTRIG_SAMPLE (1 << 13)to the define list in dg_scripts.h
"Sample",As you can guess, this line MUST coincide with the define in the dg_scripts.h file. For objects, use otrig_types, and rooms, wtrig_types.
int cast_mtrigger(char_data *ch, char_data *actor, char *targ, int spellnum)
{
trig_data *t;
char buf[MAX_INPUT_LENGTH];
if (ch == NULL)
return 1;
if (!SCRIPT_CHECK(ch, MTRIG_CAST) || AFF_FLAGGED(ch, AFF_CHARM))
return 1;
for (t = TRIGGERS(SCRIPT(ch)); t; t = t->next) {
if (TRIGGER_CHECK(t, MTRIG_CAST) &&
(number(1, 100) <= GET_TRIG_NARG(t))) {
ADD_UID_VAR(buf, t, actor, "actor");
skip_spaces(&targ);
add_var(&GET_TRIG_VARS(t), "arg", targ);
sprintf(buf, "%d", spellnum);
add_var(&GET_TRIG_VARS(t), "spell", buf);
add_var(&GET_TRIG_VARS(t), "spellname", spells[spellnum]);
return script_driver(ch, t, MOB_TRIGGER, TRIG_NEW);
}
}
return 1;
}
int cast_otrigger(obj_data *obj, char_data *actor, char *targ, int spellnum)
{
trig_data *t;
char buf[MAX_INPUT_LENGTH];
if (obj == NULL)
return 1;
if (!SCRIPT_CHECK(obj, OTRIG_CAST))
return 1;
for (t = TRIGGERS(SCRIPT(obj)); t; t = t->next) {
if (TRIGGER_CHECK(t, OTRIG_CAST) &&
(number(1, 100) <= GET_TRIG_NARG(t))) {
ADD_UID_VAR(buf, t, actor, "actor");
skip_spaces(&targ);
add_var(&GET_TRIG_VARS(t), "arg", targ);
sprintf(buf, "%d", spellnum);
add_var(&GET_TRIG_VARS(t), "spell", buf);
add_var(&GET_TRIG_VARS(t), "spellname", spells[spellnum]);
return script_driver(obj, t, OBJ_TRIGGER, TRIG_NEW);
}
}
return 1;
}
int cast_wtrigger(char_data *actor, char_data *vict, obj_data *obj, char *targ, int spellnum)
{
room_data *room;
trig_data *t;
char buf[MAX_INPUT_LENGTH];
if (!actor || !SCRIPT_CHECK(&world[IN_ROOM(actor)], WTRIG_CAST))
return 1;
room = &world[IN_ROOM(actor)];
for (t = TRIGGERS(SCRIPT(room)); t; t = t->next) {
if (TRIGGER_CHECK(t, WTRIG_CAST) &&
(number(1, 100) <= GET_TRIG_NARG(t))) {
ADD_UID_VAR(buf, t, actor, "actor");
if (vict)
ADD_UID_VAR(buf, t, vict, "vict");
if (obj)
ADD_UID_VAR(buf, t, obj, "obj");
skip_spaces(&targ);
add_var(&GET_TRIG_VARS(t), "arg", targ);
sprintf(buf, "%d", spellnum);
add_var(&GET_TRIG_VARS(t), "spell", buf);
add_var(&GET_TRIG_VARS(t), "spellname", spells[spellnum]);
return script_driver(room, t, WLD_TRIGGER, TRIG_NEW);
}
}
return 1;
}
int leave_mtrigger(char_data *actor, int dir)
{
trig_data *t;
char_data *ch;
char buf[MAX_INPUT_LENGTH];
for (ch = world[IN_ROOM(actor)].people; ch; ch = ch->next_in_room) {
if (!SCRIPT_CHECK(ch, MTRIG_LEAVE | MTRIG_LEAVE_ALL) ||
!AWAKE(ch) || FIGHTING(ch) || (ch == actor) ||
AFF_FLAGGED(ch, AFF_CHARM))
continue;
for (t = TRIGGERS(SCRIPT(ch)); t; t = t->next) {
if (((IS_SET(GET_TRIG_TYPE(t), MTRIG_LEAVE) && CAN_SEE(ch, actor)) ||
IS_SET(GET_TRIG_TYPE(t), MTRIG_LEAVE_ALL)) &&
!GET_TRIG_DEPTH(t) && (number(1, 100) <= GET_TRIG_NARG(t))) {
add_var(&GET_TRIG_VARS(t), "direction", dirs[dir]);
ADD_UID_VAR(buf, t, actor, "actor");
return script_driver(ch, t, MOB_TRIGGER, TRIG_NEW);
break;
}
}
}
return 1;
}
int leave_wtrigger(struct room_data *room, char_data *actor, int dir)
{
trig_data *t;
char buf[MAX_INPUT_LENGTH];
if (!SCRIPT_CHECK(room, WTRIG_LEAVE))
return 1;
for (t = TRIGGERS(SCRIPT(room)); t; t = t->next) {
if (TRIGGER_CHECK(t, WTRIG_LEAVE) &&
(number(1, 100) <= GET_TRIG_NARG(t))) {
add_var(&GET_TRIG_VARS(t), "direction", dirs[dir]);
ADD_UID_VAR(buf, t, actor, "actor");
return script_driver(room, t, WLD_TRIGGER, TRIG_NEW);
}
}
return 1;
}
if (!leave_mtrigger(ch, dir)) return 0; if (!leave_wtrigger(&world[ch->in_room], ch, dir)) return 0;
if (need_specials_check && special(ch, dir + 1, "")) return 0;
static char *door_act[] = {
"open",
"close",
"unlock",
"lock",
"pick",
"\n"
};
int door_mtrigger(char_data *actor, int subcmd, int dir)
{
trig_data *t;
char_data *ch;
char buf[MAX_INPUT_LENGTH];
for (ch = world[IN_ROOM(actor)].people; ch; ch = ch->next_in_room) {
if (!SCRIPT_CHECK(ch, MTRIG_DOOR) ||
!AWAKE(ch) || FIGHTING(ch) || (ch == actor) ||
AFF_FLAGGED(ch, AFF_CHARM))
continue;
for (t = TRIGGERS(SCRIPT(ch)); t; t = t->next) {
if (IS_SET(GET_TRIG_TYPE(t), MTRIG_DOOR) && CAN_SEE(ch, actor) &&
!GET_TRIG_DEPTH(t) && (number(1, 100) <= GET_TRIG_NARG(t))) {
add_var(&GET_TRIG_VARS(t), "cmd", door_act[subcmd]);
add_var(&GET_TRIG_VARS(t), "direction", dirs[dir]);
ADD_UID_VAR(buf, t, actor, "actor");
return script_driver(ch, t, MOB_TRIGGER, TRIG_NEW);
break;
}
}
}
return 1;
}
int door_wtrigger(char_data *actor, int subcmd, int dir)
{
room_data *room;
trig_data *t;
char buf[MAX_INPUT_LENGTH];
if (!actor || !SCRIPT_CHECK(&world[IN_ROOM(actor)], WTRIG_DOOR))
return 1;
room = &world[IN_ROOM(actor)];
for (t = TRIGGERS(SCRIPT(room)); t; t = t->next) {
if (TRIGGER_CHECK(t, WTRIG_DOOR) &&
(number(1, 100) <= GET_TRIG_NARG(t))) {
add_var(&GET_TRIG_VARS(t), "cmd", door_act[subcmd]);
add_var(&GET_TRIG_VARS(t), "direction", dirs[dir]);
ADD_UID_VAR(buf, t, actor, "actor");
return script_driver(room, t, WLD_TRIGGER, TRIG_NEW);
}
}
return 1;
}
if (!door_mtrigger(ch, scmd, door)) return; if (!door_wtrigger(ch, scmd, door)) return;