Advertisement
Guest User

Untitled

a guest
Mar 31st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.25 KB | None | 0 0
  1. import "std.zh"
  2.  
  3. ////////////////////////////////////////////////////////////////
  4. // Charge Bow
  5. // by grayswandir
  6. ////////////////////////////////////////////////////////////////
  7. // Description:
  8. //
  9. // This is an 8-way bow that you can charge-up, aim, and shoot. If an arrow
  10. // hits a flame source, it'll turn into a flamming arrow (fire-type weapon).
  11. ////////////////////////////////////////////////////////////////
  12. // Setup:
  13. //
  14. // This requires std.zh.
  15. //
  16. // Read through the following Integration section and change all the values to
  17. // suit your quest.
  18. //
  19. // Make sure to load the ChargeBow ffc script, and the ChargeBow_Use item
  20. // script.
  21. //
  22. // Set ChargeBow_Use as the item use script of the item used to fire
  23. // it. Change it from an arrow to a Custom Item class. (Also remember to
  24. // change the subscreen slot from arrow to that custom item class as well.)
  25. // Make the first provided argument to the script the item's id. The second
  26. // should be the first arrow tile, and the third the cset to use. The tiles
  27. // should be in order of Up, Down, Left, Right, Left-Up, Right-Up, Left-Down,
  28. // Right-Down.
  29. //
  30. // This makes use of global variables, so it will invalidate saves when added.
  31.  
  32. ////////////////////////////////////////////////////////////////
  33. // Integration
  34. ////////////////
  35. // This section is the part that needs to be set manually for each quest. Read
  36. // the description for each part and set it accordingly.
  37. ////////////////
  38.  
  39. ////////////////////////////////////////////////////////////////
  40. // Link Animation Setup
  41.  
  42. // Each link animation is a block of tiles. Advancing to the right moves
  43. // through the different directions. (The order is Up, Down, Left, Right,
  44. // Left-Up, Right-Up, Left-Down, Right-Down). The first row is with the bow &
  45. // arrow, the second row is without the arrow. Each frame is a 2 by 2 tile
  46. // that is centered on Link.
  47.  
  48. // Higher number costumes take precedence.
  49.  
  50. //// Default Costume
  51.  
  52. // The starting tile for the link animation.
  53. const int CHARGEBOW_LINK_C0_TILE = 1300;
  54.  
  55. // The cset the link animation uses.
  56. const int CHARGEBOW_LINK_C0_CSET = 6;
  57.  
  58. //// Costume 1
  59.  
  60. // The item that marks using costume 1. Set to 0 to disable.
  61. const int CHARGEBOW_LINK_C1_ITEM = 0;
  62.  
  63. // The starting tile for the link animation.
  64. const int CHARGEBOW_LINK_C1_TILE = 0;
  65.  
  66. // The cset the link animation uses.
  67. const int CHARGEBOW_LINK_C1_CSET = 6;
  68.  
  69. //// Costume 2
  70.  
  71. // The item that marks using costume 2. Set to 0 to disable.
  72. const int CHARGEBOW_LINK_C2_ITEM = 0;
  73.  
  74. // The starting tile for the link animation.
  75. const int CHARGEBOW_LINK_C2_TILE = 0;
  76.  
  77. // The cset the link animation uses.
  78. const int CHARGEBOW_LINK_C2_CSET = 6;
  79.  
  80. //// Costume 3
  81.  
  82. // The item that marks using costume 3. Set to 0 to disable.
  83. const int CHARGEBOW_LINK_C3_ITEM = 0;
  84.  
  85. // The starting tile for the link animation.
  86. const int CHARGEBOW_LINK_C3_TILE = 0;
  87.  
  88. // The cset the link animation uses.
  89. const int CHARGEBOW_LINK_C3_CSET = 6;
  90.  
  91. //// Costume 4
  92.  
  93. // The item that marks using costume 4. Set to 0 to disable.
  94. const int CHARGEBOW_LINK_C4_ITEM = 0;
  95.  
  96. // The starting tile for the link animation.
  97. const int CHARGEBOW_LINK_C4_TILE = 0;
  98.  
  99. // The cset the link animation uses.
  100. const int CHARGEBOW_LINK_C4_CSET = 6;
  101.  
  102. ////////////////////////////////////////////////////////////////
  103. // Gameplay Setup
  104.  
  105. //// Charge Level 0
  106.  
  107. // This is the sound played when you first use the bow. Set to 0 for no sound.
  108. const int CHARGEBOW_START_SOUND = 0;
  109.  
  110. // This is the sound played when you release a level 0 shot. Set to 0 for no sound.
  111. const int CHARGEBOW_L0_SHOT_SOUND = 1;
  112.  
  113. //// Charge Level 1
  114.  
  115. // This is the item id that unlocks this charge level. Set to 0 for no item
  116. // needed.
  117. const int CHARGEBOW_L1_ITEM_ID = 0;
  118.  
  119. // This is the cumulative frames you need to charge for this charge level.
  120. const int CHARGEBOW_L1_CHARGE_TIME = 45;
  121.  
  122. // This is the sound played when you reach charge level 1. Set to 0 for no
  123. // sound.
  124. const int CHARGEBOW_L1_CHARGE_SOUND = 35;
  125.  
  126. // This is the sound played when you release a level 1 shot. Set to 0 for no
  127. // sound.
  128. const int CHARGEBOW_L1_SHOT_SOUND = 1;
  129.  
  130. //// Charge Level 2
  131.  
  132. // This is the item id that unlocks this charge level. Set to 0 for no item
  133. // needed.
  134. const int CHARGEBOW_L2_ITEM_ID = 0;
  135.  
  136. // This is the cumulative frames you need to charge for this charge level.
  137. const int CHARGEBOW_L2_CHARGE_TIME = 90;
  138.  
  139. // This is the sound played when you reach charge level 2. Set to 0 for no
  140. // sound.
  141. const int CHARGEBOW_L2_CHARGE_SOUND = 36;
  142.  
  143. // This is the sound played when you release a level 2 shot. Set to 0 for no
  144. // sound.
  145. const int CHARGEBOW_L2_SHOT_SOUND = 1;
  146.  
  147. //// Effects
  148.  
  149. // This is the combo flag that sets an arrow on fire. Defaults to script 1.
  150. const int CHARGEBOW_BURN_FLAG = 98;
  151.  
  152. // This is the sound that's made when the arrow catches on fire. Set to 0 for
  153. // no sound.
  154. const int CHARGEBOW_BURN_SOUND = 0;
  155.  
  156. // This is the amount of damage the arrow does.
  157. int ChargeBow_Damage(int item_id, int charge_level, int element) {
  158. itemdata data = Game->LoadItemData(item_id);
  159. int damage = data->Power;
  160. return damage;
  161. }
  162.  
  163. // The amount of speed each level of charge adds to the arrow.
  164. const int CHARGEBOW_ARROW_CHARGE_SPEED = 1;
  165.  
  166. // This is the speed the arrow flies at. For reference, Link's movement is
  167. // 1.5. Defaults to the strongest bow that Link has.
  168. int ChargeBow_Speed(int item_id, int charge_level, int element) {
  169. int bow_id = -1;
  170. int bow_level = -1;
  171. itemdata data;
  172.  
  173. // Find the highest level bow item the player has.
  174. for (int i = 0; i < 256; ++i) {
  175. data = Game->LoadItemData(i);
  176. if (!Link->Item[i]) {continue;}
  177. if (IC_BOW != data->Family) {continue;}
  178. if (data->Level > bow_level) {
  179. bow_id = i;
  180. bow_level = data->Level;
  181. }
  182. }
  183.  
  184. // Grab the speed from that bow.
  185. data = Game->LoadItemData(bow_id);
  186. int speed = data->Power;
  187.  
  188. // Add speed for each charge level.
  189. speed += charge_level * CHARGEBOW_ARROW_CHARGE_SPEED;
  190.  
  191. return speed;
  192. }
  193.  
  194. ////////////////////////////////////////////////////////////////
  195. // Main Script
  196.  
  197. const int CHARGEBOW_ELEMENT_NONE = 0;
  198.  
  199. item script ChargeBow_Use {
  200. void run(int item_id, int tile, int cset) {
  201. int i; ffc f;
  202.  
  203. // Cancel out if there's already an arrow on screen.
  204. if (ChargeBow.IsActive()) {return;}
  205.  
  206. // Look for a free FFC slot.
  207. for (i = 1; i <= 32; ++i) {
  208. f = Screen->LoadFFC(i);
  209. if (0 == f->Data && 0 == f->Script) {break;}
  210. }
  211. // If we didn't find a free ffc, quit.
  212. if (33 == i) {return;}
  213.  
  214. // Start up the ffc script.
  215. f->Script = ChargeBow.ScriptId();
  216. f->InitD[0] = item_id;
  217. f->InitD[1] = tile;
  218. f->InitD[2] = cset;
  219.  
  220. // Play the start sound.
  221. if (CHARGEBOW_START_SOUND) {Game->PlaySound(CHARGEBOW_START_SOUND);}
  222. }
  223. }
  224.  
  225. ffc script ChargeBow {
  226.  
  227. // Get the script number for this script.
  228. int ScriptId() {
  229. int name[] = "ChargeBow";
  230. return Game->GetFFCScript(name);
  231. }
  232.  
  233. // If the chargebow ffc is currently active.
  234. bool IsActive() {
  235. int script_id = ChargeBow.ScriptId();
  236. for (int i = 1; i <= 32; ++i) {
  237. ffc f = Screen->LoadFFC(i);
  238. if (script_id == f->Script) {return true;}
  239. }
  240. return false;
  241. }
  242.  
  243. // Get a multiplier for the x component of a direction.
  244. int DirX(int dir) {
  245. if (DIR_LEFT == dir || DIR_LEFTUP == dir || DIR_LEFTDOWN == dir) {return -1;}
  246. else if (DIR_RIGHT == dir || DIR_RIGHTUP == dir || DIR_RIGHTDOWN == dir) {return 1;}
  247. else {return 0;}
  248. }
  249.  
  250. // Get a multiplier for the y component of a direction.
  251. int DirY(int dir) {
  252. if (DIR_UP == dir || DIR_LEFTUP == dir || DIR_RIGHTUP == dir) {return -1;}
  253. else if (DIR_DOWN == dir || DIR_LEFTDOWN == dir || DIR_RIGHTDOWN == dir) {return 1;}
  254. else {return 0;}
  255. }
  256.  
  257. // Get the facing based on held buttons. If nothing is held returns Link->Dir.
  258. int LinkInputDir() {
  259. if (Link->InputUp) {
  260. if (Link->InputLeft) {return DIR_LEFTUP;}
  261. else if (Link->InputRight) {return DIR_RIGHTUP;}
  262. else {return DIR_UP;}
  263. }
  264. else if (Link->InputDown) {
  265. if (Link->InputLeft) {return DIR_LEFTDOWN;}
  266. else if (Link->InputRight) {return DIR_RIGHTDOWN;}
  267. else {return DIR_DOWN;}
  268. }
  269. else if (Link->InputLeft) {return DIR_LEFT;}
  270. else if (Link->InputRight) {return DIR_RIGHT;}
  271. else {return Link->Dir;}
  272. }
  273.  
  274. // If the given charge level has been unlocked.
  275. bool LevelUnlocked(int level) {
  276. if (0 == level) {return true;}
  277. if (1 == level) {return !CHARGEBOW_L1_ITEM_ID || Link->Item[CHARGEBOW_L1_ITEM_ID];}
  278. if (2 == level) {return !CHARGEBOW_L2_ITEM_ID || Link->Item[CHARGEBOW_L2_ITEM_ID];}
  279. return false;
  280. }
  281.  
  282. // The amount of time needed to reach this charge level.
  283. int ChargeTime(int level) {
  284. if (1 == level) {return CHARGEBOW_L1_CHARGE_TIME;}
  285. if (2 == level) {return CHARGEBOW_L2_CHARGE_TIME;}
  286. return 0;
  287. }
  288.  
  289. // Play the charge sound for a given level.
  290. int PlayChargeSound(int level) {
  291. int sound = 0;
  292. if (1 == level) {sound = CHARGEBOW_L1_CHARGE_SOUND;}
  293. else if (2 == level) {sound = CHARGEBOW_L2_CHARGE_SOUND;}
  294. if (sound) {Game->PlaySound(sound);}
  295. }
  296.  
  297. // Play the shot sound for a given level.
  298. int PlayShotSound(int level) {
  299. int sound = 0;
  300. if (0 == level) {sound = CHARGEBOW_L0_SHOT_SOUND;}
  301. else if (1 == level) {sound = CHARGEBOW_L1_SHOT_SOUND;}
  302. else if (2 == level) {sound = CHARGEBOW_L2_SHOT_SOUND;}
  303. if (sound) {Game->PlaySound(sound);}
  304. }
  305.  
  306. // Get the tile base for link's graphic.
  307. int LinkTileBase() {
  308. if (CHARGEBOW_LINK_C4_ITEM && Link->Item[CHARGEBOW_LINK_C4_ITEM]) {return CHARGEBOW_LINK_C4_TILE;}
  309. else if (CHARGEBOW_LINK_C3_ITEM && Link->Item[CHARGEBOW_LINK_C3_ITEM]) {return CHARGEBOW_LINK_C3_TILE;}
  310. else if (CHARGEBOW_LINK_C2_ITEM && Link->Item[CHARGEBOW_LINK_C2_ITEM]) {return CHARGEBOW_LINK_C2_TILE;}
  311. else if (CHARGEBOW_LINK_C1_ITEM && Link->Item[CHARGEBOW_LINK_C1_ITEM]) {return CHARGEBOW_LINK_C1_TILE;}
  312. else {return CHARGEBOW_LINK_C0_TILE;}
  313. }
  314.  
  315. // Get the cset for link's graphic.
  316. int LinkCSet() {
  317. if (CHARGEBOW_LINK_C4_ITEM && Link->Item[CHARGEBOW_LINK_C4_ITEM]) {return CHARGEBOW_LINK_C4_CSET;}
  318. else if (CHARGEBOW_LINK_C3_ITEM && Link->Item[CHARGEBOW_LINK_C3_ITEM]) {return CHARGEBOW_LINK_C3_CSET;}
  319. else if (CHARGEBOW_LINK_C2_ITEM && Link->Item[CHARGEBOW_LINK_C2_ITEM]) {return CHARGEBOW_LINK_C2_CSET;}
  320. else if (CHARGEBOW_LINK_C1_ITEM && Link->Item[CHARGEBOW_LINK_C1_ITEM]) {return CHARGEBOW_LINK_C1_CSET;}
  321. else {return CHARGEBOW_LINK_C0_CSET;}
  322. }
  323.  
  324. void run(int item_id, int arrow_tile, int arrow_cset) {
  325. // Hide Link.
  326. Link->Invisible = true;
  327.  
  328. // Grab Link's graphic.
  329. int tile = ChargeBow.LinkTileBase();
  330. int cset = ChargeBow.LinkCSet();
  331.  
  332. // First, find what button we're using.
  333. bool button_a = GetEquipmentA() == item_id;
  334.  
  335. // Charge the shot.
  336. int charge_timer = 0;
  337. int charge_level = 0;
  338. while (true) {
  339. // If link got hurt, quit the script.
  340. if (LA_GOTHURTLAND == Link->Action || LA_GOTHURTWATER == Link->Action) {
  341. Link->Invisible = false;
  342. Quit();
  343. }
  344.  
  345. // Exit the loop if we've let go of the button.
  346. if (!Cond(button_a, Link->InputA, Link->InputB)) {break;}
  347.  
  348. // Increment the charge timer.
  349. ++charge_timer;
  350.  
  351. // Check if we've passed to the next level.
  352. if (LevelUnlocked(charge_level + 1) && ChargeTime(charge_level + 1) == charge_timer) {
  353. ++charge_level;
  354. PlayChargeSound(charge_level);
  355. }
  356.  
  357. // Set Link's direction.
  358. Link->Dir = ChargeBow.LinkInputDir();
  359.  
  360. // Prevent normal commands.
  361. NoAction();
  362.  
  363. // Draw Link.
  364. Screen->DrawTile(2, Link->X - 8, Link->Y - 8, tile + Link->Dir * 2, 2, 2,
  365. cset, -1, -1, 0, 0, 0, 0, true, OP_OPAQUE);
  366.  
  367. // Wait for the next frame.
  368. Waitframe();
  369. }
  370.  
  371. // Make Link visible again.
  372. Link->Invisible = false;
  373.  
  374. // Create the arrow.
  375. int dir = ChargeBow.LinkInputDir();
  376. int dx = ChargeBow.DirX(dir);
  377. int dy = ChargeBow.DirY(dir);
  378. lweapon arrow = Screen->CreateLWeapon(LW_ARROW);
  379. arrow->Damage = ChargeBow_Damage(item_id, charge_level, CHARGEBOW_ELEMENT_NONE);
  380. arrow->Dir = dir;
  381. arrow->X = Link->X + dx * 16;
  382. arrow->Y = Link->Y + dy * 16;
  383. arrow->Step = ChargeBow_Speed(item_id, charge_level, CHARGEBOW_ELEMENT_NONE) * 100;
  384. arrow->OriginalTile = arrow_tile + dir;
  385. arrow->OriginalCSet = arrow_cset;
  386. arrow->Tile = arrow_tile + dir;
  387. arrow->CSet = arrow_cset;
  388. arrow->NumFrames = 1;
  389.  
  390. while (arrow->isValid()) {
  391. Waitframe();
  392. }
  393. }
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement