Talk:OnTrigger

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Triggering Reference[edit source]

How do you get a reference to the triggering object? I have setup a trigzone and want to retrieve a reference for the object responsible for the trigger. This object is added to the game dynamically.
--Antares 09:42, 7 September 2008 (EDT)

GetActionRef
Dragoon Wraith TALK 10:41, 7 September 2008 (EDT)
The Man, thanks DragoonWraith, I thought it would be something simple. I am updating the article "See Also" section for both OnTrigger and GetActionRef.
--Antares 22:36, 7 September 2008 (EDT)

BlockType Behaviour[edit source]

It would appear that this function behaves like a GameMode block in that it won't run in other modes (MenuMode). I tried to use this function to circumvent an effectshader called on an object in GameMode from not being run in other modes. I needed a seperate script for this due to the dynamic nature of the object I was adding. I also needed a way to retrieve a reference to the dynamic object inside the seperate script so I thought creating a TrigZone and using an OnTrigger block would be the end of my problems, obviously not. OnLoad would work perfectly but I cannot see way to run OnLoad on a dynamic reference.
--Antares 23:34, 7 September 2008 (EDT)

Further information on BlockType Behaviour for this function: It would seem that when you try to run a GameMode block inside a script that has an OnTrigger block they will conflict. I was pulling my hair out wondering why my OnTrigger wasn't being triggered, I removed my Gamemode block because I changed my method and the code within became redundant and voila! it was all better. Just thought this would be useful information.
--Antares 02:46, 22 September 2008 (EDT)
OnTrigger (and OnTriggerActor) are Blocktypes. Blocktypes cannot be nested, i.e. nothing like this:
Begin GameMode
  Begin OnTrigger
    ;blah blah
  End
End
but only something more like this:
Begin GameMode

  ;blah blah

End

Begin OnTrigger

  ;blah blah more

End
I hope this clears that up for you? Or did you mean something else?
Dragoon Wraith TALK 11:10, 22 September 2008 (EDT)
Whoops, I should have been a bit more clear in my example. I am fully aware that you cannot nest blocktypes. If you attempt something like this you may experience undesired results:
Begin OnTrigger
 Message "Debug Message" ; so I can see if the OnTrigger block is being run at all. 
  ;do stuff here
End

Begin Gamemode
 ;condition here
  ;do stuff here
End
I had an OnTrigger block in my script to check (obviously) for when the player was colliding with my trigzone and then a gamemode block to prevent possible exploits. When writing the script I wrote the OnTrigger block first and play-tested it; no problems. I then wrote the GameMode block and began to experience problems with the OnTrigger block even being run at all. My findings implicate that OnTrigger only runs inside a GameMode block (this is backed up by results from others tests with a different application of an OnTrigger block). I hope I have cleared things up and hopefully the relevant information on the Nature of an OnTrigger BlockType can make its way into the appropriates articles.
--Antares 21:37, 22 September 2008 (EDT)

(going back to the left) OnTrigger cannot run inside a GameMode block - they cannot be nested. OnTrigger is a specific frame during GameMode, so any time OnTrigger works, GameMode should too (and obviously there are lots of times where GameMode works and OnTrigger doesn't). As for OnTrigger ceasing to work after adding a GameMode block... Never heard of that problem. Check Bethesda's scripts, see if they ever used both.
Dragoon Wraith TALK 00:28, 23 September 2008 (EDT)

I understand nesting blocktypes and what not, thats not got anything to do with what I was attempting. Anyway I took your advice and searched for a bethesda script which included both blocktypes in its code. This is what I found:
scriptname ExteriorLightScript

float fireTimer
short activated
ref ImOnFire

begin onTrigger Player
	if activated == 0
		cast TRAPGenericFireDamageMedium01 player
		set activated to 1
		set fireTimer to 3
	endif
end

begin gameMode

	if activated == 1
		if fireTimer > 0
			set fireTimer to fireTimer - getSecondsPassed
		endif

		if fireTimer <= 0
			set activated to 0
		endif
	endif

if gamehour >= 18 || gamehour < 7
	enable
	else
		disable
endif


end
Maybe I just happened upon some weird bug/anomaly in my particular instance and script. I think further research will be required before any information about clashing with Gamemode blocks will be included in any articles. Although for the sake of making the wiki a better place, I think it should be noted that OnTrigger blocks only run whilst Oblivion is in Gamemode. Well at least I'm about 99% sure that they do.
--Antares 06:02, 23 September 2008 (EDT)
How is an OnTrigger block supposed to run if Oblivion is not in game mode? It runs when something collides with the scripted object, which can't happen in menu mode because the game is paused. This sounds kinda obvious to me.
--Qazaaq 10:18, 24 September 2008 (EDT)
I suppose. I understood that an OnTrigger block wouldn't start to run in MenuMode as (almost) nothing can be moving, what I thought was curious though was that the OnTrigger block would not continue to run in Menumode if the object had already been triggered in gamemode. For example, if I set up a trigzone for an effectshader to play on an actor (using the pms command without specifying a duration should cause the game to play it indefinately) said actor triggers my object and the effectshader is run, however should you enter menumode whilst the actor is in view, the game will not play the effectshader. Just thought it was strange that once triggered the code will only be processed in gamemode. I hope I have adequately explained my meaning.
--Antares 01:37, 26 September 2008 (EDT)

Anything means ANYTHING[edit source]

Something I figured I'd share here. The description of onTrigger says: the block will run when anything triggers the scripted object. Take that as literally as it sounds. Anything at all inside your trigger zone will set it off. Statics, loose items, doors, etc. It doesn't matter. I found this out in a most undesirable way while trying to force-lock a door that's important for a quest. Leave out the specifics of who/what should trigger it, and you get a door that can never be opened again. Arthmoor 21:31, 25 December 2009 (EST)

Heed that note on the content page about retriggering delays on MoveTo![edit source]

I want to give a big thanks to whoever added the note about needing to delay retriggering after doing a MoveTo of the triggering actor. I spent hours trying to figure out why doing a "coc" to one of my interior cells would repeatably near-hang the game. By sheer chance, I stumbled upon that note and realized it might apply to one of my scripts in that cell. Bingo! Added a 0.5 second delay, bug fixed.

So, seriously, pay attention to that note! I'm going to examine all my other trigger zone scripts to make sure this one isn't lurking elsewhere.

Syscrusher (talk)