OnDamaged/HP Script Help

Hey guys, how’s it, going dudes and dudetes. :slight_smile:

I’m hoping someone might be able to help.

I’ve got a battle with a bunch of Xvarts, a couple of pigs a sorcerer and an Orc Boss. The way I want it to go down is - after a certain amount of HP is left on the orc boss, all fighting will cease, everybody becomes friends, then a conversation will ensue. That’s it in a nutshell.

I’ve tried using: GetIsReactionTypeHostile(), ChangeToStandardFaction()
All w/ no luck. :frowning:

As of right now - exactly nothing happens. As if the script didn’t exist. She (The Orc Boss) and all the xvarts, boars and sorcerer just keep fighting until one of us is dead. She’s supposed to stop fighting when she’s down to about 25%.

Anyhoot, code so far -

void main()
{
    //--------------------------------------------------------------------------
    // GZ: 2003-10-16
    // Make Plot Creatures Ignore Attacks
    //--------------------------------------------------------------------------
    if (GetPlotFlag(OBJECT_SELF))
    {
        return;
    }

    //--------------------------------------------------------------------------
    // Execute old NWN default AI code
    //--------------------------------------------------------------------------
    ExecuteScript("nw_c2_default6", OBJECT_SELF);


    object oXvart1;
    object oXvart2;
    object oXvart3;
    object oXvart4;
    object oXvart5;

    object oXvartSorc;

    object oBoar1;
    object oBoar2;

    object oVyxara = OBJECT_SELF;

    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);

    oXvart1 = GetObjectByTag("XVART_01_WAR");
    oXvart2 = GetObjectByTag("XVART_02_WAR");
    oXvart3 = GetObjectByTag("XVART_03_WAR");
    oXvart4 = GetObjectByTag("XVART_04_WAR");
    oXvart5 = GetObjectByTag("XVART_05_WAR");

    oXvartSorc = GetObjectByTag("XVART_SORC_01");

    oBoar1 = GetObjectByTag("RAZORBACK_01");
    oBoar2 = GetObjectByTag("RAZORBACK_02");

    int nMaxHP = GetMaxHitPoints();
    int nCurHP = GetCurrentHitPoints();
    int nRatio = (100* nCurHP)/nMaxHP;
    if (nRatio >= 25)
    {
        if ( GetIsReactionTypeHostile(oVyxara, oPC) )
        {

        SetIsTemporaryFriend(oVyxara, oPC);

        SetIsTemporaryFriend(oXvart2, oPC);
        SetIsTemporaryFriend(oXvart3, oPC);
        SetIsTemporaryFriend(oXvart4, oPC);
        SetIsTemporaryFriend(oXvart5, oPC);

        SetIsTemporaryFriend(oXvartSorc, oPC);

        SetIsTemporaryFriend(oBoar1, oPC);
        SetIsTemporaryFriend(oBoar2, oPC);

        AssignCommand(oPC, ActionStartConversation(oVyxara, "zc_Vyxara"));

        }
    }
}

Thanks to all. What a mighty bunch… :muscle:

The reliable way to stop fighting is SurrenderToEnemies() or SurrenderAllToEnemies().

Test for 25% hp BEFORE the default code - if true, surrender and return to prevent default code running.

Those are the main poins but I can dig out some more detail if you need it.

This is good for now P. Definitely gives me some ideas. Thanks! I’ll try this and get back real soon.

I would put in some feedback to see where things might not be firing.
Since you actually have the script get the OBJECT_SELF, you should park that in the GetMaxHitPoints(oVyxara) and GetCurrentHitPoints(oVyxara). You may also want to do the x100 math outside of the nRatio declaration. While it makes sense for coding how you put it, NWNscript can find weirdness in simple sections.

    int nMaxHP = GetMaxHitPoints();
    int nCurHP = GetCurrentHitPoints();
    int nCurHPx100 = 100*nCurHP;
    int nRatio = nCurHPx100/nMaxHP;
