Hello,
I want the bosses on my PW to be a bit unique and I’m not sure how to script that, which events to use and how to use them correctly.
Here are some examples, that I would like to start with:
- after random number of rounds switch target to random enemy in the area (with classes considered tanks having slightly higher chance to get aggro)
- perform certain action after every random number of rounds (e.g. use taunt, stealth, knockdown, disarm)
- perform certain action at x% of HP (e.g. heal at 25% HP, create object at 50% of HP, become immune to physical damage at 75%
1 and 2 should be scripted onHeartbeat?
Correct me if I’m wrong:
- get random number of rounds
- check for the enemies, that are in the same location as the NPC
- get random % of chance to perform certain action
- add local int on the NPC to avoid ‘stacking’
- delay command to perform the action if the local int is 0 or something
3 should be put onDamage event?
- check NPC’s HP
- keep track of that HP on every onDamage event trigger
- if it’s below x% -> perform certain action and save the local int on NPC so it doesn’t keep multi-triggering
Could anyone provide some tips/notes that I should take into consideration?
That’s pretty much it.
ClearAllActions(TRUE) will stop current combat actions before assigning a new action on heartbeat. The actions you describe will be taken promptly (before the next heartbeat) so stack control is probably unnecessary. However, see SetCommandable in the Lexicon for the method of preventing the new action being interrupted by combat AI.
GetMaxHitPoints and GetCurrentHitPoints will tell you all you need to know OnDamaged. You can make the boss immortal if you definitely want them to surrender or flee at some % HP.
1 Like
You can download my module, Sea of Shadow, from the vault and take a look at the AI scripts I wrote there, they’re all named with an ai_ prefix. They might not be the best examples, but they should give you a template to work from. After that, on the spawn script you just need to add the:
SetCreatureOverrideAIScript(OBJECT_SELF, "script name");
line to the name of your AI script.
If you don’t want to go as far as writing your own AI for the boss use:
DetermineCombatRound(oTarget);
To set the target for the AI.
Avoid giving the creature combat instructions outside of an AI script. It can cause conflicts with the AI which could cancel or override your decisions. Even if you want to have the creature perform a certain action at x% of HP, have the on damaged script set a local int on the creature that your AI script checks for the next time it runs. Spellcasting in particular is really finnicky, and doesn’t like conflicting instructions, attacks and special combat actions (disarm and knockdown) are less particular.
It is possible to have the creature run an empty AI script and specify instructions using user defined events (IIRC, that’s what Elysius used for his Battle of the Builds AI in NWN2), but it’s a fair bit more involved than using a procedural AI script.
1 Like