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! :)