untyped global function PlayAnimTeleport global function PlayAnim global function GetAnim global function HasAnim global function SetAnim global function GetAnimStartInfo global function GetRefPosition global function __PlayAnim global function TeleportToAnimStart // anim teleport function PlayAnimTeleport( guy, animation_name, reference = null, optionalTag = null, initialTime = -1.0 ) { if ( type( guy ) == "array" || type( guy ) == "table" ) { Assert( reference, "NO reference" ) entity firstEnt foreach ( ent in guy ) { if ( !firstEnt ) firstEnt = expect entity( ent ) TeleportToAnimStart( ent, animation_name, reference, optionalTag ) __PlayAnim( ent, animation_name, reference, optionalTag, 0 ) if ( initialTime > 0.0 ) guy.Anim_SetInitialTime( initialTime ) } Assert( IsValid( firstEnt ) ) WaittillAnimDone( firstEnt ) } else { if ( !reference ) reference = guy expect entity( guy ) TeleportToAnimStart( guy, animation_name, reference, optionalTag ) __PlayAnim( guy, animation_name, reference, optionalTag, 0 ) if ( initialTime > 0.0 ) guy.Anim_SetInitialTime( initialTime ) WaittillAnimDone( guy ) } } // play the anim function PlayAnim( guy, animation_name, reference = null, optionalTag = null, blendTime = DEFAULT_SCRIPTED_ANIMATION_BLEND_TIME, initialTime = -1.0 ) { if ( type( guy ) == "array" ) { foreach ( ent in guy ) { __PlayAnim( ent, animation_name, reference, optionalTag, blendTime ) if ( initialTime > 0.0 ) guy.Anim_SetInitialTime( initialTime ) } WaittillAnimDone( expect entity( guy[0] ) ) } else { __PlayAnim( guy, animation_name, reference, optionalTag, blendTime ) if ( initialTime > 0.0 ) guy.Anim_SetInitialTime( initialTime ) WaittillAnimDone( expect entity( guy ) ) } } function GetAnim( guy, animation ) { if ( !( "anims" in guy.s ) ) return animation if ( !( animation in guy.s.anims ) ) return animation return guy.s.anims[ animation ] } function HasAnim( guy, animation ) { if ( !( "anims" in guy.s ) ) return false return animation in guy.s.anims } function SetAnim( guy, name, animation ) { if ( !( "anims" in guy.s ) ) guy.s.anims <- {} Assert( !( name in guy.s.anims ), guy + " already has set anim " + name ) guy.s.anims[ name ] <- animation } AnimRefPoint function GetAnimStartInfo( entity ent, string animAlias, animref ) { string animData = expect string( GetAnim( ent, animAlias ) ) AnimRefPoint animStartInfo = ent.Anim_GetStartForRefPoint( animData, animref.GetOrigin(), animref.GetAngles() ) return animStartInfo } function GetRefPosition( reference ) { Assert( reference.HasKey( "model" ) && reference.kv.model != "", "Tried to play an anim relative to " + reference + " but it has no model/ref attachment." ) local position = {} local attach_id attach_id = reference.LookupAttachment( "REF" ) if ( attach_id ) { position.origin <- reference.GetAttachmentOrigin( attach_id ) position.angles <- reference.GetAttachmentAngles( attach_id ) } return position } // play the anim function __PlayAnim( guy, animation_name, reference = null, optionalTag = null, blendTime = DEFAULT_SCRIPTED_ANIMATION_BLEND_TIME ) { expect entity( guy ) Assert( IsValid_ThisFrame( guy ), "Invalid ent sent to PlayAnim " + animation_name ) local animation = GetAnim( guy, animation_name ) //guy.SetNextThinkNow() <- SetNextThinkNow() doesn't exist on the client if ( reference ) { if ( reference == guy ) { local position = GetRefPosition( reference ) local origin = position.origin local angles = position.angles guy.Anim_PlayWithRefPoint( animation, origin, angles, blendTime ) return } if ( optionalTag ) { if ( typeof( reference ) == "vector" ) { Assert( typeof( optionalTag ) == "vector", "Expected angles but got " + optionalTag ) guy.Anim_PlayWithRefPoint( animation, reference, optionalTag, blendTime ) return } Assert( typeof( optionalTag ) == "string", "Passed invalid optional tag " + optionalTag ) if ( guy.GetParent() == reference ) { guy.Anim_Play( animation ) } else { local attachIndex = reference.LookupAttachment( optionalTag ) local origin = reference.GetAttachmentOrigin( attachIndex ) local angles = reference.GetAttachmentAngles( attachIndex ) //local animStartPos = guy.Anim_GetStartForRefEntity_Old( animation, reference, optionalTag ) //local origin = animStartPos.origin //local angles = animStartPos.angles guy.Anim_PlayWithRefPoint( animation, origin, angles, blendTime ) } return } } else { Assert( optionalTag == null, "Reference was null, but optionalTag was not. Did you mean to set the tag?" ) } if ( reference != null && guy.GetParent() == reference ) { guy.Anim_Play( animation ) return } if ( !reference ) reference = guy local origin = reference.GetOrigin() local angles = reference.GetAngles() guy.Anim_PlayWithRefPoint( animation, origin, angles, blendTime ) } function TeleportToAnimStart( guy, animation_name, reference, optionalTag = null ) { return //<- need code feature because Anim_GetStartForRefEntity_Old doesn't exist on client Assert( reference, "NO reference" ) local animation = GetAnim( guy, animation_name ) local animStartPos if ( optionalTag ) { // this command doesnt exist yet animStartPos = guy.Anim_GetStartForRefEntity_Old( animation, reference, optionalTag ) } else { //printt( "Reference is " + reference ) //printt( "guy is " + guy ) //printt( "animation is " + animation ) local origin = reference.GetOrigin() local angles = reference.GetAngles() animStartPos = guy.Anim_GetStartForRefPoint_Old( animation, origin, angles ) } Assert( animStartPos, "No animStartPos for " + animation + " on " + guy ) // hack! shouldn't need to do this animStartPos.origin = ClampToWorldspace( expect vector( animStartPos.origin ) ) guy.SetOrigin( animStartPos.origin ) guy.SetAngles( animStartPos.angles ) }