Trigedit has an affect field.
if %actor.affect(sanctuary)% for example checks if the actor is affected by sanctuary.
Its coded as such:
Code:
if (!str_cmp(field, "affect")) {
if (subfield && *subfield) {
int spell = find_skill_num(subfield);
if (affected_by_spell(c, spell))
strcpy(str, "1");
else
strcpy(str, "0");
} else
strcpy(str, "0");
}
It works fine, usually.
The problem is when you apply something via dg_affect it cant be properly verified from a script.
Code:
spello(SPELL_DG_AFFECT, "Script-inflicted", 0, 0, 0, POS_SITTING,
TAR_IGNORE, TRUE, 0,
NULL);
spello(SPELL_SANCTUARY, "sanctuary", 110, 85, 5, POS_STANDING,
TAR_CHAR_ROOM, FALSE, MAG_AFFECTS,
"The white aura around your body fades.");
It searches for the terms in quotes in spello. So you can check if the player is affected by dg_affect, but you can't tell the nature of said affect.
I debated changing the code to work like this:
Code:
if (!str_cmp(field, "affect")) {
if (subfield && *subfield) {
char buf[MAX_STRING_LENGTH];
sprintbitarray(AFF_FLAGS(c), affected_bits, AF_ARRAY_MAX, buf);
if (str_str(buf, subfield))
strcpy(str, "1");
else
strcpy(str, "0");
} else
strcpy(str, "0");
}
But that has issues too. It'd break existing scripts because it'd look for different verbiage, ie. SANCT is the bit name for sanctuary. It also wouldn't detect things like the armor spell. The armor spell adjusts armor, but it doesn't set a bit, if you cast it repeatedly, the duration infact stacks.
I suppose I could do something like this:
Code:
if (!str_cmp(field, "affect")) {
if (subfield && *subfield) {
int spell = find_skill_num(subfield);
if (affected_by_spell(c, spell)) {
strcpy(str, "1");
} else {
char buf[MAX_STRING_LENGTH];
sprintbitarray(AFF_FLAGS(c), affected_bits, AF_ARRAY_MAX, buf);
if (str_str(buf, subfield))
strcpy(str, "1");
}else
strcpy(str, "0");
} else
strcpy(str, "0");
}
That'd return false negatives less often at least, and wouldn't break a ton of existing scripts, but it still isn't perfect.