Stop Monsters from passing through Transitions
Buddywarrior
Member Posts: 62
How do we stop monsters from following players through transitions while allowing summoned pets or familiar? I see there is a Faction "Hostile" in the Advanced Tab of the creature properties.
Unless there is a far more simple way to solve this.
if(!GetIsPC(GetEnteringObject())) { object oMob= GetEnteringObject(); string faction = GetFaction(oMob); //Is there a function to get the Faction name? if(faction == "Hostile") { DestroyObject(oMob); } }
Unless there is a far more simple way to solve this.
0
Comments
This works regardless of faction. The only non-party creatures that use doors are (a) those hostile to a PC or (b) those scripted to walk across areas (which require a further condition above if you have them).
If you prefer to filter on faction, be aware that in classic NWScript there is no way to get the faction directly. A common trick is to put a benchmark member of each faction in an inaccessible area with a tag like FactionHostile or whatever. I use CEP armour stands for this purpose so that they don't start fighting each other. Then you can use GetFactionEqual to determine whether a creature belongs to the same faction as the benchmark.
EE now allows you to read the fields in the creature .utc file directly, using TemplateToJson() and the GFF functions. However, I would be wary of manipulating faction directly, because classic NWN was never designed to do that. In particular, assigning constants to custom factions should be avoided, as the values can change if you delete a faction in the toolset.
[edit]Fixed error: JsonToObject() is ObjectToJson() of course. And it's JsonGetInt() and not JsonToInt().[/edit]
I was thinking, for example,
Does the Json returned by ObjectToJson() work with the Gff functions?
The Lexicon documentation isn't at all clear, as it has a broken link to @niv's nimtools (which I have to admit I don't understand anyway).
If so, GffGetWord() is arguably more legible, especially for those of us who are familiar with GFF edits.
json GffGetWord(json jGff, string sLabel)
is a wrapper for GffGetField(jGff, sLabel, GFF_FIELD_TYPE_WORD) with
where GffGetFieldType(json jGff, string sLabel) and GffGetFieldValue(json jGff, string sLabel) are wrappers for JsonPointer(jGff, "/" + sLabel + "/type") and JsonPointer(jGff, "/" + sLabel + "/value").
So yes, you can use GffGetWord() but it has a lot of overhead (all the type checking) and working with jsons isn't really fast anyway. So I try to avoid the functions from the gff library. In my mod I have to read 19*6=114 values to check whether two items have different colors and it's really noticeable if you have 228 calls to JsonPointer() or only 114 (actually I work with JsonDump() and string checks because that even faster ).
But if you want to use the library instead of GffGetWord() you could use GffGetFieldValue(). It's faster and it doesn't care if you're reading a byte, an int, a word or a dword.
Just something to maybe be aware of.