Skip to content

Is it possible to make enemy NPCs rest and recover their HP/spells?

In a module project I'm working on, I make sure to give regeneration to all bosses/non-respawnable enemies, so that the player is forced to defeat them in one go rather than retreating and resting.

This works great for most enemies except for magic-users, since they don't regain any of their used-up spells. If there is a way to make enemy or non-player NPCs rest when they aren't in combat, this would probably work, but I did some brief searching on Google and didn't come up with anything clear on that, so advice is appreciated.

Comments

  • ElGrilloElGrillo Member Posts: 11
    It is definitely accomplishable by script. But it depends what AI scripts you're using. I'm not sure if any of the custom AI (Jasperre's, TonyK's etc.) automatically enables resting for NPCs, but they might.
    Off the top of my head maybe look at adding something to OnCombatRoundEnd for your casters? Maybe a DelayCommand of ~30 seconds or whatever, that runs a function which checks whether they are still in combat at the end of the delay, and if they're not in combat, checks their spell slots (can't remember the function to do this) and if all are used, run ActionRest https://nwnlexicon.com/index.php?title=ActionRest ? Or you can use ForceRest which works during combat too.

    Big question to me would be how to work out how to check whether they've used up all their spells. I'm not sure how to do that. The closest useful function I can see is GetHasSpell. I don't think there's a way to simply loop through a creature's spell slots and get data on them. Of course, if you don't care whether or not they've used all spells then it's easy you can ignore this bit and just run ActionRest when they're not in combat regardless.

    FYI for the future I'd definitely recommend you come join the Neverwinter Vault discord, it's definitely the best place to ask these kinds of questions: https://neverwintervault.org/chat
  • BishopBBishopB Member Posts: 8
    Thanks. For anyone who's wondering, I found this script on NWNVault. I'll test it and see if it works.

    https://neverwintervault.org/project/nwn1/script/creatures-rest-and-wander-after-combat
  • BishopBBishopB Member Posts: 8
    BishopB wrote: »
    Thanks. For anyone who's wondering, I found this script on NWNVault. I'll test it and see if it works.

    https://neverwintervault.org/project/nwn1/script/creatures-rest-and-wander-after-combat

    The script works like a charm - only problem is that the enemies fully rest almost immediately after combat ends. I'll need to see if I can put in a delay for maybe about 30 seconds.
  • mmatmmat Member Posts: 18
    A very crude delay, but it might work for you
    void main()
    {
        int iUsrEvn = GetUserDefinedEventNumber();
    
        if (iUsrEvn == 1001) /* OnHeartbeat */
        {
            /* if wounded and no longer in combat then rest and wander */
            if ((GetCurrentHitPoints() < GetMaxHitPoints()) && !GetIsInCombat())
            {
                int i = GetLocalInt (OBJECT_SELF, "RestDelay");
                SetLocalInt (OBJECT_SELF, "RestDelay", ++i);
                if (i<5) return;
                ActionRest();
                ActionRandomWalk();
            }
           else SetLocalInt (OBJECT_SELF, "RestDelay", 0);    // in case that the idle period is interrupted and after rest
        }
    }
    
Sign In or Register to comment.