[center][b][size=6][i]Bolt! Spell[/i] (or Item)[/size][/b][/center]
[size=5][b]Description[/b][/size]

This set of scripts creates a flash of lightning on the screen, with a thundering sound, doing global damage to enemies on the screen, while at the same time, Link hurls a projectile lightning bolt at one enemy.

[size=5][b]Screenshots and Demo[/b][/size]

[u][b]Demo Quest:[/b][/u][b] [/b][url=http://zoriarpg.com/zc/ScriptDB/bolt/Bolt.qst]Bolt.qst[/url]

[size=5][b]Code[/b][/size]

[code=auto:0]import "std.zh" //Disable this if you already have imported std.zh.
import "stdExtra.zh" //Import stdExtra.zh to make the FFC script work. (Disable if you already have this.)
import "ffcscript.zh" //Import ffcscript.zh to make FFC functions work. (Disable if you already have this.)

/////////////////////
/// Bolt! Spell /////
//////////////////////////////////////////////////////////////////////////////////////////////
/// This item creates a flash on the screen, with a thundering sound, dealing damage to all //
/// enemies on the screen, while launching a projectile (lightning bolt) toward one target. //
//////////////////////////////////////////////////////////////////////////////////////////////
// D0: Damage to deal                                                                       //
// D1: Sprite to use for this item. Set in:                                                 //
//           Quest->Graphics->Sprites->Weapons/Misc.                                        //
// D2: Amount of MP to expend when using item.                                              //
// D3: Step Speed of the Projectile.                                                        //
// D4: Set this to the FFC slot number to which you assign the FlashScreen FFC script.      //
// D5: Colour of Flash (suggest 1).                                                         //
// D6: Duration of Flash (suggest 45)                                                       //
// D7: Screen-Wide Damage to Deal during Flash.                                             //
//////////////////////////////////////////////////////////////////////////////////////////////

const int BOLT_NOUSE = 0; //Set to the amount of time in frames that you wish to have as a delay between uses of this item.
const int ThunderSFX = 0; //Set to the sound in Quest->Audio->SFX Data to the sound you wish to use as a thunder effct (.wav option included in this package)
const int SFX_ERROR = 0; //Set to your global error sound effect, or any specific error SFX you wish from Quest->Audio->SFX Data.

item script BoltSpell{
    void run(int power, int arrowSprite, int magicCost, int speed, int Script_ID, int colour, int duration, int screenDamage){
	 if (Game->Counter[CR_MAGIC] >= magicCost) //Fill in the numbers for magic consumption and number of projectiles allowed on screen
        {
	 Screen->Wavy = 10; //Makes the screen waver slightly while screen flashes and bolt projectile emits.
	 Game->Counter[CR_MAGIC] -= magicCost; //Sets the MP cost for using the weapon.
	 int args[8] = {colour, duration}; //Sets the colour and duration of the flash in the FFC script.
 npc enemys; //Reads the enemies on screen...
   for(int i = 1; i<=Screen->NumNPCs(); i++) //Find out how many enemies are onscreen.
         {
         enemys = Screen->LoadNPC(i); //Targets those enemies.
         enemys->HP-=screenDamage; //Deals (value of D7) damage to all enemies on-screen during flash.
         }
        
	
		int startX; //the starting position of the LWeapon sprite (X-axis)
        int startY; //the starting position of the LWeapon sprite (Y-axis)
        int startHP = Link->HP; //Needed if you want to include an HP requirement.
        lweapon bolt; //Creates the LWeapon
        Game->PlaySound(ThunderSFX); //Makes the thunder SFX play.
        startX = Link->X+8; //Sets starting position of LWeapon based on Link's position (+8 pixels)
        startY = Link->Y+8; //Sets starting position of LWeapon based on Link's position (+8 pixels)
        Link->Action = LA_ATTACKING; //Produces Link attacking animation. 
        bolt = NextToLink(LW_ARROW, 8);  //Create in front of Link.
        bolt->UseSprite(arrowSprite); //Sets the sprite to use from Weapons->Misc.
        bolt->Damage = power; //Sets the damage of the projectile.
        bolt->Step = speed; //Sets the Step Speed of the projectile, suggest 200-240.
		RunFFCScript(Script_ID, args); //Runs the FFC script that makes the screen flash.
		Link->ItemJinx = BOLT_NOUSE;
		}
		else{
    Game->PlaySound(SFX_ERROR); //If out of MP, play ERROR Sound Effects.
    }
    }
}



//
ffc script FlashScreen{
    void run(int colour, int duration){
	
        while(duration > 0){
            if(duration % 2 == 0) Screen->Rectangle(6, 0, 0, 256, 172, colour, 1, 0, 0, 0, true, 64);
            duration--;
            Waitframe();
        }
    }
}
[/code]
[size=5][b]Setup[/b][/size]

[u][b]Step One:[/b][/u] If you do not have them already, download FFCScript.zh and stdExtra.zh and place them in your ZQ directory. If you are using this script as your base, leave the lines at the top that import these scripts (and std.zh) intact. If you are adding this to a script, disable any of these import lines that you already have in your main script, either by deletkng them or by placing two slashes before them.

[u][b]Step Two:[/b][/u] Add the sound effects (links below, or select your own) to your quest in Quest->Audio->SFX Data, using the unassigned slots (staring at No. 61). Note the number of each sound as you assign them.

[u][b]Step Three:[/b][/u] using the number you noted for the sound effects, change these lines in the script to match the numbers of the sound effects as you assigned them.




[code=auto:0]const int ThunderSFX = 0; //Set to the sound in Quest->Audio->SFX Data to the sound you wish to use as a thunder effct (.wav option included in this package)
const int SFX_ERROR = 0; //Set to your global error sound effect, or any specific error SFX you wish from Quest->Audio->SFX Data.
[/code]
[u][b]For example:[/b][/u] If you set the thunder.wav sound to slot 61, and the error.wav sound to slot 62, you would set these lines as follows:


[code=auto:0]const int ThunderSFX = 61; //Set to the sound in Quest->Audio->SFX Data to the sound you wish to use as a thunder effct (.wav option included in this package)
const int SFX_ERROR = 62; //Set to your global error sound effect, or any specific error SFX you wish from Quest->Audio->SFX Data.
[/code]
If you wish to force a delay between when Link uses [b][i]Bolt[/i][/b][i]i and when he can next use [b]Bolt[/b][/i], set the value of [i]NOUSE [/i]to a value higher than zero. The time is measured in [b][i]frames[/i] [/b]and there are [i]generally[/i] sixty (60) frames per second, so if you set [b]NOUSE = 60[/b], then Link can only fire at a rte of one shot per second; if you set [b]NOUSE = 90[/b], then Link can fire a shot every 1 1/2 seconds.

If you are using little MP for the item, you may wish a longer delay time. If Link must use a good deal of MP to use this item/spell, you should probably set a short delay time. If you set a value of 0 here, Link can continually fire for as long as he has enough MP. If you set both NOUSE and MP cost (later) to zero, link can fire continually.

[u][b]Step Four:[/b][/u] Open the tile page sheet for your quest, and click [i][b]grab[/b][/i]; then click [b][i]file[/i][/b], select the file [i]bolt_sprites.png[/i] and click [b][i]leech. [/i][/b]Set [b][i]colour depth[/i][/b][i]i to [b][u]8[/u][/b][/i] and click [b][i]OK[/i][/b]. Note the combo page that the tiles that you just imported are now on. (In an empty quest, this is usually page 47.)

Go to the Item Misc. sprite editor (Quest->Graphics->Sprites->Weapons/Misc.) and scroll down until you see the unused slots (starting with [b]zz88[/b]). Select one of these, and click [i][b]edit[/b]; [/i]change the name[i] from zzXXX [/i]to [i]Bolt[/i], then click on the empty (black) tile box. This will open the tile page sheets.

Go to the tile page where your imported tiles are located.([i]Quick Tip[/i]: hit the 'P' key on your keyboard and type the page number, followed by Enter/Return.)

Select the yellow lightning bolt sprite (ten down from the top, and the second over from the left edge) by [b][u]double clicking it[/u][/b]. This will place it in the box in the Weapons/Misc sprite editor. Then, change [b][i]animation frames[/i][/b] to [b][u]2[/u][/b] and [b][i]animation speed[/i][/b] to [b][u]5[/u][/b].

[b][i]Be sure to remember the sprite number![/i][/b]

[u][b]Step Five:[/b][/u] Go to the [b][i]script importation[/i] box [/b](Quest->Scripts->Compile ZScript...). Once there, click [b][i]import[/i]. [/b]You will be asked if it is acceptable to clear the current buffer: Click [b][i]yes[/i][/b] and select the file [i]Bolt.z[/i], then click [b][i]OK[/i][/b], and then click [b][i]compile.[/i][/b] The script will now compile, and you will be asked to assign scripts to slots.

[u][b]Step Six:[/b][/u] Once you have compiled the script, you will fsee the [b][i]script slots assignment pane[/i][/b]. This starts you out viewing [b][i]FFC Scripts[/i][/b]. Assign the FFC script [i]Flashscreen[/i] to a slot, and note what slot it is in. Then click the tab [b][i]Item[/i], [/b]where you will see the[b] [i]item script slots[/i].[/b] Here, you assign the scripts [i]BoltSpell[/i] and[i] ffcitem[/i] to item script slots. (You do not need to note these numbers.)

Check the box 'Output ZASM code to Allegro.log' if you wish to track any errors reported by ZASM, and then click [b][i]OK.[/i][/b] When you see the success report window, click [b][i]OK [/i][/b] there as well.

[u][b]Step Seven:[/b][/u] Open the[i][b] Item Editor [/b][/i](Quest>Items), and select either one of the [i]Custom Items[/i] items, or one of the [i]zzXXX[/i] items items (e.g. [i]zz101[/i]). (For this example, we will use [b][i]Custom item 01[/i][/b].)

[u][b]Step Eight:[/b][/u] In the item editor, change the [b][i]Item Class[/i] to a [u]unique[/u][/b] item class that you do not plan to use elsewhere. Select one of the [i]Custom Item Classes[/i], or a [i]zzXXX [/i]class ([i]e.g. [/i]as [i]zz089[/i]). For this example, we use [b][i]Custom Itemclass 01.[/i][/b]

Check the box [b][i]Equipment Item[/i][/b][i], [/i]and click the [b][i]GFX[/i] [/b]tab. Click on the lank (black) tile, and again go to the page where you imported the tilesheet [i]bolt_sprites.png, [/i]or to any other page containing the sprite that you want to set for the item. Select a sprite to represent the item, and set its [i]animation frames[/i] and [i]animation speed[/i]as you desire. The [i]bolt_sprites.png[/i] tilesheet has several alternative wand and staff items, although a medallion or custom sprite is all fine. That's up to you.

Next, click on the [b][i]Scripts[/i][/b] tab, and set the [b][i]action script[/i][/b][i] [/i]to the script [i]BoltSpell[/i].

Set the [i][b]arguments [/b][/i](D0-D8) as follows:

[b]D0:[/b] This is the amount of damage that the projectile lightning bolt does to enemies it hits.
[b]D1:[/b] This is the sprite you selected in the Weapins/Misc editor. Therefore, if you set the lightning bolt sprite to be Weapons/Misc. sprite 88, make the value of D1 '88' (no quotes).
[b]D2: [/b]Set this to the amount of MP that yu wish Link to spend each time he uses this item. Note that a single magic container has 32MP.
[b]D3:[/b] Set this to the speed you wish the lightning bolt projectile to travel in pixels per second. A value of 200-240 is good here.
[b]D4: [/b]Set this to the FFC slot number that you noted hen you set the FFC Script [i]FlashScreen[/i].
[b]D5:[/b] Set this to the colour of the flash. If using the classic tikleset, a value of '1' (no quotes), which is white works best. if you are using another tileset, or another colour palette, find out where the colour is in your palette that you wish the screen to flash (for lightning effects) in Quest->Graphics->Palettes->Main. The number of this value must be [b][i]decimal,[/i][/b][b] starting at zero[/b]. Each row contains [u]sixteen[i] colours[/i][/u][i], [/i]so count the rows, and then the number of swatches from left to right to deduce what colour number of your palette you are using.
[b]D6:[/b] This is the duration of the flash [b][i]in frames[/i][/b][i].[/i]The best number here is '45' (no quotes).
[b]D7:[/b] This is the amount of damage that the spell does to all enemies on-screen during the flash effect. This is best set to 1, or possibly 2 in a difficult game. You can set this to '0' (no quotes) if you wish no global damage.

When you have set all of the arguments, click [b][i]OK.[/i][/b]

[i][b]You have completed set-up of this item.[/b][/i]

[size=5][b]Resources[/b][/size]
[u][b]Requires[/b][/u]
[url=http://www.purezc.net/forums/index.php?showtopic=55349&view=findpost&p=851243&hl=%2Bstdextra]Header: stdExtra.zh[/url]
[url=http://www.purezc.net/forums/index.php?showtopic=50511&hl=ffcscript]Header: ffcscript.zh[/url]

[u][b]Sound Effects[/b][/u]
[url=http://zoriarpg.com/zc/ScriptDB/bolt/bolt.wav]bolt.wav[/url]
[url=http://zoriarpg.com/zc/ScriptDB/bolt/error.wav]error.wav[/url]
[url=http://zoriarpg.com/zc/ScriptDB/bolt/sonic.wav]sonic.wav[/url]

[u][b]Graphics[/b][/u]
[url=http://zoriarpg.com/zc/ScriptDB/bolt/bolt_sprites.png]bolt_sprites.png[/url]

[size=5][b]Credits (Alphabetical)[/b][/size]
[u][b]Script Concept & Creation:[/b][/u]
ZoriaRPG

[u][b]Basecode Resources & Headers[/b][/u]
Colossal, Moscowmodder, Saffith

[u][b]Sound Effects & Graphics[/b][/u]
(bolt.wav) [i]Freesound.org,[/i] (error.wav) [i]Dracula II: Noroi no Fuin[/i], (sonic.wav) [i]Doctor Who [/i](1996, film)

[u][b]Tiles [/b][/u]
Saffith, ZoriaRPG