Spawning creature through fade in

It’s weird…When using the just the jumping from another area to this place maybe there is some fade in but it’s hardly noticeable. It’s just jerky for some reason. Maybe this is because I’m using it in the middle of a dialogue instead of at the end of one. Maybe something disturbs the animation…It wouldn’t be the first time in dialogues.

EDIT: No it looks better with my latest attempt, even if there are two instances of the character (the first version has the fade in) and looks still a bit odd:

#include "ginc_object"

void PrepForDestruction(object oTarget)
{
	SetPlotFlag(oTarget,FALSE);
    SetImmortal(oTarget,FALSE);
    AssignCommand(oTarget,SetIsDestroyable(TRUE,FALSE,FALSE));
}


void RunTheEffect()
{

//Apply visual effect to creature. Script example by Dann Pigdon 2012 from Handy_VFX. Edited by andgalf 2021.
//Requires fx_ambient_fade_in.sef by Semper put in the override folder or in a hak pak.

object oTarget = GetObjectByTag("niva");
string sVFX = "fx_ambient_fade_in.sef";
//string sVFX = "fx_ghost_glow_a8.sef";
//Assign VFX to spell id 100 (light spell)

effect eDrink = SetEffectSpellId(EffectNWN2SpecialEffectFile(sVFX), 100);
SetWeaponVisibility(oTarget, 0, 0);//Make weapons and shields invisible
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDrink, oTarget,1.5);


}

void SpawnNew()
{

object oSatyr = SpawnCreatureAtWP("niva2", "nivaappe_wp");

}

void DestroyNiva()
{

object oNiva1 = GetObjectByTag("niva");

SetCollision(oNiva1,FALSE);
PrepForDestruction(oNiva1);
DestroyObject(oNiva1,1.2);

}

void main()
{

object oNiva1 = SpawnCreatureAtWP("niva", "nivaappe_wp");


//object oNiva = GetObjectByTag("niva");
//object oWP = GetObjectByTag("nivaappe_wp");
//RunTheEffect();
//location lLocation = GetLocation(oWP);
//CreateObject(OBJECT_TYPE_CREATURE,"niva",lLocation,TRUE);
DelayCommand(0.2,DestroyNiva());


DelayCommand(1.4,SpawnNew());
//AssignCommand(oNiva, ClearAllActions());
//DelayCommand(0.6,AssignCommand(oNiva, ActionJumpToObject(oWP)));
//AssignCommand(oNiva, ActionJumpToObject(oWP));
//
//RunTheEffect();
//SetScriptHidden(oNiva,FALSE);
//DelayCommand(0.1,RunTheEffect());


}

If only there was a way to make Semper’s fade in effect not loop when using it on Appearace(Visual Effect) then everything would be solved.

@andgalf

QUOTE: If applied to Appearance (Visual Effect) it is invisible from the start, but then the animation loops instead

Do this then, and remove the effect at the end of its duration after a short delay. IE Remove sef before the effect loops again.

You’ll have to test different delays on the removal to get it right, but it sounds a delay of around 1.5 seconds is required before removal, just before it loops again.

I would also think you could delay the speed of the actual fading itself by editing the sef itself using the VFX editor. Of course, you would then need to ensure the delay for removing the sef matches any new speed you adjust to.

1 Like

there might even be a ‘no loop’ or ‘playonce’ or somethin that amounts to the same thing in the VFX editor (idk)

1 Like

@kevL_s

You beat me to it :grinning: … I was going to suggest looking for the same, but I can’t recall all the various options in the editor myself.

1 Like

Thanks for the replies, guys!

All of your points are sound and logical. However, I have no idea how to remove a Appearance(Visual Effect) on a creature. Maybe it’s simple, but to me it seems like it’s something that’s attached to it forever.
That’s why I went the route that Semper originally suggested of adding the effect through a script but that didn’t quite have the desired effect.

I haven’t found one, but it would be logical that there is one. If you know how to do it, please tell me.

EDIT: I tried to alter my script to this, but it doesn’t remove the Appearance effect (just as I thought)

#include "ginc_object"

// Removes all effects from a given creature.
void RemoveAllEffects(object oCreature)
{
	effect eLoop = GetFirstEffect(oCreature);
	while (GetIsEffectValid(eLoop))
	{
		RemoveEffect(oCreature, eLoop);
		eLoop = GetFirstEffect(oCreature); // go back to the 'first' effect each time.
	}
}


void main()
{

object oNiva1 = SpawnCreatureAtWP("niva", "nivaappe_wp");

object oNiva = GetObjectByTag("niva");

DelayCommand(2.0, RemoveAllEffects(oNiva));



}

