'NPC-only' Trigger Zone?

Post » Tue Jun 29, 2010 4:06 pm

I want an NPC to play a custom animation at a specific spot, and a custom sound that loops as long as the NPC is at that spot. I was trying to figure out how I might go about attempting to do this. A (very) rough idea I have is to set up a small trigger zone around a custom (idle?) marker assigned with the custom animation, and the custom sound placed as a persistent reference nearby linked to the trigger. The idle marker and the trigger zone would have ownership assigned to the NPC so no one else can activate it. I want this to be repeatable, as in part of the NPC's AI package where he will go to that spot at certain times during the day to trigger the animation and the sound, which then has to loop for the duration of the time he spends in that spot. In (wild) theory, when the NPC's AI package directs to travel to that custom marker, he will activate the trigger as he moves onto the marker, play the custom animation, and the custom sound will loop.

I am pretty sure my rough idea of how to go about this is utterly stupid and would not work (but it's a plan with 'steps').

Can you actually assign ownership to trigger zones that prevent other NPCs and the player from triggering them? For that matter, I think when idle markers are assigned ownership, NPCs actually stop using them. Thoughts and suggestions please.
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm

Post » Tue Jun 29, 2010 3:02 am

Try using OnTriggerEnter NPCref. That will execute your script only when the referenced NPC enters it, allowing you to play a looping sound. You can use OnTriggerExit NPCref to stop the sound. I don't know how the ownership of the idle marker will work as I never used that.
User avatar
Melanie Steinberg
 
Posts: 3365
Joined: Fri Apr 20, 2007 11:25 pm

Post » Tue Jun 29, 2010 9:27 am

Thanks for the OnTriggerEnter tip. I think I've come up with something even simpler: I am thinking of specifying the time for the custom sound so it corresponds to the NPC's AI package. This way, the sound will only play at the time between the start of the package when the NPC should be at the xmarker and playing the animation, and stop when the time for his package is over. Think it'll work?
User avatar
rebecca moody
 
Posts: 3430
Joined: Mon Mar 05, 2007 3:01 pm

Post » Tue Jun 29, 2010 5:41 am

Thanks for the OnTriggerEnter tip. I think I've come up with something even simpler: I am thinking of specifying the time for the custom sound so it corresponds to the NPC's AI package. This way, the sound will only play at the time between the start of the package when the NPC should be at the xmarker and playing the animation, and stop when the time for his package is over. Think it'll work?

To me, that sounds more difficult, and possibly not as reliable as well. The trigger setup using OnTriggerEnter and OnTriggerExit really is exactly what it was designed for, where as basing things on packages can be really flaky at times because they like to get dropped or overridden so often. Just my opinion...
User avatar
Monika Krzyzak
 
Posts: 3471
Joined: Fri Oct 13, 2006 11:29 pm

Post » Tue Jun 29, 2010 3:43 am

To me, that sounds more difficult, and possibly not as reliable as well. The trigger setup using OnTriggerEnter and OnTriggerExit really is exactly what it was designed for, where as basing things on packages can be really flaky at times because they like to get dropped or overridden so often. Just my opinion...


I was afraid of that, since I can't script for beans :) But here is my first try:

scn PlaySoundScriptshort DoOnceref myLinkbegin GameMode	OnTriggerEnter NPCref	if DoOnce == 0		set myLink to GetLinkedRef		myLink.enable		set DoOnce to 1	endif	OnTriggerExit NPCref	if DoOnce == 1		set myLink to GetLinkedRef		myLink.enable		set DoOnce to 0	endifend


Basically, I place a xmarker (initially disabled) and a sound object in the cell (with the xmarker as parent and "pop-in' checked), draw the trigger zone around the marker, and attach the script to the trigger. Now, can someone please correct my script because just looking at it, I can tell it's a bloody mess... :P

Also, let's say I want the script to choose randomly from 5 different sound objects to play when the zone is triggered by the NPC, one at a time, any suggestions on that would be appreciated as well.
User avatar
Trent Theriot
 
Posts: 3395
Joined: Sat Oct 13, 2007 3:37 am

Post » Tue Jun 29, 2010 7:10 am

http://geck.gamesas.com/index.php/OnTrigger and http://geck.gamesas.com/index.php/OnTriggerLeave (not "OnTriggerExit") are blocktypes, just like http://geck.gamesas.com/index.php/GameMode, so should be used with http://geck.gamesas.com/index.php/Begin statements instead of being placed within existing Begin/End blocks:
ScriptName PlaySoundScriptshort DoOnceref myLinkBegin OnTriggerEnter NPCref	if DoOnce == 0		set myLink to GetLinkedRef		myLink.Enable		set DoOnce to 1	endifEndBegin OnTriggerLeave NPCref	if DoOnce		set myLink to GetLinkedRef		myLink.Disable		set DoOnce to 0	endifEnd
I assume that you mean to http://geck.gamesas.com/index.php/Disable the http://geck.gamesas.com/index.php/Reference#Linked_Ref in your http://geck.gamesas.com/index.php/OnTriggerLeave block, but if I'm wrong just change that line back to use http://geck.gamesas.com/index.php/Enable again.

Note that you'll need to replace "NPCref" with the editorRefID of the persistent reference that you want to be able to "activate" the trigger. If you haven't done so already, you'll also need to specify the reference that you want to http://geck.gamesas.com/index.php/Enable as the trigger's http://geck.gamesas.com/index.php/Reference#Linked_Ref.

If you want to select a random action, you'll want to use http://geck.gamesas.com/index.php/GetRandomPercent to store a random value in a variable, then check the value of that variable and decide on an action depending on its value.

Cipscis
User avatar
Max Van Morrison
 
Posts: 3503
Joined: Sat Jul 07, 2007 4:48 pm

Post » Tue Jun 29, 2010 11:22 am

Ah, thanks so much for the correction Cipscis. Another question: what if instead of "random", I want to play the sounds in sequence?
User avatar
FirDaus LOVe farhana
 
Posts: 3369
Joined: Thu Sep 13, 2007 3:42 am

Post » Tue Jun 29, 2010 3:17 am

I'm not sure if there is a way to determine if a sound is already playing, but I would use a staged timer to play each sound in sequence and the use the timer to wait until the first sound is done before playing the second. This all implies that the sounds aren't looping and have a finite duration that you can discover.
User avatar
Floor Punch
 
Posts: 3568
Joined: Tue May 29, 2007 7:18 am

Post » Tue Jun 29, 2010 11:34 am

I'm not sure if there is a way to determine if a sound is already playing, but I would use a staged timer to play each sound in sequence and the use the timer to wait until the first sound is done before playing the second. This all implies that the sounds aren't looping and have a finite duration that you can discover.


Thanks, although that sounds a bit messy. I think the timer method you described was also the method used by someone who was scripting a custom jukebox. I thinking a quick and dirty method to play the sounds in sequence would be to edit the wav files by stitching them together, although that would inflate the size of the wav and I am not sure what impact that would have. Ideally, what I'd like to do is to randomize the sound so that every time the player enters the cell while the NPC is at the xmarker and has triggered the script, that a random sound will play, and then continue to play until the NPC has left the trigger zone or the player leaves the cell (if that makes any sense).
User avatar
sas
 
Posts: 3435
Joined: Thu Aug 03, 2006 8:40 am

Post » Tue Jun 29, 2010 6:32 am

How does this look for randomizing 5 different sounds? I can also remove the sound object that was placed in the cell, no?

scn PlaySoundScriptshort DoOnceref myLinkint RanNumBegin OnTriggerEnter NPCref	if DoOnce == 0		set myLink to GetLinkedRef		myLink.Enable		set RanNum to GetRandomPercent		if RanNum <= 20			playsound wavfile01		elseif RanNum <= 40			playsound wavfile02		elseif RanNum <= 60			playsound wavfile03		elseif RanNum <= 80			playsound wavfile04		elseif RanNum <= 80			playsound wavefile05		endif		set DoOnce to 1	endifEndBegin OnTriggerLeave NPCref	if DoOnce		set myLink to GetLinkedRef		myLink.Disable		set DoOnce to 0	endifEnd

User avatar
FoReVeR_Me_N
 
Posts: 3556
Joined: Wed Sep 05, 2007 8:25 pm

Post » Tue Jun 29, 2010 4:50 pm

That last elseif should be <=100, you have two <=80's in there. But that should work. If you want the sounds to play continuously, they need to be looping sounds.
User avatar
Ebou Suso
 
Posts: 3604
Joined: Thu May 03, 2007 5:28 am

Post » Tue Jun 29, 2010 12:48 pm

That last elseif should be <=100
Actually, it should just be "else". http://geck.gamesas.com/index.php/GetRandomPercent will never return a number greater than 100 so there's no point in checking that.

Cipscis
User avatar
Love iz not
 
Posts: 3377
Joined: Sat Aug 25, 2007 8:55 pm

Post » Tue Jun 29, 2010 6:22 am

Thanks to the both of you for help out. I was so tired I missed that. I have another problem though. With this script, the sounds will play even when the player has left the cell, which I don't want. I think I have to stick to placing sound objects inside the cell and use the script to randomize which sound object is activated. What command can I use for that?

In fact, I was thinking. Maybe this should be a separate script attached to the xmarker instead of the trigger zone. Since the sound object(s) is activated through the xmarker.
User avatar
TWITTER.COM
 
Posts: 3355
Joined: Tue Nov 27, 2007 3:15 pm

Post » Tue Jun 29, 2010 5:52 pm

I may have obverlooked the fact that you were enabling a linked ref and then disabling a linked ref and, in between, playing different sounds. What exactly is the linked ref object? Enabling and disablling for sounds only works if you are enabling and disabling a sound object that has been placed in the game. If you use the playsound command and the sound is a looping sound, it won't turn off and there is no way of turning off a looping sound that has been played with that command. If this is the case, then you need to get away from using the enable/disable on a linked ref and, instead, place one sound object for each sound and then enable and disable each one for each type of random sound you want. That means that you would have to explicitly enable each sound object from within each code segment that coresponds to that particular sound. You can disable all of them with out checking for which one was enabled though.
User avatar
^~LIL B0NE5~^
 
Posts: 3449
Joined: Wed Oct 31, 2007 12:38 pm

Post » Tue Jun 29, 2010 9:18 am

I may have obverlooked the fact that you were enabling a linked ref and then disabling a linked ref and, in between, playing different sounds. What exactly is the linked ref object? Enabling and disablling for sounds only works if you are enabling and disabling a sound object that has been placed in the game. If you use the playsound command and the sound is a looping sound, it won't turn off and there is no way of turning off a looping sound that has been played with that command. If this is the case, then you need to get away from using the enable/disable on a linked ref and, instead, place one sound object for each sound and then enable and disable each one for each type of random sound you want. That means that you would have to explicitly enable each sound object from within each code segment that coresponds to that particular sound. You can disable all of them with out checking for which one was enabled though.


Basically, these are sounds that accompany an idle marker that I have scheduled an NPC to use at specific times. What I've gotten to work so far:

1) NPC enters trigger zone
2) uses the idle marker and performs the animation
3) triggers sound
4) sound stops when NPC leaves the trigger zone once the time for this activity in his AI package is over.

