Advertisement
ywkls

Scripted Ladder

Jan 28th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.53 KB | None | 0 0
  1. //Main Files
  2. #include "include/std.zh"
  3. //Imports functions exclusive to my quest
  4. //#include "CustomFunctions.zs"// You probably won't need this.
  5. //I'm not sure you'll need this either.
  6. #include "headers/stdExtra.zh"
  7.  
  8. // Section 28. ffcscript.zh
  9. // Version 1.1.1
  10. // Be sure to check if you're already importing ffcscript.zh
  11. // Adjust to match the settings therein
  12.  
  13. // Combo to be used for generic script vehicle FFCs. This should be
  14. // an invisible combo with no type or flag. It cannot be combo 0.
  15. const int FFCS_INVISIBLE_COMBO = 1;
  16.  
  17. // Range of FFCs to use. Numbers must be between 1 and 32.
  18. const int FFCS_MIN_FFC = 1;
  19. const int FFCS_MAX_FFC = 32;
  20.  
  21.  
  22. int RunFFCScript(int scriptNum, float args){
  23. // Invalid script
  24. if(scriptNum<0 || scriptNum>511)
  25. return 0;
  26.  
  27. ffc theFFC;
  28.  
  29. // Find an FFC not already in use
  30. for(int i=FFCS_MIN_FFC; i<=FFCS_MAX_FFC; i++){
  31. theFFC=Screen->LoadFFC(i);
  32.  
  33. if(theFFC->Script!=0 ||
  34. (theFFC->Data!=0 && theFFC->Data!=FFCS_INVISIBLE_COMBO) ||
  35. theFFC->Flags[FFCF_CHANGER])
  36. continue;
  37.  
  38. // Found an unused one; set it up
  39. theFFC->Data=FFCS_INVISIBLE_COMBO;
  40. theFFC->Script=scriptNum;
  41.  
  42. if(args!=NULL){
  43. for(int j=Min(SizeOfArray(args), 8)-1; j>=0; j--)
  44. theFFC->InitD[j]=args[j];
  45. }
  46.  
  47. return i;
  48. }
  49.  
  50. // No FFCs available
  51. return 0;
  52. }
  53.  
  54. ffc RunFFCScriptOrQuit(int scriptNum, float args){
  55. // Invalid script
  56. if(scriptNum<0 || scriptNum>511)
  57. Quit();
  58.  
  59. int ffcID=RunFFCScript(scriptNum, args);
  60. if(ffcID==0)
  61. Quit();
  62.  
  63. return Screen->LoadFFC(ffcID);
  64. }
  65.  
  66. int FindFFCRunning(int scriptNum){
  67. // Invalid script
  68. if(scriptNum<0 || scriptNum>511)
  69. return 0;
  70.  
  71. ffc f;
  72.  
  73. for(int i=1; i<=32; i++){
  74. f=Screen->LoadFFC(i);
  75. if(f->Script==scriptNum)
  76. return i;
  77. }
  78.  
  79. // No FFCs running it
  80. return 0;
  81. }
  82.  
  83. int FindNthFFCRunning(int scriptNum, int n){
  84. // Invalid script
  85. if(scriptNum<0 || scriptNum>511)
  86. return 0;
  87.  
  88. ffc f;
  89.  
  90. for(int i=1; i<=32; i++){
  91. f=Screen->LoadFFC(i);
  92. if(f->Script==scriptNum){
  93. n--;
  94. if(n==0)
  95. return i;
  96. }
  97. }
  98.  
  99. // Not that many FFCs running it
  100. return 0;
  101. }
  102.  
  103. int CountFFCsRunning(int scriptNum){
  104. // Invalid script
  105. if(scriptNum<0 || scriptNum>511)
  106. return 0;
  107.  
  108. ffc f;
  109. int numFFCs=0;
  110.  
  111. for(int i=1; i<=32; i++){
  112. f=Screen->LoadFFC(i);
  113. if(f->Script==scriptNum)
  114. numFFCs++;
  115. }
  116.  
  117. return numFFCs;
  118. }
  119.  
  120. const int LADDER_COMB0 =3;//Combo used to show ladder
  121. const int LADDER_CSET =5;//CSet of that combo
  122. const int LADDER_SCRIPT =1;//Script slot used by ladder script
  123. const int LADDER_WALKABLE =2;//A walkable combo. Place inherent flags to limit enemy movement
  124. const int I_SCRIPT_LADDER =50;//Item id of scripted ladder. Defaults to Amulet 1
  125. const int GH_INVISIBLE_COMBO=1;//An invisible combo.
  126.  
  127. //Place in items active slot
  128. item script BetterLadder{
  129. void run(){
  130. //You aren't currently running the ladder script
  131. if(!CountFFCsRunning(LADDER_SCRIPT)){
  132. int Args[8];
  133. NewFFCScript(LADDER_SCRIPT, Args);
  134. }
  135. }
  136. }
  137.  
  138. // A better function for launching ffcs
  139. int NewFFCScript(int scriptNum, float args){
  140. // Invalid script
  141. if(scriptNum<0 || scriptNum>511)
  142. return 0;
  143.  
  144. ffc theFFC;
  145.  
  146. // Find an FFC not already in use
  147. for(int i=FFCS_MIN_FFC; i<=FFCS_MAX_FFC; i++){
  148. theFFC=Screen->LoadFFC(i);
  149.  
  150. if(theFFC->Script!=0 ||
  151. (theFFC->Data!=0 && theFFC->Data!=FFCS_INVISIBLE_COMBO) ||
  152. theFFC->Flags[FFCF_CHANGER])
  153. continue;
  154.  
  155. // Found an unused one; set it up
  156. theFFC->Data=FFCS_INVISIBLE_COMBO;
  157. theFFC->TileWidth = 1;
  158. theFFC->TileHeight = 1;
  159. theFFC->Script=scriptNum;
  160.  
  161. if(args!=NULL){
  162. for(int j=Min(SizeOfArray(args), 8)-1; j>=0; j--)
  163. theFFC->InitD[j]=args[j];
  164. }
  165. theFFC->Flags[FFCF_ETHEREAL]= true;
  166. return i;
  167. }
  168.  
  169. // No FFCs available
  170. return 0;
  171. }
  172.  
  173. //Check to see if a particular location can be crossed with a ladder
  174. //Supports checks of layers 1 and 2
  175. bool CanLadder(int loc){
  176. int Layer1_Map = Screen->LayerMap(1);
  177. int Layer1_Screen= Screen->LayerScreen(1);
  178. int Layer2_Map = Screen->LayerMap(2);
  179. int Layer2_Screen= Screen->LayerScreen(2);
  180. if (Screen->ComboT[loc]==CT_LADDERONLY)
  181. return true;
  182. if (Screen->ComboT[loc]==CT_LADDERHOOKSHOT)
  183. return true;
  184. if (Screen->ComboT[loc]==CT_WATER)
  185. return true;
  186. if(Game->GetComboType(Layer1_Map,Layer1_Screen,loc)==CT_LADDERONLY)
  187. return true;
  188. if(Game->GetComboType(Layer1_Map,Layer1_Screen,loc)==CT_LADDERHOOKSHOT)
  189. return true;
  190. if(Game->GetComboType(Layer2_Map,Layer2_Screen,loc)==CT_LADDERONLY)
  191. return true;
  192. if(Game->GetComboType(Layer2_Map,Layer2_Screen,loc)==CT_LADDERHOOKSHOT)
  193. return true;
  194. return false;
  195. }
  196.  
  197. //Script run when ladder is used
  198. ffc script That_Ladder{
  199. void run(){
  200. //Set up appearance of ladder ffc
  201. this->Data= LADDER_COMB0;
  202. this->CSet= LADDER_CSET;
  203. //Make sure it still runs while holding up an item
  204. this->Flags[FFCF_IGNOREHOLDUP]= true;
  205. //Orient based on the direction you're facing
  206. if(Link->Dir==DIR_LEFT||
  207. Link->Dir==DIR_RIGHT){
  208. if(Link->Dir==DIR_LEFT)
  209. this->X= GridX(Link->X-8);
  210. else
  211. this->X= GridX(Link->X+24);
  212. this->Y= GridY(Link->Y+8);
  213. }
  214. else{
  215. if(Link->Dir==DIR_UP)
  216. this->Y= GridY(Link->Y-8);
  217. else
  218. this->Y= GridY(Link->Y+24);
  219. this->X= GridX(Link->X+8);
  220. }
  221. //Check what button is being used by the ladder
  222. bool A_Button;
  223. if(GetEquipmentA()==I_SCRIPT_LADDER)
  224. A_Button= true;
  225. //FFC position checks
  226. int Combo_X= GridX(this->X);
  227. int Combo_Y= GridY(this->Y);
  228. int loc = ComboAt(Combo_X,Combo_Y);
  229. //Hold data for combo replaced by the script
  230. int Saved_Combo=-1;
  231. int Saved_CSet;
  232. //Used to simplify checks for future ffc position
  233. int X;
  234. int Y;
  235. //Check if the spot the ffc is on is a ladder spot
  236. if(CanLadder(loc)){
  237. //Replace the walkable combo's tile with the tile of the combo the ladder is on
  238. CopyTile(Game->ComboTile(Screen->ComboD[loc]),
  239. Game->ComboTile(LADDER_WALKABLE));
  240. //Save the data for the combo the ladder is on
  241. Saved_Combo= Screen->ComboD[loc];
  242. Saved_CSet= Screen->ComboC[loc];
  243. //Replace the combo the ladder is on with a walkable one
  244. Screen->ComboD[loc] =LADDER_WALKABLE;
  245. Screen->ComboC[loc] = Saved_CSet;
  246. }
  247. //Save the direction you're facing when you place the ladder
  248. int dir= Link->Dir;
  249. //You've made a ladder spot walkable
  250. if(Saved_Combo!=-1){
  251. //The ladder is on the A button
  252. if(A_Button){
  253. //You haven't pressed A
  254. while(!Link->PressA){
  255. Waitframe();
  256. //Check what direction you were facing when you placed the ladder
  257. if(dir==DIR_UP
  258. ||dir==DIR_DOWN){
  259. //Check your current coordinates relative to the ffc
  260. if(Link->Y<=this->Y+15
  261. && Link->Y+17>=this->Y){
  262. if(Link->X>=this->X-2
  263. && Link->X<=this->X+18){
  264. //You're on the ladder
  265. //Don't let the player walk off the left or right side
  266. //Don't let the player remove the ladder
  267. Link->X= this->X;
  268. Link->PressA=false;
  269. }
  270. }
  271. }
  272. else{
  273. if(Link->X<=this->X+15
  274. && Link->X+17<=this->X){
  275. if(Link->Y<=this->Y+18
  276. && Link->Y+17>=this->Y){
  277. Link->Y= this->Y;
  278. Link->PressA=false;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. else{
  285. //This ladder is on the B button
  286. //You haven't pressed B
  287. while(!Link->PressB){
  288. Waitframe();
  289. if(dir==DIR_UP
  290. ||dir==DIR_DOWN){
  291. if(Link->Y<=this->Y+15
  292. && Link->Y+17>=this->Y){
  293. if(Link->X<=this->X+15
  294. && Link->X+17>=this->X){
  295. Link->X= this->X;
  296. Link->PressB=false;
  297. }
  298. }
  299. }
  300. else{
  301. if(Link->X<=this->X+15
  302. && Link->X+15>=this->X){
  303. if(Link->Y<=this->Y+15
  304. && Link->Y+17>=this->Y){
  305. Link->Y= this->Y;
  306. Link->PressB=false;
  307. }
  308. }
  309. }
  310. }
  311. }
  312. }
  313. else{
  314. //The ladder isn't on a ladder spot
  315. while(true){
  316. //On the A button
  317. if(A_Button){
  318. //You haven't pressed A
  319. while(!Link->PressA)
  320. Waitframe();
  321. break;
  322. }
  323. else{
  324. //On the B button
  325. //You haven't pressed B
  326. while(!Link->PressB)
  327. Waitframe();
  328. break;
  329. }
  330. Waitframe();
  331. }
  332. }
  333. //Make the ladder invisible
  334. this->Data= GH_INVISIBLE_COMBO;
  335. //If you replaced a combo, restore it
  336. if(Saved_Combo!=-1){
  337. Screen->ComboD[loc]= Saved_Combo;
  338. Screen->ComboC[loc]= Saved_CSet;
  339. }
  340. //Keep you from using the ladder for a bit
  341. Waitframes(30);
  342. //This script is done
  343. Quit();
  344. }
  345. }
  346.  
  347. //Checks for matching combo flag and type.
  348.  
  349. //D0- On scren location.
  350. //D1- Combo Flag to check.
  351. //D2- Combo Type to check.
  352.  
  353. bool ComboFIT(int loc,int flag,int type){
  354. if(ComboFI(loc,flag)&& Screen->ComboT[loc]==type)return true;
  355. return false;
  356. }
  357.  
  358. //Checks for matching combo flag and type.
  359.  
  360. //D0- On scren location.
  361. //D1- Combo Flag to check.
  362. //D2- Combo Type to check.
  363.  
  364. bool ComboFIT(int X, int Y,int flag,int type){
  365. int loc = ComboAt(X,Y);
  366. if(ComboFI(loc,flag)&& Screen->ComboT[loc]==type)return true;
  367. return false;
  368. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement