Jump to content

[LE] Apply effect to an NPC


Recommended Posts

Hello,

 

It turns out I don't know how to apply an effect to NPCs.

For example, I'd like to apply an effect that increases the npc's health by 25%.

Here's what I did:

1) Set up a Perk, check playable box, set it to Modify Skill Use, multiply by 1.25.

2) Set up a Magic Effect. I used "Well Rested" as a template:

- Peak Value modifyer as archtype

- Constant Effect

- Delivery: self

- Assoc. item: Health

- Perk to apply: Previously defined perk

- Attached Timed Ability Script. TIme set to 2 hours, ability to remove set to spell in next point:

3) Set up a Spell Ability.

- Type: Ability

- Effects: The previously defined Magic Effect.

 

Then, in the script where I want to apply this, I just write

SPELL Property Spell_in_point3  Auto
 
function ApplySpell(Actor akTarget)
    Spell_in_point3.Cast(akTarget,akTarget)
    Debug.Notification("Funcation ran fine.") ; I do get this report, so scripts run fine.
endfunction

But in-game, nothing happens, the effect is not applied to the npc.

What am I doing wrong again?

Edited by WhiteWolf424242
Link to comment
Share on other sites

You cannot add dynamically 'Perks' to npcs in-game, it is not supported, you can only use perks to npcs as in their default state (created in CK) and that's it...

Adding perks through scripts or magic effects works ONLY on the PLAYER.


To change the npcs health percentage you need to use "ModActorValue()" or "SetActorValue()" according always with what you are trying to do.

Link to comment
Share on other sites

I wouldn't use script ModAv or SetAv because then returning to the original value can be a problem, at least I've had problems with that in the past. Instead you can just do it with the ability magic effect. Change the effect archetype to Value Modifier. Assoc item 1 to health. Then in your script you can use SetNthEffectMagnitude before adding the spell:

 

Actor Property MyActor Auto 
Spell Property HealthAbility Auto

Event SomeEvent() 

    HealthAbility.SetNthEffectMagnitude(0, (MyActor.GetAv("Health") * 0.25)) ;includes current buffs in calculation
    ;Or
    HealthAbility.SetNthEffectMagnitude(0, (MyActor.GetBaseAv("Health") * 0.25)) ;doesn't include current buffs in calculation 
    
    MyActor.AddSpell(HealthAbility)
EndEvent 
Then use MyActor.RemoveSpell(HealthAbility)
Note that this does require SKSE, and if you want to change the magnitude, you have to remove the spell before changing, then add it back for the changes to take effect.
Edited by dylbill
Link to comment
Share on other sites

I see, thanks :smile:

 

I wouldn't use a direct setav command either, that just sounds too hard to control.

So I changed the magic effect to Value Modifier.

I also added the line:

HealthAbility.SetNthEffectMagnitude(0, (MyActor.GetBaseAv("Health") * 0.25))

However, to have better trackability, instead of AddSpell, I opted for an alias that loads the spell, and the script sets this alias to the actor. It seems to work.

 

Now the spell is indeed added to the npc, it's visible in the console (mfg), and also if I expand, the magnitude seems correct.

However, the npc's health is unchanged. As if the spell was doing nothing.

I'll attach a screenshot of the magic effect in a sec.

 

EDIT: here's the magic effect:

magic-effect.png

Edited by WhiteWolf424242
Link to comment
Share on other sites

If you are uncomfortable using Mod - Set - Get Value, then use dylbill suggestion, it can do the job and SKSE is something that only inexperienced players / users don't have or know what it is, SKSE by now has become a 'Hard Requirement'.

Link to comment
Share on other sites

I'm sure that's what I did :D

(The mod already uses quite a lot of skse calls, it's not introducing a new requirement either.)

 

I just wanted to make removing the spell easier, that's why instead of "AddSpell", I force the npc to an alias that has this spell. Later to remove it is just to clear the alias, which the script always has on hand. (But the script may not have the actual npc at hand anymore at a later point, so RemoveSpell might be tricky).

 

But the spell is there. It's applied to the npc for sure, I can see that in the console. That part's correct now. But it's not applying its effect for some reason, the health of the npc is not changed. And I don't yet see why.

Link to comment
Share on other sites

Hmmm, not sure why that would be. Make sure in your spell it's the Ability type and not the spell type. If you want to use modAv as maxaturo suggested, in your script you can do:

 

Actor Property MyActor Auto 
Float ModHealthValue

Function ModHealth()
    ModHealthValue = (MyActor.GetBaseAv("Health") * 0.25)
    MyActor.ModAv("Health", ModHealthValue)
EndFunction 

Function ReturnHealth()
    MyActor.ModAv("Health", -ModHealthValue)
EndFunction
Link to comment
Share on other sites

Okay, this is very, very weird.

 

I tried it on another npc, and... it works. Applied properly, health value changed correctly. :huh:

(So it doesn't work for npc1, but after that now the alias has been set then to npc2, and it works.)

Extra weird part: If I now go back now to npc1 (clears alias of npc2 and set it to npc1 once again) - then now it works on npc1 as well!

 

Baffling. I'm guessing that the alias has a hard time getting activated on that one npc when it's filled for the first time.... or I don't know.... or it's just Skyrim being.... Skyrim. :dry:

 

 

I'll try the AddSpell way tomorrow, but I'll have to solve the problem that the actor info is not at hand for the script. I was thinking something like

Actor AffectedActor
 
function TheActualApplierFunction(Actor akTarget)
    ; here: stuff from previous posts to add the spell to akTarget

    ;save actor info:
    AffectedActor = akTarget
 
    ; removing is done after 2 hours.
    UnRegisterForUpdateGameTime()
    RegisterForSingleUpdateGameTime(2)
endfunction
 
Event OnUpdateGameTime()
    ; previously this just cleared the alias, now instead here is how the actor will be available:
    AffectedActor.RemoveSpell( the spell)
EndEvent

So I'm effectively just substituting the always available alias with an always available placeholder variable.

Edited by WhiteWolf424242
Link to comment
Share on other sites

  • Recently Browsing   0 members

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