Need help with this script

Post » Sat May 28, 2011 9:05 am

Thank you Kir! The script finally works perfectly! :celebration: :clap: I did have to make one additional modification - which was to increase the GetDistance player from > 50 back up to > 150 when giving the resume wander instruction, because the NPC was walking away or resuming his idle gesture before he was finished speaking(!) Here's what the final script looks like:

Begin FW_greeting_N_nice_W1        short doOnce    float timer    short wanderingNPC        if ( doOnce == 0 )        if ( ( GetDistance player ) < 200 ) ; increased from 150 (too close)            if ( GetCurrentAIPackage == 0 ) ; wandering                set wanderingNPC to 1            endif            set doOnce to 1            AIFollow player 0 0 0 0        endif    elseif ( doOnce == 1 )        set timer to ( timer + GetSecondsPassed )        if ( timer < 1 )            return        else            set timer to 0            set doOnce to 3            say "vo\N\m\Hlo_NM135.mp3" "Hail and welcome friend, hail!"        endif    elseIf ( doOnce == 3 )        if ( ( GetDistance player ) > 150 ) ; increased from 50 to allow NPC to complete dialogue before resuming wander            if ( wanderingNPC == 1 )                set wanderingNPC to 0                AIWander 2000 5 0 60 20 10 10 0 0 0 0            endif            set doOnce to 4 ; stop following but don't check for vicinity yet        endif	elseif ( doOnce == 4 )		if ( ( Getdistance player ) > 500 ) ; NOW you can reset			set doOnce to 0		endif    endif    End FW_greeting_N_nice_W1


So once again, many thanks and much appreciation to you and all the other experts who helped me with this script! Thank you all !!! :bowdown:
User avatar
Jerry Jr. Ortiz
 
Posts: 3457
Joined: Fri Nov 23, 2007 12:39 pm

Post » Sat May 28, 2011 9:45 am

Hi All,

I guess I spoke too soon... there is another slight glitch with the script. It works fine as stated before, BUT... the NPC will say his/her line of dialogue even when he/she is laying there dead! Kind of funny, but not what I was intending. Is there something I can add to this script to prevent the NPC from talking when they are deceased? Thanks!
User avatar
Crystal Clear
 
Posts: 3552
Joined: Wed Aug 09, 2006 4:42 am

Post » Sat May 28, 2011 12:44 am

