Sirgallyhave Posted September 25 Share Posted September 25 I have a quest with a bunch of ReferenceAlias objects. Inside each ReferenceAlias is an Actor set with a forced ref. During the game, those Actor objects go into a trigger box via AI packages (or maybe it's PlayerRef or a follower) and I need to get access to the ReferenceAlias the Actor is in. I only have: event OnTriggerEnter(ObjectReference akActivator) Every Actor in these ReferenceAlias objects has a script attached that extends ReferenceAlias. I need access to the script attached to each Actor via the ReferenceAlias. Is there a way to cast ObjectReference akActivator to the ReferenceAlias script? MyRefAliasScript myVariable = akActivator as MyRefAliasScript won't compile because we can't cast an ObjectReference type to a ReferenceAlias. How do I do this? I'm using Skyrim v1.6.1170.0 and SKSE is no problem. I can cycle through every alias in the quest using SKSE's GetNthAlias() to compare GetReference() to akActivator. But it'd be slower than casting to get access to the attached script from akActivator, if it's doable. Link to comment Share on other sites More sharing options...
PeterMartyr Posted September 25 Share Posted September 25 an actor is object reference, for example an Reference Alias that is an actor Alias.getReference() should return the object reference through polymorphism and the alias should return an Actor with alias.getReference() as Actor please post the script But as far has I can ascertain, you want to know if one of bunch of Actor Alias has triggered a Trigger Box, start with and ReferenceAlias Array if the fore mention Alias, and do a validation with a while loop. ALSO you cannot make up your own hierarchy when casting, it is This alias as this Script and I 100% agree, that does not return ObjectReference or Actor but the ReferenceAlias... Post the Script.. Edit Spoiler My compiled fine, it also use SKSE to get the Display Name require SKSE to compile Event OnTriggerEnter(ObjectReference akActionRef) int index = MyAlias.Length While index > 0 ; index -= 1 ObjectReference myActor = MyAlias[index].getReference() if myActor != None && MyActor == akActionRef Debug.MessageBox("My Alias " + (myActor as Actor).GetDisplayName() + " just trigger this TriggerBox") EndIf EndWhile EndEvent Link to comment Share on other sites More sharing options...
PeterMartyr Posted September 25 Share Posted September 25 BTW that was teaching code, I would make a separate bool function with a Return to handle the Alias Array and to break the loop, and.. too stay in the Event. Spoiler Scriptname TriggerBoxScript extends ObjectReference ReferenceAlias[] Property MyAlias Auto Event OnTriggerEnter(ObjectReference akActionRef) If IsMyAlias(akActionRef) == True Debug.MessageBox("My Alias " + (akActionRef as Actor).GetDisplayName() + " just trigger this TriggerBox") EndIf EndEvent Bool Function IsMyAlias(ObjectReference akActionRef) int index = MyAlias.Length While index > 0 index -=1 ObjectReference myActor = MyAlias[index].getReference() if myActor != None && MyActor == akActionRef Return True EndIf EndWhile Return False EndFunction Link to comment Share on other sites More sharing options...
Sirgallyhave Posted September 25 Author Share Posted September 25 Thanks for the prompt response, Peter. There really isn't anything to post from the script other than the examples I gave above. It's really just one line of code that will either make or break everything. I can either cast from ObjectReference (or potentially ObjectReference.GetBaseObject()) to something that allows me to gain access to the ReferenceAlias containing the reference (the result of GetReference()), or I'm going to have to search through a ton of different aliases every time actors enter various big trigger box areas to find out which alias each actor is in, which is likely going to cause stuttering in the game when many different actors are coming and going. The script each RefererenceAlias attaches saves the gear the actor is wearing, then strips them to prepare them to be equipped in a custom outfit. That script (the ReferenceAlias one) has a function called Undress() that I want to call from OnTriggerEnter but I can't figure out how to get access to a ref alias script when all I know is the actor's ObjectReference from OnTriggerEnter events. It's a large script that'd make no sense if I posted it because it's part of a big custom outfit system that itself is part of a mod like the Luxury Suite. I'm just stuck on one line of code and it's just a matter of whether it's possible to get at the ReferenceAlias an Actor is "in" (forced ref) via the attached script or something else that I'm not thinking of (an inventory object, keyword or faction from the alias), or I'm going to have to do it the slow way of searching tons of different aliases from the top-down every time someone enters or leaves various trigger boxes. The actors are potentially employees of the residence, who should stay in their uniforms and not wear custom outfits (like a random Daily-Wear outfit) in the trigger areas. Others are guests from around Skyrim, others are residents of the estate, and the player and his or her followers go in other ReferenceAlias objects spread across multiple quests that I don't want to have to search through because it'll be slow. This is the third time I've redesigned the whole system just because I can't figure out how to store what gear (and outfit) is equipped on each actor before equipping custom outfits. I was using arrays with one array holding each actor's ref ID, another holding the original outfit the Actor is wearing, but it's not enough. Followers end up with gear that isn't in outfits, and my mod is mainly driven by followers the player puts in his game and then invites to parties and whatnot at my version of the Luxury Suite. I think I'm going to have to go back to using a spell to get the script attached to actors who enter various trigger areas. It's what the Luxury Suite does, and is what I originally did months ago, but it's slow and scripts attached to spells lag due to multithreading. Though I suppose it's no worse than scripts attached to ReferenceAlias objects. Link to comment Share on other sites More sharing options...
xkkmEl Posted September 25 Share Posted September 25 (edited) You might use a faction to record each actor's index in your list of aliases. Assuming you don't have more than 128 such aliases, you might simply do: Faction Property MyAliasIndexFaction function setReferenceAlias( int index, Actor npc) (getAlias( index) as ReferenceAlias).forceRefTo( npc) npc.setFactionRank( MyAliasIndexFaction, index) endfunction ReferenceAlias function getReferenceAlias( Actor npc) return getAlias( npc.getFactionRank( MyAliasIndexFaction)) as ReferenceAlias endfunction function clearReferenceAlias( int index) ReferenceAlias ra = getAlias( index) as ReferenceAlias ra.getActorReference().removeFromFaction( MyAliasIndexFaction) ra.clear() endfunction Edited September 25 by xkkmEl Link to comment Share on other sites More sharing options...
scorrp10 Posted September 25 Share Posted September 25 I would not bother with aliases, but place a Magic Effect on Actors entering the area. And have that effect handle the outfit management. Then, on exit, effect would reset to original gear and dispel itself. Link to comment Share on other sites More sharing options...
Sirgallyhave Posted September 26 Author Share Posted September 26 18 hours ago, xkkmEl said: You might use a faction to record each actor's index in your list of aliases. Assuming you don't have more than 128 such aliases, you might simply do: Faction Property MyAliasIndexFaction function setReferenceAlias( int index, Actor npc) (getAlias( index) as ReferenceAlias).forceRefTo( npc) npc.setFactionRank( MyAliasIndexFaction, index) endfunction ReferenceAlias function getReferenceAlias( Actor npc) return getAlias( npc.getFactionRank( MyAliasIndexFaction)) as ReferenceAlias endfunction function clearReferenceAlias( int index) ReferenceAlias ra = getAlias( index) as ReferenceAlias ra.getActorReference().removeFromFaction( MyAliasIndexFaction) ra.clear() endfunction It's a good idea. Thanks for taking the time to respond. I don't think I'll do it in this case but I'm definitely going to keep it in mind for other uses in the future because it could come in really handy. Link to comment Share on other sites More sharing options...
Sirgallyhave Posted September 26 Author Share Posted September 26 18 hours ago, scorrp10 said: I would not bother with aliases, but place a Magic Effect on Actors entering the area. And have that effect handle the outfit management. Then, on exit, effect would reset to original gear and dispel itself. Agreed, it's what I've ended up doing. I need the ReferenceAlias objects to put AI packages on various actors to get them to come to my homestead and sit at whatever table for breakfast, lunch or dinner. I figured I could kill two birds with one stone by having a script on each alias do the outfit management, but a magic effect is the way to go in this case and it's what the Luxury Suite does in its pools/spas too, so I know it works. Thanks for responding. Link to comment Share on other sites More sharing options...
Sirgallyhave Posted October 5 Author Share Posted October 5 Just in case someone else runs into this thread in the future and wonders what I did originally, a way to get an actor to pay attention to a script that extends ReferenceAlias is to add something to the inventory of that actor, like an amulet you give a unique name and ID in the CK. For example, if you need an actor to do something that uses data or functions in a ReferenceAlias script if the actor enters a trigger, you could do this: Armor property my_custom_amulet auto event OnTriggerEnter(ObjectReference akActivator) Actor actor_ref = akActivator as Actor if actor_ref actor_ref.AddItem(my_custom_amulet) actor_ref.EquipItem(my_custom_amulet) endif endevent Then in the ReferenceAlias script attached to the actor via an alias, watch for items being equipped: Armor property my_custom_amulet auto event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) Armor armor_base = akBaseObject as Armor if !armor_base && akReference ;got a persistent ref? armor_base = akReference.GetBaseObject() as Armor endif if armor_base && armor_base == my_custom_amulet ;do whatever needs doing here endif endevent Link to comment Share on other sites More sharing options...
Recommended Posts