EDIT2: Wait a minute! I just found a function that could be what I’m looking for:
void RemoveSEFFromObject( object oObject, string sSEFName );

EDIT3: I still doesn’t work! What the heck! I did it like this both with the suffix .sef and without it in the string name, but it won’t remove it. Man, this is frustrating!

#include "ginc_object"

// Removes all effects from a given creature.
void RemoveAllEffects(object oCreature)
{
	effect eLoop = GetFirstEffect(oCreature);
	while (GetIsEffectValid(eLoop))
	{
		RemoveEffect(oCreature, eLoop);
		eLoop = GetFirstEffect(oCreature); // go back to the 'first' effect each time.
	}
}

void RemoveSEF()
{

object oNiva = GetObjectByTag("niva");

RemoveSEFFromObject(oNiva,"fx_ambient_fade_in.sef");



}

void main()
{

object oNiva1 = SpawnCreatureAtWP("niva", "nivaappe_wp");



DelayCommand(2.0, RemoveSEF());



}

@Lance_Botelle - Since nothing seems to work here, would it be possible to try and remove the sef by xml coding? Or maybe if it doesn’t work with normal scripting, it wouldn’t work with that either? Just asking…

@andgalf

As it is a sef, the remove sef from object function is the one to use and should work.

I’ll take a closer look at your script when at main computer.

Edit: Make sure “niva” is unique.

1 Like

Yep. I don’t understand why it doesn’t.

It is.

@andgalf

EDIT: Actually, as far as I can see, creatures appear to “fade in” by default anyway. i.e. Even without this script, a creature fades in at around that speed. i.e. My own creatures do NOT instantly appear without this script, but fade in …

Otherwise, for a slightly longer “fade in”, here is what I did …

This worked for me when added to the creatures OnSpawn script … i.e. I avoid the use of having to “remove” it after application by simply making it temporary in the first place. This addition to a creature’s OnSpawn will make it “fade in” as you create it …

effect eVis = EffectNWN2SpecialEffectFile("fx_ambient_fade_in");		
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, OBJECT_SELF, 1.5);

And these settings on the “Fade In” figures, make the fade a little longer … feels slightly “longer” to me.

Here is my full OnSpawn addition to ensure only those with a variable set do the fade in …

    ///////////////////////////////////////////////////////////////////////////////////////////////////
	// FADE IN EFFECT
	///////////////////////////////////////////////////////////////////////////////////////////////////
	 
	if(GetLocalInt(OBJECT_SELF, "FADEIN"))
	{
		effect eVis = EffectNWN2SpecialEffectFile("fx_ambient_fade_in");		
		ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, OBJECT_SELF, 1.5);
	}

Well, since I can’t remove the sef this doesn’t help much.

Well, mine do so…

I’ll test the OnSpawn thing then.

@andgalf

Well, that is interesting … I wonder what the difference is that makes your creatures “instant” appear and my own “fade in” by default then?

I’ll see if I have anything else going on … although, nothing obvious comes to mind just yet.

For the record, I am spawning a creature using this … via a “lever pull” script.

CreateObject(OBJECT_TYPE_CREATURE, "alb_npc_agnes", GetLocation(OBJECT_SELF));

At first it seemed like the OnSpawn you did worked quite well for me. Then I added the other effect, the effect really need to have on the creature, and then it was behaving oddly again by “double fading in” the character in a jerky way. I’m so tired of this.

I have this creature spawn in the middle of a conversation. On the same node that this is happening I have this script:

#include "ginc_object"

void main()
{

object oCreature = SpawnObjectAtWP(OBJECT_TYPE_PLACED_EFFECT,"fx_okku_l","nivaa_wp",FALSE,"fx_okku_l");

}

And the effect that I have on the creature that is to fade in is this:

fx_ghost_glow_a8.7z (627 Bytes)

I took the stock onspawn script and just added your code on top so it looks like this:

// NW_C2_DEFAULT9
/*
    Default OnSpawn handler
 
    To create customized spawn scripts, use the "Custom OnSpawn" script template. 
*/
//:://////////////////////////////////////////////////
//:: Copyright (c) 2002 Floodgate Entertainment
//:: Created By: Naomi Novik
//:: Created On: 12/11/2002
//:://////////////////////////////////////////////////
//:: Updated 2003-08-20 Georg Zoeller: Added check for variables to active spawn in conditions without changing the spawnscript
// ChazM 6/20/05 ambient anims flag set on spawn for encounter cratures.
// ChazM 1/6/06 modified call to WalkWayPoints()
// DBR 2/03/06  Added option for a spawn script (AI stuff, but also handy in general)
// ChazM 8/22/06 Removed reference to "kinc_globals".
// ChazM 3/8/07 Added campaign level creature spawn modifications script.  Moved excess commented code out to template.
// ChazM 4/5/07 Incorporeal creatures immune to non magic weapons
// JSH-OEI 5/1/08 - Check creature type before spawning random treasure.

