-- LUA Script - precede every function and global member with lowercase name of script ai_viewanimations_from = {} ai_viewanimations_to = {} ai_viewanimations_pressed = false ai_viewanimations_loop = {} ai_viewanimations_looping = {} ai_viewanimations_first_frame = {} ai_viewanimations_entity = nil ai_viewanimations_frozen = false function ai_viewanimations_angle_dist (x1, x2, z1, z2) x1 = x1 or 0 x2 = x2 or 0 z1 = z1 or 0 z2 = z2 or 0 local xdiff = x1 - x2 local zdiff = z1 - z2 local abs_xdiff = math.abs(xdiff) local abs_zdiff = math.abs(zdiff) if xdiff == 0 and zdiff == 0 then return 0, 0 end -- distance from object 1 to object 2 local dist_to_obj = math.sqrt((abs_xdiff*abs_xdiff) + (abs_zdiff*abs_zdiff)) local obj_angle = 0 -- angle from object to object, default north if abs_xdiff < 1 then if zdiff < 0 then -- straight south (ish) obj_angle = 180 end elseif abs_zdiff < 1 then if xdiff < 0 then -- straight west (ish) obj_angle = 270 else -- straight east (ish) obj_angle = 90 end else -- simple cases out of the way now for some math if xdiff > 0 then if zdiff > 0 then obj_angle = math.deg (math.asin (abs_xdiff / dist_to_obj)) else obj_angle = 90 + math.deg (math.asin (abs_zdiff / dist_to_obj)) end else if zdiff < 0 then obj_angle = 180 + math.deg (math.asin (abs_xdiff / dist_to_obj)) else obj_angle = 270 + math.deg (math.asin (abs_zdiff / dist_to_obj)) end end end return obj_angle, dist_to_obj end function ai_viewanimations_init(e) CharacterControlLimbo(e) ai_viewanimations_from[e] = 0 ai_viewanimations_to[e] = 0 ai_viewanimations_loop[e] = false ai_viewanimations_first_frame[e] = true SetAnimationSpeed(e, 0.5) end function ai_viewanimations_main(e) local angle, dist = ai_viewanimations_angle_dist(g_Entity[e]['x'], g_PlayerPosX, g_Entity[e]['z'], g_PlayerPosZ); if dist < 1000 then if ai_viewanimations_entity == nil then ai_viewanimations_entity = e elseif ai_viewanimations_entity ~= e then if math.abs(g_PlayerAngY - angle) < 10 then ai_viewanimations_entity = e ai_viewanimations_pressed = false end end end if ai_viewanimations_entity == e then CharacterControlLimbo(e) if g_MouseClick==0 and g_KeyPressE==0 and g_Scancode==0 then ai_viewanimations_pressed = false end if g_KeyPressE==1 then if g_KeyPressSHIFT==1 and not ai_viewanimations_pressed then ai_viewanimations_pressed = true if not ai_viewanimations_loop[e] then ai_viewanimations_loop[e] = true else ai_viewanimations_loop[e] = false ai_viewanimations_looping[e] = false end elseif not ai_viewanimations_pressed then ai_viewanimations_pressed = true if not ai_viewanimations_first_frame[e] then ai_viewanimations_first_frame[e] = true else ai_viewanimations_first_frame[e] = false end end end if g_KeyPressSHIFT==1 or not ai_viewanimations_pressed then if g_MouseClick==1 then StopAnimation(e) ai_viewanimations_looping[e] = false ai_viewanimations_pressed = true if ai_viewanimations_first_frame[e] then ai_viewanimations_from[e] = ai_viewanimations_from[e] + 1 if ai_viewanimations_from[e] > ai_viewanimations_to[e] then ai_viewanimations_to[e] = ai_viewanimations_from[e] end else ai_viewanimations_to[e] = ai_viewanimations_to[e] + 1 end end if g_MouseClick==2 and ai_viewanimations_from[e] > 0 then StopAnimation(e) ai_viewanimations_looping[e] = false ai_viewanimations_pressed = true if ai_viewanimations_first_frame[e] then ai_viewanimations_from[e] = ai_viewanimations_from[e] - 1 elseif ai_viewanimations_to[e] > ai_viewanimations_from[e] then ai_viewanimations_to[e] = ai_viewanimations_to[e] -1 end end end if not ai_viewanimations_loop[e] then ai_viewanimations_looping[e] = false if ai_viewanimations_first_frame[e] then SetAnimationFrame(e, ai_viewanimations_from[e]) PromptLocal (e, "frame= " .. ai_viewanimations_from[e]) else SetAnimationFrame(e, ai_viewanimations_to[e]) PromptLocal (e, "to_frame= " .. ai_viewanimations_to[e]) end else if not ai_viewanimations_looping[e] then SetAnimation(e) SetAnimationFrames(ai_viewanimations_from[e], ai_viewanimations_to[e]) LoopAnimation(e) ai_viewanimations_looping[e] = true end PromptLocal (e, "from_frame= " .. ai_viewanimations_from[e] .. " to_frame= " .. ai_viewanimations_to[e]) end if g_Scancode==50 and not ai_viewanimations_pressed then ai_viewanimations_pressed = true if not ai_viewanimations_frozen then ai_viewanimations_frozen = true FreezePlayer() HideHuds() SetPlayerWeapons(0) else ai_viewanimations_frozen = false UnFreezePlayer() ShowHuds() SetPlayerWeapons(1) end end Prompt("Mouse l/r inc/dec (+shift), E - toggle to/from (+shift to start looping)") end end