Next Question: NPC scripts during combat?

Hello!

Everyone’s been so helpful thus far! I feel bad for all the questions.

I’m on a cracked-screen phone in a boring meeting so thinking of scripts, but not easy to trawl through lexicon and wikis haha.

Is there a standard way to affect NPCs during combat, as OnHeartbeat doesn’t work while in combat correct?

My only current thoughts would be to use an invisible object’s OnHeartbeat and get calls from the NPC. this seems pretty rogue though and not sure it would even work.

Example:

NPC explodes into blood at 50% and a zombie appears in its place.

I guess I’d like a ‘when’ function instead of ‘if’ but that’s no possible, so the 6 second tick of OnHeartbeat of a invisible object / waypoint checking the NPCs percentage health, and then if 50% destroy NPC, spawn Zombie - would be the only way to achieve this?

Any other ideas / methods?

I really want to build lots of scripted fights this is just a basic example.

Thanks,
Roarthing

OnHeartbeat can work in combat,it’s just that OnHeartbeat scripts usually include lines that make the script void in case the owner is in combat.

Ah fantastic.

My post was vaguely pointless then sorry!

I’ll remove any lines that stop the script firing and have test when I’m home :slight_smile:

Thank you!

Btw, this is what Lilac Soul’s NWN Script Generator came up with when used OnDeath (which makes it much simpler).

/* Script generated by
Lilac Soul’s NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625 */

//Put this script OnDeath
#include “nw_i0_generic”
void main()
{

object oPC = GetLastKiller();

while (GetIsObjectValid(GetMaster(oPC)))
{
oPC=GetMaster(oPC);
}

if (!GetIsPC(oPC)) return;

object oTarget;
oTarget = OBJECT_SELF;

//Visual effects can’t be applied to waypoints, so if it is a WP
//the VFX will be applied to the WP’s location instead

int nInt;
nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_COM_BLOOD_LRG_RED), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_COM_BLOOD_LRG_RED), GetLocation(oTarget));

object oSpawn;
location lTarget;
oTarget = oPC;

lTarget = GetLocation(oTarget);

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, “resref of creature”, lTarget);

oTarget = oSpawn;

SetIsTemporaryEnemy(oPC, oTarget);

AssignCommand(oTarget, ActionAttack(oPC));

AssignCommand(oTarget, DetermineCombatRound(oPC));

}

It’d probably make sense to do checks that depend on damage having been dealt to the NPC via the OnDamaged event; that way, the code doesn’t run unless it’s actually needed. If the hit points didn’t change, no sense in checking what they are now.

But if you ever have a need for a custom loop of any sort that’s separate from OnHeartbeat, you can just write your own:

void CustomLoop()
{
    // Abort the loop if:
    if (GetIsDead(OBJECT_SELF) ||
        !GetIsInCombat(OBJECT_SELF) ||
        GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF) == OBJECT_INVALID)
        return;

    // Do things here.

    // Run the next round of the loop:
    DelayCommand(3.0, CustomLoop());
}