PDA

View Full Version : Enemy Editor is HERE, basically



C-Dawg
01-01-2007, 08:03 PM
From my thread in Developer's Exchange:

http://users.sephiroth.ws/C-Dawg/SideQuest.zip

Included in this zip file (which I update frequently) is an example quest file and the exported ZScript. In the ZScript are numerous utility functions I'm using to make custom bosses. I want to draw your attention to the enemy_ghosting script, which is as follows:



// =====================================
// 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 = Screen->CreateNPC(enemy_id);
ghost_enemy->HP = hit_points;
int x = this->X;
int y = this->Y;

while (true){

if (Screen->NumNPCs() >= 1){

ghost_enemy->X = x;
ghost_enemy->Y = y;
x = this->X;
y = this->Y;
}

Waitframe();

} // end of while loop

} // end of void run

} // end of enemy_ghosting


All that this script does is:
(1) Creates an enemy at the FFC's location with as many hit points as you like; and
(2) Moves the enemy where ever the FFC goes.

This simple script is the basis for the most powerful custom boss ability we have had yet, and functions essentially as an enemy editor. For instance, if you delete the "fire" enemy's tiles and place a "fire" enemy with 100 hit points on top of a moving FFC using this script, you've now made a moving target that takes 100 hits before dying. Set enemies->secrets on that screen, and viola; instant (if simple) custom boss.

Ah, but it gets better. Let's say you want the boss to move according to a script, or fire projectiles, or whatnot. Easy as pie. Set FFC1 to be invisible, and load it with a script to move around the screen. (Saffith's follow_link is a good place to start; you'll also find figure_8 and pursue_player in the zip file I provided.) Now, let's say your boss is 2x2. FFC2,3,4, and 5 will be the combos making up your boss. Make em damage combos. Draw the appropriate tiles and select em. Link them all FFC1, and make sure FFC1 is centered at the middle of your boss. Because you Linked the other FFCs to FFC1, moving FFC1 moves the boss. Easy!

EDIT: Be careful that your movement script always moves FFC1 by changing its VELOCITY, not it's POSITION. (Vx as opposed to X). It appears that the velocity assigned to FFC1 will apply to all linked FFCs, but position assigned to FFC1 will not be assigned to the linked FFCs. If your boss isn't following the mover FFC, this may be why.

The ghosting script can now be used to set up the boss's weak point. Assign the ghosting script to FFC2,3,4, or 5 and set a fire enemy with however many hit points you care to use. The ghosting script can also be used to give the boss projectile attacks. Just ghost a Fire Shooter, Arrow Shooter, etc onto one of the other FFCs.

One quirk about this procedure is that all of the Linked FFCs seem to refer to the cooridinates of FFC1 when running scripts; that is, it doesn't matter which FFC (2,3,4, or 5) you set to be the "target" fire enemy, the game will move it to FFC1. Same with the projectiles. This is why, generally, you should center FFC1 inside your custom boss.

EDIT : I have discovered the reason this happens. The "this->" function is bugged, at least in ZCb.15. It always points to the position of FFC1, which, in this case, is the invisible mover FFC. If you change the enemy_ghosting script to use "this_ffc" style pointers instead of "this" style pointers, you should be able to place weak points and shooters on whichever particular part of the enemy you wish.

This custom boss procedure should scale marvelously. If you want more complicated behavior, just make a more complicated moving alorithm. If you want to get really fancy, involve other FFCs to set up special effects. In the example quest, seaweed_spitter is one example of this. (Though I'd like to change his behavior eventually.)

One last warning: the ghosting script is a little picky about enemies being on the screen. If you kill all the enemies on the screen, and don't warp away, ZQuest often crashes. I don't see why it's doing that, as I'm checking to see whether there are enemies on the screen BEFORE I tell it to modify one, but there you go. You can avoid this problem by making sure that the ghosted enemy's death triggers secret pit warps or otherwise gets the player off of the screen.

A few assorted FYIs :

Shooter enemies do not count towards enemies on the screen for purposes of enemies->secrets flag. So you don't have to worry about them when setting up a custom boss this way.

If an FFC moves off the screen too far (more than two tiles' width, it seems) it will vanish forever and not respond to scripting. So if your custom boss moves around, make sure he doesn't move too far off the screen or he'll come back missing parts.

If you want a 1x1 custom enemy that fires projectiles, you could make a new FFC script that ghosts both a fire enemy (for hit ponits) and a shooter (for the effect). Or, and probably easier, you can make two FFCs that just move together as one, only one of which has an enemy graphic on it. The rest are blank.

Master_of_Power
01-03-2007, 01:18 PM
Ok, now I was wondering if it were possible for you to make the FFC follow the Enemy?

C-Dawg
01-03-2007, 01:36 PM
Well, sure. Nearly the same code, just reverse the order of the assignment statements.

_L_
01-03-2007, 01:39 PM
Hooray!


One last warning: the ghosting script is a little picky about enemies being on the screen. If you kill all the enemies on the screen, and don't warp away, ZQuest often crashes.Maybe you need to make sure that the ghost_enemy pointer still points to a present enemy?
If an FFC moves off the screen too far (more than two tiles' width, it seems) it will vanish forever and not respond to scripting. So if your custom boss moves around, make sure he doesn't move too far off the screen or he'll come back missing parts.You can counteract this by turning on the Screen Flag that makes FFCs wrap around. Of course, then you have to make sure that they don't accidentally wrap around...

C-Dawg
01-03-2007, 01:44 PM
_L_, you bastard. Now that you're back, explain how your gravity script / screen flag works. I need to get my jumping script to cooperate with it.

_L_
01-04-2007, 02:19 AM
Sure, whatever.

Link has a variable called "Fall"*, which you might be able to access in ZScript in approaching betas. There are also constants GRAVITY (which is 16) and TERMINALV (terminal velocity, which is 320).

In sideview, here's what happens to Link:
* Fall starts at 0.
* On every frame, (Fall / 100) is added to Y.
* If Link is standing on an unwalkable combo, Fall becomes 0.
* If the top of Link's head collides with an unwalkable combo, Fall becomes 0.
* If Link is not standing on an unwalkable combo, and if Fall <= TERMINALV, and the Hover Boots haven't run out, then GRAVITY is added to Fall.

That is all.
(Hmm... in order for Link to be shot up to the top of the screen, Fall must be becoming extremely negative...)

*Currently accepting better names, but note that Fall influences the Z variable in topdown and the Y variable in sideview.

CJC
01-04-2007, 02:26 AM
This is great for custom bosses (And would probably be amazing when combined with my own custom boss styles), but I'm not sure yet if I'd want to use this type of setup for all my enemies. (I need 2x2 enemies, but doing them all with FFC would make the quest file huge)


Still, this should tide people over for a while, and the code looks great. I'll definitely use this.

Nice code, C-Dawg.

C-Dawg
01-09-2007, 01:33 PM
Updated opening post to reflect new information learned about the way this code works.