Advertisement
ZoriaRPG

ZScript: Rewind NPC Template

Jul 4th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.56 KB | None | 0 0
  1. const int NPCM_HISTORY_PTR = 15;
  2. npc script foo{
  3.     void run(){
  4.         int history_index = -1;
  5.         int hp_history[600];
  6.         int x_history[600];
  7.         int y_history[600];
  8.         int z_history[600];
  9.         int jump_history[600];
  10.         int dir_history[600];
  11.         int misc_00_history[600];
  12.         int misc_01_history[600];
  13.         int misc_02_history[600];
  14.         int misc_03_history[600];
  15.         int misc_04_history[600];
  16.         int misc_05_history[600];
  17.         int misc_06_history[600];
  18.         int misc_07_history[600];
  19.         int misc_08_history[600];
  20.         int misc_09_history[600];
  21.         int misc_10_history[600];
  22.         int misc_11_history[600];
  23.         int misc_12_history[600];
  24.         int misc_13_history[600];
  25.         int misc_14_history[600];
  26.         int misc_15_history[600];
  27.        
  28.         int history_ptrs[]={history_index, hp_history, x_history, y_history, z_history,
  29.             jump_history, dir_history, misc_00_history, misc_01_history,
  30.             misc_02_history, misc_03_history, misc_04_history, misc_05_history,
  31.             misc_06_history, misc_07_history, misc_08_history, misc_09_history,
  32.             misc_10_history, misc_11_history, misc_12_history, misc_13_history,
  33.             misc_14_history, misc_15_history };
  34.            
  35.         int Q[16]; int tempptr;
  36.            
  37.         npc n = Screen->CreateNPC(foo); //Replace with ghost creation
  38.         n->Misc[NPCM_HISTORY_PTR] = history_ptrs; //Store the pointer for external use.
  39.            
  40.         while(true){
  41.             //update the history every frame
  42.             if ( history_index < 599 ) history_index++;
  43.             if ( history_index == 599 ) {
  44.                 //Shift walues downward.
  45.                 //here is where slowdown could occur.
  46.                 for ( Q[0] = SizeOfArray(history_ptrs); Q[0] > 0; Q[0]-- ) {
  47.                     tempptr = history_ptrs[Q[0]];
  48.                     for ( Q[1] = 599; Q[1] > 0; Q[1]-- ) {
  49.                         tempptr[Q[1]-1] = tempptr[Q[1]];
  50.                     }
  51.                 }
  52.             }
  53.                
  54.                
  55.                
  56.             hp_history[history_index] = n->HP;
  57.             x_history[history_index] = n->X;
  58.             y_history[history_index] = n->Y;
  59.             z_history[history_index] = n->Z;
  60.             jump_history[history_index] = n->Jump;
  61.             dir_history[history_index] = n->Dir;
  62.             misc_00_history[history_index] = n->Misc[0];
  63.             misc_01_history[history_index] = n->Misc[1];
  64.             misc_02_history[history_index] = n->Misc[2];
  65.             misc_03_history[history_index] = n->Misc[3];
  66.             misc_04_history[history_index] = n->Misc[4];
  67.             misc_05_history[history_index] = n->Misc[5];
  68.             misc_06_history[history_index] = n->Misc[6];
  69.             misc_07_history[history_index] = n->Misc[7];
  70.             misc_08_history[history_index] = n->Misc[8];
  71.             misc_09_history[history_index] = n->Misc[9];
  72.             misc_10_history[history_index] = n->Misc[10];
  73.             misc_11_history[history_index] = n->Misc[11];
  74.             misc_12_history[history_index] = n->Misc[12];
  75.             misc_13_history[history_index] = n->Misc[13];
  76.             misc_14_history[history_index] = n->Misc[14];
  77.             misc_15_history[history_index] = n->Misc[15];
  78.            
  79.             //NPC code
  80.             Waitframe();
  81.         }
  82.     }
  83.     void Rewind(int frames, npc n){
  84.         int ptr = n->Misc[NPCM_HISTORY_PTR];
  85.         int q; int end_index = ptr[0];
  86.         int fcount = (end_index - frames);
  87.         fcount = VBound(fcount, 0, 600);
  88.         for ( q = end_index, q > fcount ; q-- ) { //This may be right.
  89.             n->X = ptr[1[q]];
  90.             n->Y = ptr[2[q]];
  91.             n->Z = ptr[3[q]];
  92.             n->Jump = ptr[4[q]];
  93.             n->Dir = ptr[5[q]];
  94.             n->Misc[1] = ptr[6[q]];
  95.             n->Misc[2] = ptr[7[q]];
  96.             n->Misc[3] = ptr[8[q]];
  97.             n->Misc[4] = ptr[9[q]];
  98.             n->Misc[5] = ptr[10[q]];
  99.             n->Misc[6] = ptr[11[q]];
  100.             n->Misc[7] = ptr[12[q]];
  101.             n->Misc[8] = ptr[13[q]];
  102.             n->Misc[9] = ptr[14[q]];
  103.             n->Misc[10] = ptr[15[q]];
  104.             n->Misc[11] = ptr[16[q]];
  105.             n->Misc[12] = ptr[17[q]];
  106.             n->Misc[13] = ptr[18[q]];
  107.             n->Misc[14] = ptr[19[q]];
  108.             n->Misc[15] = ptr[20[q]];
  109.             Waitframe();
  110.         }
  111.         ptr[0] = q;
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement