Jump to content

[LE] Papyrus test if is a key.


Recommended Posts

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 Auto
Key Property CaptKey Auto
Key Property DeckKey Auto
Key Property GallyKey Auto
Key Property Locker01 Auto
Key Property Locker02 Auto
Key Property Locker03 Auto
Key Property Locker04 Auto
Key Property Locker05 Auto
Key Property Locker06 Auto
Bool 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 nothing
EndState
;

 

 

Edited by NexusComa
Link to comment
Share on other sites

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

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.com
ObjectReference 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 nothing
EndState
;


This is the Script on the hidden container.


Scriptname Ship00_ArcaneAcidPool extends ObjectReference
;* Arcane Acid Pool * By: NexusComa * ; nexusmods.com
Sound Property Acid Auto
Bool 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 nothing
EndState
;

 

Edited by NexusComa
Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...