Advertisement
ZoriaRPG

Item Removal Script Engine Example for Alucard

Mar 3rd, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. bool firstplay = true;
  2.  
  3. //Link active script
  4. link script links
  5. {
  6.     int collected_items[256];
  7.     int item_scripts[512];
  8.     int data[2048];
  9.     const int REMOVAL_SCRIPT = 0; //array index of data[]
  10.     void run()
  11.     {
  12.         data[REMOVAL_SCRIPT] = Game->GetItemScript("ItemRemoval");
  13.         while(1)
  14.         {
  15.             CheckInventory();
  16.             Waitdraw();
  17.             Waitframe();
  18.         }
  19.        
  20.     }
  21.     void CheckInventory()
  22.     {
  23.         for ( int q = 1; q < 512; ++q )
  24.         {
  25.             if ( collected_items[q] )
  26.             {
  27.                 if ( !Link->Item[q] )
  28.                 {
  29.                     itemdata id = Game->LoadItemData(q);
  30.                     id->Script = data[REMOVAL_SCRIPT];
  31.                     id->RunScript();
  32.                     collected_items[q] = 0; //Fuly remove from inventory.
  33.                 }
  34.             }
  35.         }
  36.        
  37.     }
  38. }
  39.  
  40. item script ItemRemoval
  41. {
  42.     void run()
  43.     {
  44.         bool done = false;
  45.         //effect here
  46.         //can be made to run for more than one frame
  47.         //with a while loop as of 2.55 Alpha 2 or 3 or 4.
  48.         while(!done)
  49.         {
  50.             //when our oop ends
  51.             done = true;
  52.             Waitframe();
  53.         }
  54.         //when done, set back the original item script
  55.         this->Script = links.item_scripts[this->ID];
  56.        
  57.     }
  58. }
  59.  
  60. //Link Init Script
  61. link script linkinit
  62. {
  63.     void run()
  64.     {
  65.         int collectscriptid = Game->GetItemScript("ItemCollect"); //cache here
  66.         itemdata id;
  67.         for ( int q = 1; q < 512; ++q )
  68.         {
  69.             id = Game->LoadItemData(q);
  70.             id->PScript = collectscriptid; //auto-set the collect script for every item in the quest
  71.         }
  72.         if ( firstplay )
  73.         {
  74.             for ( int q = 1; q < 512; ++q )
  75.             {
  76.                 id = Game->LoadItemData(q);
  77.                 links.item_scripts[q] = id->Script; //cache all original item scripts at the very start of the game
  78.             }
  79.             firstplay = false;
  80.         }
  81.     }
  82. }
  83.  
  84. //Generic collect script to put on a items.
  85. //Can be forced on all items with Link's init script at the start of every session
  86. //Marks if Link owns an item, for use when toggling Link->Item[] elsewhere.
  87. item script ItemCollect
  88. {
  89.     void run()
  90.     {
  91.         links.collected_items[this->ID] = 1;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement