Jump to content

[LE] Player Heals an NPC Script?


luvadea

Recommended Posts

Here is the thing I need:

Player finds an unconscious NPC and

1 Player casts healing spell (any)

2 Laying (by AI package) NPC "wakes up"

How do I connect casting the healing spell (any healing spell-not one particular) by player with the package change?

 

Sorry guys if I'm asking daft questions..just give me a clue please..

Link to comment
Share on other sites

Most healing spells are cast on self. This is why stock NPCs that want healed ask for a potion.

 

At any rate, here is a probable possible method. If you put all the spells you want to be recognized in a single formlist you could use the OnSpellCast event, get the spell that was cast and see if the formlist has that spell. If you get a matching spell, update a global variable that you use as a condition on the NPC's AI package and then force their AI package to re-evaluate. Script running the OnSpellCast event would need to know the NPC to be "healed". Probably best to use a quest alias and assign the desired NPC to the alias and then have the AI package stuff on the quest alias rather than on the NPC directly.

Link to comment
Share on other sites

A script could be as follow like IsharaMeradin has written. Make sure your script has a unique name!

 

luvaPlayerAliasScript

 

Scriptname luvaPlayerAliasScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/8054773-player-heals-an-npc-script/

  GlobalVariable PROPERTY myGlobalAI auto Conditional    ; "use as a condition on the NPCs AI package"
  ReferenceAlias PROPERTY myNPC      auto                ; "use a quest alias and assign the desired NPC to the alias"

  FormList PROPERTY myList auto        ; "put all the healing spells you want to be recognized in a single formlist"

; steps
; -----
; (0) create a globalVar and the formlist
; (1) create a quest
; (2) create two aliases (for the player and desired NPC)
; (3a) attach this script to the player alias
; read this topic: https://forums.nexusmods.com/index.php?/topic/8049858-question-regarding-player-alias/
; (3b) fill properties by using Creation Kit
; (3c) compile this script
; (4) make a condition on NPC AI package (How to?)

; -- EVENTs --

EVENT OnInit()  ; native
    Debug.Trace(" OnInit() - has been reached.. " +self)                ; debugging only
ENDEVENT


EVENT OnPlayerLoadGame()  ; native
    Debug.Trace(" OnPlayerLoadGame() - has been reached.. " +self)      ; debugging only
ENDEVENT


EVENT OnSpellCast(Form akSpell)  ; native
; https://www.creationkit.com/index.php?title=OnSpellCast_-_ObjectReference
; akSpell can be Spell, Enchantment, Potion or Ingredient (see WIKI above, your browser needs cookies enabled!)

IF (akSpell as Spell)
ELSE
    RETURN    ; - STOP -    not a spell
ENDIF
;---------------------
    int i = myList.Find(akSpell)
    IF (i >= 0)
        myF_Action()     ; player is healing someone, spell was found in list
    ENDIF
ENDEVENT


; -- FUNCTION --

;--------------------
FUNCTION myF_Action()
;--------------------
    myGlobalAI.Mod(1)            ; == myGlobalAI.setValue( myGlobalAI.GetValue() + 1.0 )
;;;    myGlobalAI.Mod(-1)        ; == myGlobalAI.setValue( myGlobalAI.GetValue() - 1.0 )

    actor aRef

    IF ( myNPC )
        aRef = myNPC.GetActorReference()        ; get NPC
    ENDIF

    IF ( aRef )
        aRef.EvaluatePackage()                  ; refresh the current AI package
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Thank you both for answering!

This is the solution if anybody is looking for it

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
if(akSource.hasKeyword(MagicRestoreHealth))
Actor Youractor = getReference() as Actor
getOwningQuest().setStage(20)
Link to comment
Share on other sites

Thats what i wanted to suggest You :x...

 

But how about little upgrade?...

Event OnInit()
	GoToState( "Wait" )
EndEvent


State Wait
	Event OnHit( ObjectReference QArg, Form QSrc, Projectile QPrc, bool A, bool B,  bool C, bool D)
		If( QSrc.hasKeyword( MagicRestoreHealth ))
			GoToState( "Done" )
		Else
	EndEvent
EndState

State Done
	; Empty State
EndState
; The End

Without States you will SET STAGE every time player cast Healing Spell on Your NPC :x...

You could also add another IF to check if stage is for example 10 - otherwise player can jump from stage 0 to 20 skiping everything before

 

//Edit:

and ofc.

getOwningQuest().setStage(20)

 

xDDDD

Edited by TobiaszPL
Link to comment
Share on other sites

  • Recently Browsing   0 members

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