How do I script the Portcullis to close?

Post » Thu Oct 15, 2009 6:12 pm

I'm using this http://img203.imageshack.us/img203/8695/67968369.jpg in Pelagiad Expanded and I want it to close at 2000 and open at 0600 everyday. I was looking at Immersive Chargen mod and he has the same kind of thing where one of the metal doors closes after a certain action. But I can't see how he got it to work as the script he has only says this: I tried the one Melian wrote and it works fine, except that when the gate opens and closes, it plays the MournGates sound 5 or 6 times in a row. Any clue why it does that?


Try moving this condition after the SetPos

if ( GetSoundPlaying "MournGates" == 0 )		PlaySound3d "MournGates"endif


elseif ( gamehour < 20.1 ) ;close now	if ( ( GetPos z ) > 1830.5 )		MoveWorld z -177	elseif ( ( GetPos z ) < 1829.5 )		SetPos z 1830        if ( GetSoundPlaying "MournGates" == 0 )		PlaySound3d "MournGates"	endif	endif


That should fix it.
User avatar
Ana
 
Posts: 3445
Joined: Sat Jul 01, 2006 4:29 am

Post » Thu Oct 15, 2009 7:24 pm

I moved it down after GetPos and when it closes, it only plays once. But when it opens back up at 0600, it plays it 6 times. :unsure: What else do I need to switch? I tried to move the

	if ( GetSoundPlaying "MournGates" == 0 )		PlaySound3d "MournGates"	endif


....to after the
if ( gamehour < 5.9 )  ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830


but it just played it continuously as soon as I loaded my game. :unsure:


Begin PE_Gate_Moveif ( gamehour < 5.9 )  ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endifelseif ( gamehour < 6.1 )  ;open now	if ( ( GetPos z ) < 2006.5 )		MoveWorld z 177	elseif ( ( GetPos z ) > 2007.5 )		SetPos z 2007	endif	if ( GetSoundPlaying "MournGates" == 0 )		PlaySound3d "MournGates"	endifelseif ( gamehour < 19.9 ) ;should already be open	if ( ( GetPos z ) < 2006.5 )		SetPos z 2007	endifelseif ( gamehour < 20.1 ) ;close now	if ( ( GetPos z ) > 1830.5 )		MoveWorld z -177	elseif ( ( GetPos z ) < 1829.5 )		SetPos z 1830		if ( GetSoundPlaying "MournGates" == 0 )		PlaySound3d "MournGates"	endif	endifelse ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endifendifEnd PE_Gate_Move

User avatar
:)Colleenn
 
Posts: 3461
Joined: Thu Aug 31, 2006 9:03 am

Post » Thu Oct 15, 2009 7:15 pm

No, the sound should be there in both places, one for 6:00 and another for 20:00. The problem was that it was playing *all* the time between 5.9 and 6.1.
begin PE_Gate_Moveshort doSoundif ( gamehour < 5.9 )  ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endif	set doSoind to 0elseif ( gamehour < 6.1 )  ;open now	if ( ( GetPos z ) < 2006.5 )		MoveWorld z 177	elseif ( ( GetPos z ) > 2007.5 )		SetPos z 2007	endif	if ( doSound = 0 )		if ( GetSoundPlaying "MournGates" == 0 )			PlaySound3d "MournGates"		endif	endif	set doSoind to 1elseif ( gamehour < 19.9 ) ;should already be open	if ( ( GetPos z ) < 2006.5 )		SetPos z 2007	endif	set doSoind to 0elseif ( gamehour < 20.1 ) ;close now	if ( ( GetPos z ) > 1830.5 )		MoveWorld z -177	elseif ( ( GetPos z ) < 1829.5 )		SetPos z 1830	endif	if ( doSound = 0 )		if ( GetSoundPlaying "MournGates" == 0 )			PlaySound3d "MournGates"		endif	endif	set doSoind to 1else ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endif	set doSoind to 0endifend

User avatar
sunny lovett
 
Posts: 3388
Joined: Thu Dec 07, 2006 4:59 am

Post » Thu Oct 15, 2009 9:25 pm

Horay! It works now.
You accidentally spelled sound like soind, fyi
I changed the second sound to MournGatesClose instead. But yes, I went through a few game days of waiting and resting and watching it and it works perfectly and doesn't mess up.

Begin PE_Gate_Moveshort doSoundif ( gamehour < 5.9 )  ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endif	set doSound to 0elseif ( gamehour < 6.1 )  ;open now	if ( ( GetPos z ) < 2006.5 )		MoveWorld z 177	elseif ( ( GetPos z ) > 2007.5 )		SetPos z 2007	endif	if ( doSound = 0 )		if ( GetSoundPlaying "MournGates" == 0 )			PlaySound3d "MournGates"		endif	endif	set doSound to 1elseif ( gamehour < 19.9 ) ;should already be open	if ( ( GetPos z ) < 2006.5 )		SetPos z 2007	endif	set doSound to 0elseif ( gamehour < 20.1 ) ;close now	if ( ( GetPos z ) > 1830.5 )		MoveWorld z -177	elseif ( ( GetPos z ) < 1829.5 )		SetPos z 1830	endif	if ( doSound = 0 )		if ( GetSoundPlaying "MournGatesClose" == 0 )			PlaySound3d "MournGatesClose"		endif	endif	set doSound to 1else ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endif	set doSound to 0endifEnd PE_Gate_Move