#include "x0_i0_anims"
#include "x0_i0_treasure"
#include "x2_inc_switches"

void main()
{

	effect eVis = EffectNWN2SpecialEffectFile("fx_ambient_fade_in");		
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, OBJECT_SELF, 1.5);
	
    // Run this campaign's standard creature spawn modifications script (set in module load)
    string sScriptSpawnCreature = GetGlobalString("N2_SCRIPT_SPAWN_CREATURE");
    if (sScriptSpawnCreature != "")
    {
		ExecuteScript(sScriptSpawnCreature, OBJECT_SELF);
    }

    // ***** Spawn-In Conditions ***** //
    // See x2_inc_switches for more information about these
    
    // Enable stealth mode by setting a variable on the creature
    // Great for ambushes
    if (GetCreatureFlag(OBJECT_SELF, CREATURE_VAR_USE_SPAWN_STEALTH) == TRUE)
    {
        SetSpawnInCondition(NW_FLAG_STEALTH);
    }
    
    // Make creature enter search mode after spawning by setting a variable
    // Great for guards, etc
    if (GetCreatureFlag(OBJECT_SELF, CREATURE_VAR_USE_SPAWN_SEARCH) == TRUE)
    {
        SetSpawnInCondition(NW_FLAG_SEARCH);
    }

    // Enable immobile ambient animations by setting a variable
    if (GetCreatureFlag(OBJECT_SELF, CREATURE_VAR_USE_SPAWN_AMBIENT_IMMOBILE) == TRUE)
    {
        SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS);
    }

    // Enable mobile ambient animations by setting a variable
    if (GetCreatureFlag(OBJECT_SELF, CREATURE_VAR_USE_SPAWN_AMBIENT) == TRUE)
    {
        SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
    }

    // ***** DEFAULT GENERIC BEHAVIOR ***** //
    // * Goes through and sets up which shouts the NPC will listen to.
    SetListeningPatterns();

    // * Walk among a set of waypoints if they exist.
    // * 1. Find waypoints with the tag "WP_" + NPC TAG + "_##" and walk
    // *    among them in order.
    // * 2. If the tag of the Way Point is "POST_" + NPC TAG, stay there
    // *    and return to it after combat.
    //
    // * If "NW_FLAG_DAY_NIGHT_POSTING" is set, you can also
    // * create waypoints with the tags "WN_" + NPC Tag + "_##"
    // * and those will be walked at night. (The standard waypoints
    // * will be walked during the day.)
    // * The night "posting" waypoint tag is simply "NIGHT_" + NPC tag.
    WalkWayPoints(FALSE, "spawn");
    
    //* Create a small amount of treasure on the creature
    if (GetLocalInt(GetModule(), "X2_L_NOTREASURE") == FALSE
        && GetLocalInt(OBJECT_SELF, "X2_L_NOTREASURE") == FALSE
		&& GetRacialType(OBJECT_SELF) != RACIAL_TYPE_ANIMAL
		&& GetRacialType(OBJECT_SELF) != RACIAL_TYPE_BEAST
		&& GetRacialType(OBJECT_SELF) != RACIAL_TYPE_CONSTRUCT
		&& GetRacialType(OBJECT_SELF) != RACIAL_TYPE_ELEMENTAL
		&& GetRacialType(OBJECT_SELF) != RACIAL_TYPE_VERMIN)
    {
		if (GetChallengeRating(OBJECT_SELF) <= 5.0)
		{
        	CTG_GenerateNPCTreasure(TREASURE_TYPE_LOW, OBJECT_SELF);
		}
		else if (GetChallengeRating(OBJECT_SELF) >5.0 && GetChallengeRating(OBJECT_SELF) <=10.0)
		{
			CTG_GenerateNPCTreasure(TREASURE_TYPE_MED, OBJECT_SELF);
		}
		else
		{
			CTG_GenerateNPCTreasure(TREASURE_TYPE_HIGH, OBJECT_SELF);
		}
    }
    
    // encounter creatures use ambient animations
    if (GetIsEncounterCreature())
		SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS, TRUE);

    // * If Incorporeal, apply changes
    if (GetCreatureFlag(OBJECT_SELF, CREATURE_VAR_IS_INCORPOREAL) == TRUE)
    {
        effect eConceal = EffectConcealment(50, MISS_CHANCE_TYPE_NORMAL);
        eConceal = ExtraordinaryEffect(eConceal);
        effect eGhost = EffectCutsceneGhost();
        eGhost = ExtraordinaryEffect(eGhost);
        effect eImmuneToNonMagicWeapons = EffectDamageReduction(1000, DAMAGE_POWER_PLUS_ONE, 0, DR_TYPE_MAGICBONUS);
        eImmuneToNonMagicWeapons = ExtraordinaryEffect(eImmuneToNonMagicWeapons);
		
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eConceal, OBJECT_SELF);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eGhost, OBJECT_SELF);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eImmuneToNonMagicWeapons, OBJECT_SELF);
    }	
	
	if (GetLocalInt(OBJECT_SELF, "NX2_NO_ORIENT_ON_DIALOG"))
		SetOrientOnDialog(OBJECT_SELF, FALSE);
    	
	//DBR 2/03/06 - added option for a spawn script (ease of AI hookup)
	string sSpawnScript=GetLocalString(OBJECT_SELF,"SpawnScript");
	if (sSpawnScript!="")
		ExecuteScript(sSpawnScript,OBJECT_SELF);
		

}

