Advertisement
Saito100

Amnesia Entity Recorder and Playback

Feb 17th, 2021
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. void OnStart()
  2. {
  3.     SetEntityPlayerInteractCallback("box", "BeginRecording", true);
  4. }
  5.  
  6. void BeginRecording(string &in asEntity)
  7. {
  8.   SetLocalVarInt("array_index_" + asEntity, 0);
  9.   SetLocalVarInt("reverse_" + asEntity, 1);
  10.   AddDebugMessage("Starting recording of " + asEntity, false);
  11.   TimerRecord(asEntity);
  12. }
  13.  
  14. void TimerRecord(string &in asEntity)
  15. {
  16.   int index = GetLocalVarInt("array_index_" + asEntity);
  17.  
  18.   if (index < 600)
  19.   {
  20.     string name = "placeholder_" + asEntity + "_" + index;
  21.     CreateEntityAtArea(name, "placeholder.ent", "PlaceholderArea", false);
  22.     PlaceEntityAtEntity(name, asEntity, "", true);
  23.     AddTimer(asEntity, 0.0f, "TimerRecord");
  24.     AddLocalVarInt("array_index_" + asEntity, 1);
  25.   }
  26.   else
  27.   {
  28.     AddDebugMessage("Finished recording for " + asEntity, false);
  29.     SetPropStaticPhysics(asEntity, true);
  30.     TimerPlayback(asEntity);
  31.   }
  32. }
  33.  
  34. void TimerPlayback(string &in asEntity)
  35. {
  36.   int index = GetLocalVarInt("array_index_" + asEntity);
  37.   PlaceEntityAtEntity(asEntity, "placeholder_" + asEntity + "_" + index, "", true);
  38.  
  39.   if (GetLocalVarInt("reverse_" + asEntity) == 1)
  40.   {
  41.     if (index > 0)
  42.     {
  43.       AddLocalVarInt("array_index_" + asEntity, -1);
  44.     }
  45.     else
  46.     {
  47.       SetLocalVarInt("reverse_" + asEntity, 0);
  48.     }
  49.   }
  50.   else
  51.   {
  52.     if (index < 600)
  53.     {
  54.       AddLocalVarInt("array_index_" + asEntity, 1);
  55.     }
  56.     else
  57.     {
  58.       SetLocalVarInt("reverse_" + asEntity, 1);
  59.     }
  60.   }
  61.  
  62.   AddTimer(asEntity, 0.0f, "TimerPlayback");
  63. }
  64.  
  65. /*
  66. class Vec3
  67. {
  68.     float x;
  69.     float y;
  70.     float z;
  71. }
  72.  
  73. Vec3[] boxes(600);
  74.  
  75. void TimerRecordBoxPos(string &in asTimer)
  76. {
  77.     int index = GetLocalVarInt("array_index");
  78.     Vec3 box = boxes[index];
  79.     box.x = GetEntityPosX("box");
  80.     box.y = GetEntityPosY("box");
  81.     box.z = GetEntityPosZ("box");
  82.     boxes[index] = box;
  83.  
  84.     if (index < boxes.length() - 1)
  85.     {
  86.       AddLocalVarInt("array_index", 1);
  87.       AddTimer("loop", 0.0f, "TimerRecordBoxPos");
  88.       string log = "Box index " + index + ": X = " + box.x + ", Y = " + box.y + ", Z = " + box.z;
  89.       AddDebugMessage(log, false);
  90.     }
  91.     else
  92.     {
  93.       AddTimer("loop", 0.0f, "TimerSetBoxPos");
  94.       SetPropStaticPhysics("box", true);
  95.     }
  96. }
  97.  
  98. void TimerSetBoxPos(string &in asTimer)
  99. {
  100.     int index = GetLocalVarInt("array_index");
  101.     Vec3 box = boxes[index];
  102.     SetEntityPos("box", box.x, box.y, box.z);
  103.  
  104.     if (GetLocalVarInt("reverse") == 1)
  105.     {
  106.       if (index > 0)
  107.       {
  108.         AddLocalVarInt("array_index", -1);
  109.       }
  110.       else
  111.       {
  112.         SetLocalVarInt("reverse", 0);
  113.       }
  114.     }
  115.     else
  116.     {
  117.       if (index < boxes.length() - 1)
  118.       {
  119.         AddLocalVarInt("array_index", 1);
  120.       }
  121.       else
  122.       {
  123.         SetLocalVarInt("reverse", 1);
  124.       }
  125.     }
  126.  
  127.     AddTimer("loop", 0.0f, "TimerSetBoxPos");
  128. }
  129. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement