1 #using scripts\codescripts\struct;
2 #using scripts\shared\array_shared;
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\system_shared;
5 #using scripts\shared\util_shared;
7 #insert scripts\shared\shared.gsh;
13 #namespace clientfaceanim;
17 #define FACIAL_STATE_COMBAT "combat"
18 #define FACIAL_STATE_COMBAT_SHOOT "combat_shoot"
19 #define FACIAL_STATE_DEATH "death"
20 #define FACIAL_STATE_MELEE "melee"
21 #define FACIAL_STATE_PAIN "pain"
22 #define FACIAL_STATE_SWIMMING "swimming"
23 #define FACIAL_STATE_JUMPING "jumping"
24 #define FACIAL_STATE_SLIDING "sliding"
25 #define FACIAL_STATE_SPRINTING "sprinting"
26 #define FACIAL_STATE_WALLRUNNING "wallrunning"
28 #define FACIAL_STATE_INACTIVE "inactive"
29 #define FACIAL_SYSTEM_FADE_DIST 1000
30 #define FACIAL_SYSTEM_FADE_DISTSQ 1000 * 1000
52 self notify(
"stopFacialThread");
54 corpse =
self GetPlayerCorpse();
55 if ( !isDefined( corpse ) )
57 if (
IS_TRUE( corpse.facialDeathAnimStarted ) )
61 if ( isDefined( corpse ) )
64 corpse.facialDeathAnimStarted =
true;
71 self endon(
"entityshutdown");
72 self waittill(
"death");
76 self notify(
"stopFacialThread");
78 corpse =
self GetPlayerCorpse();
79 if (
IS_TRUE( corpse.facialDeathAnimStarted ) )
83 if ( isDefined( corpse ) )
86 corpse.facialDeathAnimStarted =
true;
103 if( !IsDefined( level.__clientFacialAnimationsList ) )
105 level.__clientFacialAnimationsList = [];
107 level.__clientFacialAnimationsList[
FACIAL_STATE_COMBAT] =
array(
"ai_face_male_generic_idle_1",
"ai_face_male_generic_idle_2",
"ai_face_male_generic_idle_3" );
109 level.__clientFacialAnimationsList[
FACIAL_STATE_DEATH] =
array(
"ai_face_male_death_1",
"ai_face_male_death_2",
"ai_face_male_death_3" );
121 foreach( deathAnim
in deathAnims )
123 assert( !IsAnimLooping( localClientNum, deathAnim ),
"FACIAL ANIM - Death facial animation " + deathAnim +
" is set to looping in the GDT. It needs to be non-looping." );
130 if ( !isdefined( localClientNum ) )
136 min_wait_distance_sq = 50 * 50;
137 max_wait_distance_sq = 800 * 800;
139 local_player = GetLocalPlayer( localClientNum );
141 if ( !isdefined( local_player ) )
144 if ( local_player ==
self && !IsThirdPerson( localClientNum ) )
147 distanceSq = DistanceSquared( local_player.origin,
self.origin );
149 if ( (distanceSq > max_wait_distance_sq) )
151 else if ( (distanceSq < min_wait_distance_sq) )
154 distance_factor = (distanceSq - min_wait_distance_sq) / (max_wait_distance_sq - min_wait_distance_sq);
156 return ((max_wait - min_wait) * distance_factor) + min_wait;
161 self endon (
"entityshutdown");
162 self notify(
"stopFacialThread");
163 self endon(
"stopFacialThread");
166 if( IsDefined(
self.__clientFacialAnimationsThinkStarted ) )
169 self.__clientFacialAnimationsThinkStarted =
true;
171 assert(
self IsPlayer() );
175 while( isdefined(
self ) )
189 if ( !isdefined( player ) )
192 if ( !isdefined( localClientNum ) )
195 if( !IsDefined( player._currentFaceState ) )
198 currFaceState = player._currentFaceState;
199 nextFaceState = player._currentFaceState;
201 if( player IsInScritpedAnim() )
209 if( player IsPlayerDead() )
213 else if( player IsPlayerFiring() )
217 else if( player IsPlayerSliding() )
221 else if( player IsPlayerWallRunning() )
226 else if( player IsPlayerSprinting() )
230 else if( player IsPlayerJumping() || player IsPlayerDoubleJumping() )
234 else if( player IsPlayerSwimming() )
245 Assert( IsDefined( level.__clientFacialAnimationsList[nextFaceState] ) );
247 ApplyNewFaceAnim( localClientNum, array::random( level.__clientFacialAnimationsList[nextFaceState] ) );
248 player._currentFaceState = nextFaceState;
256 if( IsDefined( animation ) )
258 self._currentFaceAnim = animation;
259 self SetFlaggedAnimKnob(
"ai_secondary_facial_anim", animation, 1.0, 0.1, 1.0 );
268 if( IsDefined(
self ) && IsDefined( level.__clientFacialAnimationsList ) && IsDefined( level.__clientFacialAnimationsList[
FACIAL_STATE_DEATH] ) )
277 if( IsDefined(
self._currentFaceAnim ) &&
self hasdobj(localClientNum) )
279 self ClearAnim(
self._currentFaceAnim, 0.2 );
281 self._currentFaceAnim = undefined;