I think the conversation thing might be the biggest culprit in this fading. Conversations have screwed with animations before for me.

Now I need to get out of the building a bit. Can’t stand being inside nomore right now. I’m going for a bike ride I think. Be back in an hour or something like that…

@Lance_Botelle - Anyway, big thanks for trying to help me!

@andgalf

You need to do it like this then … Note I have left the variable check in place, which you can remove/not use/comment out. (I just commented it out for you in the example below.)

NB: REMOVE the effect from the creature template and allow script to manage it.

    ///////////////////////////////////////////////////////////////////////////////////////////////////
	// FADE IN EFFECT
	///////////////////////////////////////////////////////////////////////////////////////////////////
	 
	//if(GetLocalInt(OBJECT_SELF, "FADEIN"))
	{
		effect eVis = EffectNWN2SpecialEffectFile("fx_ambient_fade_in");		
		ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, OBJECT_SELF, 1.5);

        eVis = EffectNWN2SpecialEffectFile("fx_ghost_glow_a8");		
		DelayCommand(1.5, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eVis, OBJECT_SELF));
	}

You must allow the temporary fade in effect to finish within its allotted duration and then add the permanent one.

Although, as far as I can, all you need to do is this (if you don’t need the extra long delay beyond the default fade in) …

effect eVis = EffectNWN2SpecialEffectFile("fx_ghost_glow_a8");		
		DelayCommand(1.5, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eVis, OBJECT_SELF));

Ok, I’ll try it.

Now we’re almost there. This looks the best so far. Sometimes though there’s still a little glitch just before the spawn of the creature. I’m wondering if that’s because of the object I spawn just before on the same node.

I think it will be just a case of including or excluding the front end fade, and then messing around with the delay figures for timing. Just remember not to have any effect on the creature in the toolset prior spawning. i.e. Add and remove the effects via scripting only. (In my own test usage, there was no glitch that I could see.)

What do you mean? How do I exclude the front end fade?

Weird thing is: Sometimes there is no glitch just when it’s about to spawn the creature. Then I did a movie so that you could see what happens on my end. When I played there was a glitch, but in the movie I can’t see it strangely enough. Maybe the frame rate of the video capture program is not high enough for it to capture it…

If I had to guess the glitch could absolutely have to do with some other stuff that is happening in the dialogue, like a creature looking elsewhere or something odd…

As I mean in the script post above where one has the “fx_ambient_fade_in” effect just prior the “fx_ghost_glow_a8” effect, or without the fade in and just use the “fx_ghost_glow_a8” effect by itself as the creature appears to fade in anyway without the initial vfx. The only real advantage of the fade prior is to make it seem slightly longer.

Try the script without the fade in part, like this …

Again, mine doesn’t fade in without this.

But sure, just to humor you, I’ll try it out.

EDIT: Tested it. Just as I thought. Now she appears instantly without any fade in at all. Have you tried in the middle of a conversation on your end?

OK … Most strange … maybe it’s something to do with being done from a conversation.

If you have the time to test, try spawning the creature from a lever script rather than during a conversation to see if it makes any difference to the creature’s initial appearing.

OR … maybe now we have removed the VFX from the build creature, the delayed VFX will work as expected. i.e. It’s important that no VFX is on the creature prior its spawning.