Jump to content

Counting Kills Made by an NPC?


user826

Recommended Posts

So, the issue right now is that I'm not sure how to handle tracking which targets he's already engaged. For instance, if he attacks someone, then finds a bigger threat, kills that, and re-engages the first target, that first target counts as 2 enemies engaged instead of one. This is where I thought adding a token would be helpful, but I've found that in some cases, using the token tends to stop enemies from fighting for some reason. They will aggro, but then as soon as they have the token in their inventory, they'll just stand there, waiting to be attacked. This means the token idea is out.

 

This is the script as it exists right now:

if (CustomizableCompanionREF.GetCombatTarget != CurrentTarget) && (CustomizableCompanionREF.GetCombatTarget != 0)
	set CurrentTarget to CustomizableCompanionREF.GetCombatTarget
	if (KillCountDoOnce == 0)
		set CustomizableCompanionREF.EnemiesEngaged to (CustomizableCompanionREF.EnemiesEngaged + 1)
		set KillCountDoOnce to 1
	endif
endif
if (CurrentTarget != 0)
	if (CurrentTarget.GetDead == 1)
		if (CurrentTarget.IsKiller CustomizableCompanionREF)
			set CustomizableCompanionREF.EnemiesKilled to (CustomizableCompanionREF.EnemiesKilled + 1)
			set CurrentTarget to 0
			set KillCountDoOnce to 0
		else
			set CurrentTarget to 0
			set KillCountDoOnce to 0
		endif
	endif
endif

The problem is that if he's engaging an enemy, then finds a new threat and engages that, KillCountDoOnce has not been reset to 0, so his Enemies Engaged counter will not increase.

 

I'm going to try using a dummy spell with no duration or effects, and calling IsSpellTarget as the check condition, and using Dispel on death to clear it.

Link to comment
Share on other sites

This is where I thought adding a token would be helpful, but I've found that in some cases, using the token tends to stop enemies from fighting for some reason. They will aggro, but then as soon as they have the token in their inventory, they'll just stand there, waiting to be attacked.

 

 

This sounds weird.

What kind of item is your token?

Do you use a Misc Item with no weight?

Link to comment
Share on other sites

I used an armor with no weight, no DT, no DR, no body slots, marked unplayable. As far as I know, Misc Items can't be marked unplayable, so if somehow the player were to open the inventory of the enemy before the script had a chance to remove the item, they would see it.

Link to comment
Share on other sites

Ah yeah, that's true sorry.

I cannot remember having used token items myself previously...

 

 

But have you tried using a copy of a regular armor, just without DT, DR, worth and weight?

 

To make sure the NPC isn't equipping the armor you may add it with 0 health. Maybe the token is intervening, as the NPC isn't sure what to do with that item. XD

Link to comment
Share on other sites

I'm trying it with a Misc Item right now, actually, but without the name field filled in. So far, when I call OpenTeammateContainer 1 on the target he's engaging, the item doesn't show in the inventory, which is awesome! However, I'm still noticing the targets stop fighting, although I'm not sure if that's just normal cowering/flee behavior.

Link to comment
Share on other sites

I've often found that using a "compound conditional test" statement while developing can lead to unexpected complications. Try splitting it up into two nested conditions first (the equivalent of the "&&"), debug them, and then see if you really want them to be "compound" after all. For example:

if (CustomizableCompanionREF.GetCombatTarget != CurrentTarget) && (CustomizableCompanionREF.GetCombatTarget != 0)
    set CurrentTarget to CustomizableCompanionREF.GetCombatTarget
    if (KillCountDoOnce == 0)
        set CustomizableCompanionREF.EnemiesEngaged to (CustomizableCompanionREF.EnemiesEngaged + 1)
        set KillCountDoOnce to 1
    endif
endif

can be rewritten as:

if (CustomizableCompanionREF.GetCombatTarget != CurrentTarget)
  if (CustomizableCompanionREF.GetCombatTarget != 0)
    set CurrentTarget to CustomizableCompanionREF.GetCombatTarget
    if (KillCountDoOnce == 0)
        set CustomizableCompanionREF.EnemiesEngaged to (CustomizableCompanionREF.EnemiesEngaged + 1)
        set KillCountDoOnce to 1
    endif
  endif ; added end of test line
endif

