Jump to content

Counting Kills Made by an NPC?


user826

Recommended Posts

Would anyone be able to tell me the most efficient way to count the number of kills made by an NPC? I'm trying to add a kill count stat to my customizable companion so that I can factor that number into his XP gain calculation. So far, I've tried the following:

 

1) Created an effect script:

scn aaaSCPTCustomizableCompanionKillCount

begin ScriptEffectStart
	set CustomizableCompanionREF.EnemiesEngaged to (CustomizableCompanionREF.EnemiesEngaged + 1)
	set CustomizableCompanionREF.EnemiesEngagedTotal to (CustomizableCompanionREF.EnemiesEngagedTotal + 1)
end

begin OnDeath CustomizableCompanionREF
	set CustomizableCompanionREF.EnemiesKilled to (CustomizableCompanionREF.EnemiesKilled + 1)
	set CustomizableCompanionREF.EnemiesKilledTotal to (CustomizableCompanionREF.EnemiesKilledTotal + 1)
end

2) Created a new Base Effect:

  • Effect Archetype: Script
  • Assoc. Item: aaaSCPTCustomizableCompanionKillCount
  • Hostile
  • Detrimental
  • Recover
  • Self (<< I don't think this flag is correct, but if I don't include it, I can't select this base effect when making my Actor Effect)
  • Touch
  • Target

3) Created a new Actor Effect:

  • Type: Ability
  • Disallow Absorb/Reflect
  • Script Effect Always Applies
  • Area Effect Ignores LOS
  • Auto-Calculate
  • Effect: Kill Count
  • Magnitude: 1
  • Range: Self (<< Again, I don't think this is correct, but there is no other option available)

4) Created a new Perk

  • Perk Entry: Ability (aaaSPELCustomizableCompanionKillCount)

 

5) Added the perk to the companion

 

And it doesn't work! I suspect it's because he's casting the effect on himself, instead of the enemy he's engaging. How do I fix this?

Link to comment
Share on other sites

So, I found a workaround solution involving a timer that constantly casts an area of effect spell on the NPC, and any hostile actors in the vicinity are given a non-playable piece of armor as a marker token. When added to the enemy's inventory, the token advances the "Enemies Engaged" counter by 1, and when killed by the NPC, the token removes itself from the enemy's inventory and advances the "Enemies Killed" counter by 1.

 

While this works, it's bloated and not very elegant, so I'm still holding out hope that my original idea can be salvaged. If you're more knowledgeable about the GECK than I am, please weigh in!

Link to comment
Share on other sites

Have you tried using a combination of these functions?

 

https://geckwiki.com/index.php?title=GetCombatTarget

https://geckwiki.com/index.php?title=GetCombatTargets

https://geckwiki.com/index.php?title=GetKiller

https://geckwiki.com/index.php?title=IsKiller

 

If a fight breaks out, track who the companion is targeting. With the reference to the target of the companion, check if they die, and if they do, check if the companion killed him.

 

Alternatively, considering the player gets XP for whoever their companion kills, the converse should work as well. With that in mind, just get how much XP the player gets and give it to the companion after the fight:

 

https://geckwiki.com/index.php?title=GetKillXP

https://geckwiki.com/index.php?title=GetXPForNextLevel

Edited by WarMachineDD7
Link to comment
Share on other sites

I don't use NVSE or JIP NVSE to make my mods, so I can't use GetCombatTargets, or GetKiller. I'm currently using GetCombatTarget and IsKiller, but it's not working reliably 100% of the time.

 

Also, the companion is using my own custom XP system, independent of the player's XP, so I can't piggyback off of the player. I want him to get XP if he does all the work and I don't kill anyone for him.

Edited by user826
Link to comment
Share on other sites

Any particular reason why no NVSE or JIP? They're pretty common nowadays, especially with other common mods like The Mod Configuration Menu requiring them.

Anyway, with those restrictions you can still use GetCombatTarget and IsKiller to figure out who the companion killed. With that, you can probably manually compute the XP based on the target's level and the game difficulty (*):

https://geckwiki.com/index.php?title=Experience_Settings

 

*Edit: From the page I linked "In Fallout: New Vegas, FalloutNV.esm sets these all to 1.0 so there is no XP bonus for playing at a higher combat difficulty."

Edited by WarMachineDD7
Link to comment
Share on other sites

I don't like using third-party per-requisites for my mods. I find it challenging to try and design things to work using only vanilla assets. In any case, here's what I've got so far:

 

The following area-of-effect script is cast on my NPC every three seconds. It checks if any actors within its area of effect are targeting the NPC or are being targeted by the NPC. If so, it adds the Kill Count Token to their inventory.

scn aaaSCPTKillCountEffect

ref MySelf

