ZoriaRPG

Item Disabling for Custom Counters

Dec 23rd, 2017
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int OwnsItems[256];
  2.  
  3.  
  4. //For every item in the game, if it uses a counter, set the index that matches its ID to
  5. //the desired counter. The pickup-script does this for you, but there is no way to read
  6. //what counter an item would use in 2.50.x, so you need to use an InitD arg.
  7. //I'm initialising this manually, because counte r0 is CR_LIFE, and if we initialised
  8. //each index to '0', then items would all use HP. :D
  9. int TieToCounter[256] =
  10.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  11.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  12.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  13.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  14.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  15.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  16.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  17.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  18.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  19.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  20.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  21.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  22.       -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1 };
  23.  
  24. //Likewise, this stores the minimum cost of every item.
  25. //I'm initialising this manually so that it has a clear table, for hard-coding, if needed.
  26. int ItemCounterCosts[256] =
  27.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  28.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  29.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  30.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  31.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  32.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  33.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  34.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  35.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  36.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  37.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  38.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  39.       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  40.  
  41. int GetItemCounter(int itm_id) { return TieToCounter[itm_id]; }
  42. int GetItemCost(int itm_id) { return ItemCounterCosts[itm_id]; }
  43.  
  44.  
  45. //! Item Script Args :
  46. //!     These are shared between the pickup-script and the action-script, per item!
  47. //! D0: The message to display, if any.
  48. //! D1: The ID of the item. In 2.54, you could do this->ID, but in 2.50.x this is needed.
  49. //! D2: The counter to use.
  50. //! D3: The cost per use.
  51.  
  52. //Pick-Up Scriot
  53. item script new_item
  54. {
  55.     //D2 is the counter. Don't leave it at '0' unless you want the item
  56.     //to drain Link's HP!
  57.     //(If the cost value is also '0', then that would be safe, but it isn't a good idea.)
  58.     void run(int msg, int itm_id, int use_ctr, int cost)
  59.     {
  60.         OwnsItems[itm_id] = 1;
  61.         if ( msg > 0 ) Screen->Message(msg);
  62.         TieToCounter[itm_id] = use_ctr;
  63.         ItemCounterCosts[itm_id] = cost;
  64.     }
  65. }
  66.  
  67. //Action Script
  68. item script use_counter_cost
  69. {
  70.     void run(int a, int itm_id, int c, int d)
  71.     //InitD args are shared between use and pickup scripts.
  72.     {
  73.         Game->DCounter[GetItemCounter(itm_id) -= GetItemCost(itm_id);
  74.         //Do other item stuff here if needed.
  75.     }
  76. }
  77.  
  78. void EnableDisableItems()
  79. {
  80.     int c;
  81.     for ( int q = 0; q < 256; ++q )
  82.     {
  83.         c = GetItemCounter(q);
  84.         if ( OwnsItem[q] )
  85.         {
  86.             if ( Link->Item[q] )
  87.             {
  88.                 if ( c > 0 )
  89.                 {
  90.                     if ( Game->Counter[c] <= GetItemCost(q) )
  91.                     {
  92.                         Link->Item[q] = false;
  93.                     }
  94.                 }
  95.             }
  96.             if ( !Link->Item[q] )
  97.             {
  98.                 //No counter assigned.
  99.                 if ( c <= 0 ) { Link->Item[q] = true; }
  100.                 //! Caution, this may interfere with other things that set items false.
  101.                 if ( c > 0 )
  102.                 {
  103.                     if ( Game->Counter[c] >= GetItemCost(q) )
  104.                     {
  105.                         Link->Item[q] = true;  //same possible problem.
  106.                         //Multiple sources of setting/unsetting items can create script bugs.
  107.                     }
  108.                 }
  109.             }
  110.         }    
  111.     }
  112. }
  113.  
  114.  
  115.  
  116. global script test
  117. {
  118.     void run()
  119.     {
  120.         while(true)
  121.         {
  122.             EnableDisableItems();
  123.             Waitdraw();
  124.             Waitframe();
  125.         }
  126.     }
  127. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×