Jump to content

Help with OnCombatStateChanged function


Vylssius

Recommended Posts

Hello, I was looking to get some help with the OnCombatStateChanged function for a mod I'm working on.

 

Currently my setup is potion>Magic Effect>Script

 

It all compiles the way it should, but when I actually get into combat the rest of my code doesn't execute.

 

I wouldn't be surprised if I am simply overlooking something, but I am still really new to modding on Fallout 4 so I would appreciate the help!

 

Thank you in advance for the help :)

Link to comment
Share on other sites

You'd like to use the onCombatStateChanged event on the Player only? If so, just create a Quest and a Reference Alias.

 

Quest data: Start Game Enabled.

 

Alias data: Fill type > Unique Actor > Player.

 

Attach a script like this to the alias:

Scriptname YOURSCRIPTNAME extends ReferenceAlias Const


Event OnCombatStateChanged(Actor akTarget, int aeCombatState)

	;***aeCombatState values: 0: not in combat. 1: in combat. 2: searching.

	If aeCombatState == 0

		Debug.Notification("I am no longer in combat.")

	ElseIf aeCombatState == 1

		Debug.Notification("I am in combat.")

	EndIf

EndEvent


Edited by LarannKiar
Link to comment
Share on other sites

 

You'd like to use the onCombatStateChanged event on the Player only? If so, just create a Quest and a Reference Alias.

 

Quest data: Start Game Enabled.

 

Alias data: Fill type > Unique Actor > Player.

 

Attach a script like this to the alias:

Scriptname YOURSCRIPTNAME extends ReferenceAlias Const


Event OnCombatStateChanged(Actor akTarget, int aeCombatState)

	;***aeCombatState values: 0: not in combat. 1: in combat. 2: searching.

	If aeCombatState == 0

		Debug.Notification("I am no longer in combat.")

	ElseIf aeCombatState == 1

		Debug.Notification("I am in combat.")

	EndIf

EndEvent


That looks awesome! Thank you for your reply, I'll give that a try when I get some free time! I thought about using a quest, but I wasn't sure how it all worked because I'm still trying to get the hang of the ck lol

But I really appreciate your reply!

Link to comment
Share on other sites

So doing what was recommended by LarannKiar seemed to work, the only problem I am having now is what do I do if i want that quest with the script to only affect the player after they use a specific item i.e. a medicine?

Link to comment
Share on other sites

So doing what was recommended by LarannKiar seemed to work, the only problem I am having now is what do I do if i want that quest with the script to only affect the player after they use a specific item i.e. a medicine?

 

1. Create a Global Variable. Name: MyMod_MedicineActive. Value: 0. Constant = false.

 

2. Create a Quest. Name: MyModQuest. Click on Scripts tab. Add new script. Name: MyQuestScript. Namescape: MyModFolder. Here's the script:

Scriptname MyModFolder:MyQuestScript extends Quest Const

GlobalVariable Property MyMod_MedicineActive Auto Const

float Property MedicineEffectTime = 0.5 Auto Const     ;Medicine effect time. 0.5 == 30 ingame minutes.


Function MedicineON()                                  ;Called by the magic effect script. See point 7.

	MyMod_MedicineActive.SetValueInt(1)            ;This global variable is used as a condition in the onCombatStateChange event. See point 8.

	StartTimerGameTime(MedicineEffectTime, 555)    ;Medicine effect timer starts. 555 is the timer ID.

EndFunction

Event OnTimerGameTime(int aiTimerID)                   ;This event fires when the timer expires.

	If aiTimerID == 555

		MyMod_MedicineActive.SetValueInt(0)    ;Sets the global variable back to 0.

	EndIf

EndEvent

3. Compile the script, then open its Properties. Click on "Auto-Fill all" to fill the properties with the FormIDs.

 

4. Create a Potion item. Data: Food item = true, leave everything else blank / none.

 

5. Create a Magic Effect. Name: MyModEffect. Data: No Area = true, Painless = true, No Hit Effect = true, Effect Archetype: Script, Casting Type: Fire and Forget, Delivery: Self, leave everything else blank / none.

 

6. Open your potion item. To add new effect: right click, then "New". You should see the "Effect Item" window now. Choose your magic effect (MyModEffect) from the dropdown menu.

 

7. Open your magic effect. Add new script. Name: MyMagicEffectScript. Namescape: MyModFolder. Const = true, leave everything else unchecked. Open the script. Here's the code:

Scriptname MyModFolder:MyMagicEffectScript extends activemagiceffect Const

GlobalVariable Property MyMod_MedicineActive Auto Const