begin ScriptEffectStart
    set MySelf to GetSelf
    if (MySelf != Player) && (MySelf != CustomizableCompanionREF) && (MySelf.GetCombatTarget == CustomizableCompanionREF)
        if (MySelf.GetItemCount aaaARMOKillCountToken == 0)
            MySelf.AddItem aaaARMOKillCountToken 1
        endif
    elseif (CustomizableCompanionREF.GetCombatTarget MySelf)
        if (MySelf.GetItemCount aaaARMOKillCountToken == 0)
            MySelf.AddItem aaaARMOKillCountToken 1
        endif
    endif
end

The Kill Count Token runs the following script. When added to an actor's inventory, it advances the "Enemies Engaged" counter by 1. When the enemy is killed by the NPC, it advances the "Enemies Killed" counter by 1.

scn aaaSCPTKillCountToken

ref MySelf
short DoOnce

begin OnAdd
	set MySelf to GetContainer
	if (DoOnce == 0)
		set CustomizableCompanionREF.EnemiesEngaged to (CustomizableCompanionREF.EnemiesEngaged + 1)
		set CustomizableCompanionREF.EnemiesEngagedTotal to (CustomizableCompanionREF.EnemiesEngagedTotal + 1)
		set DoOnce to 1
	endif
end

begin GameMode
	if (MySelf.IsKiller CustomizableCompanionREF == 1)
		if (MySelf.GetItemCount aaaARMOKillCountToken > 0)
			set CustomizableCompanionREF.EnemiesKilled to (CustomizableCompanionREF.EnemiesKilled + 1)
			set CustomizableCompanionREF.EnemiesKilledTotal to (CustomizableCompanionREF.EnemiesKilledTotal + 1)
			RemoveMe
		endif
	endif
end

The issue I'm having right now is that some enemies (i.e. the giant rats in Cerulean Robotics) are being killed by the NPC, but they're not being registered. The "Enemies Engaged" and "Enemies Killed" counters remain at 0. This also sometimes happens with human enemies, where the NPC will kill a raider, but it won't register, then he'll kill another raider in the same room and it does register. I have no idea why it's being so inconsistent.

Link to comment
Share on other sites

I think you're missing an == here, so some NPCs aren't getting the kill count token:

elseif (CustomizableCompanionREF.GetCombatTarget MySelf)

Also, why do you add the kill count token to enemies who the companion hasn't engaged? There's no way he can kill them if he doesn't engage them back.

Edited by WarMachineDD7
Link to comment
Share on other sites

Yeah, I noticed that and changed it. Thanks for pointing it out too! I also added some Return statements, and it seems to be working now. The script looks like this at the moment:

scn aaaSCPTKillCountEffect

ref MySelf

begin ScriptEffectStart
	set MySelf to GetSelf
	if (MySelf != Player) && (MySelf != CustomizableCompanionREF)
		if (MySelf.GetCombatTarget == CustomizableCompanionREF)
			if (MySelf.GetItemCount aaaARMOKillCountToken == 0)
				MySelf.AddItem aaaARMOKillCountToken 1
				Return
			endif
		elseif (CustomizableCompanionREF.GetCombatTarget == MySelf)
			if (MySelf.GetItemCount aaaARMOKillCountToken == 0)
				MySelf.AddItem aaaARMOKillCountToken 1
				Return
			endif
		endif
	endif
end

Also, I count enemies attacking him as an engagement. Like, if you get jumped by a group of hostiles, even if you haven't gotten a shot off yet, you are considered to have engaged the enemy.

 

EDIT: For some reason, the giant rats still aren't registering as engagements or kills, and I don't know why. Could it be perhaps that since they can't equip the armor, that it doesn't register? Should that even matter? The script should run during the OnAdd block.

Edited by user826
Link to comment
Share on other sites

Could it be perhaps that since they can't equip the armor

I don't think so since any creature could have weird loot, but I'm not sure how reliable OnAdd is when the item is added through a script.

 

And again, the companion can't kill someone if the companion doesn't engage them, so I don't see the point of tracking when an enemy targets the companion.

 

Anyway, I think the whole script would be a lot simpler if you just used a quest on GameMode like this:

scn killCounterQuestScript

ref currentTarget
int companionKillCount

begin GameMode
	if companionREF.GetCombatTarget != currentTarget && companionREF.GetCombatTarget != 0	//If companion engages a new target and the reference is not zero.
		set currentTarget to companionREF.GetCombatTarget				//Get companion's current target
	endif

	if currentTarget != 0			                                    //Companion is engaging an enemy
		if currentTarget.GetDead	                                    //Check if target died
			if currentTarget.IsKiller companionREF			    //Target killed by companion.
				set companionKillCount to companionKillCount + 1    //+1 to kill count
				set currentTarget to 0				    //End check until a new target comes up
			else							    //Target was not killed by companion
				set currentTarget to 0				    //End check until a new target comes up
			endif
		endif
	endif
end
Edited by WarMachineDD7
Link to comment
Share on other sites

  • Recently Browsing   0 members

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