SendMessageToPC(oPC, "Current HPs are "+IntToString(nCurHP)+". The Ratio is "+IntToString(nRatio));
 if (nRatio >= 25)
    {
SendMessageToPC(oPC, "Ratio triggered");
        if ( GetIsReactionTypeHostile(oVyxara, oPC) )
        {
SendMessageToPC(oPC, "I am Hostile");

Also, probably want <= rather than >=, I’d think.

Incidentally, if the conversation MUST take place, flag the boss as Immortal. That way, they can go down to 1 hp, but never die.

Oh, that’s a great idea Proleric! Thanks to Mannast and meaglyn for their input as well. :slight_smile:

if (nRatio <= 25) is correct not the above quote. Cant believe I missed that.
All is well. Code is firing perfectly now. Thanks to everybody who helped!

Here’s the code now, up and running. :slight_smile:

void main()
{
    object oXvart1;
    object oXvart2;
    object oXvart3;
    object oXvart4;
    object oXvart5;

    object oXvartSorc;

    object oBoar1;
    object oBoar2;

    object oVyxara = OBJECT_SELF;

    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);

    oXvart1 = GetObjectByTag("XVART_01_WAR");
    oXvart2 = GetObjectByTag("XVART_02_WAR");
    oXvart3 = GetObjectByTag("XVART_03_WAR");
    oXvart4 = GetObjectByTag("XVART_04_WAR");
    oXvart5 = GetObjectByTag("XVART_05_WAR");

    oXvartSorc = GetObjectByTag("XVART_SORC_01");

    oBoar1 = GetObjectByTag("RAZORBACK_01");
    oBoar2 = GetObjectByTag("RAZORBACK_02");

    int nMaxHP = GetMaxHitPoints();
    int nCurHP = GetCurrentHitPoints();
    int nRatio = (100* nCurHP)/nMaxHP;
    if (nRatio <= 25)
    {
        AssignCommand(oVyxara, SurrenderToEnemies());
        AssignCommand(oPC, ActionStartConversation(oVyxara, "zc_vyxara"));
    }
    //--------------------------------------------------------------------------
    // GZ: 2003-10-16
    // Make Plot Creatures Ignore Attacks
    //--------------------------------------------------------------------------
    if (GetPlotFlag(OBJECT_SELF))
    {
        return;
    }

    //--------------------------------------------------------------------------
    // Execute old NWN default AI code
    //--------------------------------------------------------------------------
    ExecuteScript("nw_c2_default6", OBJECT_SELF);
}
1 Like

Checking over my own code, it can help to set the plot flag on the NPC, too.

That prevents the NPC from retaliating if some delayed combat activity occurs for any reason.

Further action is required in the special case that, by design, not all enemies are surrendering at once.

The default AI tells the NPC to fight the remaining enemies, rather than wait for the PC to speak to them. Highly undesirable if the NPC is immortal and/or plot!

The reason for this seems to be that SurrenderToEnemies() sets the party’s reputation to friendly (100), not 89 as stated in the Lexicon.

As far as I can see there is a very simple solution - set the NPC’s plot flag, then. in their OnConversation script, don’t respond to shouts if the plot flag is set.

P.S. It’s strange that Bioware didn’t place a universal block on plot characters entering combat. Several of the default AI scripts block this at the outset, but it looks like that change was quite late in the day and incomplete.

Check, and done. Plot flag is set.
I was getting some wayward combat results without the plot flag being set. :smile:

Hmm, I get halfway through the conversation, and everyone attacks again. Can’t quite figure out what sets them off again?
Initially I thought the poison from the Xvart spears was causing the disruption - They do, however, cause everyone to turn hostile, but it’s not the only disruption.
After a small amount of time elapses, if for no other reason than there is none, everyone turns hostile again.
I’m going to have a look at few dialog nodes to see if I can glean anything useful. :cowboy_hat_face:

It’s intermittent in nature. Sometimes they attack, sometimes it even goes off without a hitch.
The last dialog node of the conversation causes everyone to attack!