Scripting question...

Post » Sat May 28, 2011 8:07 am

My first question concerning a door is thus, I've been working on getting a door that only opens via terminals on opposite sides of it, while also maintaining the "Active Parent" idea where you can't open it (IE specifically I want the little message that says "This is opened elsewhere" or whatever and not have "Requires Key" on the label for MY IMMERSION). So there is that, then I was also trying to throw in an auto-close script for good measure. I've got everything there and more or less set up, the main thing that doesn't work is the whole Active Parent + terminals thing. If I have the terminals as the active parent then the door opens before I even fully open the terminal, and if I have the terminals not in the active parent list then I can't open it with SetOpenState 1. Then I'm not sure if I have the auto-close stuff right either, I have the auto-close trigger (its the "Create Cubic Activator" button to create primitives right? The wiki wasn't really clear...) linked to the door with the below script, and the door has the trigger as an activate parent (in order to keep the above functionality). What am I doing wrong/how do I get the functionality I want?

scn MTHAutoCloseDoorTriggerref rLinkedRefBegin onload	set rLinkedRef to GetLinkedRefEndBegin OnTriggerLeave	if rLinkedRef.GetOpenState 1 ;Door is open		rLinkedRef.SetOpenState 0  ; Close	endifEnd




And then my other question concerns this script, but it's not working when I tried to add the timer and explosions. Before I created the timer and explosion "section" the disable references were in the "menu" and it worked fine.

scn MTHMetroCenterBombScriptShort iButtonShort ExplodedFloat TimerBegin OnActivate	ShowMessage MTHMetroCenterBombMessageEndBegin GameMode	set iButton to GetButtonPressed	if iButton == -1 ; No button has been pressed yet		Return	elseif iButton == 0 ; Remove bomb		set Timer to 10		set Exploded to 0	elseif iButton == 1 ; Walk away	endif	if Exploded == 0		if Timer > 0			set Timer to Timer - GetSecondsPassed		else			MTHBombREF.PlaceAtMe MTHBombFlash			MTHBombREF.PlaceAtMe MTHBombExplosion			MTHBombSmoke01.Enable			MTHBombSmoke02.Enable			MTHBombSmoke03.Enable			MTHMetroFloodLightGenerator.Disable			MTHBombREF.Disable			set Exploded to 1		endif	endifEnd

User avatar
Cccurly
 
Posts: 3381
Joined: Mon Apr 09, 2007 8:18 pm

Post » Sat May 28, 2011 10:27 am

scn MTHMetroCenterBombScriptShort iButtonShort ExplodedFloat Timershort myStateBegin OnActivate	if Exploded == 0		ShowMessage MTHMetroCenterBombMessage		set myState to 1	endifEndBegin GameMode	if myState == 1		set iButton to GetButtonPressed		if iButton == -1 ; No button has been pressed yet			Return		elseif iButton == 0 ; Remove bomb			set Timer to 10			set Exploded to 1		endif	endif	if Exploded == 1		if Timer > 0			set Timer to Timer - GetSecondsPassed		else			MTHBombREF.PlaceAtMe MTHBombFlash			MTHBombREF.PlaceAtMe MTHBombExplosion			MTHBombSmoke01.Enable			MTHBombSmoke02.Enable			MTHBombSmoke03.Enable			MTHMetroFloodLightGenerator.Disable			MTHBombREF.Disable			set Exploded to 2		endif	endifEnd

1. You should NEVER leave a GameMode block always running and intercepting button presses. I added the variable myState to only run it when its needed.

2. Exploded is going to equal 0 when the script starts, and timer will not be greater than 0, so the script runs immediately. Use a different value than the default 0. Also, the 'return' you have in the buttonpressed is causing the rest of the script to never run since that would be true only for one FPS cycle when you actually click the button.

3. The last button == 1 is not necessary.

4. I made it so it will only work once with the condition check in the OnActivate block.
User avatar
N3T4
 
Posts: 3428
Joined: Wed Aug 08, 2007 8:36 pm

Post » Sat May 28, 2011 5:27 pm

You're using http://geck.gamesas.com/index.php/GetOpenState incorrectly. It takes no parameters - you should check the value that it returns:
if GetOpenState == 1

If you want the "This door is activated elsewhere" message to appear when the door is activated by the player, use a script like this:
Begin OnActivate	if IsActionRef player		ShowMessage ActivatedElsewhereMessage	endifEnd
That will prevent the door from being opened via a regular activation, but http://geck.gamesas.com/index.php/SetOpenState should still work.

When it comes to using a http://geck.gamesas.com/index.php/OnTriggerLeave block to close the doors automatically, you'll probably want to keep track of the number of actors in the area so it doesn't just close when the first actor leaves:
int iCountref rLinkedRefBegin OnTriggerEnter	set iCount to iCount + 1EndBegin OnTriggerLeave	set iCount to iCount - 1	if iCount <= 0		set iCount to 0 ; In case actors begin within the trigger and aren't picked up by the OnTriggerEnter block - not sure if this can happen but it's better to be safe		set rLinkedRef to GetLinkedRef		if rLinkedRef.GetOpenState < 3 ; Neither closed nor closing			rLinkedRef.SetOpenState 0 ; Close		endif	endifEnd

Cipscis
User avatar
Rik Douglas
 
Posts: 3385
Joined: Sat Jul 07, 2007 1:40 pm

Post » Sat May 28, 2011 11:55 am

Thanks a ton for the help guys!

One last quick question, how would I have the player exit out of the terminal menu when they click one of the choices (open/close)?

Bah and I still can't get the bomb script to work now, here's the current code, the "disable further activations" part works since I can only activate the bomb the one time but then nothing happens afterwards.

scn MTHMetroCenterBombScriptShort iButtonShort ExplodedFloat Timershort myStateBegin onactivate	if Exploded == 0		ShowMessage MTHMetroCenterBombMessage		set myState to 1	endifEndBegin GameMode	if myState == 1		set iButton to GetButtonPressed		if iButton == -1 ; No button has been pressed yet			Return		elseif iButton == 0 ; Remove bomb			set Timer to 10			set Exploded to 1		endif	endif	if Exploded == 1		if Timer > 0			set Timer to Timer - GetSecondsPassed		else			MTHBombREF.PlaceAtMe MTHBombFlash 1			MTHBombREF.PlaceAtMe MTHBombExplosion 1			MTHBombSmoke01.Enable			MTHBombSmoke02.Enable			MTHBombSmoke03.Enable			MTHMetroFloodLightGenerator.Disable			MTHBombREF.Disable			set Exploded to 2		endif	endifEnd


It's an object script if that matters, thought I'm pretty sure that's right.
User avatar
Heather Kush
 
Posts: 3456
Joined: Tue Jun 05, 2007 10:05 pm

Post » Sat May 28, 2011 6:12 am

Your code is getting stuck because after button 0 is pressed, Mystate still equals one. So, the next iteration, the button check part runs again and this time there is no button pressed so the Return command is used and the rest of the code is skipped. If you only want this button selection message to happen once, the add a 'Set MyState to 2' after the 'Set Exploded to 1' line.

To force the player out of the terminal automatically, use 'ForceTerminalBack' once for each nested level of the terminal. In other words, from a single terminal, use that line once in the results script for the option (at the end of any other code). If its a sub-terminal, use the command twice. Each use of ForceTerminalBack will bring up the prior nested terminal.
User avatar
Sherry Speakman
 
Posts: 3487
Joined: Fri Oct 20, 2006 1:00 pm

Post » Sat May 28, 2011 7:24 pm

Thank you so much! It's all more or less working, thought the smoke effect isn't rendering for some reason, I'll probably just try a different one or something.

One other thing, I got everything working more or less perfectly how I want it (it's quite cool if I do say so myself :wink_smile:), but I was testing it out in various ways and start crashing constantly when trying to change cells, so is the method I'm using "tried and true" or prone to crashes? I kind of think/hope what I've done is fine and it's MMM Ghoul Raise that's causing the issue as I remembered it is really bad in the Metro Tunnels (need to get rid of it...), especially with as many mods as I have and that's where the mod takes place...

Anyway, here's what happens, my final code, click the bomb,

scn MTHMetroCenterBombScriptShort iButtonShort ExplodedShort myStateFloat TimerBegin OnActivate	if Exploded == 0		ShowMessage MTHMetroCenterBombMessage		set myState to 1	endifEndBegin GameMode	if myState == 1		set iButton to GetButtonPressed		if iButton == -1 ; No button has been pressed yet			Return		elseif iButton == 0 ; Remove bomb			set Timer to 10			MTHBombBellREF.Enable			set Exploded to 1			set myState to 2		endif	endif	if Exploded == 1		if Timer > 0			set Timer to Timer - GetSecondsPassed		else			MTHBombBellREF.Disable			MTHBombBellREF.MarkForDelete			MTHBombREF.PlaceAtMe MTHBombExplosion 1			Player.AddItem MTHSmokeToken 1			MTHBombSmoke01.Enable			MTHMetroFloodLightGenerator.Disable			MTHBombREF.Disable			set Exploded to 2		endif	endifEnd


I get a token and this happens

scn MTHMetroCenterSmokeFloat TimerInt SmokeBegin OnAdd Player	Set Timer to 600	Set Smoke to 1EndBegin GameMode	If Smoke == 1		If Timer > 0			Set Timer to Timer - GetSecondsPassed		Else			If Player.GetInCell MetroCenter01 == 1				Return			Else				Player.RemoveItem MTHSmokeToken 1				MTHBombSmoke01.Disable				MTHBombSmoke01.MarkForDelete				Set Smoke to 2			Endif		Endif	EndifEnd


Is that OK? Also when/how/should I use MarkForDelete? And does it cascade to children if I delete the parent?
User avatar
Alexx Peace
 
Posts: 3432
Joined: Thu Jul 20, 2006 5:55 pm

Post » Sat May 28, 2011 10:29 am

Shameless bump. I'd like to figure out when/how to use MarkForDelete properly and make sure the scripts are working as intended.
User avatar
Adrian Powers
 
Posts: 3368
Joined: Fri Oct 26, 2007 4:44 pm

Post » Sat May 28, 2011 6:34 am

Others may have a different point of view, but for me, disable & mark for delete (used together) are primarily used on spawned actors to remove the possibility of save game bloat. I see no need to mark for delete your smoke in any case. Disabling should be fine.
User avatar
Theodore Walling
 
Posts: 3420
Joined: Sat Jun 02, 2007 12:48 pm


Return to Fallout 3