NexusComa Posted March 10, 2020 Share Posted March 10, 2020 (edited) Need to find a better way than listing all the keys I don't want to be put in a chest. Is there a simple way to simply test if an obj is a key or not. Concept script. Scriptname Ship00_ArcaneAcidPool extends ObjectReference;* Arcane Acid Pool ... Sound Property Acid AutoKey Property CaptKey AutoKey Property DeckKey AutoKey Property GallyKey AutoKey Property Locker01 AutoKey Property Locker02 AutoKey Property Locker03 AutoKey Property Locker04 AutoKey Property Locker05 AutoKey Property Locker06 AutoBool flag = false;Event OnInit() flag = false GoToState("Done")EndEvent;------------Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If (akSourceContainer == (Game.GetPlayer())) If (akBaseItem == (CaptKey)) flag = true EndIf If(akBaseItem == (DeckKey)) flag = true EndIf If(akBaseItem == (GallyKey)) flag = true EndIf If(akBaseItem == (Locker01)) flag = true EndIf If(akBaseItem == (Locker02)) flag = true EndIf If(akBaseItem == (Locker03)) flag = true EndIf If(akBaseItem == (Locker04)) flag = true EndIf If(akBaseItem == (Locker05)) flag = true EndIf If(akBaseItem == (Locker06)) flag = true EndIf If(flag == (false)) Acid.Play(Self) Self.RemoveItem(akBaseItem, aiItemCount) Else Self.RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer) EndIf EndIF utility.Wait(1.0) GoToState("Done")EndEvent;State Done ;do nothingEndState; Edited March 10, 2020 by NexusComa Link to comment Share on other sites More sharing options...
FrankFamily Posted March 10, 2020 Share Posted March 10, 2020 You try casting it as that type, if it isn't it will be None, I think you need to cast to MiscObject first, at least the wiki says key extends MiscObject and then that extends form. So, something like this: If (whatever as MiscObject) as Key ;It should be a key Link to comment Share on other sites More sharing options...
NexusComa Posted March 10, 2020 Author Share Posted March 10, 2020 (edited) Figured it out ...This is for a Arcane Acid Pool (aka trashcan). Something I've always wanted in Skyrim is to be able to just throw stuff I don't want away easily.I used the model for the "enchant pool" set up as an ordinary activator and then attached via script a hidden container to be the trashcan ...It will delete anything you can drop in a container but keys. This is the Script on the activator. Scriptname Ship00_Activator extends ObjectReference;* Activator * By: NexusComa * ; nexusmods.comObjectReference Property Activated Auto;Event OnInit() GoToState("Done")EndEvent;------------Event OnActivate(ObjectReference akActionRef) If (akActionRef == (Game.GetPlayer())) Activated.Activate(Game.GetPlayer(), true) EndIf GoToState("Done")EndEvent;State Done ;do nothingEndState; This is the Script on the hidden container. Scriptname Ship00_ArcaneAcidPool extends ObjectReference;* Arcane Acid Pool * By: NexusComa * ; nexusmods.comSound Property Acid AutoBool flag = false;Event OnInit() GoToState("Done")EndEvent;------------Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If (akSourceContainer == (Game.GetPlayer())) If (akBaseItem.GetType() == (45)) ;Key flag = true Else flag = false EndIf If (flag == (false)) Acid.Play(Self) Self.RemoveItem(akBaseItem, aiItemCount) Else Self.RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer) EndIf EndIf utility.Wait(1.0) GoToState("Done")EndEvent;State Done ;do nothingEndState; Edited March 10, 2020 by NexusComa Link to comment Share on other sites More sharing options...
foamyesque Posted March 10, 2020 Share Posted March 10, 2020 You try casting it as that type, if it isn't it will be None, I think you need to cast to MiscObject first, at least the wiki says key extends MiscObject and then that extends form. So, something like this: If (whatever as MiscObject) as Key;It should be a key You can cast directly from Form to Key without issue. Link to comment Share on other sites More sharing options...
NexusComa Posted March 10, 2020 Author Share Posted March 10, 2020 I did look into that. Thank you. But I then found the command .GetType() Link to comment Share on other sites More sharing options...
foamyesque Posted March 10, 2020 Share Posted March 10, 2020 I did look into that. Thank you. But I then found the command .GetType() GetType is far slower than a simple cast, or even multiple ones in succession, because it is a frame-linked function call. It's generally good practice to avoid those, especially when it's simple to do so and loses you no functionality, as here. Link to comment Share on other sites More sharing options...
NexusComa Posted March 11, 2020 Author Share Posted March 11, 2020 (edited) Good point. In this case it's just testing one item. It is very fast and can even hold up to spamming the crap out of the key. This was just added to my: Enchanted Ship in a Bottle mod.For the newest version 3.0 ... Thank you for the input. Edited March 11, 2020 by NexusComa Link to comment Share on other sites More sharing options...
Recommended Posts