const int IC_LITEM = 71;//Item class used for custom level specific items. Default is Custom Item Class 5.
const int LI_STONEBEAK = 0x20;// Test expanded level item
//litems.zh
//Custom level-specific items
//1. Global script combining: Put UpdateSubscreenLitems() function between Waitdraw and Waitframe comaands inside main loop of Active global script.
//2. Set up a sequence of tiles for each custom level specific item: 2 blank tiles and then item`s tile. Animation is not supported.
//3. Set IC_LITEM for custom level specific item class. Default is Custom Item Class 5.
//4. Import and compile the library. Assign 2 item scripts, global script and 1 FFC script. No libraries beyond std.zh needed.
// Item setup
//5. Set item class to one assigned in step 3.
//6. Set tile to 3rd one in sequence from step 2.
//7. Assign LevelItem or MagicLevelItem item script.
//D0 - Litem ID. Must be a power of 2, or you will give Link multiple items at once.
//D1 - Message string ID.
//D2 - ID of tile used by item, from step 6. Scripts cannot access Item`s tile in 2.53 :-(
//Subscreen setup
//8. Create and place 1x1 tile block with tile assigned to leftmost blank tile from sequence in step 2 and CSet to one used by item.
//9. Repeat steps 2 and 5-7 for each custom level specific item to be inclused in the quest.
//Example global script for handling custom level items in subscreen.
global script LItemsSubscreenActive{
void run(){
while(true){
Waitdraw();
UpdateSubscreenLitems();
Waitframe();
}
}
}
//Main function for updating level specific items in subscreen. Run every frame.
void UpdateSubscreenLitems(){
itemdata it;
int level = Game->GetCurLevel();
for (int i=0; i<256;i++){
it = Game->LoadItemData(i);
if (it->Family!=IC_LITEM)continue;
CopyTile(Cond(GetLevelSpecificItem(level, it->InitD[0]),it->InitD[2],it->InitD[2]-1), it->InitD[2]-2);
}
}
//Sets the state of level specific item. Litem ID must be a power of 2, or you will work with multiple items at once.
void SetLevelSpecificItem(int level, int litem, bool remove){
if (!remove) Game->LItems[level] |= litem;
else Game->LItems[level] &= (~litem);
}
//Returns true, if Link has all of the requested level items, Ored together in litem.
//For instance, if litem is 14, the function will return true only if Link has map, compass and boss key of the given level.
bool GetLevelSpecificItem(int level, int litem){
return (Game->LItems[level]&litem) >0;
}
//Grants Link Level specific item/s (ORed together) for all levels.
void SetMagicLevelSpecificItem(int litem){
for(int i=0; i<512;i++){
Game->LItems[i]|=litem;
}
}
//Item script that grants level specific items.
//D0 - Litem ID. Must be a power of 2, or you will give Link multiple items at once.
//D1 - Message string ID.
//D2 - ID of tile used by item. Scripts cannot access Item`s tile in 2.53 :-(
item script LevelItem{
void run(int id, int msg, int tile){
Screen->Message(msg);
int level = Game->GetCurLevel();
SetLevelSpecificItem(level, id, false);
CopyTile(tile, tile-2);
}
}
//Item script that grants level specific items for all levels.
//D0 - Litem ID. Must be a power of 2, or you will give Link multiple items at once.
//D1 - Message string ID.
//D2 - ID of tile used by item. Scripts cannot access Item`s tile in 2.53 :-(
item script MagicLevelItem{
void run(int id, int msg, int tile){
Screen->Message(msg);
SetMagicLevelSpecificItem(id);
CopyTile(tile, tile-2);
}
}
//Link`s Awakening bird statue. If Link inserts stone beak from the same level, it displays message.
//Place at bird statue`s location.
//D0 - Message ID.
ffc script LAHintBirdStatue{
void run(int msg){
int level = Game->GetCurLevel();
while(true){
if (LinkCollision(this)&&(Link->PressA)){
if (GetLevelSpecificItem(level, LI_STONEBEAK)) Screen->Message(msg);
}
Waitframe();
}
}
}