1 #using scripts\shared\util_shared;
3 #insert scripts\shared\shared.gsh;
9 return RandomInt( 100 ) >= 50;
23 function clamp( val, val_min, val_max )
31 else if (val > val_max)
54 return clamp(( (num - min_a) / (max_a - min_a) * (max_b - min_b) + min_b ), min_b, max_b);
69 function lag(desired, curr, k, dt)
73 if (((k * dt) >= 1.0) || (k <= 0.0))
80 r = curr + k * err * dt;
90 center = ( center[0]/2, center[1]/2, center[2]/2 ) + mins;
96 if ( mins[0] > point[0] )
98 mins = ( point[0], mins[1], mins[2] );
101 if ( mins[1] > point[1] )
103 mins = ( mins[0], point[1], mins[2] );
106 if ( mins[2] > point[2] )
108 mins = ( mins[0], mins[1], point[2] );
116 if ( maxs[0] < point[0] )
118 maxs = ( point[0], maxs[1], maxs[2] );
121 if ( maxs[1] < point[1] )
123 maxs = ( maxs[0], point[1], maxs[2] );
126 if ( maxs[2] < point[2] )
128 maxs = ( maxs[0], maxs[1], point[2] );
149 return (abs(vec1[0] - vec2[0]) < .001) && (abs(vec1[1] - vec2[1]) < .001) && (abs(vec1[2] - vec2[2]) < .001);
154 return (RandomFloatRange(-1 * max_length, max_length), RandomFloatRange(-1 * max_length, max_length), RandomFloatRange(-1 * max_length, max_length));
159 outvalue = ( oldangle - newangle ) % 360;
166 if ( outvalue > 180 )
168 outvalue=(outvalue-360)*-1;
176 return ( x >= 0 ? 1 : -1 );
181 return ( RandomIntRange( -1, 1 ) >= 0 ? 1 : -1 );
200 assert( isdefined( v_point ),
"v_point is a required parameter for get_dot" );
202 if ( !isdefined( b_ignore_z ) )
207 if ( !isdefined( b_normalize ) )
212 if ( !isdefined( str_direction ) )
214 str_direction =
"forward";
217 if ( !isdefined( b_use_eye ) )
221 if ( IsPlayer(
self ) )
227 v_angles =
self.angles;
228 v_origin =
self.origin;
235 if ( IsPlayer(
self ) )
237 v_angles =
self GetPlayerAngles();
240 v_angles =
self GetGunAngles();
246 v_angles = ( v_angles[ 0 ], v_angles[ 1 ], 0 );
247 v_point = ( v_point[ 0 ], v_point[ 1 ], 0 );
248 v_origin = ( v_origin[ 0 ], v_origin[ 1 ], 0 );
251 switch ( str_direction )
254 v_direction = AnglesToForward( v_angles );
258 v_direction = AnglesToForward( v_angles ) * ( -1 );
262 v_direction = AnglesToRight( v_angles );
266 v_direction = AnglesToRight( v_angles ) * ( -1 );
270 v_direction = AnglesToUp( v_angles );
274 v_direction = AnglesToUp( v_angles ) * ( -1 );
278 AssertMsg( str_direction +
" is not a valid str_direction for get_dot!" );
279 v_direction = AnglesToForward( v_angles );
283 v_to_point = v_point - v_origin;
287 v_to_point = VectorNormalize( v_to_point );
290 n_dot = VectorDot( v_direction, v_to_point );
310 assert( isdefined( v_point ),
"v_point is a required parameter for get_dot_right" );
332 assert( isdefined( v_point ),
"v_point is a required parameter for get_dot_up" );
354 assert( isdefined( v_point ),
"v_point is a required parameter for get_dot_forward" );
376 assert( isdefined( v_point ),
"v_point is a required parameter for get_dot_forward" );
377 Assert( ( IsPlayer(
self ) || IsAI(
self ) ),
"get_dot_from_eye was used on a " +
self.classname +
". Valid ents are players and AI, since they have tag_eye." );
399 assert( IsArray(
array ) );
400 assert(
array.size > 0 );
404 for ( i = 0; i <
array.size; i++ )
409 return ( total /
array.size );
424 assert( IsArray(
array ) );
425 assert(
array.size > 0 );
428 for ( i = 0; i <
array.size; i++ )
434 for ( i = 0; i < tmp.size; i++ )
436 total = total + tmp[i];
439 return Sqrt( total /
array.size );
466 x1 = 2 * RandomFloatRange( 0, 1 ) - 1;
467 x2 = 2 * RandomFloatRange( 0, 1 ) - 1;
468 w = x1 * x1 + x2 * x2;
471 w = Sqrt( ( -2.0 * Log( w ) ) / w );
474 number = mean + y1 * std_deviation;
476 if ( isdefined( lower_bound ) && number < lower_bound )
478 number = lower_bound;
481 if ( isdefined( upper_bound ) && number > upper_bound )
483 number = upper_bound;
493 lineMagSqrd = lengthsquared(lineEnd - lineStart);
495 t = ( ( ( point[0] - lineStart[0] ) * ( lineEnd[0] - lineStart[0] ) ) +
496 ( ( point[1] - lineStart[1] ) * ( lineEnd[1] - lineStart[1] ) ) +
497 ( ( point[2] - lineStart[2] ) * ( lineEnd[2] - lineStart[2] ) ) ) /
509 start_x = lineStart[0] + t * ( lineEnd[0] - lineStart[0] );
510 start_y = lineStart[1] + t * ( lineEnd[1] - lineStart[1] );
511 start_z = lineStart[2] + t * ( lineEnd[2] - lineStart[2] );
513 return (start_x,start_y,start_z);
518 vector = (
end[0] - start[0],
end[1] - start[1], 0);
530 if ( vecX == 0 && vecY == 0 )
533 if ( vecY < 0.001 && vecY > -0.001 )
536 yaw = atan( vecX / vecY );
552 for( i = 0; i < ( exp - 1 ); i++ )