Advertisement
ZoriaRPG

Barriers Patch for Nightmeres

Feb 2nd, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.27 KB | None | 0 0
  1. const int CMB_FFC_INVIS = 1; //Combo higher than ID 0 with an invisible tile.
  2.  
  3. // ID's of barrier-related combos
  4. // Barriers in raised state
  5. const int BARRIER_A_RAISED = 15036;
  6. const int BARRIER_B_RAISED = 15038;
  7.  
  8. // Barriers in lowered state
  9. const int BARRIER_A_LOWERED = 15037;
  10. const int BARRIER_B_LOWERED = 15039;
  11.  
  12. // Barriers animating to raised state
  13. const int BARRIER_A_ANIMRAISE = 15041;
  14. const int BARRIER_B_ANIMRAISE = 15043;
  15.  
  16. // Barriers animating to lowered state
  17. const int BARRIER_A_ANIMLOWER = 15040;
  18. const int BARRIER_B_ANIMLOWER = 15042;
  19.  
  20. // Raised barriers that Link can walk on
  21. const int BARRIER_A_WALKABLE = 15044;
  22. const int BARRIER_B_WALKABLE = 15045;
  23.  
  24. // Barrier switches
  25. const int BARRIER_A_SWITCH = 15046;
  26. const int BARRIER_B_SWITCH = 15047;
  27.  
  28. const int BARRIER_SWITCH_DUMMY = 191; // ID of a switch hit detection dummy enemy
  29. const int BARRIER_SWITCH_DUMMY_HP = 32767;
  30.  
  31. // Global array to store the state of barriers per dmap
  32. // If you have more than 16 dmaps you can change the capacity in the []'s
  33. // You may change the states in other scripts, but the changes will not be visible
  34. // until there is a new screen, so set them before Barriers_NewScreen() is called.
  35. bool barriers[255]; // false = blue barriers raised, true = red barriers raised
  36.  
  37.  
  38. const int ffcNumber = 32; //The number of the FFC used. This script will "hijack" this one, so don't use it for anything else on screens when you expect the player to have a follower.
  39. const int firstFollowerCombo = 23568; //combo of the first combo. In order, the concecutive combos must be "still up", "still down", "still left", "still right", "moving up", "moving down", "moving left", "moving right".
  40. const int csetOfFollower = 11;
  41. const int reqItem = 158; //Item that makes the FFC follower follow you
  42. const int BAR_PASTX = 14;
  43. const int BAR_PASTY = 14;
  44.  
  45. global script slot2 {
  46. void run() {
  47. // Initialize variables used to listen on screen changes
  48. int curscreen = -1;
  49. bool firstCheck = false; //leave this alone
  50. ffc follower;
  51.  
  52. int followerX[15];
  53. int followerY[15];
  54.  
  55. int switch_index;
  56.  
  57. while (true) {
  58. // Keep track of screen changes
  59. // Run a Barrier script on every screen change
  60. if (Game->GetCurScreen() != curscreen) {
  61. curscreen = Game->GetCurScreen();
  62. Barriers_NewScreen();}
  63. if(Link->Item[reqItem] == true){
  64. if(Link->Action != LA_SCROLLING && follower->Data==0){
  65. follower = Screen->LoadFFC(ffcNumber);
  66. follower->Data = firstFollowerCombo;
  67. follower->CSet = csetOfFollower;
  68.  
  69. followerX[BAR_PASTX] = Link->X;
  70. follower->X = Link->X;
  71. followerY[BAR_PASTY] = Link->Y;
  72. follower->Y = Link->Y;
  73.  
  74. for ( int i = 0; i < 13; i++ ){
  75. followerX[i] = Link->X;
  76. followerY[i] = Link->Y;
  77. }
  78.  
  79. firstCheck = true;
  80. }
  81. if(Link->Action != LA_SCROLLING){
  82. if((Link->InputUp || Link->InputDown || Link->InputRight || Link->InputLeft)&&(!(Link->InputA || Link->InputB))){
  83. followerX[BAR_PASTX] = follower->X;
  84. follower->X = followerX[0];
  85. for(switch_index=0; switch_index<12; switch_index++){
  86. followerX[switch_index] = followerX[switch_index + 1];
  87. }
  88. followerX[12] = Link->X;
  89.  
  90. followerY[BAR_PASTY] = follower->Y;
  91. follower->Y = followerY[0];
  92. for(switch_index=0; switch_index<12; switch_index++){
  93. followerY[switch_index] = followerY[switch_index + 1];
  94. }
  95. followerY[12] = Link->Y;
  96. }
  97.  
  98. if(follower->Y > followerY[BAR_PASTY]){
  99. follower->Data = firstFollowerCombo + 5;
  100. }
  101. else if(follower->Y < followerY[BAR_PASTY]){
  102. follower->Data = firstFollowerCombo + 4;
  103. }
  104. else if(follower->X > followerX[BAR_PASTX]){
  105. follower->Data = firstFollowerCombo + 7;
  106. }
  107. else if(follower->X < followerX[BAR_PASTX]){
  108. follower->Data = firstFollowerCombo + 6;
  109. }
  110. if(!(Link->InputUp || Link->InputDown || Link->InputRight || Link->InputLeft)){
  111. if((follower->Data == (firstFollowerCombo + 4))||(follower->Data == (firstFollowerCombo + 5))||(follower->Data == (firstFollowerCombo + 6))||(follower->Data == (firstFollowerCombo + 7))){
  112. follower->Data = follower->Data - 4;
  113. }
  114. else if((follower->Data == (firstFollowerCombo + 3))||(follower->Data == (firstFollowerCombo + 2))||(follower->Data == (firstFollowerCombo + 1))||(follower->Data == (firstFollowerCombo))){
  115.  
  116. }
  117. else{
  118. follower->Data = firstFollowerCombo;
  119. }
  120. }
  121. }
  122. if(Link->Action == LA_SCROLLING){
  123. firstCheck = false;
  124. }}
  125.  
  126. Waitframe();}}}
  127.  
  128.  
  129. // Function that makes preparations for barriers on each screen and starts an FFC script
  130. void Barriers_NewScreen() {
  131.  
  132. // Search for a barrier-related combo
  133. for (int i = 0; i <= 175; i++) {
  134. int cd = Screen->ComboD[i];
  135. if (cd == BARRIER_A_RAISED || cd == BARRIER_A_LOWERED || cd == BARRIER_A_SWITCH ||
  136. cd == BARRIER_B_RAISED || cd == BARRIER_B_LOWERED || cd == BARRIER_B_SWITCH) {
  137. // A barrier-related combo was found
  138.  
  139. // Make initial changes to combos
  140. if (barriers[Game->GetCurLevel()]) {
  141. for (int j = i; j <= 175; j++) {
  142. int cd = Screen->ComboD[j];
  143. if (cd == BARRIER_A_RAISED) Screen->ComboD[j] = BARRIER_A_LOWERED;
  144. else if (cd == BARRIER_B_LOWERED) Screen->ComboD[j] = BARRIER_B_RAISED;
  145. else if (cd == BARRIER_A_SWITCH) Screen->ComboD[j] = BARRIER_B_SWITCH;}}
  146. else {
  147. for (int j = i; j <= 175; j++) {
  148. int cd = Screen->ComboD[j];
  149. if (cd == BARRIER_B_RAISED) Screen->ComboD[j] = BARRIER_B_LOWERED;
  150. else if (cd == BARRIER_A_LOWERED) Screen->ComboD[j] = BARRIER_A_RAISED;
  151. else if (cd == BARRIER_B_SWITCH) Screen->ComboD[j] = BARRIER_A_SWITCH;}}
  152.  
  153. // So run FFCscript to control barriers
  154. int fif[]="Barriers";
  155. ffc f = Screen->LoadFFC(ffcNumber);
  156. f->Script = Game->GetFFCScript(fif);
  157. f->Data = CMB_FFC_INVIS;
  158. f->X = -100;
  159. f->Y = -100;
  160. f->Flags[FFCF_PRELOAD] = true;
  161. break;}
  162. }}
  163.  
  164. // This lets you toggle barriers on any dmap
  165. bool ToggleBarriers(int dmap) {
  166. if (dmap == Game->GetCurLevel()) ToggleBarriers();
  167. else barriers[dmap] = !barriers[dmap];
  168. return barriers[dmap];}
  169.  
  170. // This toggles barriers on the current dmap
  171. bool ToggleBarriers() {
  172. int curdmap = Game->GetCurLevel();
  173. if (!barriers[curdmap]) {
  174. barriers[curdmap] = true;
  175. for (int i = 0; i <= 175; i++) {
  176. int cd = Screen->ComboD[i];
  177. if (cd == BARRIER_A_RAISED || cd == BARRIER_A_WALKABLE || cd == BARRIER_A_ANIMRAISE) {
  178. Screen->ComboD[i] = BARRIER_A_ANIMLOWER;}
  179. else if (cd == BARRIER_B_LOWERED || cd == BARRIER_B_ANIMLOWER) {
  180. Screen->ComboD[i] = BARRIER_B_ANIMRAISE;}
  181. else if (cd == BARRIER_A_SWITCH) {Screen->ComboD[i] = BARRIER_B_SWITCH;}}}
  182. else {
  183. barriers[curdmap] = false;
  184. for (int i = 0; i <= 175; i++) {
  185. int cd = Screen->ComboD[i];
  186. if (cd == BARRIER_B_RAISED || cd == BARRIER_B_WALKABLE || cd == BARRIER_B_ANIMRAISE) {
  187. Screen->ComboD[i] = BARRIER_B_ANIMLOWER;}
  188. else if (cd == BARRIER_A_LOWERED || cd == BARRIER_A_ANIMLOWER) {
  189. Screen->ComboD[i] = BARRIER_A_ANIMRAISE;}
  190. else if (cd == BARRIER_B_SWITCH) {Screen->ComboD[i] = BARRIER_A_SWITCH;}}}
  191.  
  192. return barriers[curdmap];
  193. }
  194.  
  195. // This script controls barriers on the screen
  196. // The FFC is automatically created by Barriers_NewScreen()
  197. ffc script Barriers {
  198. void run() {
  199.  
  200. // Initialize storage for bswitch hit dummies
  201. int bswitch_count;
  202. npc bswitch[8];
  203.  
  204. for (int i = 0; i <= 175; i++) {
  205. if (Screen->ComboD[i] == BARRIER_A_SWITCH || Screen->ComboD[i] == BARRIER_B_SWITCH) {
  206. npc bs = CreateNPCAt(BARRIER_SWITCH_DUMMY, ComboX(i), ComboY(i));
  207. bs->HitWidth = 8; // Smaller hit box to avoid annoying collisions with Link
  208. bs->HitHeight = 8;
  209. bs->HP = BARRIER_SWITCH_DUMMY_HP;
  210. bswitch[bswitch_count++] = bs;}}
  211.  
  212. // Change raised barriers to walkable ones if Link enters screen on a raised barrier
  213. int lcombo = LinkOnComboD();
  214. bool onbarrier = (lcombo == BARRIER_A_RAISED || lcombo == BARRIER_B_RAISED);
  215. if (onbarrier) for (int i = 0; i < 176; i++) {
  216. if (Screen->ComboD[i] == BARRIER_A_RAISED) {Screen->ComboD[i] = BARRIER_A_WALKABLE;}
  217. else if (Screen->ComboD[i] == BARRIER_B_RAISED) {Screen->ComboD[i] = BARRIER_B_WALKABLE;}}
  218.  
  219.  
  220. while (true) {
  221.  
  222. // Detect hits on bswitches, and change combos accordingly
  223. for (int j = 0; j < bswitch_count; j++) {
  224. if (bswitch[j]->HP < BARRIER_SWITCH_DUMMY_HP) {
  225. bswitch[j]->HP = BARRIER_SWITCH_DUMMY_HP;
  226. ToggleBarriers();
  227. break;}} //break so that only one bswitch hit may register per frame
  228.  
  229.  
  230. // Make barriers walkable if Link is on raised barriers, or unwalkable if not
  231. lcombo = LinkOnComboD();
  232. if (!onbarrier && (lcombo == BARRIER_A_RAISED || lcombo == BARRIER_B_RAISED)) {
  233. onbarrier = true;
  234. for (int i = 0; i <= 175; i++) {
  235. if (Screen->ComboD[i] == BARRIER_A_RAISED) {Screen->ComboD[i] = BARRIER_A_WALKABLE;}
  236. else if (Screen->ComboD[i] == BARRIER_B_RAISED) {Screen->ComboD[i] = BARRIER_B_WALKABLE;}}}
  237. else if (onbarrier && !(lcombo == BARRIER_A_WALKABLE || lcombo == BARRIER_B_WALKABLE)) {
  238. onbarrier = false;
  239. for (int i = 0; i <= 175; i++) {
  240. if (Screen->ComboD[i] == BARRIER_A_WALKABLE) {Screen->ComboD[i] = BARRIER_A_RAISED;}
  241. else if (Screen->ComboD[i] == BARRIER_B_WALKABLE) {Screen->ComboD[i] = BARRIER_B_RAISED;}}}
  242.  
  243. Waitframe();}
  244. }}
  245.  
  246.  
  247.  
  248. // A utility function that returns the ID of the combo that Link appears to stand on
  249. int LinkOnComboD() {
  250. return Screen->ComboD[ComboAt(Link->X+8, Link->Y+13)];
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement