Weapon (ZScript)

From ZCWiki
Jump to navigationJump to search

The lweapon data type represents a scriptable weapon that can be used to damage enemeies. The eweapon data type represents a scriptable weapon that can be used by enemies to damage Link. These objects can be created/loaded as necessary in a script, and provide a means of letting Zelda Classic figure out a portion of the weapon's control, visual effects, and damage effects (versus having to track all these things "manually" in the script).

Sytax and Usage

Declare a variable of type lweapon and/or eweapon as follows:

// A weapon that will damage enemies.
lweapon ProjectileWeapon;

// An enemy weapon that will damage Link.
eweapon EnemyBlast;

Until you initialze the variable, it does not actually "point to" any particular lweapon or eweapon, and thus any properties or methods you attempt to use will be invalid. You must initialize the variable by using the appropariate Load or Create method of the Screen object. For example:

// You can initialize at declaration...
lweapon ProjectileWeapon = Screen->CreateLWeapon(LW_ARROW);

// ...or you can initialize later.
ProjectileWeapon = Screen->LoadLWeapon(1);

Refer to the following Screen methods:

Note that you can use the LoadWeapon functions to gain control of weapons that you did not create with the CreateWeapon functions. For instance, with a "normal" Zora on the screen, you can use the LoadEWeapon function manipulate the fireballs she spits out.

Methods and Properties

lweapons and eweapons possess exactly the same attributes, although their designation affect how they are treated by the engine. The values here correspond to both the lweapon and eweapon type.


There are no methods associated with lweapon and eweapon.


bool isValid()

Returns whether this weapon pointer is still valid. A weapon pointer becomes invalid when the weapon fades away or disappears or Link leaves the screen. Accessing any variables using an invalid weapon pointer prints an error message to allegro.log and does nothing.

int ID

The weapon's ID number. The effect of writing to this field is currently undefined.

int X

The weapon's X position on the screen, in pixels.

int Y

The weapon's Y position on the screen, in pixels.

int Z

The weapon's Z position on the screen, in pixels.

int Jump

The weapon's falling speed on the screen. Bombs, Bait and Fire weapons obey gravity, although this may only be noticable in sideview.

int DrawStyle

An integer representing how the weapon is to be drawn. Use one of the DS_ constants in std.zh to set or compare this value.

int Dir

The direction of the weapon momement. This is used by certain weapon types to determine movement, shield deflection and such.

For projectile type weapons (such as arrows) set this to the direction the projectile should travel. For melee weapons (such as a hammer) this will be the direction of the attack. If Angular is true, then the value of Angle is used to determine the direction of movement - however, Dir is still required to determine shield deflection.

Note that for some weapons, you may also need to flip the tile to acheive the desired look. For example, arrows are evidently always spwaned with the shaft oreiented veritcally, which can look rather silly when the arrow is moving from right to left.

int OriginalTile

The starting tile of the weapon's animation.

int Tile

The current tile associated with this weapon.

int OriginalCSet

The starting CSet of the weapon's animation.

int CSet

This weapon's current CSet.

int FlashCSet

The CSet used during this weapon's flash frames, if this weapon flashes.

int NumFrames

The number of frames in this weapon's animation.

int Frame

The weapon's current animation frame.

int ASpeed

The speed at which this weapon animates, in screen frames.

int Damage

The amount of damage that this weapon causes to Link/an enemy upon contact.

int Step

Usually associated with the weapon's velocity.

int Angle

The weapon's current angle, in radians. Angular must be set to true before setting this property. In this case, the Angle overrides Dir for the direction of movement; however, Dir must still be specified to determine shield deflection.

bool Angular

Specifies whether a weapon has angular movement. Must be set to true before attributing the weapon an angle.

int DeadState

The current state of the weapon. A value of -1 indicates that it is active, and moves according to the weapon's Dir, Step, Angular, and Angle values (in other words, set DeadState to -1 if you want the engine to handle movement). Use any value below -1 if you want a dummy weapon that you can control on your own.

If you want to remove the weapon, write one of the WDS_ constants in std.zh (appropriate for the weapon) to this variable.

bool Flash

Whether or not the weapon flashes. A flashing weapon alternates between its CSet and its FlashCSet.

int Flip

Whether and how the weapon's tiles should be flipped.

  • 0: No flip
  • 1: Vertical flip
  • 2: Horizontal flip
  • 3: Rotate 180 degrees
  • 4: Rotate clockwise 90 degrees
  • 7: Rotate counter-clockwise 90 degrees

int Extend

Whether to extend the sprite of the weapon.

See Also