Haagaar Posted April 7, 2020 Share Posted April 7, 2020 (edited) Hi everyone ! I am (still) working on a player house mod, and I have a set of 9 activators (DweButton01) each enabling a different door. I would like to put a restriction in my script that block the said doors from being enabled if one already is. I tried with a formlist, but I think I did it wrong, I can't figure this out. Could somebody give me a idea ofn how to do this ? Anything. Here is my script, as is, applied to each button without any "restriction" : Scriptname AHVA_PortalButtonScript extends ObjectReference ObjectReference Property FXSource auto ObjectReference Property DoortoSummon auto ObjectReference Property DoorLight auto ObjectReference Property FogVFX auto ObjectReference Property BeamVFX01 auto ObjectReference Property BeamVFX02 auto ObjectReference Property BeamVFX03 auto Sound Property RumbleSFX auto Sound Property DoorAppearSFX auto Sound Property DoorDisappearSFX auto Sound Property DoorLoopSFX auto Sound Property BeamFireSFX auto Sound Property BeamOffSFX auto Sound Property BeamLoopSFX auto Auto State Waiting Event OnActivate(ObjectReference akActivator) If akActivator == Game.GetPlayer() If DoortoSummon.IsDisabled() GoToState("Busy") RumbleSFX.Play(FXSource) Game.ShakeCamera(afDuration = 2) BeamFireSFX.Play(FXSource) BeamVFX01.Enable(true) BeamFireSFX.Play(FXSource) BeamVFX02.Enable(true) BeamFireSFX.Play(FXSource) BeamVFX03.Enable(true) FogVFX.Enable(true) DoorLight.Enable() DoorAppearSFX.Play(FXSource) DoortoSummon.Enable(true) GoToState("Waiting") Else GoToState("Busy") BeamVFX01.Disable(true) BeamOffSFX.Play(FXSource) BeamVFX02.Disable(true) BeamOffSFX.Play(FXSource) DoortoSummon.Disable(true) DoorDisappearSFX.Play(FXSource) DoorLight.Disable() BeamVFX03.Disable(true) BeamOffSFX.Play(FXSource) FogVFX.Disable(true) GoToState("Waiting") EndIf EndIf While BeamVFX01.isEnabled() BeamLoopSFX.PlayAndWait(BeamVFX01) BeamLoopSFX.PlayAndWait(BeamVFX02) BeamLoopSFX.PlayAndWait(BeamVFX03) EndWhile While DoortoSummon.isEnabled() DoorLoopSFX.PlayAndWait(DoortoSummon) EndWhile EndEvent EndState State Busy Event OnActivate(ObjectReference akActivator) ; Do nothing EndEvent EndState Thank you all in advance ! :smile: EDIT : I put in states but i don't think it's useful here.. Edited April 7, 2020 by Haagaar Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 7, 2020 Share Posted April 7, 2020 Here is one potential solution:Create a global variable record, leave it at the default float value of 0.0.Attach the following script (yours with modifications)Ensure all properties are assigned correctly and test it out on a game that has not seen the mod in question. Scriptname AHVA_PortalButtonScript extends ObjectReference ObjectReference Property FXSource auto ObjectReference Property DoortoSummon auto ObjectReference Property DoorLight auto ObjectReference Property FogVFX auto ObjectReference Property BeamVFX01 auto ObjectReference Property BeamVFX02 auto ObjectReference Property BeamVFX03 auto Sound Property RumbleSFX auto Sound Property DoorAppearSFX auto Sound Property DoorDisappearSFX auto Sound Property DoorLoopSFX auto Sound Property BeamFireSFX auto Sound Property BeamOffSFX auto Sound Property BeamLoopSFX auto GlobalVariable Property myBusyGV Auto Event OnActivate(ObjectReference akActivator) If myBusyGV.GetValue() == 1.0 ;a door has been summoned RETURN ;skip this activation Else If akActivator == Game.GetPlayer() ;player activated If DoortoSummon.IsDisabled() ;door disabled myBusyGV.SetValue(1.0) ;door will be summoned - block others by setting value to 1.0 RumbleSFX.Play(FXSource) Game.ShakeCamera(afDuration = 2) BeamFireSFX.Play(FXSource) BeamVFX01.Enable(true) BeamFireSFX.Play(FXSource) BeamVFX02.Enable(true) BeamFireSFX.Play(FXSource) BeamVFX03.Enable(true) FogVFX.Enable(true) DoorLight.Enable() DoorAppearSFX.Play(FXSource) DoortoSummon.Enable(true) Else BeamVFX01.Disable(true) BeamOffSFX.Play(FXSource) BeamVFX02.Disable(true) BeamOffSFX.Play(FXSource) DoortoSummon.Disable(true) DoorDisappearSFX.Play(FXSource) DoorLight.Disable() BeamVFX03.Disable(true) BeamOffSFX.Play(FXSource) FogVFX.Disable(true) myBusyGV.SetValue(0.0) ;door has been unsummoned - unblock others by setting value to 0.0 EndIf EndIf While BeamVFX01.isEnabled() BeamLoopSFX.PlayAndWait(BeamVFX01) BeamLoopSFX.PlayAndWait(BeamVFX02) BeamLoopSFX.PlayAndWait(BeamVFX03) EndWhile While DoortoSummon.isEnabled() DoorLoopSFX.PlayAndWait(DoortoSummon) EndWhile EndIf EndEvent Link to comment Share on other sites More sharing options...
Haagaar Posted April 7, 2020 Author Share Posted April 7, 2020 (edited) Thank you for this ultimately fast answer haha ! I'm testing that right away ! EDIT : Doesn't work. When a door is enabled by an activator, the others still enable their respective doors, don't know why. I'm investigating. But still, thank you for your help, I didn't think of that possibility ! Edited April 7, 2020 by Haagaar Link to comment Share on other sites More sharing options...
Haagaar Posted April 7, 2020 Author Share Posted April 7, 2020 (edited) Ok so a description line was at stake. The one just above "RETURN" ; the compiler understood it as part of the description because of the blank space I guess :smile: But I don't know why, this stilll let other doors be enabled while one already is.. So again thank you so much, I spent days trying to solve that ! And this is the second time haha ! You will be credited when the mod is on Nexus ! Edited April 7, 2020 by Haagaar Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 7, 2020 Share Posted April 7, 2020 So removing my side comments resolved the issue? If so, that is good to know. Weird that it happened tho. At least it was resolved in the end. Link to comment Share on other sites More sharing options...
Haagaar Posted April 7, 2020 Author Share Posted April 7, 2020 No, this is weird but it did nothing different. I think this isn't working because I apply the script to 9 buttons, that activate each a different door, so maybe your addition considers only the door assigned to the property DoortoSummon in the question "is it enabled?". If so, maybe adding a formlist to take all of the doors into consideration would give the expected result ? I don't know if I'm being clear, sorry.The thing is, all my attempts to bring in formlists to this script has resulted in my event looping because of the "while" statement that goes with them. I think I'm doing this wrong somewhat.. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 8, 2020 Share Posted April 8, 2020 Double check the global variable property. Make sure it has been properly assigned on all the objects that the script is attached. Its default value is 0.0 this will allow the first script to access it to activate. In the enabling block the global variable is set to 1.0 which should prevent the other buttons from processing. If the property is not filled, it would never have a 1.0 value to prevent the processing on any of the script's instances. A good way to test that is to check the value of the variable via the console both before summoning a door and after and then again after unsummoning the door. This should work. If necessary add debug statements to give feedback while testing. Using a formlist with all the doors might be possible but it would be extra coding. A formlist would have been ideal if you were using a single button to activate the doors with a message box menu where you'd have the response values match the index values of the doors in the formlist. Link to comment Share on other sites More sharing options...
Haagaar Posted April 8, 2020 Author Share Posted April 8, 2020 You are right. Sorry for being a little stubborn and not understanding what you said.I did it right but the problem was that once one door was summoned, all the event was blocked, the door could not be disabled as well as other could not be enabled. So I tweaked it like that and it worked perfectly : Scriptname AHVA_PortalButtonScript extends ObjectReference {Enables or disable a portal door, does nothing if another is already} ObjectReference Property FXSource auto ObjectReference Property DoortoSummon auto ObjectReference Property DoorLight auto ObjectReference Property FogVFX auto ObjectReference Property BeamVFX01 auto ObjectReference Property BeamVFX02 auto ObjectReference Property BeamVFX03 auto Sound Property RumbleSFX auto Sound Property DoorAppearSFX auto Sound Property DoorDisappearSFX auto Sound Property DoorLoopSFX auto Sound Property BeamFireSFX auto Sound Property BeamOffSFX auto Sound Property BeamLoopSFX auto GlobalVariable Property myBusyGV auto Auto State Waiting Event OnActivate(ObjectReference akActivator) If myBusyGV.GetValue() == 0.0 ; a door is already enabled If akActivator == Game.GetPlayer() If DoortoSummon.IsDisabled() myBusyGV.SetValue(1.0) ; door will be enabled - block other doors by setting the value to 1.0 RumbleSFX.Play(FXSource) Game.ShakeCamera(afDuration = 2) BeamFireSFX.Play(FXSource) BeamVFX01.Enable(true) BeamFireSFX.Play(FXSource) BeamVFX02.Enable(true) BeamFireSFX.Play(FXSource) BeamVFX03.Enable(true) FogVFX.Enable(true) DoorLight.Enable() DoorAppearSFX.Play(FXSource) DoortoSummon.Enable(true) GoToState("Busy") EndIf EndIf While BeamVFX01.isEnabled() BeamLoopSFX.PlayAndWait(BeamVFX01) BeamLoopSFX.PlayAndWait(BeamVFX02) BeamLoopSFX.PlayAndWait(BeamVFX03) EndWhile While DoortoSummon.isEnabled() DoorLoopSFX.PlayAndWait(DoortoSummon) EndWhile Else ;Do nothing EndIf EndEvent EndState State Busy Event OnActivate(ObjectReference akActivator) If myBusyGV.GetValue() == 1.0 If akActivator == Game.GetPlayer() If DoortoSummon.IsEnabled() BeamVFX01.Disable(true) BeamOffSFX.Play(FXSource) BeamVFX02.Disable(true) BeamOffSFX.Play(FXSource) DoortoSummon.Disable(true) DoorDisappearSFX.Play(FXSource) DoorLight.Disable() BeamVFX03.Disable(true) BeamOffSFX.Play(FXSource) FogVFX.Disable(true) myBusyGV.SetValue(0.0) GoToState("Waiting") EndIf EndIf Else ; Do nothing EndIf EndEvent EndState Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 8, 2020 Share Posted April 8, 2020 Now that you explained what happened I can see the error on my part and how it would block a second activation. That usage of states is a good way to get around it. The variable blocks the other scripts and the states allow you to change behavior because the variable prevents the default activation. Good solution. Link to comment Share on other sites More sharing options...
Haagaar Posted April 8, 2020 Author Share Posted April 8, 2020 Though I would never have had the idea of using a global variable on my own, thank you for that. Link to comment Share on other sites More sharing options...
Recommended Posts