Npc (ZScript)

From ZCWiki
Jump to: navigation, search

The keyword npc specifies that a variable is a pointer (a reference) to a non-playing character, such as an enemy, on the screen.

Syntax and Initialization

Declare a variable as type npc as follows:

npc AnEnemy;

Until you initialze the variable, it does not actually "point to" any particular non-playing character, and thus any properties or methods you attempt to use will be invalid. You must initialize the variable by using the Screen->CreateNPC or Screen->LoadNPC methods, as follows:

// You can initialize at declaration...
npc AnEnemy = Screen->LoadNPC(1);

// ...or you can initialize later.
AnEnemy = Screen->LoadNPC(1);

Properties and Methods

The syntax for accessing the methods and properties associated with an npc type variable is as follows:

npc-variable->method-or-property;

where npc-variable is a variable of type npc and method-or-property is one of the methods or properties listed below. For instance, the following snippet would get the hitpoints of the first enemy on the screen.

// Create an npc variable and set it
// to the first enemy on the screen
npc AnEnemy = Screen->LoadNPC(1);
int Hitpoints = 0;

Hitpoints = AnEnemy->HP;

As with any expression, you can use these methods or properties as the evaluation criteria in control loops, if statements, and so forth.

Properties

int ASpeed

The speed of the NPC's animation, in screen frames.

int BossPal

The boss pallete used by this NPC; this pallete is only used if CSet is 14 (the reserved boss cset). Use the BPAL_ constants in std.zh to set or compare this value.

int CSet

The CSet used by this NPC.

int Damage

The amount of damage dealt to a naked Link when he touches this NPC, in quarter-hearts.

int Dir

The direction the NPC is facing. Use the DIR_ constants in std.zh to set and compare this value.

int DrawStyle

The way the NPC is animated. Use the DS_ constants in std.zh to set or compare this value.

int Extend

Whether to extend the sprite of an item or enemy, as with extended Link tile modifiers.

int HP

The NPC's current hitpoints. Each swing of the wooden sword removes 2 hitpoints.

int Haltrate

The extent to which the NPC stands still while moving around the screen. As a point of reference, the Zols and Gels have haltrate of 16.

int ItemSet

The items that the NPC might drop when killed. Use the IS_ constants in std.zh to set or compare this value.

int Rate

The rate at which the NPC changes direction. For a point of reference, the Octorok on Crack has a rate of 16.

int SFX

The sound effects emitted by the enemy. Use the SFX_ constants in std.zh to set or compare this value.

int Step

The NPC's movement rate. As a point of reference, the Octorok on Crack has a step of 200.

int Tile

The number of the starting tile used by this NPC.

int Weapon

The weapon used by this enemy. Use the WPN_ constants in std.zh to set or compare this value. Note that it typically only makes sense to assign weapons labelled as enemy weapons (WPN_ENEMY) (with the exception of WPN_NONE) to this value.

int WeaponDamage

The amount of damage dealt to a naked Link by this NPC's weapon, in quarter-hearts.

int X

The NPC's current X coordinate, in pixels.

int Y

The NPC's current Y coordinate, in pixels.

Methods

isValid

The isValid method indicates whether or not this NPC pointer is still valid. A return value of true indicates the pointer is still valid.

A pointer becomes invalid if the enemy dies or Link leaves the screen. Trying to access any variable of an invalid NPC pointer prints an error to allegro.log and does nothing.

Introduced in Version
2.5 (beta)
Prototype and Arguments
bool isValid()