Quest Property MyModQuest Auto Const


Event OnEffectStart(Actor akTarget, Actor akCaster)

        (MyModQuest as MyModFolder:MyQuestScript).MedicineON()           ;When you take the medicine, the effect starts. When the effect starts, the magic effect script calls the function "MedicineON()" that's been defined in the quest script.

EndEvent

8. Modify the Reference Alias script that I made earlier:

Scriptname YOURSCRIPTNAME extends ReferenceAlias Const

GlobalVariable Property MyMod_MedicineActive Auto Const



Event OnCombatStateChanged(Actor akTarget, int aeCombatState)

	;***aeCombatState values: 0: not in combat. 1: in combat. 2: searching.

	If MyMod_MedicineActive.GetValueInt() == 1

		If aeCombatState == 0

			Debug.Notification("I am no longer in combat.")

		ElseIf aeCombatState == 1

			Debug.Notification("I am in combat.")

		EndIf

	ElseIf MyMod_MedicineActive.GetValueInt() == 0

		;*** medicine effect is inactive. You can put additional functions here.

	EndIf

EndEvent

9. Don't forget to fill the script Property.

Edited by LarannKiar
Link to comment
Share on other sites

 

So doing what was recommended by LarannKiar seemed to work, the only problem I am having now is what do I do if i want that quest with the script to only affect the player after they use a specific item i.e. a medicine?

 

1. Create a Global Variable. Name: MyMod_MedicineActive. Value: 0. Constant = false.

 

2. Create a Quest. Name: MyModQuest. Click on Scripts tab. Add new script. Name: MyQuestScript. Namescape: MyModFolder. Here's the script:

Scriptname MyModFolder:MyQuestScript extends Quest Const

GlobalVariable Property MyMod_MedicineActive Auto Const

float Property MedicineEffectTime = 0.5 Auto Const     ;Medicine effect time. 0.5 == 30 ingame minutes.


Function MedicineON()                                  ;Called by the magic effect script. See point 7.

	MyMod_MedicineActive.SetValueInt(1)            ;This global variable is used as a condition in the onCombatStateChange event. See point 8.

	StartTimerGameTime(MedicineEffectTime, 555)    ;Medicine effect timer starts. 555 is the timer ID.

EndFunction

Event OnTimerGameTime(int aiTimerID)                   ;This event fires when the timer expires.

	If aiTimerID == 555

		MyMod_MedicineActive.SetValueInt(0)    ;Sets the global variable back to 0.

	EndIf

EndEvent

3. Compile the script, then open its Properties. Click on "Auto-Fill all" to fill the properties with the FormIDs.

 

4. Create a Potion item. Data: Food item = true, leave everything else blank / none.

 

5. Create a Magic Effect. Name: MyModEffect. Data: No Area = true, Painless = true, No Hit Effect = true, Effect Archetype: Script, Casting Type: Fire and Forget, Delivery: Self, leave everything else blank / none.

 

6. Open your potion item. To add new effect: right click, then "New". You should see the "Effect Item" window now. Choose your magic effect (MyModEffect) from the dropdown menu.

 

7. Open your magic effect. Add new script. Name: MyMagicEffectScript. Namescape: MyModFolder. Const = true, leave everything else unchecked. Open the script. Here's the code:

Scriptname MyModFolder:MyMagicEffectScript extends activemagiceffect Const

GlobalVariable Property MyMod_MedicineActive Auto Const

Quest Property MyModQuest Auto Const


Event OnEffectStart(Actor akTarget, Actor akCaster)

        (MyModQuest as MyModFolder:MyQuestScript).MedicineON()           ;When you take the medicine, the effect starts. When the effect starts, the magic effect script calls the function "MedicineON()" that's been defined in the quest script.

EndEvent

8. Modify the Reference Alias script that I made earlier:

Scriptname YOURSCRIPTNAME extends ReferenceAlias Const

GlobalVariable Property MyMod_MedicineActive Auto Const



Event OnCombatStateChanged(Actor akTarget, int aeCombatState)

	;***aeCombatState values: 0: not in combat. 1: in combat. 2: searching.

	If MyMod_MedicineActive.GetValueInt() == 1

		If aeCombatState == 0

			Debug.Notification("I am no longer in combat.")

		ElseIf aeCombatState == 1

			Debug.Notification("I am in combat.")

		EndIf

	ElseIf MyMod_MedicineActive.GetValueInt() == 0

		;*** medicine effect is inactive. You can put additional functions here.

	EndIf

EndEvent

9. Don't forget to fill the script Property.

 

very detailed and helpful response again, thank you for the help! :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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