Hi, everyone. Just to know: is it possible to create an NPC who lies there unconscious where you place him when he first spawns, but promptly wakes up and talks to you when you click on him, only to go back to sleep after the conversation? Are there perhaps certain lines in his 'OnSpawn' script which I need to 'uncomment'? It's a dragon NPC I've got in mind, by the way. Any help will be appreciated, thanks. :)
I think you just need to ApplyEffectToObject() an EffectSleep() on the creature in it's OnSpawn event. DURATION_TYPE_PERMANENT.
The creature mustn't be immune to sleep effects, though, which is the case for most(?) template dragons, so you'd want to make your own creature that uses a dragon appearance but isn't sleep immune.
If you want to end the sleep effect on conversation, call RemoveAmbientSleep() in OnConversation.
You can place scripts to fire when the conversation ends in the conversation editor; it's the last tab to the right; Current File; reapply the sleep effect there.
Slight improvement to the spawn script:
effect eLieDown = EffectSleep();
effect eSnore = EffectVisualEffect (VFX_IMP_SLEEP);
effect eSleep = EffectLinkEffects (eLieDown, eSnore);
ApplyEffectToObject (DURATION_TYPE_PERMANENT, eSleep, OBJECT_SELF);
Thanks so much for the help, everyone. :)
Call me dumb, but how do you remove your dragon NPC's sleep immunity?
No need for name-calling, we've all been there :-)
Go to the dragons inventory, choose the tab in the top of the inventory window that says "Natural equipment" (or Creature Items, I forget it's name)
The sleep immunity is on its "skin" (like natural armour)m, where you can remove it.
If its a blueprint you're editing, then you need to make a new skin without the sleep immunity and replace the old skin.
(If my description is too inaccurate, I'll correct it when I come home later)
/Pap
Thanks for the tip!
What I've found is that all dragon skins/hides have the quality of conferring immunity against sneak attacks, paralysis and mind-affecting spells. But nothing specifically against sleep. Or does 'sleep' come under 'mind-affecting spells'?
Sleep is a mind-affecting effect.
According to one article (which I haven't tested), you don't need to change the skin. You can overcome the immunity using ExtraordinaryEffect instead.
Thanks for the help!
Just tested everything. Didn't seem to work; the dragon NPC was as awake as ever when first encountered. :( Perhaps it's not so much a question of making him actually go to sleep, as of making him play his sleeping or dead animations? (Wait: if dragons don't sleep, then do they have sleeping animations? :) )
What I did was append to the x2_def_spawn script the ApplyEffectToObject effects as detailed in the posts above before saving the new script under a different name and using that script in the NPC's OnSpawn slot. Maybe the dragon had insomnia. :) Well, at most maybe I'll just forget the whole thing. But thanks for all the help all the same!
(EDIT: Didn't change or remove the skin, by the way. Think I'll try that!)
Changed the skin so it no longer conferred immunity to mind-affecting spells. Can't be sure if there have been some changes to the dragon's behavior; if he was sleeping, then he must be capable of sleeping while standing. :D Well, that's not exactly what I wanted; I wanted to see him lie down, with his head on the floor.
Bit of a hassle getting the thing to work, but even if it hasn't worked as I wanted it to, I guess I've still learned a few things from you fellas. And for that I'm still grateful. :)
Dragons don't actually have the "lay down" emote. Its actually "fall down" or something like that. Good to know about the immune to sleep!
But, as a non-scripter.. I found this bit of info interesting as there could be one (OnSpawn) script and then variables to apply and I was thinking of doing this with some NPCs to make areas look more "busy".
I have heard that HeartBeat scripts can be laggy, so I like to try to stay away from those.
P.S. - its my son who does all the scripting for me.
My mistake, I read in the NWN Omnibus that for dragons you need the animation ANIMATION_LOOPING_DEAD_FRONT in addition to the normal sleep code.
In such cases, where a duration has to be specified, but the intention is permanent, I like to use the following constant for legibility:
const float FOREVER = 1000000000000.0; // 1 trillion seconds = about 5000 years of gameplay
so
ActionPlayAnimation(ANIMATION_LOOPING_DEAD_FRONT, 1.0, FOREVER);
Actually, I suspect that the pose will endure while the dragon is asleep, but there's no harm in belt-and-braces.
Will try this out. Thanks! :)
It worked beautifully. Now the dragon lies peacefully on the floor. And when my PC talks to him, he promptly wakes and gets up on all fours for a chat. :)
Only one small question left: how do you make the dragon play dead again when the conversation ends?
In the conversation editor, go to the rightmost tab on the root. There are script slots for conversation normal end and abort. Just add the sleep script to both.
It worked!
Thanks, pal!