Companion scripting help?

Post » Sat May 28, 2011 9:24 am

So, I have two problems.

1. I'd like to be able to select a dialogue option with an NPC and, as a result, have them use a specific animation (playing an instrument) and have a sound file play (music) simultaneously. The sound file and animation would loop until the player speaks to the NPC again.

I know the former is probably done in a few naughty mods, but I'd really prefer to not install those just to see how they work. It would have something to do with setting the animation to an AI package, like alchemy and reading, yes? Then scripting it to toggle on after the dialogue is selected, but then off again if NPC.istalking. Something like that; even with my minimal scripting knowledge, I might be able to make it work. But how do I get the sound file to play?

2. I'd like to be able to command an NPC to lockpick something, preferably via dialogue.

As for the second, Talkie Toaster does something similar in his wonderful Companion Share and Recruit mod. However, there is so much framework in place for it, what with the command keys and orders system; even were I to ask him for permission to use his scripts, I don't know if I could dissect it well enough to use on an individual, stand-alone companion. An illusion of lockpicking with the NPC casting a dummy spell would work, but I wouldn't know how to make them target the nearest locked object. Maybe with OBSE?
User avatar
Britta Gronkowski
 
Posts: 3475
Joined: Mon Apr 09, 2007 3:14 pm

Post » Sat May 28, 2011 6:12 pm

So, I have two problems.

1. I'd like to be able to select a dialogue option with an NPC and, as a result, have them use a specific animation (playing an instrument) and have a sound file play (music) simultaneously. The sound file and animation would loop until the player speaks to the NPC again.

I know the former is probably done in a few naughty mods, but I'd really prefer to not install those just to see how they work. It would have something to do with setting the animation to an AI package, like alchemy and reading, yes? Then scripting it to toggle on after the dialogue is selected, but then off again if NPC.istalking. Something like that; even with my minimal scripting knowledge, I might be able to make it work. But how do I get the sound file to play?

2. I'd like to be able to command an NPC to lockpick something, preferably via dialogue.

As for the second, Talkie Toaster does something similar in his wonderful Companion Share and Recruit mod. However, there is so much framework in place for it, what with the command keys and orders system; even were I to ask him for permission to use his scripts, I don't know if I could dissect it well enough to use on an individual, stand-alone companion. An illusion of lockpicking with the NPC casting a dummy spell would work, but I wouldn't know how to make them target the nearest locked object. Maybe with OBSE?

1. use a dialogue result script - pickIdle (?) and you may enable a sound (reference > make it persistent > initially disabled )
You do not need to install mods to see how they work - just dl them and open them up in the CS (or TES4EDIT)
User avatar
Amber Ably
 
Posts: 3372
Joined: Wed Aug 29, 2007 4:39 pm

Post » Sat May 28, 2011 6:06 pm

So I'm using a modified version of Reaper's Animated Lute scripts. (I'll get permission if I can get them to work.) These were initially configured for the player, but I put this in my NPC's -- OdileRef -- script.

if playlutetoggle == 1		if ( OdileRef.getitemcount a1OdileLute 1 )			OdileRef.EquipItem a1OdileLute 1			set a1OdileLuteGlobal to 1			playsound a1OdileLuteSound			OdileRef.pickidle			return		elseif ( OdileRef.getitemcount a1OdileLute 0 )		        Message "Odile doesn't have her lute."		        set playlutetoggle to 0		endifelseif playlutetoggle == 0			OdileRef.UnEquipItem a1OdileLute 1			set a1OdileLuteGlobal to 0			OdileRef.pickidle		endif


a1OdileLute is the lute item, and there is a "play the lute" idle animation set for when a1OdileLuteGlobal is set to 1. I have it set so dialogue toggles the playlutetoggle variable.

It's not working though; currently when I select the dialogue option nothing happens and I am no longer able to speak with my NPC. Panic! D=

EDIT: Essentially gave up on the above script and trying a new approach; making the lute an animobject and setting it to an AI package toggle. Also not working, and this isn't even bringing the sound aspect of it in . . . le sigh. :unsure:
User avatar
Fiori Pra
 
Posts: 3446
Joined: Thu Mar 15, 2007 12:30 pm

Post » Sat May 28, 2011 5:34 am

I think your problem is in your script syntax. You at least need to make the following edits:

if playlutetoggle == 1		if ( OdileRef.getitemcount a1OdileLute > 0 )			OdileRef.EquipItem a1OdileLute 1			set a1OdileLuteGlobal to 1			playsound a1OdileLuteSound			OdileRef.pickidle			return		else		        Message "Odile doesn't have her lute."		        set playlutetoggle to 0		endifelseif playlutetoggle == 0			OdileRef.UnEquipItem a1OdileLute 1			set a1OdileLuteGlobal to 0			OdileRef.pickidle		endif


Obviously, you'll also need to set the Idle with proper conditions so that anyone with the a1OdileLute equipped will pick that idle.

EDIT: You'll also need to make sure you end the conversation properly before this stuff happens.
User avatar
roxxii lenaghan
 
Posts: 3388
Joined: Wed Jul 05, 2006 11:53 am

Post » Sat May 28, 2011 10:53 am

Hrm. I'd use an AI package. A UseItemAt package probably, and then pick the Lute as the target object? I mean, it works for drinking or reading anims.

I'd then use a Begin OnPackageStart block to set a variable that affects an if code block in the main Begin GameMode block to get the music playing, and use a Begin OnPackageChange to stop it.

i.e.

scn Blahscriptshort willplayluteforyouBegin GameModeif willplayluteforyou == 1   (code to loop music)elseif willplayforyou == 0   (code to stop music)endifEndBegin OnPackageStart PlayLuteAIset willplayluteforyou to 1EndBegin OnPackageChange PlayLuteAIset willplayluteforyou to 0End


You'll obviously need some sort of exit to get the NPC to stop playing though. Easiest is through dialogue as they don't interrupt AI packages. Whenever the player asks them to play, simply load the PlayLuteAI, to stop, simply change the PlayLuteAI to something else (like a Wander package, or just remove the PlayLuteAI and make them resume their normal AI packages if they're common NPC's)

Haven't tried it myself, but I've used something similar successfully in some 'random' dialogue before. e.g. my companion NPC burps after eating, or says something immediately after waking up.
User avatar
matt white
 
Posts: 3444
Joined: Fri Jul 27, 2007 2:43 pm


Return to IV - Oblivion