Aller au contenu

Photo

Trouble stopping AI mid-combat


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
gedweyignasia

gedweyignasia
  • Members
  • 16 messages

I'm trying to make the AI run a check on a local variable mid-combat and immediately stop attacking if that flag is set, but it's turning out to be an immense pain. Can anyone give me a hand here and point me at the right part of the right script?



#2
rjshae

rjshae
  • Members
  • 4 485 messages

Are you using a custom heartbeat script or implementing it as a user event?



#3
Tchos

Tchos
  • Members
  • 5 042 messages

I did something like this, by putting the code in the creature's On End Combat Round script.  (Technically I set the creature to signal the event and used the On User Defined Event, but the effect is the same.)

	SurrenderAllToEnemies(OBJECT_SELF);
	object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
	SurrenderAllToEnemies(oPC);
	ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_COMMONER);
	ActionStartConversation(oPC);(oPC);

First the creature stops fighting, then I also make the PC stop fighting so it doesn't start a new fight, then I change the creature's faction to Commoner.

 

Since this is at the end of the combat round, it's not immediate, but it's no more than 6 seconds (if the command came at the very beginning of the round).

 

Note, you need:

#include "x0_i0_partywide"

at the beginning of the script to use the SurrenderAllToEnemies() function.



#4
gedweyignasia

gedweyignasia
  • Members
  • 16 messages

Is there a way to run the check instead when the creature is attacked, makes an attack, or is damaged in combat? (The OnDamaged event doesn't fire off during combat.) I'd rather not wait until the end of the round if possible.



#5
gedweyignasia

gedweyignasia
  • Members
  • 16 messages

Are you using a custom heartbeat script or implementing it as a user event?

Custom heartbeat. I know it's polite to use UserDef, but I just want to get it working quick and dirty before I go to the trouble. Copy/pasted the heartbeat, added my check to the very top of it. Does not seem to be called during combat, though...



#6
Tchos

Tchos
  • Members
  • 5 042 messages

You don't need to use On User Defined if you don't want to, as long as it does what you want. 

 

On Damaged does fire during combat in my experience.  On Damaged is what I used to signal the phase changes for my boss battles in BSoCC.



#7
Dann-J

Dann-J
  • Members
  • 3 161 messages

 

 

On Damaged does fire during combat in my experience. 

 

Indeed.  My ankheg scripts use the OnDamaged script to determine whether or not they should retreat and burrow down into the ground (with the likelihood increasing as they lose more hit points).

 

A quick and dirty way to stop a creature from fighting back is to blind and deafen it and to assign ClearAllActions(TRUE) to it. Once it's blind and deaf it can't reinitiate combat (provided it doesn't have True Seeing, of course), even if it's still in a hostile faction. It become the very epitome of the sitting duck.



#8
gedweyignasia

gedweyignasia
  • Members
  • 16 messages

Thanks! I think I've got it now! (Switched to UserDef events; much cleaner and easier now. Turns out the problem is that when two creatures are in combat the orientation check doesn't work the way it's supposed to, so I did some quick vector math. The check was firing when needed!) I'm applying the cutscene immobilize effect to stop it from fighting.

 

Quick question: Is there a way to make NPCs immune to all damage? Flagging them as immortal just prevents them from dying; I want to preserve their hitpoints. (Edit: It's the plot flag! I hate that naming convention.)



#9
gedweyignasia

gedweyignasia
  • Members
  • 16 messages

You're all totally right; OnDamaged fires in combat. I dunno where I got it into my head that it doesn't.



#10
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

You're all totally right; OnDamaged fires in combat. I dunno where I got it into my head that it doesn't.


Hi,

Actually, can I clarify/ask something ... Surely, "OnDamaged" will only fire if the attack in a combat does damage? i.e. If an attack misses, then any script attached to this hook will NOT fire during combat. That is how I understand it anyway.

Why not use the "OnPhysicallyAttacked" and "OnSpellCastAt" hooks?

Cheers,
Lance.