dizietemblesssma Posted March 28, 2020 Author Share Posted March 28, 2020 Use the Add button to add a new entry to the list, then you can drag-n-drop whatever object you need at that index. This is what I don't understand, the spell array is going to be populated (correct terminology?) later by the script when it runs, I have no way of knowing what is to go in there.Can arrays not be accessed from other scripts this way? diziet Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 29, 2020 Share Posted March 29, 2020 (edited) For understanding: Spell[] myArray ; script variableas same as Spell[] PROPERTY myArray auto Hidden ; script property which cannot be prefilled by CK (because Hidden flag), treated like variable aboveby using this construct you have to (or can) pre-assign the entries of the array as IsharaMeradin posted Spell[] PROPERTY myArray auto ; script property that is predefined in length and entries by CKI would suggest following "and sorry for breaking in to this posting" Scriptname dz_player_only_enter_skse extends ObjectReference ;;we set the arrays and variables as properties so that they can be accessed from other scripts such as dz_player_only_leave_skse ; https://forums.nexusmods.com/index.php?/topic/8244443-access-variable-from-other-script/page-2 Form[] Fight ; array for equipped weapons, shield, ammo, torch, shout (if any) ; [0] Weapon equippedleft ; [1] Weapon equippedright ; [2] Armor player_shield ; [3] Ammo player_ammo ; [4] Light player_torch ; [5] Shout player_shout Spell[] Spell_1 ; array for all equipped spells (if any) ; [0] Left hand ; [1] Right hand ; [2] Other ; [3] Instant ; you cannot re_equip this spell !! Armor[] Property Armor_1 auto Hidden ; for armour slots 30 to 49 incl. Armor[] Property Armor_2 auto Hidden ; for armour slots 52 to 61 incl. Bool Property disrobed auto ; to track player naked Int Property iCameraState auto ; this will store the view mode, 0 = first person Actor Property PlayerRef Auto ; this allows us to use the fast PlayerRef reference ; -- Events -- 3 EVENT OnInit() ; triggered once only at first script contact with new game or saved game !!! Debug.Trace(" OnInit() - has been reached.. " +self) ENDEVENT EVENT OnCellAttach() ; event triggered every time when the cell of this trigger is part of players parent cells attachement ; player is going into the triggerbox cell myF_Init(TRUE) ENDEVENT EVENT OnCellDetach() ; event triggered every time when the cell of this trigger will be removed from players .. ; player is leaving the triggerbox cell myF_Init(False) ENDEVENT EVENT OnTriggerEnter(ObjectReference triggerRef) ; your code ENDEVENT EVENT OnTriggerLeave(ObjectReference triggerRef) ; your code ENDEVENT ; -- FUNCTIONs -- ;-------------------------- FUNCTION myF_Init(Bool bOK) ;-------------------------- IF ( bOK ) ; init arrays in size you need Armor_1 = new Armor[20] Armor_2 = new Armor[10] Spell_1 = new Spell[4] Fight = new Form[6] ; (Fight.Length == 6) ELSE Armor[] a Armor_1 = a ; destroy array of type armor Armor_2 = a Spell[] b Spell_1 = b ; destroy array of type spell Form[] c Fight = c ; destroy array of type form ENDIF ENDFUNCTION Edited March 29, 2020 by ReDragon2013 Link to comment Share on other sites More sharing options...
dizietemblesssma Posted March 29, 2020 Author Share Posted March 29, 2020 Thanks for jumping in!I'm going to try the 'hidden' bit first and then look at the rest of your suggestion.Who knew taking someones clothes off could be so complicated? :) (Also, apparently there are body replacers with something called a 'havok object' that I'm messing with - aaargh"!) diziet Link to comment Share on other sites More sharing options...
dizietemblesssma Posted March 29, 2020 Author Share Posted March 29, 2020 Hey! It works:) Diolch yn fawr!A question about OnCellAttach, is that preserved in save games? i.e. if I'm in a cell, then save and I load that save, does the OnCellAttach not fire because I'm already there? diziet Link to comment Share on other sites More sharing options...
dizietemblesssma Posted March 29, 2020 Author Share Posted March 29, 2020 @ReDragon2013 Also forgot to check,so the OnCellAtach part of a script won't wait for the triggerbox to be entered, it will in fact fire upon cell entry even though the script it is in is attached to a trigger?Because that seems quite useful. diziet Link to comment Share on other sites More sharing options...
dizietemblesssma Posted March 31, 2020 Author Share Posted March 31, 2020 Now my second problem, I wish to attach the same script to two items (pools) and then have a second script attached to a third item - doorway exit, and have the variables from the first script accessible by the second.I've got this working for one pool, thanks to everyone here; but since the property in the second script has to reference that pool (triggerbox) it can't reference the second pool.What should I be reading up on if this is possible?Will I have to rename the script and double the variables? diziet Link to comment Share on other sites More sharing options...
dizietemblesssma Posted April 2, 2020 Author Share Posted April 2, 2020 I had an idea that if I put the variables/property in the doorway exit script and put a property in the two pool entrance scripts I could access the exit script variables from the two pool scripts.I got the scripts to compile, but not joy so far: doorway exit script: scriptname dz_player_NPC_leave2_skse Extends ObjectReference Actor Property PlayerRef Auto ;this allows us to use the fast PlayerRef reference Spell Property dz_undress_spell Auto ;this is the spell that will undress NPCs MagicEffect Property dz_undress_effect Auto ;this is the magic effect from the spell ;;;we require access to the stored variables from dz_player_NPC_enter_skse scriptname ;dz_player_NPC_enter_skse Property dz_ent Auto Form[] Property Fight Auto Hidden ;[0] Weapon equippedleft, [1] Weapon equippedright, [2] Armor player_shield, [3] Ammo player_ammo Armor[] Property Armor_1 Auto Hidden ;for armour slots 30 to 49 incl. Armor[] Property Armor_2 Auto Hidden ;for armour slots 52 to 61 incl. Spell[] Property Spell_1 Auto Hidden ;this array will hold all equipped spells Bool Property disrobed Auto ;to track player naked Bool Property First Auto ;define variable for camera state int Property iCameraState Auto Event OnInit() ;=========== Armor_1 = new Armor[20] Armor_2 = new Armor[10] Spell_1 = new Spell[4] Fight = new Form[5] First = False Disrobed = False EndEvent Event OnTriggerEnter(ObjectReference triggerRef) EndEvent Event OnTriggerLeave(ObjectReference triggerRef) ;this is triggered when exiting the trigger box ;debug.messagebox("camera is "+iCameraState) If (triggerRef as Actor) Else Return ;if not exit the function EndIf If triggerRef == PlayerRef ;checks to see if the trigger is the player debug.messagebox("Dressing the Player") dz_redress_player_F() ;if so call the function to re-dress the player EndIf If triggerRef as Actor ;is the trigger an actor (NPC)? dz_redress_NPC_F(triggerRef as Actor) ;then re-dress the NPC EndIf EndEvent Function dz_redress_player_F() ;define the function to re-dress the player If ( disrobed == True ) ;is the player undressed ;debug.messagebox("disrobed = "+disrobed) Else ;debug.messagebox("disrobed = "+disrobed) Return ;the player is not undressed, exit the function EndIf ;debug.messagebox("iCameraState = "+iCameraState) If (SKSE.GetVersion() > 0) ;return to first person if necessary ;If Game.IsCamSwitchControlsEnabled() ;switch cam is possible for player If ( First == True ) ; skse function ; change to third person if not already Game.ForceFirstPerson() ; 1st Person First = False Endif ;EndIf EndIf ;--------------------- ; https://www.creationkit.com/index.php?title=EquipItemEx_-_Actor int i ;for using arrays below armor AR If (SKSE.GetVersion() > 0) ;re-equip the first armour array i = armor_1.Length While (i) i = i - 1 AR = armor_1[i] If ( AR ) PlayerRef.EquipItemEx(AR, 0, False, True) ;skse function EndIf EndWhile ;re-equip the second armour array i = armor_2.Length While (i) i = i - 1 AR = armor_2[i] If ( AR ) PlayerRef.EquipItemEx(AR, 0, False, True) ;skse function EndIf EndWhile ;re-equip weapons If ( Fight[0] as Weapon ) ;equippedLeft PlayerRef.EquipItemEx(Fight[0], 2, False, True) ;skse function EndIf If ( Fight[1] as Weapon ) ;equippedRight PlayerRef.EquipItemEx(Fight[1], 1, False, True) ;skse function EndIf ;re-equip shield If ( Fight[2] as Armor ) ;player_shield PlayerRef.EquipItemEx(Fight[2], 0, False, True) ;skse function EndIf ;re-equip ammo debug.messagebox("The Ammo is "+Fight[3]) If ( Fight[3] as Ammo ) ;player_ammo PlayerRef.EquipItemEx(Fight[3], 0, False, True) ;skse function EndIf ;re-equip torch If ( Fight[4] as Light ) PlayerRef.EquipItemEx(Fight[4], 0, False, True) EndIf Else ;do not use skse functions ;re-equip the first armour array i = armor_1.Length ;debug.messagebox("Armor1 Length = "+armor_1.length) While (i) i = i - 1 AR = armor_1[i] ;debug.messagebox("Armour = "+armor_1[i]) If ( AR ) PlayerRef.EquipItem(AR, False, True) ;vanilla function EndIf EndWhile ;re-equip the second armour array i = armor_2.Length While (i) i = i - 1 AR = armor_2[i] If ( AR ) PlayerRef.EquipItem(AR, False, True) ;vanilla function EndIf EndWhile ;re-equip weapons If ( Fight[0] as Weapon ) ; equippedLeft PlayerRef.EquipItem(Fight[0], False, True) ;vanilla function EndIf If ( Fight[1] as Weapon ) ; equippedRight PlayerRef.EquipItem(Fight[1], False, True) ;vanilla function; EndIf ;re-equip shield If ( Fight[2] as Armor ) ; player_shield PlayerRef.EquipItem(Fight[2], False, True) ;vanilla function EndIf ;re-equip ammo ;this function can't be used without skse ;If ( Fight[3] as Ammo) ; player_ammo ;PlayerRef.EquipItem(Fight[3], 0, False, True) ;EndIf EndIf ;re-equip spells i = spell_1.Length While (i) i = i - 1 spell sp = spell_1[i] If ( sp ) PlayerRef.EquipSpell(sp, i) EndIf EndWhile disrobed = False ;store the dressed state of the player EndFunction Function dz_redress_NPC_F(Actor NPCRef) If (NPCRef as Actor).HasMagicEffect(dz_undress_effect) ;does the NPC have the spell on them? NPCRef.DispelSpell(dz_undress_spell) ;dispell the undress spell on the NPC EndIf EndFunction the script on the two pool entrances scriptname dz_player_NPC_enter2_skse Extends ObjectReference ;;we set the arrays and variables as properties so that they can be accessed from other scripts such as dz_player_only_leave_skse Actor Property PlayerRef Auto ;this allows us to use the fast PlayerRef reference Spell Property dz_undress_spell Auto ;this is the spell that will undress NPCs MagicEffect Property dz_undress_effect Auto ;this is the magic effect from the spell dz_player_NPC_leave2_skse Property dz_ent Auto ;/ Form[] Property Fight Auto Hidden ;[0] Weapon equippedleft, [1] Weapon equippedright, [2] Armor player_shield, [3] Ammo player_ammo Armor[] Property Armor_1 Auto Hidden ;for armour slots 30 to 49 incl. Armor[] Property Armor_2 Auto Hidden ;for armour slots 52 to 61 incl. Spell[] Property Spell_1 Auto Hidden ;this array will hold all equipped spells Bool Property disrobed Auto ;to track player naked Bool Property First Auto ;define variable for camera state int Property iCameraState Auto /; ;this will store the view mode, 0 = first person ; -- Events -- 3 ;/ Event OnInit() ;=========== dz_ent.Armor_1 = new Armor[20] dz_ent.Armor_2 = new Armor[10] dz_ent.Spell_1 = new Spell[4] dz_ent.Fight = new Form[5] EndEvent /; Event OnCellAttach() ;event triggered every time when the cell of this trigger is part of players parent cells attachement ;debug.messagebox("Entering cell") ;player is going into the triggerbox cell, we need to prevent activating the change to first person code in dz_player_only_leave_skse dz_ent.iCameraState = 1 EndEvent ;in this script the combat checks are in the events, in my mcm scripts the combat checks are in the player undress functions Event OnTriggerEnter(ObjectReference triggerRef) ;this is triggered when entering the trigger box If (triggerRef as Actor) ;is the trigger an actor? Else Return ;if not exit the function EndIf If triggerRef == PlayerRef && !PlayerRef.isincombat() ;checks to see if the trigger is the player and also not in combat dz_undress_player_F() ;if so call the function to undress the player return ;we are done, exit the function EndIf If triggerRef as Actor ;is the trigger an actor (NPC)? dz_undress_NPC_F(triggerRef as Actor) ;then call the function to undress the NPC EndIf EndEvent Event OnTriggerLeave(ObjectReference triggerRef) EndEvent ;---------------------------------------- Ammo Function GetEquippedAmmo(Actor aRef) ;---------------------------------------- ; returns the ammo equipped by the passed in actor, otherwise it returns NONE int i If ( aRef ) ;is the actor valid? i = aRef.GetNumItems() ;skse function EndIf While i > 0 i -= 1 Form AM = aRef.GetNthForm(i) ;skse function If AM as Ammo && aRef.IsEquipped(AM) Return AM as Ammo EndIf EndWhile Return None ;no ammunition EndFunction Form Function GetEquippedTorch(Actor aRef) If aRef.GetEquippedItemType(0) == 11 Form TCH = aRef.GetEquippedObject(0) ;skse function Return TCH EndIf EndFunction Function dz_undress_player_F() ;define the function to undress the player If (SKSE.GetVersion() > 0) ;If Game.IsCamSwitchControlsEnabled() ;switch cam is possible for player dz_ent.iCameraState = Game.GetCameraState() ;skse function If ( dz_ent.iCameraState == 0) ; change to third person dz_ent.First = True Game.ForceThirdPerson() ;3rd Person Else EndIf ;EndIf Else Game.ForceThirdPerson() ;3rd Person EndIf If ( dz_ent.disrobed ) Return ;if the player is already undressed exit the function EndIf ;--------------------- dz_ent.disrobed = True ;set the player is undressed variable ; get weapons dz_ent.Fight[0] = PlayerRef.GetEquippedWeapon(True) as Form ;store equippedleft in Fight array dz_ent.Fight[1] = PlayerRef.GetEquippedWeapon(False) as Form ;store equippedright in Fight array ; get shield dz_ent.Fight[2] = PlayerRef.GetEquippedShield() as Form ;store player_shield in Fight array If (SKSE.GetVersion() > 0) ; get ammo dz_ent.Fight[3] = GetEquippedAmmo(PlayerRef) as Form ;store player ammo in Fight array using custom function debug.messagebox("Ammo is "+dz_ent.Fight[3]) ;get torch dz_ent.Fight[4] = GetEquippedTorch(PlayerRef) as Form ;store player torch in Fight array using custom function EndIf int i ;for filling arrays below i = dz_ent.spell_1.Length ;should be 4 While (i) ;loop through array indexes ;debug.messagebox("i = "+i) i = i - 1 dz_ent.spell_1[i] = PlayerRef.GetEquippedSpell(i) ;fill the spell_1 array - [0] Left hand, [1] Right hand, [2] Other, [3] Instant ;debug.messagebox("Spell = "+spell_1[i]) EndWhile ; fill the first armour array i = dz_ent.armor_1.length ;should be 20 While (i) ;loop through array indexes ;debug.messagebox("i = "+(i + 30)) i = i - 1 dz_ent.armor_1[i] = PlayerRef.GetEquippedArmorInSlot(i + 30) ;fill armour slots 30 to 49 incl ;debug.messagebox("Armour = "+armor_1[i]) EndWhile ; fill the second armour array i = dz_ent.armor_2.length ;shoulod be 10 While (i) ;loop through array indexes i = i - 1 dz_ent.armor_2[i] = PlayerRef.GetEquippedArmorInSlot(i + 52) ;fill armour slots 52 to 61 incl. EndWhile PlayerRef.UnEquipAll() ;undress the player player EndFunction Function dz_undress_NPC_F(Actor NPCRef) If (NPCRef as Actor).HasMagicEffect(dz_undress_effect) ;is the NPC already undressed Return ;if so we are done, exit the function EndIf dz_undress_spell.Cast(NPCRef, NPCRef) ; cast the undress spell on the NPC EndFunction diziet Link to comment Share on other sites More sharing options...
dizietemblesssma Posted April 4, 2020 Author Share Posted April 4, 2020 I have managed to get this to work, with an unexplainable (by me) caveat. If I disable my mod plugins, start an old game save that has never seen any mods, fast travel to the site of the player home that I'm writing this patch for, and save; then reload the new save with my patch enabled; it only works if I was using skse when I made the second save. If I was not using skse when making the second save and I restart the game using skse then the patch doesn't work, and by doesn't work I mean the redressing doesn't happen, undressing happens, change of 1st/3rd person happens, which means that the undress and redress functions are being called. Using debug notifications I can see that the filling of the arrays and variables for equipped items doesn't happen. Now if I quit, unistall the player home, restart - using skse, save, quit, reinstall the player home, restart and load that save then the patch works. so there is a way for users to get the patch to work without goping back a save but it is a faff. Assuming that the user did not already have skse installed, which they might not have. I'm not sure I want to publish this patch while I don't understand what is going on. Any ideas? diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 4, 2020 Share Posted April 4, 2020 Just tell users that if they did not have SKSE installed prior to wanting to use this patch, then they need to install SKSE and start the game and make a save at least once before adding in the patch. Not sure why it is happening that way. Maybe because you are at the site where the home is located when making the save and loading the patch? Try approaching the area from another location instead of saving right on the spot. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted April 5, 2020 Author Share Posted April 5, 2020 Try approaching the area from another location instead of saving right on the spot. Indeed, that works, as long as the player hasn't already been to the player home first.It occurs to me - see what sleep can do:) - that perhaps the reason for all this is that this player home uses unequipall on both NPC and player, but only manages to redress the NPC. To keep the mod authors intent but add player redressing I have had to disable the existing undressing scripts in favour of my own. Upon saving, perhaps the original scripts are baked into the save and then still act, even though my patch disables them? Still don't see why saving with skse enabled makes a difference though. Sudden thought, perhaps my mistake is to use the original trigger boxes, the two pool entrance ones and the doorway exit?If I disabled those they wouldn't be baked into the save would they? Then recreated my own in the same places with my scripts attached. Shall try. diziet Link to comment Share on other sites More sharing options...
Recommended Posts