That shows that you are only resetting "CurrentTarget" if your companion is not currently engaged. Every "If" at least implies an "Else" condition you should consider. You need an "Else" for when they are engaged. That you are then immediately following the current "If" block with another separate test that the "CurrentTarget" is not null shows you are considering them as separate conditions as opposed to two states of the same condition; or at least are not waiting for the variable changes to take effect. If the second block is turned into an "ElseIF" of the rewritten initial test statement:

if (CustomizableCompanionREF.GetCombatTarget != CurrentTarget)
  ...
ElseIf (CurrentTarget != 0)

you now more clearly know that they have switched targets and the first is still valid (or at least has not tested out as "dead").

 

You might find 'TIP Debugging Compound Conditionals' under the "Scripting" section of the wiki "Getting started creating mods using GECK" article helpful.

 

You might try using an "unplayable slave collar" for your token. It's something "wearable" but not going to potentially replace anything the Actor currently is wearing outside of "Dead Money".

 

-Dubious-

Link to comment
Share on other sites

Okay, so the following combination seems to be working well enough so far. I've got this block running in my quest script with the delay set to 1:

if (CustomizableCompanionREF.GetCombatTarget != CurrentTarget)
	if (CustomizableCompanionREF.GetCombatTarget != 0)
		set CurrentTarget to CustomizableCompanionREF.GetCombatTarget
		if (CurrentTarget.GetItemCount aaaMISCKillCountToken < 1)
			CurrentTarget.AddItem aaaMISCKillCountToken 1
			set CustomizableCompanionREF.EnemiesEngaged to (CustomizableCompanionREF.EnemiesEngaged + 1)
		endif
	endif
elseif (CurrentTarget != 0)
	if (CurrentTarget.GetDead == 1)
		set CurrentTarget to 0
	endif
		endif

My kill count token is a Misc Item with an empty name field so that it won't show up in the enemy's inventory, even if the player manages to access it while they're being attacked by the companion. The token runs the following script:

scn aaaSCPTKillCountToken

ref MySelf

begin OnAdd
	set MySelf to GetContainer
end

begin OnCombatEnd
	if (MySelf.GetDead == 0)
		RemoveMe
	endif
end

begin GameMode
	if (MySelf.GetDead == 1)
		if (MySelf.IsKiller CustomizableCompanionREF)
			set CustomizableCompanionREF.EnemiesKilled to (CustomizableCompanionREF.EnemiesKilled + 1)
		endif
		RemoveMe
	endif
end

@Dubious - Your suggestion seems to have helped, although it hasn't completely solved the "do nothing while being attacked" issue. I've noticed that the enemies exhibiting this behaviour all seem to play the "bend over and pick something up off the ground" animation at least once.

Link to comment
Share on other sites

That animation plays (to my limited understanding) when the Actor has 1) dropped or been forced to drop their weapon (to include when the current weapon condition drops to zero), 2) a "better" (higher damage potential) weapon is next to it on the ground AND they have ammo for it, 3) it is out of ammo for the current weapon. That is not a definitive list of situations. Don't know if the same applies to "armor".

 

"Logic Conditions" can be applied to animations. They can be found under the "Animation Browser" at:

Gameplay -> Idle Animations -> Character\_Male\IdleAnims\

The "Pickup" anim mentioned seems to be

ActivateIdles -> \NPCPickupItem -> \LoosePickUpGroundObject

As for the "do nothing while being attacked" situation, are you sure the Actor is not engaged in some "combat dialog" or is not missing an appropriate AI package triggered at that point? Recall that using "AddScriptPackage <packagename>" is a "one off" function. See the old threads "NPC Loot Bodies / Pickup Items?" and "NPC preferred weapon" as well as 'TIP Making NPCs move aka AI Packages' under the "Custom NPCs" section of the wiki "Getting started creating mods using GECK" article.

 

-Dubious-

Link to comment
Share on other sites

Upon further reflection, I'm thinking you're right, it might be the weapon pickup thing - perhaps combined with cowering/flee behaviour. In any case, it's not game-breaking. Just a little eccentricity. Most players might not even notice. I only noticed because I wasn't doing any shooting, and letting the companion do all the work. Someone who's actually playing using the mod would probably have shot and killed all the non-responsive ones without even noticing that they weren't fighting back.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...