Thank you Kir, Miles, Melian & Yorgle. I'll give you guys all credit in the readme. This was quite an arduous task to say the least.
User avatar
Joanne Crump
 
Posts: 3457
Joined: Sat Jul 22, 2006 9:44 am

Post » Thu Oct 15, 2009 9:12 pm

:facepalm:
Sorry! What I really meant to write was this:
begin PE_Gate_Moveif ( gamehour < 5.9 )  ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endifelseif ( gamehour < 6.1 )  ;open now	if ( ( GetPos z ) < 2006.5 )		MoveWorld z 177		if ( GetSoundPlaying "MournGates" == 0 )			PlaySound3d "MournGates"		endif	elseif ( ( GetPos z ) > 2007.5 )		SetPos z 2007	endifelseif ( gamehour < 19.9 ) ;should already be open	if ( ( GetPos z ) < 2006.5 )		SetPos z 2007	endifelseif ( gamehour < 20.1 ) ;close now	if ( ( GetPos z ) > 1830.5 )		MoveWorld z -177		if ( GetSoundPlaying "MournGates" == 0 )			PlaySound3d "MournGates"		endif	elseif ( ( GetPos z ) < 1829.5 )		SetPos z 1830	endifelse ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endifendifend

... But if you only want the sound played once, Kir's version is better anyway (I had assumed you'd want the sound played the whole time it's moving, however long that is).
User avatar
Stephani Silva
 
Posts: 3372
Joined: Wed Jan 17, 2007 10:11 pm

Post » Thu Oct 15, 2009 10:15 pm

Thing is, it is only moving not between 5.9 and 6.1 *hours*, but between 1830 and 2007 *units*... which is 177 units distance. Which, with MoveWorld's parameter 177, gives exactly one second of moving. Which, incidentally, is the length of MournGates sound. "I love it when a plan comes together" :D.
User avatar
Dale Johnson
 
Posts: 3352
Joined: Fri Aug 10, 2007 5:24 am

Post » Thu Oct 15, 2009 7:53 pm

With that script that Melian posted right above Kir's post, the gate and sounds work fine, but it closes and opens a little early. It doesn't do it exactly at 2000 or 0600, but like, a few seconds before. Whereas the one Kir wrote does. What is the difference between the two? Is either one better or more reliable or less likely to have glitches?

@Kir, are you talking about the script you wrote or the one Melian just recently wrote?
User avatar
Nicola
 
Posts: 3365
Joined: Wed Jul 19, 2006 7:57 am

Post » Fri Oct 16, 2009 10:25 am

OK, so I didn't check the sound file at all :P A do-once (Kir's version) would definitely be better then, since it'll work even on systems where GetSoundPlaying is no good (rare bug).

With that script that Melian posted right above Kir's post, the gate and sounds work fine, but it closes and opens a little early. It doesn't do it exactly at 2000 or 0600, but like, a few seconds before. Whereas the one Kir wrote does. What is the difference between the two? Is either one better or more reliable or less likely to have glitches?

Reason is: GameHour is a float variable that's updated every frame (NOT every second!) by the game. So checking "if GameHour == 6" wouldn't work, because it would have to be *exactly* 6, where it's more likely to go from 5.9880 straight to 6.0001 or something like that. So I gave it a 'window' around that time and basically said 'if it's around 6 am, open; but if it's way past, pretend you've been open all along' (if you see what I mean).

If you want it to be '6 am or slightly after' rather than 'around 6 am', you could use this instead:
begin PE_Gate_Moveshort doonceif ( gamehour < 6 )  ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endifelseif ( gamehour < 6.1 )  ;open now	if ( ( GetPos z ) < 2006.5 )		MoveWorld z 177		if ( doonce == 0 )			PlaySound3d "MournGates"			set doonce to 1		endif	elseif ( ( GetPos z ) > 2007.5 )		SetPos z 2007	endifelseif ( gamehour < 20 ) ;should already be open	if ( ( GetPos z ) < 2006.5 )		SetPos z 2007	endif	set doonce to 0elseif ( gamehour < 20.1 ) ;close now	if ( ( GetPos z ) > 1830.5 )		MoveWorld z -177		if ( doonce == 0 )			PlaySound3d "MournGates"			set doonce to 1		endif	elseif ( ( GetPos z ) < 1829.5 )		SetPos z 1830	endifelse ;should already be closed	if ( ( GetPos z ) > 1830.5 )		SetPos z 1830	endif	set doonce to 0endifend

User avatar
Jerry Cox
 
Posts: 3409
Joined: Wed Oct 10, 2007 1:21 pm

Post » Fri Oct 16, 2009 3:50 am

Well I was thinking that the guards are opening this gate at dawn, basically. And they don't have alarm clocks or anything. So in real life, the gate wouldn't open at the exact same time any ways. So I think the way you have it works out better. Thanks Melian. Thank you to everyone, really.
User avatar
Spooky Angel
 
Posts: 3500
Joined: Thu Aug 10, 2006 5:41 pm


Return to III - Morrowind