Jump to content

How to tell if object is a container?


Recommended Posts

What papyrus function can I use to tell if a non-actor spell target is a container, like a chest? Would checking for "akTarget as Container" work?

Link to comment
Share on other sites

But, if you really wanted you could apply a script with the OnHit event to the container and check for the impact of a particular spell. Might be compatibility issues to consider, however...

 

I went with checking it as a crosshair ref. What are the compatibility issues you have in mind? Would the OnHit event deal with them better or worse?

Link to comment
Share on other sites

 

But, if you really wanted you could apply a script with the OnHit event to the container and check for the impact of a particular spell. Might be compatibility issues to consider, however...

 

I went with checking it as a crosshair ref. What are the compatibility issues you have in mind? Would the OnHit event deal with them better or worse?

 

Mods that add new container will not have the onhit script attached to them.

It depends on what you're using this for.

Link to comment
Share on other sites

Be careful with using the crosshair ref event from SKSE. I've used that before and EVERYTHING (anything that displays interaction text, i.e. NPCs, furniture, activators, etc..) triggers it. You have to have sanity checking to weed stuff out so your code doesn't get unnecessarily processed. Also, if you have more than one script registered for the event it can bog down the game big time as each script will try to do its processing at the same time.

 

That last would be true of users that have more than one mod using the event. Without some sort of warning, I could see users complaining that whichever mod was last installed for them broke their game.

 

All that said, just test the heck out of it and make sure nothing undesired happens.

Link to comment
Share on other sites

It's the OnCrosshairRefChange event that's the potential performance killer. Since you're trying to make a spell that acts on containers you don't need that and shouldn't see any performance problem at all when you make the spell a Self type with a script that then uses GetCurrentCrosshairRef() to find the container.

Event OnEffectStart(Actor akTarget, Actor akCaster)
	ObjectReference ref = Game.GetCurrentCrosshairRef()
	if ref && ref.GetBaseObject() as Container
		Debug.Notification("Found a container")
	else
		Debug.Notification("No container found")
	endif
EndEvent

Link to comment
Share on other sites

Code like cdcooley's works though there are a few things that aren't containers that still pass somehow. I've noticed them in the qasmoke cell - they're those pylons with the buttons do things like give you spells and spawn mobs in the cage. I'm not sure how often things like that will be found in the normal game world. Not often enough to be a big problem, I think.

 

Thanks for the notices about OnCrosshairRefChange.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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