Here's the script, with a seperate void for the function.
...so, no further modification is required.
everything else, same as before:
You can have (max.) 8 Dummy Chests with individual items + 1 engine chest on the same screen.
This (advanced) version of my UncleBugChests will also check if you already got the contained item and switch color and item, in this case.
It allows you to differ between Gen Keys and Lvl Keys...
Place an invisible (Changer) FFC at a Dummy Chest's X/Y coordiniates (FFC has to be on grid).
...check "Run Script on Screen Init"
...assign the D0-D7 variables and let the script do the rest.
import "std.zh"
//remove this line if already imported
void EnemyStun(int stun_time)//a little shortcut to stun enemies during item hold. Inspired by MooshPit.
{
for(int i=Screen->NumNPCs(); i>=1; i--){
npc n = Screen->LoadNPC(i);
n->Stun = Max(n->Stun, stun_time);
}
}
void GiveItem(int itm_id, int holdtype)//Fixed version of the std_extension "GiveLinkItem".
{
item i = Screen->CreateItem(itm_id);
i->X = Link->X;
i->Y = Link->Y;
i->Z = Link->Z;
if ( holdtype == 1 )
{
Link->HeldItem = itm_id;
if ( Link->Action == LA_SWIMMING ) Link->Action = LA_HOLD1WATER;
else if ( Link->Action == LA_DIVING ) Link->Action = LA_HOLD1WATER;
else Link->Action = LA_HOLD1LAND;
}
else if ( holdtype == 2 )
{
Link->HeldItem = itm_id;
if ( Link->Action == LA_SWIMMING ) Link->Action = LA_HOLD2WATER;
else if ( Link->Action == LA_DIVING ) Link->Action = LA_HOLD2WATER;
else Link->Action = LA_HOLD2LAND;
}
else
{
if ( holdtype == LA_HOLD1LAND || holdtype == LA_HOLD2LAND || holdtype == LA_HOLD1WATER || holdtype == LA_HOLD2WATER )
{
Link->HeldItem = itm_id;
Link->Action = holdtype;
}
}
}
//D0 = Screen D0-D7 Attribute, to read and write to.
//checks if the chest has already been opened.
//you can use max 8 chests on 1 screen, each has to check/write to unique ScreenD (0-7)
//D1 = ID of the open chest combo
//use dummy chests for the UncleBug Chests
//The open chest combo doesn't need to be the next in list.
//D2 = Item (item_a), the chest shall contain
//D3 = alternative Item (item_b, if you already got item_a)
//D4 = Hold Type (0 = no hold up, 1 = One Hand, 2 = Two Hands)
//D5 = Lock Type/ required Key
//( 0 = unlocked, 1 = General Key, 2 = Lvl specific Key, 3 = Boss Key)
//Gen Keys can not unlock Level specific Chests and Lvl Keys can't unlock General Key chests)
//D6 = CSet of the Chest.
//D7 = Alternative CSet
const int CHEST_SOUND = 4; //Boomerang sfx by default
ffc script UncleBugChest_COLOR
{
void run(int check_d, int open_cmb, int item_a, int item_b, int hld_type, int req_key, int color_a, int color_b)
{
unless(Screen->D[check_d] == 0){
if(Screen->D[check_d] == 1){
Screen->ComboD[ComboAt(this->X, this->Y)] = open_cmb;
Screen->ComboC[ComboAt(this->X, this->Y)] = color_a;
Quit();
}
else if(Screen->D[check_d] == 2){
Screen->ComboD[ComboAt(this->X, this->Y)] = open_cmb;
Screen->ComboC[ComboAt(this->X, this->Y)] = color_b;
Quit();
}
}
if((Screen->D[check_d] == 0) && (!Link->Item[item_a])){
Screen->ComboC[ComboAt(this->X, this->Y)] = color_a;
}
else if((Screen->D[check_d] == 0) && (Link->Item[item_a])){
Screen->ComboC[ComboAt(this->X, this->Y)] = color_b;
}
while(true){
if(!Link->Item[item_a]){
if((Distance(CenterLinkX(), CenterLinkY(), CenterX(this), CenterY(this))<=9) && (Link->Y > this->Y+7)&&(Link->Dir ==DIR_UP)){
if(req_key == 1 && Game->Counter[CR_KEYS] < 1){return;}
else if(req_key == 2 && Game->LKeys[Game->GetCurLevel()] < 1){return;}
else if((req_key == 3) && (!Game->LItems[Game->GetCurLevel()] == LI_BOSSKEY)){return;}
EnemyStun(18);
Audio->PlaySound(CHEST_SOUND);
Screen->ComboD[ComboAt(this->X, this->Y)] = open_cmb;
if(req_key == 1){Game->Counter[CR_KEYS] -=1;}
if(req_key == 2){Game->LKeys[Game->GetCurLevel()] -=1;}
WaitNoAction(6);
GiveItem(item_a, hld_type);
WaitNoAction(12);
Screen->D[check_d] += 1;
Waitframes(3);
Quit();
}
}
else if(Link->Item[item_a]){
if((Distance(CenterLinkX(), CenterLinkY(), CenterX(this), CenterY(this))<=9) && (Link->Y > this->Y+7)&&(Link->Dir ==DIR_UP)){
if(req_key == 1 && Game->Counter[CR_KEYS] < 1){return;}
else if(req_key == 2 && Game->LKeys[Game->GetCurLevel()] < 1){return;}
else if((req_key == 3) && (!Game->LItems[Game->GetCurLevel()] == LI_BOSSKEY)){return;}
EnemyStun(18);
Audio->PlaySound(CHEST_SOUND);
Screen->ComboD[ComboAt(this->X, this->Y)] = open_cmb;
if(req_key == 1){Game->Counter[CR_KEYS] -=1;}
if(req_key == 2){Game->LKeys[Game->GetCurLevel()] -=1;}
WaitNoAction(6);
GiveItem(item_b, hld_type);
WaitNoAction(12);
Screen->D[check_d] += 2;
Waitframes(3);
Quit();
}
}
Waitframe();
}
}
}
Edited by Bagu, 01 November 2021 - 02:39 PM.