C-Dawg
01-21-2007, 12:49 PM
This is getting annoying. When you have a script that creates an NPC and a pointer to that NPC, it appears that it crashes without fail upon that NPC's death. This code, for instance, crashes upon the enemy's death.
// =====================================
// enemy_hp_ghosting - This ffc will create
// a specified enemy at the location of the
// ffc. It will set the enemy's HP to a
// defined value. The enemy will be kept
// centered at the ffc.
// This script will monitor the health of the
// creature it created, and either warps or
// changes the combo of the FFC when the NPCs
// health is below 10.
// Use to give an FFC "hit points" by creating
// a fire enemy or shooter that moves with it.
// D0 = The enemy ID you want to create.
// D1 = The HP you want the enemy to have.
// D2 = 0 -> Switch FFC combo
// Any other value -> Warp player
// D2 = The destination DMAP.
// D3 = The screen on the destination DMAP.
// D4 = The number of this FFC (for this-> bug)
// =======================================
ffc script enemy_hp_ghosting{
void run(int enemy_id, int hit_points, int warp_or_change, int dest_dmap, int dest_screen, int this_ffc_number){
npc ghost_enemy = Screen->CreateNPC(enemy_id);
ghost_enemy->HP = hit_points;
int x = this->X;
int y = this->Y;
bool enemy_defeated = false;
ffc this_ffc = Screen->LoadFFC(this_ffc_number);
while (!enemy_defeated){
ghost_enemy->X = x;
ghost_enemy->Y = y;
x = this_ffc->X;
y = this_ffc->Y;
if (ghost_enemy->HP <= 10) {
ghost_enemy->HP = 0;
ghost_enemy = Screen->LoadNPC(1);
enemy_defeated = true;
if ( warp_or_change == 0 ){
Game->PlaySound(3);
this_ffc->Data++;
}
else{
Link->Warp(dest_dmap, dest_screen);
}
}
Waitframe();
} // end of while loop
} // end of void run
} // end of enemy_ghosting
I tried to make sure this code would never, ever refer to ghost_enemy once it had died. When it is down to 10 hit points, a variable is set that disables the while loop. The enemy is then killed by setting HP to zero. There should be no time where the engine is looking for an NPC that isnt there. Yet, as soon as an enemy dies, it's crashtown.
// =====================================
// enemy_hp_ghosting - This ffc will create
// a specified enemy at the location of the
// ffc. It will set the enemy's HP to a
// defined value. The enemy will be kept
// centered at the ffc.
// This script will monitor the health of the
// creature it created, and either warps or
// changes the combo of the FFC when the NPCs
// health is below 10.
// Use to give an FFC "hit points" by creating
// a fire enemy or shooter that moves with it.
// D0 = The enemy ID you want to create.
// D1 = The HP you want the enemy to have.
// D2 = 0 -> Switch FFC combo
// Any other value -> Warp player
// D2 = The destination DMAP.
// D3 = The screen on the destination DMAP.
// D4 = The number of this FFC (for this-> bug)
// =======================================
ffc script enemy_hp_ghosting{
void run(int enemy_id, int hit_points, int warp_or_change, int dest_dmap, int dest_screen, int this_ffc_number){
npc ghost_enemy = Screen->CreateNPC(enemy_id);
ghost_enemy->HP = hit_points;
int x = this->X;
int y = this->Y;
bool enemy_defeated = false;
ffc this_ffc = Screen->LoadFFC(this_ffc_number);
while (!enemy_defeated){
ghost_enemy->X = x;
ghost_enemy->Y = y;
x = this_ffc->X;
y = this_ffc->Y;
if (ghost_enemy->HP <= 10) {
ghost_enemy->HP = 0;
ghost_enemy = Screen->LoadNPC(1);
enemy_defeated = true;
if ( warp_or_change == 0 ){
Game->PlaySound(3);
this_ffc->Data++;
}
else{
Link->Warp(dest_dmap, dest_screen);
}
}
Waitframe();
} // end of while loop
} // end of void run
} // end of enemy_ghosting
I tried to make sure this code would never, ever refer to ghost_enemy once it had died. When it is down to 10 hit points, a variable is set that disables the while loop. The enemy is then killed by setting HP to zero. There should be no time where the engine is looking for an NPC that isnt there. Yet, as soon as an enemy dies, it's crashtown.