Advertisement
Mudbill

Amnesia animation script

Jan 31st, 2017
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. /**
  2. * Loops through a series of images at the specified intervals.
  3. * asName - The name of the [name]_0.ent part of the files.
  4. * asArea - The script area in the level to play the animation at.
  5. * frameAmount - Total number of frames to play.
  6. * fps = The frames per second (speed) of the animation. Only 1-60 valid.
  7. */
  8. void StartImageAnimation(string asName, string asArea, int frameAmount, int fps) {
  9.  
  10.     /* Setup unique variables to store the data. */
  11.     SetLocalVarString("_anim_area_"+asName, asArea);
  12.     SetLocalVarInt("_anim_fps_"+asName, fps>60?60:(fps<1?1:fps));
  13.     SetLocalVarInt("_anim_frames_"+asName, frameAmount);
  14.    
  15.     /* Used to count which frame is currently played. */
  16.     SetLocalVarInt("_anim_currentframe_"+asName, 0);
  17.    
  18.     /* Call the timer which will render the frames. */
  19.     _anim_DisplayFrame(asName);
  20. }
  21.  
  22. void _anim_DisplayFrame(string &in asTimer) {
  23.    
  24.     /* Check if animation still has remaining frames to play. */
  25.     if(GetLocalVarInt("_anim_currentframe_"+asTimer)
  26.     <  GetLocalVarInt("_anim_frames_"+asTimer)) {
  27.    
  28.         /* If first loop, create a new frame entity. */
  29.         if(GetLocalVarInt("_anim_currentframe_"+asTimer) == 0) {
  30.             CreateEntityAtArea(
  31.                 "_anim_ent_"+asTimer+"_"+GetLocalVarInt("_anim_currentframe_"+asTimer),
  32.                 asTimer+GetLocalVarInt("_anim_currentframe_"+asTimer)+".ent",
  33.                 GetLocalVarString("_anim_area_"+asTimer),
  34.                 false
  35.             );
  36.         } else {
  37.        
  38.             /* If consecutive loop, replace previous frame entity. */
  39.             ReplaceEntity(
  40.                 "_anim_ent_"+asTimer+"_"+(GetLocalVarInt("_anim_currentframe_"+asTimer)-1),
  41.                 "",
  42.                 "_anim_ent_"+asTimer+"_"+GetLocalVarInt("_anim_currentframe_"+asTimer),
  43.                 asTimer+GetLocalVarInt("_anim_currentframe_"+asTimer)+".ent",
  44.                 false
  45.             );
  46.            
  47.         }
  48.         /* Increment the counter. */
  49.         AddLocalVarInt("_anim_currentframe_"+asTimer, 1);
  50.     } else {
  51.    
  52.         /* If counter has reached the end. */
  53.         SetEntityActive(
  54.             "_anim_ent_"+asTimer+"_"+(GetLocalVarInt("_anim_currentframe_"+asTimer)-1),
  55.             false
  56.         );
  57.        
  58.         /* Stop creating new timers after last frame is removed. */
  59.         return;
  60.     }
  61.    
  62.     /* Add the timer for the next frame. */
  63.     AddTimer(
  64.         asTimer,
  65.         1.0f/GetLocalVarInt("_anim_fps_"+asTimer),
  66.         "_anim_DisplayFrame"
  67.     );
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement