PDA

View Full Version : Moving Enemies with an FFC



C-Dawg
12-31-2006, 06:35 PM
This is the second time I've encountered a bug like this. What I want to happen is for an enemy to follow the ffc around the screen. That doesn't happen. The enemy gets created and moved to the x,y coordinates of the ffc's original starting location, but as the ffc moves, the enemy stays put. The code IS moving the enemy each frame, as evidenced by the fact what the enemy doesn't move anywhere.



// =====================================
// enemy_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.
// 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.
// =======================================

ffc script enemy_ghosting{

void run(int enemy_id, int hit_points){

npc ghost_enemy = npc CreateNPC(enemy_id);
ghost_enemy->HP = hit_points;
int x = this->X;
int y = this->Y;

while (true){

ghost_enemy->X = x;
ghost_enemy->Y = y;
int x = this->X;
int y = this->Y;
Waitframe();

} // end of while loop

} // end of void run

} // end of enemy_ghosting

jman2050
12-31-2006, 07:00 PM
ghost_enemy->X = x;
ghost_enemy->Y = y;
int x = this->X;
int y = this->Y;
Waitframe();

You're not doing what you think you're doing. What you're indeed doing is setting the enemy's X/Y to the X/Y defined at the start of the script, and then you declare two NEW variables (the fact that they're named the same is of no consequence, by using int x you're declaring a new variable. I'm not sure if it's supposed to be legal, but that's how it works currently).

Just take out the int x, int y and replace it with just x and y, and you should be fine.

eXodus
01-01-2007, 10:20 PM
A couple of questions about the script in general:


Are int x/y even necessary? I'm not exactly seeing why you can't just manipulate this->X/Y and set it to them at the moment.
Wouldn't npc ghost_enemy be invalid by the second frame? You might need to specify its number as a parameter and reload it if you run into any problems...

C-Dawg
01-02-2007, 12:31 PM
Yea, the x and y are necessary. I don't know why, but when I set this code up like so:



ghost_enemy->X = this->X;
ghost_enemy->Y = this->Y;


It would spawn them at 0,0 and never move em. I have no idea why; there were no complicating factors. (Single ffc, no other scripts, no movement.)

As to your second question: No, it doesn't get "invalidated" by the second frame. ghost_enemy is declared as pointing to the npc that the script just gave birth to, and keeps pointing at it each frame until you re-assign it. There IS a problem when the enemy dies, however. What appears to happen is the script just grabs another enemy on the screen without being prompted. If there are no more enemies, it will crash. I'm trying to work around this.