In case anyone else wants to utilize this code. I have completely refactored the code and it now provides four functions instead of two. You can now fade in only, fade out only, fade and spawn, and fade and spawn forced for those tricky places where something would fail to spawn. In my code you can also see I do specific checks to certain actor classes to get the target alpha. This will need to be taken into consideration when spawning your own monsters. In classic Doom, the Spectre and Lost Soul are the only two to consider. The Spectre always has a default alpha of 0.5 and the Lost Soul can vary depending on the transsouls CVAR. These scripts take both into consideration.
This source is set up for use in vanilla Doom. Adding new condition checks should be obvious to any experienced ACS coder. Basically where the script is checking actor classes, you will need to change these checks to reflect your custom monsters. You can also control the length of the fade effect by changing the FADE_TICS constant. Currently the script is set up by default to take one second (or 35 tics) to fade in. The fading is completely secondary to the spawning, so nothing waits on the fade to finish. All important actions happen before the fading begins, so killing monsters early should not cause problems.
NOTE: There is an issue with Spectres that cannot be solved and thus is forced in the script. If you use a fuzz renderstyle for them in your preferences the fading will NOT work, ever. If the style is set to anything other than Translucent, the Spectre will simply instantly appear. So, to counter this the script always forces the renderstyle to translucent and then returns it to your setting for OptFuzzy upon finishing. For a smooth effect, it is suggested that you set "use fuzz effect" to translucent!
DOWNLOADS:
SOURCE TEXT DOWNLOAD: EXAMPLE WAD (UDMF, Doom 2): SOURCE:
Code: Select all
/* --- FADING THINGS IN AND OUT V5 ------------------------------------------------------------- */
/* USAGE AND EXAMPLES:
IMPORTANT NOTE: It is critical that you separate out newTIDs between actors with different alpha
values or renderstyles. You will get undesirable results if you try to spawn things with a preset
alpha value with the same newTID of a thing with a normal renderstyle. The last thing to spawn
will get priority and all previous actors sharing the same newTID will be affected. This means
that you should always give different newTIDs to things which have different renderstyles/alphas.
USAGE:
{
Thing_FadeIn(int tid);
tid = thing ID of any thing to fade in, usually one previously faded out
Thing_FadeSpawn(int spotTID, int spawnID, int newTID);
spotTID = MapSpot or TID of the thing to spawn the new thing at
spawnID = the spawnID or T_ name identifier of the thing to spawn
newTID = the new TID to give the spawned thing, if 0 a unique TID is assigned
Thing_FadeSpawnForced(int spotTID, str className, int newTID);
spotTID = MapSpot or TID of the thing to force spawn the new thing at
className = the class name of the actor to be spawned
newTID = the new TID to give the spawned thing, if 0 a unique TID is assigned
Thing_FadeOut(int thingID, bool keepThing);
thingID = the TID of the thing to fade out
keepThing = set to 1 to only fade out the thing, 0 will also remove the thing
}
EXAMPLES:
{
Thing_FadeIn(1);
Fades in any thing with a TID of 1, should be used on a thing with TID of 1 that was faded out
Thing_FadeSpawn(1, T_IMP, 0);
Fades in a normal Imp at MapSpot 1, then assigns a unique newTID to the spawned thing
Thing_FadeSpawnForced(1, "DoomImp", 42);
Fades in a normal Imp at MapSpot 1 with a preset newTID of 42
Thing_FadeOut(42, 0);
Fades out the Imp that would have been faded in from above and then removes it from the map
}
*/
#define FADE_TICS 35
#define FADE_AMOUNT (1.0 / FADE_TICS)
// Script for fading in any thing
script 998 (int tid)
{
int targetAlpha = 0.0;
int currentAlpha = 0.0;
int renderStyle = 0;
if(CheckActorClass(tid, "Spectre")) targetAlpha = 0.50;
else if(CheckActorClass(tid, "LostSoul")) targetAlpha = GetCVar("transsouls");
else targetAlpha = 1.0;
int fadeStep = FixedMul(FADE_AMOUNT, targetAlpha);
Thing_Activate(tid);
SoundSequenceOnActor(tid, "SpawnThing");
SetActorProperty(tid, APROP_RenderStyle, STYLE_Translucent);
SetActorProperty(tid, APROP_Alpha, currentAlpha);
for(int counter = 0; counter < FADE_TICS; counter++)
{
currentAlpha += fadeStep;
if(targetAlpha < currentAlpha) currentAlpha = targetAlpha;
SetActorProperty(tid, APROP_Alpha, currentAlpha);
Delay(1);
}
if(CheckActorClass(tid, "Spectre")) renderStyle = STYLE_OptFuzzy;
else if(CheckActorClass(tid, "LostSoul")) renderStyle = STYLE_SoulTrans;
else renderStyle = STYLE_Normal;
SetActorProperty(tid, APROP_Alpha, targetAlpha);
SetActorProperty(tid, APROP_RenderStyle, renderStyle);
}
// Script for fading out any thing and optionally removing it
script 999 (int thingID, int keepThing)
{
int currentAlpha = GetActorProperty(thingID, APROP_Alpha);
int fadeStep = FixedMul(FADE_AMOUNT, currentAlpha);
int targetAlpha = 0.0;
Thing_Deactivate(thingID);
SetActorProperty(thingID, APROP_RenderStyle, STYLE_Translucent);
for(int counter = 0; counter < FADE_TICS; counter++)
{
currentAlpha -= fadeStep;
if(targetAlpha > currentAlpha) currentAlpha = targetAlpha;
SetActorProperty(thingID, APROP_Alpha, currentAlpha);
Delay(1);
}
SetActorProperty(thingID, APROP_Alpha, targetAlpha);
if(keepThing == 0) Thing_Remove(thingID);
}
// Functions for fading in and out
function void Thing_FadeIn (int tid)
{
ACS_ExecuteWithResult(998, tid);
}
function void Thing_FadeSpawn (int spotTID, int spawnID, int newTID)
{
if(newTID == 0) newTID = UniqueTID();
Thing_SpawnFacing(spotTID, spawnID, 1, newTID);
ACS_ExecuteWithResult(998, newTID);
}
function void Thing_FadeSpawnForced (int spotTID, str className, int newTID)
{
if(newTID == 0) newTID = UniqueTID();
SpawnSpotFacingForced(className, spotTID, newTID);
ACS_ExecuteWithResult(998, newTID);
}
function void Thing_FadeOut (int thingID, int keepThing)
{
ACS_ExecuteWithResult(999, thingID, keepThing);
}
Code: Select all
:SpawnThing
play misc/teleport
nostopcutoff
attenuation normal
end
NOTES:
There is only one major drawback to this and it should be obvious like it is to me now, if you plan to use new TIDs you will need to manually separate those out when doing the spawning. So spawning a translucent monster with a newTID of 33 and then spawning something like a ZombieMan with the same newTID will cause the translucent monster to have their alpha moved up to the wrong value. They will need different newTIDs. If you are using a map where you need to do a ThingCount, you will need to do an additive count like so:
Code: Select all
While((ThingCount(T_NONE, 1) + ThingCount(T_NONE, 2) + ThingCount(T_NONE, 3)) > 0)
//do stuff
Code: Select all
script 1 (void)
{
int s1tid1 = UniqueTID();
int s1tid2 = UniqueTID();
int s1tid3 = UniqueTID();
Delay(5);
Thing_FadeSpawn(1, T_IMP, s1tid1);
Thing_FadeSpawn(2, T_SPECTRE, s1tid2);
Thing_FadeSpawn(3, T_LOSTSOUL, s1tid3);
Delay(10);
While((ThingCount(T_NONE, s1tid1) + ThingCount(T_NONE, s1tid2) + ThingCount(T_NONE, s1tid3)) > 0) Delay(10);
Delay(35);
Door_Open(16, 64, 0);
}
There may be another special case where you fade in and spawn some things with newTID of 255 for example. This is all good and fine but what if you want to spawn more with the same newTID to use for a ThingCount before the previous 255's are all dead? What will happen is the others you spawned first will still be set at 255 since things don't lose their TIDs when they die and they will re-fade in again. They won't spawn again since the spot they spawn and their new TID are always separate, but they will fade in again. In this case, you will need to use separate newTIDs even if they should be the same, and then do an additive ThingCount as shown above.
After the ThingCount condition has passed and the actors with those newTIDs are no longer needed, you could do something like this after all is said and done, that is if you plan to spawn more later with the same newTID yet again:
Code: Select all
Thing_ChangeTID(255, 0);
CREDITS:
- Kaiser and Agent Spork for the original fade in version
- Me for the original fade out version
- Original code taken from Scalliano's TOP mod
- Thanks to KeksDose for helping build this better version
- Example map made by me