theblackpixel Posted June 10, 2021 Share Posted June 10, 2021 I have a script attached to a magic effect that should update a gobal variable, but in practice it does not: The script: Scriptname TBPUnderwaterCheck extends activemagiceffect Conditional import PO3_SKSEFunctions GlobalVariable property TBPUnderwaterCheckGlobal auto Event OnEffectStart(Actor akTarget, Actor akCaster) if IsActorUnderwater(akCaster) == 1 if TBPUnderwaterCheckGlobal.getValue() == 0 as Float TBPUnderwaterCheckGlobal.setvalue(1 as float) else TBPUnderwaterCheckGlobal.setvalue(0 as float) ;Add 16 times the detail endif endif EndEventThe magic effect is a script with a constant effect and a self delivery. The idea behind this is that it updates my global variable to 1 when the player is underwater, allowing me to use that as a condition in spell conditions. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted June 10, 2021 Share Posted June 10, 2021 Slight tweak, see if it works: Scriptname TBPUnderwaterCheck extends activemagiceffect Conditional import PO3_SKSEFunctions GlobalVariable property TBPUnderwaterCheckGlobal auto Event OnEffectStart(Actor akTarget, Actor akCaster) if IsActorUnderwater(akCaster) TBPUnderwaterCheckGlobal.setvalue(1.0) else TBPUnderwaterCheckGlobal.setvalue(0.0) ;Add 16 times the detail endif EndEvent I don't think it will though as it is a constant effect which means that the effect starts only once and thus the OnEffectStart event only runs once. You may need to check every so often with a re-registrating single update. Link to comment Share on other sites More sharing options...
theblackpixel Posted June 10, 2021 Author Share Posted June 10, 2021 I tried your version and edited to script to your suggestion but still nothing happensthe script right now: Scriptname TBPUnderwaterCheck extends activemagiceffect import PO3_SKSEFunctions GlobalVariable property TBPUnderwaterCheckGlobal auto Function OnEffectStart(Actor akTarget, Actor akCaster) RegisterForUpdate(5.0) EndFunction Event OnUpdate() Actor Player = Game.GetPlayer() if IsActorUnderwater(Player) TBPUnderwaterCheckGlobal.setvalue(1.0) Debug.Trace("Underwater") else TBPUnderwaterCheckGlobal.setvalue(0.0) Debug.Trace("Not underwater") ;Add 16 times the detail EndIf EndEventIt's as if the script itself just does not fire Link to comment Share on other sites More sharing options...
maxarturo Posted June 10, 2021 Share Posted June 10, 2021 (edited) "Self" will always return the actor of the magic effect target and especially on Ab Spells. Edited June 11, 2021 by maxarturo Link to comment Share on other sites More sharing options...
theblackpixel Posted June 10, 2021 Author Share Posted June 10, 2021 Sorry IsharaMeradin for stepping in, but although that i haven't used this plugin function shouldn't this be something like:If ( Self.IsActorUnderwater() == True ) That doesn't compile, I've tried switching it out with IsSwimming and no results with that either Link to comment Share on other sites More sharing options...
NexusComa2 Posted June 10, 2021 Share Posted June 10, 2021 (edited) Did you actually manually create the global in the Creation Kit 1st? ... Is the global set to an INT then being called as a float?If you're looking for a 1 or 0 set the global to an INT.exp:GlobalVariable Property v1 Auto <- set to my premade INT global made in the CK.If(v1.GetValueInt()==(1)) v1.SetValueInt(0)EndIfThere is also a problem with calling a global over and over. They don't always update as fast as you would wish.For some odd reason this works better. Especially if you have a lot of globals. Int v0 = 0GlobalVariable Property v1 Auto v0=(v1.GetValueInt())If(v0==(1)) v1.SetValueInt(0)EndIfAlso ...if IsActorUnderwater(akCaster) == 1 ... False = 0, True = -1I may be wrong here but normally true = -1If ( Self.IsActorUnderwater() == True ) and extends activemagiceffect ... looks like you're asking if the effect is underwater.Idk ... maybe change the reference to who it is vs self. Edited June 10, 2021 by NexusComa2 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted June 10, 2021 Share Posted June 10, 2021 (edited) 1) approach with cloak Spell and effect script like this:TBPUnderwaterCheck Scriptname TBPUnderwaterCheck extends ActiveMagicEffect conditional ; https://forums.nexusmods.com/index.php?/topic/10127098-using-global-variables-as-conditions/ GlobalVariable PROPERTY TBPUnderwaterCheckGlobal auto Conditional ; new created with CK, do not forget to assign this property! Actor myActor ; to make caster persistent for a while ;----------------------------------------------------------------------------------- ; see script source "PO3_SKSEFunctions.psc" https://github.com/powerof3/PapyrusExtenderSSE ;;Returns whether plugin exists ; bool Function IsPluginFound(String akName) global native ;;Returns whether the actor is in cell water or lava ; bool Function IsActorInWater(Actor akActor) global native ;;Returns whether the actor is underwater ; bool Function IsActorUnderwater(Actor akActor) global native ;---------------------------------------------------------------- ; -- EVENTs -- 3 EVENT OnEffectStart(Actor akTarget, Actor akCaster) Debug.Trace("TBPU: OnEffectStart() - target = " +akTarget+ ", caster = " +akCaster) ; debugging only myActor = akCaster RegisterForSingleUpdate(1.0) ; first time register ENDEVENT EVENT OnEffectFinish(Actor akTarget, Actor akCaster) Debug.Trace("TBPU: OnEffectFinish() - for " +self) ; debugging only myActor = None ; remove actor persistent ENDEVENT EVENT OnUpdate() myF_Action() ENDEVENT ; -- FUNCTION -- ;-------------------- FUNCTION myF_Action() ; "myPlugin.esp" is a dummy, put in the name of your own created mod !!! ;-------------------- IF (myActor) && PO3_SKSEFunctions.IsPluginFound("myPlugin.esp") ELSE RETURN ; - STOP - missing actor /or/ plugin not found! ENDIF ;--------------------- bool bOK = PO3_SKSEFunctions.IsActorUnderwater(myActor) IF ( bOK ) IF (TBPUnderwaterCheckGlobal.GetValue() == 0) Debug.Trace("Underwater first time") ; ** TBPUnderwaterCheckGlobal.SetValue(1) ; first time success under water check ELSE Debug.Trace("Underwater") ; ** ;Add 16 times the detail ?? ; actor is still under water ENDIF ELSE Debug.Trace("Underwater") ; ** TBPUnderwaterCheckGlobal.SetValue(0) ; no more under water ENDIF RegisterForSingleUpdate(1.0) ; register for event again ENDFUNCTION 2) approach with new created quest and player filled alias, which should use next script.TBPUnderwaterCheckPlayerAliasScript Scriptname TBPUnderwaterCheckPlayerAliasScript extends ReferenceAlias conditional ; https://forums.nexusmods.com/index.php?/topic/10127098-using-global-variables-as-conditions/ GlobalVariable PROPERTY TBPUnderwaterCheckGlobal auto Conditional ; new created with CK, do not forget to assign this property! ;----------------------------------------------------------------------------------- ; see script source "PO3_SKSEFunctions.psc" https://github.com/powerof3/PapyrusExtenderSSE ;;Returns whether plugin exists ; bool Function IsPluginFound(String akName) global native ;;Returns whether the actor is in cell water or lava ; bool Function IsActorInWater(Actor akActor) global native ;;Returns whether the actor is underwater ; bool Function IsActorUnderwater(Actor akActor) global native ;---------------------------------------------------------------- ; -- EVENTs -- 4 EVENT OnInit() Debug.Trace("TBPU_Alias: OnInit() - has been reached.. " +self) ; debugging only RegisterForSingleUpdate(1.0) ; first time register on new game or saved game ENDEVENT EVENT OnPlayerLoadGame() Debug.Trace("TBPU_Alias: OnPlayerLoadGame() - has been reached.. " +self) ; debugging only RegisterForSingleUpdate(2.0) ; continous register on saved game loaded ENDEVENT EVENT OnDeath(Actor akKiller) UnRegisterForUpdate() ; just in case TBPUnderwaterCheckGlobal.SetValue(0) ENDEVENT EVENT OnUpdate() myF_Action() ENDEVENT ; -- FUNCTION -- ;-------------------- FUNCTION myF_Action() ; "myPlugin.esp" is a dummy, put in the name of your own created mod !!! ;-------------------- IF (myActor) && PO3_SKSEFunctions.IsPluginFound("myPlugin.esp") ELSE RETURN ; - STOP - missing actor /or/ plugin not found! ENDIF ;--------------------- bool bOK = PO3_SKSEFunctions.IsActorUnderwater(myActor) IF ( bOK ) IF (TBPUnderwaterCheckGlobal.GetValue() == 0) Debug.Trace("Underwater first time") ; ** TBPUnderwaterCheckGlobal.SetValue(1) ; first time success under water check ELSE Debug.Trace("Underwater") ; ** ;Add 16 times the detail ?? ; actor is still under water ENDIF ELSE Debug.Trace("Underwater") ; ** TBPUnderwaterCheckGlobal.SetValue(0) ; no more under water ENDIF RegisterForSingleUpdate(1.5) ; register for event again, in 1.5 seconds ENDFUNCTION Edited June 10, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
theblackpixel Posted June 11, 2021 Author Share Posted June 11, 2021 It works, thank you very much, this was a major roadblock in the development of what I am working on at the moment. You went above and beyond and included checks and features I did not think of. Kudos well earned. Link to comment Share on other sites More sharing options...
Recommended Posts