Just for amusement, this is how something like that would work in ZScript, with a number of precautionary conditions in place...
ffc script SpecialEnemyDrop{
void run(int enemy_id, int special_drop, int special_percentage, int reg, int special_drop_sfx){
//Each index is a 1% chamce f dropping a specific item.
item i;
int droplist[100]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int factor = Rand(1,100);
npc n; int q[10];
//Check to see if the special enemy is on the screen. If so, mark it.
for ( q[0] = Screen->NumNPCs(0; q[0] > 0; q[0]-- ) {
n = Screen->LoadNPC(q[0]);
if ( n->ID == enemy_id ) { q[1] = q[0]; break; }
}
//If the enemy is not on the screen, and Link had grabbed the special item, or it has never spawned, exit.
if ( !q[1] && Screen->D[reg] <= 0 ) { this->Script = 0; this->Data = 0; Quit(); }
//Create the special item if the register values are set. This is so that if Link left the room without taking it,
//that it reappears.
if ( !q[1] && Screen->D[reg] > 0 ) {
if ( special_drop_sfx ) Game->PlaySound(special_drop_sfx); //Play the sound.
i = Screen->CreateItem(special_drop);
i->X = Screen->D(reg) << 0; //Read the Screen->D[reg] values to position it precisely where it had fallen before.
i->Y = (Screen->D[reg] - (Screen->D[reg] << 0)) * 10000;
}
//While the npc is alive, store is coordinates.
while(n->isValid()) {
q[3] = n->X;
q[4] = n->Y;
q[5] = q[4] / 10000; //Save the coordinaes to Screen->D[reg]
if ( n->HP <= 0 ) break;
Waitframe();
}
//If we passed the percentage check, and we have not made the special item in the past...
if ( special_drop && factor <= special_percentage && !Screen->D[reg] >= 0 ) {
if ( special_drop_sfx ) Game->PlaySound(special_drop_sfx); //Play the special drop sound.
i = Screen->CreateItem(special_drop);
i->X = q[3];
i->Y = q[4];
q[6] = q[3]+q[5];
Screen->D[reg] = q[6]
}
else { //The special item percentage roll failed, or the item was already created in the past.
i = Screen->CreateItem(droplist[factor]); //Make an item from the random drops list.
i->X = q[3];
i->Y = q[4];
i->Pickup = IP_TIMEOUT; //Make it an ordinary drop.
this->Script = 0; this->Data = 0; Quit();
}
//If the special item is on the screen:
while(i->isValid()){
if ( LinkCollision(i) ) {
Screen->D[reg] = -1; //If Link picks it up, set the register to denote it is no loner to spawn.
this->Script = 0; this->Data = 0; Quit();
}
Waitframe();
}
//If we reach here, we're done.
this->Script = 0; this->Data = 0; Quit();
}
}
You would just place that ffc on the screem. If you used a global active script to do this, then you would check Game->CetCurScreen(), Game->GetCurDMap(), and change the while loops into statements.
Edited by ZoriaRPG, 30 November 2016 - 06:50 PM.