if ( MenuNode == 1 ) ; (this one isn'r related to the question, but was needed anyway)	returnendifif ( OnDeath > 0 )	set doOnce to 99 endif
in the beginning
User avatar
Neko Jenny
 
Posts: 3409
Joined: Thu Jun 22, 2006 4:29 am

Post » Sat May 28, 2011 2:23 am

Thanks (again) Kir!
User avatar
Sammygirl
 
Posts: 3378
Joined: Fri Jun 16, 2006 6:15 pm

Post » Sat May 28, 2011 9:59 am

Sorry to keep bringing this script up, but hopefully this will be the last time. I need to make a slight modification to it for a third condition. The original script triggered a forced greeting from a stationary NPC. The second condition addressed the same from a wandering NPC (by temporarily putting him into AiFollow until the greeting is recited). Now I have an NPC who is stationary, but has an animation running on him (one of RX-31's animation sequences). So while the NPC is not wandering, he is in constant motion, making hand gestures, etc. When I walk up to him, I'd like him to stop whatever gesture he is doing and turn to face the player and recite his line (like a wandering NPC).

I started by placing the wandering NPC script on him. That stopped the animation, made the NPC face the player and recite his greeting all perfectly. However, after the greeting, he started wandering around - not surprising, since the script is written to return him to wander mode. For this animated character, instead of returning to AiWander, I just need to get him out of AiFollow after he's said his greeting. Easier said than done (for me), because whatever I'm doing isn't working. This is the script that works for wandering NPC's:

Begin FW_greeting_NM_wander_nice01        short doOnce    float timer    short wanderingNPC    	if ( OnDeath > 0 )    		set doOnce to 99 	endif    	if ( doOnce == 0 )        if ( ( GetDistance player ) < 200 ) ; increased from 150 (too close)            if ( GetCurrentAIPackage == 0 ) ; wandering                set wanderingNPC to 1            endif            set doOnce to 1            AIFollow player 0 0 0 0        endif    elseif ( doOnce == 1 )        set timer to ( timer + GetSecondsPassed )        if ( timer < 1 )            return        else            set timer to 0            set doOnce to 3            say "vo\N\m\Hlo_NM135.mp3" "Hail and welcome friend, hail!"        endif    elseIf ( doOnce == 3 )        if ( ( GetDistance player ) > 150 ) ; increased from 50 to allow NPC to complete dialogue before resuming wander            if ( wanderingNPC == 1 )                set wanderingNPC to 0                AIWander 2000 5 0 60 20 10 10 0 0 0 0            endif            set doOnce to 4 ; stop following but don't check for vicinity yet        endif	elseif ( doOnce == 4 )		if ( ( Getdistance player ) > 500 ) ; NOW you can reset			set doOnce to 0		endif    endifEnd FW_greeting_NM_wander_nice01



I modified that script to the following for the stationary but animated NPC (the first part is just a sleep timer to make this character appear between certain hours, and I wanted to keep that function so just combined it with the greeting script):

begin FW_greeting_ANIMATEDif ( GetDisabled )	if ( GameHour >= 8 )		if ( GameHour <= 22 )			enable		endif	endif	returnendifif ( GameHour > 22 )	disable	returnelseif ( GameHour < 8 )	disableendif       short doOnce    float timer    short wanderingNPC    	if ( OnDeath > 0 )    		set doOnce to 99 	endif    	if ( doOnce == 0 )        if ( ( GetDistance player ) < 200 ) ; increased from 150 (too close)           set doOnce to 1            AIFollow player 0 0 0 0        endif    elseif ( doOnce == 1 )        set timer to ( timer + GetSecondsPassed )        if ( timer < 1 )            return        else            set timer to 0            set doOnce to 3            say "vo\I\m\Hlo_IM151.mp3" "Well hello there! How are you?"        endif    elseIf ( doOnce == 3 )        if ( ( GetDistance player ) > 150 ) ; increased from 50 to allow NPC to complete dialogue before resuming wander            if ( GetCurrentAIPackage == 3 )                GetCurrentAIPackage == -1           endif            set doOnce to 4 ; stop following but don't check for vicinity yet        endif	elseif ( doOnce == 4 )		if ( ( Getdistance player ) > 500 ) ; NOW you can reset			set doOnce to 0		endif    endifend


The 9th and 10th lines from the bottom are the ones I changed. I figured the NPC is in AiFollow mode (AiPackage 3), and want to change it to None (AiPackage -1). But that didn't work, because now he's stalking me. :confused: What did I do wrong this time, and how do I fix it? Many thanks in advance.
User avatar
Amy Masters
 
Posts: 3277
Joined: Thu Jun 22, 2006 10:26 am

Post » Fri May 27, 2011 5:51 pm

Get usually is prefix for functions reading, not changing things.
You should use something like
AIWander distance starthour duration 0 idle2 idle3 idle4 idle5 idle6 idle7
For instance, assuming your desired animation idle is idle6, try something like (100 meaning 100% idle probability)
AIWander 0 0 0 0 0 0 0 0 100
instead of
GetCurrentAIPackage == -1
User avatar
Alan Whiston
 
Posts: 3358
Joined: Sun May 06, 2007 4:07 pm

Post » Fri May 27, 2011 11:18 pm

Get usually is prefix for functions reading, not changing things.
You should use something like
AIWander distance starthour duration 0 idle2 idle3 idle4 idle5 idle6 idle7
For instance, assuming your desired animation idle is idle6, try something like (100 meaning 100% idle probability)
AIWander 0 0 0 0 0 0 0 0 100
instead of
GetCurrentAIPackage == -1


Thanks abot. I will give that a shot.
User avatar
kevin ball
 
Posts: 3399
Joined: Fri Jun 08, 2007 10:02 pm

Post » Fri May 27, 2011 8:39 pm

Get usually is prefix for functions reading, not changing things.
You should use something like
AIWander distance starthour duration 0 idle2 idle3 idle4 idle5 idle6 idle7
For instance, assuming your desired animation idle is idle6, try something like (100 meaning 100% idle probability)
AIWander 0 0 0 0 0 0 0 0 100
instead of
GetCurrentAIPackage == -1


Tried this, and it's closer to working, but still not 100%. The NPC now says the greeting correctly and goes into his idle sequence afterward (without following me), which is perfect. However, the animation is NOT the RX-31 gesture set that he was doing before, which is odd because I did not change that. That animation uses Idle6, which I had set to 100 (with all the rest at 0). I replicated the AiWander package stats for wander distance (0), duration (5), and Time of day (0), in addition to the idle chances in the script, so it reads: AiWander 0 5 0 0 0 0 0 100 0 0 0, as shown below.

begin FW_greeting_animated01	if ( GetDisabled )		if ( GameHour >= 8 )			if ( GameHour <= 22 )				enable			endif		endif		return	endif	if ( GameHour > 22 )		disable		return	elseif ( GameHour < 8 )		disable	endif	short doOnce	float timer	short wanderingNPC    	if ( OnDeath > 0 )    		set doOnce to 99 	endif    	if ( doOnce == 0 )        if ( ( GetDistance player ) < 200 ) ; increased from 150 (too close)            if ( GetCurrentAIPackage == 0 ) ; wandering                set wanderingNPC to 1            endif            set doOnce to 1            AIFollow player 0 0 0 0        endif    elseif ( doOnce == 1 )        set timer to ( timer + GetSecondsPassed )        if ( timer < 1 )            return        else            set timer to 0            set doOnce to 3            say "vo\I\m\Hlo_IM151.mp3" "Hello there! How are you?"        endif    elseIf ( doOnce == 3 )        if ( ( GetDistance player ) > 150 ) ; increased from 50 to allow NPC to complete dialogue before resuming wander            if ( wanderingNPC == 1 )                set wanderingNPC to 0                AIWander 0 5 0 0 0 0 0 100 0 0 0            endif            set doOnce to 4 ; stop following but don't check for vicinity yet        endif	elseif ( doOnce == 4 )		if ( ( Getdistance player ) > 500 ) ; NOW you can reset			set doOnce to 0		endif    endifend    


This should work, right? I wondered if maybe the post-greeting gesture was the default MW Idle6 gestures, so I set that to 0 in the NPC's stat window (so ALL Idles read 0), but that didn't change anything. Do I need to add some other command to start the animation file and override the Idle? BTW the animation is "Misc\anim_gestureset_03.nif." Any other ideas? Thanks.
User avatar
Jonathan Egan
 
Posts: 3432
Joined: Fri Jun 22, 2007 3:27 pm

Post » Fri May 27, 2011 9:52 pm

Try temporarily attaching this test script to the NPC, pressing sneak should cycle between different idles, so you can find the proper aiwander command.
begin idleTestScriptif ( MenuMode )    returnendiffloat timerif ( timer > 0 )    set timer to ( timer - GetSecondsPassed )    returnendifset timer to 0short stateif ( GetPCSneaking )    set timer to 3.5    if ( state == 0 )        AIWander 0 5 0 0 100 0 0 0 0 0 0 0        Messagebox "idle2"        set state to 1    elseif ( state == 1 )        AIWander 0 5 0 0 0 100 0 0 0 0 0 0        Messagebox "idle3"        set state to 2    elseif ( state == 2 )        AIWander 0 5 0 0 0 0 100 0 0 0 0 0        Messagebox "idle4"        set state to 3    elseif ( state == 3 )        AIWander 0 5 0 0 0 0 0 100 0 0 0 0        Messagebox "idle5"        set state to 4    elseif ( state == 4 )        AIWander 0 5 0 0 0 0 0 0 100 0 0 0        Messagebox "idle6"        set state to 5    elseif ( state == 5 )        AIWander 0 5 0 0 0 0 0 0 0 100 0 0        Messagebox "idle7"        set state to 6    elseif ( state == 6 )        AIWander 0 5 0 0 0 0 0 0 0 0 100 0        Messagebox "idle8"        set state to 7    elseif ( state == 7 )        AIWander 0 5 0 0 0 0 0 0 0 0 0 100        Messagebox "idle9"        set state to 0    endifendifend

User avatar
john page
 
Posts: 3401
Joined: Thu May 31, 2007 10:52 pm

Post » Sat May 28, 2011 6:36 am

Thanks (again) abot. This sounds like a cool little diagnostic. I will test it out and let you know how it goes. Very much appreciate your help with this.
User avatar
Melis Hristina
 
Posts: 3509
Joined: Sat Jun 17, 2006 10:36 pm

Previous

Return to III - Morrowind