The linked ref is a xmarker that is the destination for this activity in the NPC's AI package. It is also responsible for triggering the sound object when it is enabled (when the NPC enters the trigger zone reserved for him). Everything works great, and is exactly what I initially aimed for. What I would like to try and do now is to modify step 3) such that the sound which is triggered when the NPC enters the trigger zone is one of 4 or 5 different sound objects that have been placed in the cell. So every time the NPC starts this activity as part of his AI package (which probably won't be more than once or twice per day), there is a chance a different sound object will play.
User avatar
brian adkins
 
Posts: 3452
Joined: Mon Oct 01, 2007 8:51 am

Post » Tue Jun 29, 2010 5:36 pm

Ok, so this is what I've come up with as a script meant to be attached to the xmarker

scn randomsoundscriptshort RanNumsoundobjectref01.disablesoundobjectref02.disablesoundobjectref03.disablesoundobjectref04.disableBegin OnActivate xmarkerref	set RanNum to GetRandomPercent	if RanNum <= 40		soundobjectref01,enable	elseif RanNum <= 60		soundobjectref02.enable	elseif RanNum <= 80		soundobjectref03.enable	else		soundobjectref04.enable	endifend


Hm..I am not thinking this through.....can I even attach a script to an xmarker? I think I need to go back to square one..
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm

Post » Tue Jun 29, 2010 4:48 am

Here is what I've done:

I've set up 4 markers with the trigger zone as linked ref. Placed 4 sound objects in the cell, a different marker for each sound object is selected in enabled parent. Markers are initially disabled to prevent the sounds from playing until the NPC moves into the trigger zone.

scn PlaySoundScriptshort DoOnceshort RanNumref Marker1 ref Marker2 ref Marker3 ref Marker4 Begin OnTriggerEnter npcref	if DoOnce == 0		set Marker1 to GetLinkedRef		set Marker2 to GetLinkedRef		set Marker3 to GetLinkedRef		set Marker4 to GetLinkedRef		set RanNum to GetRandomPercent		if RanNum <= 20			Marker1.enable		elseif RanNum <= 40			Marker2.enable		elseif RanNum <= 80			Marker3.enable		else			Marker4.enable		endif		set DoOnce to 1	endifEndBegin OnTriggerLeave npcref	if DoOnce		set Marker1 to GetLinkedRef		set Marker2 to GetLinkedRef		set Marker3 to GetLinkedRef		set Marker4 to GetLinkedRef		Marker1.Disable		Marker2.Disable		Marker3.Disable		Marker4.Disable		set DoOnce to 0	endifEnd


The problem is that...it doesn't work? :P Only the first sound will play.
User avatar
Andrea Pratt
 
Posts: 3396
Joined: Mon Jul 31, 2006 4:49 am

Post » Tue Jun 29, 2010 7:50 am

From your code, markers 1-4 will all be set to the same linked ref. If this is the only version of the code running, that is. What ever the linked ref of the object that this code is running on will become equal to all 4 of your "marker" varaibles.

If it were me, I would keep the linked ref portion for all the activation stuff except the sound objects and just enable/disable them explicitly within your code, like this:

scn PlaySoundScriptshort DoOnceshort RanNumref Marker1 Begin OnTriggerEnter npcref		if DoOnce == 0				set Marker1 to GetLinkedRef		Marker1.enable					set RanNum to GetRandomPercent				if RanNum <= 20						SoundObject1.enable				elseif RanNum <= 40						SoundObject2.enable				elseif RanNum <= 80						SoundObject3.enable				else						SoundObject4.enable				endif				set DoOnce to 1		endifEndBegin OnTriggerLeave npcref		if DoOnce				set Marker1.disable				SoundObject1.Disable				SoundObject2.Disable				SoundObject3.Disable				SoundObject4.Disable				set DoOnce to 0		endifEnd


Just make sure each of the sound objects is persistant and has a reference editor ID equal to SoundObject1 through SoundObject4 or what ever you want to name them.
User avatar
sw1ss
 
Posts: 3461
Joined: Wed Nov 28, 2007 8:02 pm

Post » Tue Jun 29, 2010 5:23 am

Eh, thanks for cleaning up my crappy codes :). So just to be clear, what you are saying is that instead of having 4 individual markers each controlling one sound object, I should go back to having just one marker controlling 4 sounds?

Thet code wouldn't compile, so I've edited your edit a bit and changed

Begin OnTriggerLeave npcref		if DoOnce				set Marker1.disable				SoundObject1.Disable				SoundObject2.Disable				SoundObject3.Disable				SoundObject4.Disable				set DoOnce to 0		endifEnd


to

Begin OnTriggerLeave npcref	if DoOnce == 1	   		   set myLink to GetLinkedRef		   myLink.Disable	  		   set DoOnce to 0		endifEnd


I've changed marker1 to myLink simply because I am now back to using just one linkref. I also figured that if the xmarker is the parent of all the sound objects, once you disable it, you disable them all, no? The problem now is that all 4 sounds will play at the same time rather than one sound.
User avatar
Astargoth Rockin' Design
 
Posts: 3450
Joined: Mon Apr 02, 2007 2:51 pm

Post » Tue Jun 29, 2010 5:44 pm

The way I've been doing stuff like this is to make an activator (usually use the holodisk model - doesn't matter) that has a script attached.

MyActivatorREF (persistent) using MyActivatorSCRIPT. In the NPC's package OnStart: set MyActivatorREF.StartSequence to 1, and OnEnd: set MyActivatorREF.StartSequence to 0.

scn MyActivatorSCRIPTshort StartSequenceshort dicefloat timerBegin GameMode	if (StartSequence == 1)			if (timer <= 0)			set dice to (1 + 0.04 * GetRandompercent)						if (dice == 1)				PlaySound MySound01				set timer to ###; length of sound						elseif (dice == 2)				PlaySound MySound02				set timer to ###; length of sound						elseif (dice == 3)				PlaySound MySound03				set timer to ###; length of sound						elseif (dice == 4)				PlaySound MySound04				set timer to ###; length of sound							endif				elseif (timer)			set timer to (timer - GetSecondsPassed)		endif		else			if (timer)			set timer to 0		endif		endifEnd

Dunno how proper that is though.
User avatar
ruCkii
 
Posts: 3360
Joined: Mon Mar 26, 2007 9:08 pm

Post » Tue Jun 29, 2010 6:52 am

Thanks for sharing that. I've gotten my script to work. Basically, by disabling the other 3 sound objects through the script when one of them is enabled, I can avoid having all 4 sounds play at the same time. And the 4 sounds do randomized now. So....

SUCCESS!

Thanks guys. But I've also realized I've been going about what I want to do in the wrong way. It's funny how sometimes you get something working after much frustration and realize that there are easier alternatives to handling the situation :P
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am


Return to Fallout 3