Advertisement
ZoriaRPG

ZScript: Rewind NPC Template v2

Jul 6th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.50 KB | None | 0 0
  1. const int NPCM_HISTORY_PTR = 15;
  2. const int NPC_HISTORY_ROLLS = 23;
  3.  
  4. npc script foo{
  5.     void run(){
  6.         int history_index = -1;
  7.         int hp_history[600];
  8.         int x_history[600];
  9.         int y_history[600];
  10.         int z_history[600];
  11.         int jump_history[600];
  12.         int dir_history[600];
  13.         int misc_00_history[600];
  14.         int misc_01_history[600];
  15.         int misc_02_history[600];
  16.         int misc_03_history[600];
  17.         int misc_04_history[600];
  18.         int misc_05_history[600];
  19.         int misc_06_history[600];
  20.         int misc_07_history[600];
  21.         int misc_08_history[600];
  22.         int misc_09_history[600];
  23.         int misc_10_history[600];
  24.         int misc_11_history[600];
  25.         int misc_12_history[600];
  26.         int misc_13_history[600];
  27.         int misc_14_history[600];
  28.         int misc_15_history[600];
  29.        
  30.         //int rolls;
  31.        
  32.         int history_ptrs[]={history_index, hp_history, x_history, y_history, z_history,
  33.             jump_history, dir_history, misc_00_history, misc_01_history,
  34.             misc_02_history, misc_03_history, misc_04_history, misc_05_history,
  35.             misc_06_history, misc_07_history, misc_08_history, misc_09_history,
  36.             misc_10_history, misc_11_history, misc_12_history, misc_13_history,
  37.             misc_14_history, misc_15_history, 0 };
  38.            
  39.         int Q[16]; int tempptr;
  40.            
  41.         npc n = Screen->CreateNPC(foo); //Replace with ghost creation
  42.         n->Misc[NPCM_HISTORY_PTR] = history_ptrs; //Store the pointer for external use.
  43.            
  44.         while(true){
  45.             //update the history every frame
  46.             if ( history_index < 599 ) history_index++;
  47.             if ( history_index == 599 ) {
  48.                 history_ptrs[NPC_HISTORY_ROLLS] = 1; //we only need to know if it has ever rolled.
  49.                 history_index = 0;
  50.             }
  51.                
  52.                
  53.                 //Shift walues downward.
  54.                 //here is where slowdown could occur.
  55.                 //for ( Q[0] = SizeOfArray(history_ptrs); Q[0] > 0; Q[0]-- ) {
  56.                 //  tempptr = history_ptrs[Q[0]];
  57.                 //  for ( Q[1] = 599; Q[1] > 0; Q[1]-- ) {
  58.                 //      tempptr[Q[1]-1] = tempptr[Q[1]];
  59.                 //  }
  60.                 //}
  61.             }
  62.                
  63.                
  64.                
  65.             hp_history[history_index] = n->HP;
  66.             x_history[history_index] = n->X;
  67.             y_history[history_index] = n->Y;
  68.             z_history[history_index] = n->Z;
  69.             jump_history[history_index] = n->Jump;
  70.             dir_history[history_index] = n->Dir;
  71.             misc_00_history[history_index] = n->Misc[0];
  72.             misc_01_history[history_index] = n->Misc[1];
  73.             misc_02_history[history_index] = n->Misc[2];
  74.             misc_03_history[history_index] = n->Misc[3];
  75.             misc_04_history[history_index] = n->Misc[4];
  76.             misc_05_history[history_index] = n->Misc[5];
  77.             misc_06_history[history_index] = n->Misc[6];
  78.             misc_07_history[history_index] = n->Misc[7];
  79.             misc_08_history[history_index] = n->Misc[8];
  80.             misc_09_history[history_index] = n->Misc[9];
  81.             misc_10_history[history_index] = n->Misc[10];
  82.             misc_11_history[history_index] = n->Misc[11];
  83.             misc_12_history[history_index] = n->Misc[12];
  84.             misc_13_history[history_index] = n->Misc[13];
  85.             misc_14_history[history_index] = n->Misc[14];
  86.             misc_15_history[history_index] = n->Misc[15];
  87.            
  88.             //NPC code
  89.             Waitframe();
  90.         }
  91.     }
  92.     void Rewind(int frames, npc n,){
  93.         int ptr = n->Misc[NPCM_HISTORY_PTR];
  94.         int rolls = ptr[NPC_HISTORY_ROLLS];
  95.         int q; int end_index = ptr[0];
  96.         int fcount;
  97.         int subptr;
  98.         if (!rolls ) {
  99.             for ( q = end_index, q >= 0 ; q-- ) {
  100.                 if ( fcount >= frames ) break;
  101.                 subptr = ptr[1];
  102.                 n->X = subptr[q];
  103.                 subptr = ptr[2];
  104.                 n->Y = subptr[q];
  105.                 subptr = ptr[3];
  106.                 n->Z = subptr[q];
  107.                 subptr = ptr[4];
  108.                 n->Jump = subptr[q];
  109.                 subptr = ptr[5];
  110.                 n->Dir = subptr[q];
  111.                 subptr = ptr[6];
  112.                 n->Misc[1] = subptr[q];
  113.                 subptr = ptr[7];
  114.                 n->Misc[2] = subptr[q];
  115.                 subptr = ptr[8];
  116.                 n->Misc[3] = subptr[q];
  117.                 subptr = ptr[9];
  118.                 n->Misc[4] =subptr[q];
  119.                 subptr = ptr[10];
  120.                 n->Misc[5] = subptr[q];
  121.                 subptr = ptr[11];
  122.                 n->Misc[6] = subptr[q];
  123.                 subptr = ptr[12];
  124.                 n->Misc[7] = subptr[q];
  125.                 subptr = ptr[13];
  126.                 n->Misc[8] = subptr[q];
  127.                 subptr = ptr[14];
  128.                 n->Misc[9] = subptr[q];
  129.                 subptr = ptr[15];
  130.                 n->Misc[10] = subptr[q];
  131.                 subptr = ptr[16];
  132.                 n->Misc[11] = subptr[q];
  133.                 subptr = ptr[17];
  134.                 n->Misc[12] = subptr[q];;
  135.                 subptr = ptr[18];
  136.                 n->Misc[13] = subptr[q];
  137.                 subptr = ptr[19];
  138.                 n->Misc[14] = subptr[q];
  139.                 subptr = ptr[20];
  140.                 n->Misc[15] = subptr[q];
  141.                 fcount++;
  142.                 Waitframe();
  143.             }
  144.         }
  145.        
  146.         if ( rolls ) {
  147.             for ( q = end_index, q >= 0 ; q-- ) {
  148.                 if ( fcount >= frames ) break;
  149.                 subptr = ptr[1];
  150.                 n->X = subptr[q];
  151.                 subptr = ptr[2];
  152.                 n->Y = subptr[q];
  153.                 subptr = ptr[3];
  154.                 n->Z = subptr[q];
  155.                 subptr = ptr[4];
  156.                 n->Jump = subptr[q];
  157.                 subptr = ptr[5];
  158.                 n->Dir = subptr[q];
  159.                 subptr = ptr[6];
  160.                 n->Misc[1] = subptr[q];
  161.                 subptr = ptr[7];
  162.                 n->Misc[2] = subptr[q];
  163.                 subptr = ptr[8];
  164.                 n->Misc[3] = subptr[q];
  165.                 subptr = ptr[9];
  166.                 n->Misc[4] =subptr[q];
  167.                 subptr = ptr[10];
  168.                 n->Misc[5] = subptr[q];
  169.                 subptr = ptr[11];
  170.                 n->Misc[6] = subptr[q];
  171.                 subptr = ptr[12];
  172.                 n->Misc[7] = subptr[q];
  173.                 subptr = ptr[13];
  174.                 n->Misc[8] = subptr[q];
  175.                 subptr = ptr[14];
  176.                 n->Misc[9] = subptr[q];
  177.                 subptr = ptr[15];
  178.                 n->Misc[10] = subptr[q];
  179.                 subptr = ptr[16];
  180.                 n->Misc[11] = subptr[q];
  181.                 subptr = ptr[17];
  182.                 n->Misc[12] = subptr[q];;
  183.                 subptr = ptr[18];
  184.                 n->Misc[13] = subptr[q];
  185.                 subptr = ptr[19];
  186.                 n->Misc[14] = subptr[q];
  187.                 subptr = ptr[20];
  188.                 n->Misc[15] = subptr[q];
  189.                 fcount++;
  190.                 Waitframe();
  191.             }
  192.             for ( q = 599; q < end_index; q-- ) {
  193.                 if ( fcount >= frames ) break;
  194.                 subptr = ptr[1];
  195.                 n->X = subptr[q];
  196.                 subptr = ptr[2];
  197.                 n->Y = subptr[q];
  198.                 subptr = ptr[3];
  199.                 n->Z = subptr[q];
  200.                 subptr = ptr[4];
  201.                 n->Jump = subptr[q];
  202.                 subptr = ptr[5];
  203.                 n->Dir = subptr[q];
  204.                 subptr = ptr[6];
  205.                 n->Misc[1] = subptr[q];
  206.                 subptr = ptr[7];
  207.                 n->Misc[2] = subptr[q];
  208.                 subptr = ptr[8];
  209.                 n->Misc[3] = subptr[q];
  210.                 subptr = ptr[9];
  211.                 n->Misc[4] =subptr[q];
  212.                 subptr = ptr[10];
  213.                 n->Misc[5] = subptr[q];
  214.                 subptr = ptr[11];
  215.                 n->Misc[6] = subptr[q];
  216.                 subptr = ptr[12];
  217.                 n->Misc[7] = subptr[q];
  218.                 subptr = ptr[13];
  219.                 n->Misc[8] = subptr[q];
  220.                 subptr = ptr[14];
  221.                 n->Misc[9] = subptr[q];
  222.                 subptr = ptr[15];
  223.                 n->Misc[10] = subptr[q];
  224.                 subptr = ptr[16];
  225.                 n->Misc[11] = subptr[q];
  226.                 subptr = ptr[17];
  227.                 n->Misc[12] = subptr[q];;
  228.                 subptr = ptr[18];
  229.                 n->Misc[13] = subptr[q];
  230.                 subptr = ptr[19];
  231.                 n->Misc[14] = subptr[q];
  232.                 subptr = ptr[20];
  233.                 n->Misc[15] = subptr[q];
  234.                 fcount++;
  235.                 Waitframe();           
  236.             }  
  237.            
  238.         }
  239.         ptr[0] = q;
  240.     }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement