Automated Weapon or Item

SubmittedDecember 14, 2016

0.0 rating

Featured Screenshot

Author

ZoriaRPG

Download Quest

[]

Download Script Package

s132_AutomatedWeaponorItem.zip

Description

This set of functions permits the use of items that have hardcoded effects, called in an automatic manner. While this demo uses a self-shooting arrow, you can also do similar things with any item that the player has, and by varying the conditions, cause hardcoded effects created by items (e.g. Din's Fire) to occur without the player actually using the item.

The main drawback is that for a very small duration, the item that you are activating is shifted into the B-button slot, and then, then item that was previously there is restored. If you wish to make an item that manually repeats while holding a button, i will be uploading a script for that in the near future.

Script Setup Details

Import this library (repeatingItem.z), and its dependencies:

std.zh
ItemHandling.zh (v6.7 or higher)
Timers.zh (v1.0 or higher)

Usage is relatively straightforward, assuming that you want a single item of this nature at any given time.

AutofireInitiate() sets the condition on the item to use. If using an item that produces an lweapon, specify it with AutofireInitiate(item, true) , rather than AutofireInitiate(item).

(This technically also allows you to use any item, even if it has instances on the screen, thus allowing machimne-gun type weapons, or other auto-weapons, based around a timer.)

Note: The attached ZC Custrom Quest (repeatingItem.qst) has all the functions needed to produce this effect in its buffer, so that you may see them as isolated functions, and understand what's happening, and required.

Using the Quest

Enable the item that appears to be a longbow as the B-button item, then press B, and wait. Link will start firing arrows, on a regular basis; and you may select a different B-item, while still firing.

The automated item sue continues until you again select the bow item, and press B to turn it off, or press R to suspend it (thus, using the setRepeatOff() function).

Script Contents

import "std.zh"

import "ItemHandling.zh" //Requires v6.7 or higher.
import "Timers.zh" //Requires v1.0 or higher.

//////////////////////////////
/// Automatic Item ///////////
/// v1.9 - 23rd Sept, 2014 ///
/// Creator: ZoriaRPG ///
//////////////////////////////

///Variables, Arrays, and Constants

bool isAutofire = false; //Used to define if autofire is on, or off.
//bool isAutoFire[10]={false,false,false,false,false,false,false,false,false,false};
//An array template, to permit multiple autofire items.

const int I_REPEAT = 14; //Repeating item.

//int Timers[2]={0,0}; //Timers.zh array.
const int TI_REPEAT = 0;

int equipmB; //Holds the value of the B-Slot item, between automatic activations.

///Global Scripts

global script Init{
void run(){
setTimer(TI_REPEAT, 0);
}
}

global script onExit{
void run(){
setTimer(TI_REPEAT, 0);
}
}

global script activeRepeatingItem{
void run(){
while(true){

setTimer(TI_REPEAT,100);
setRepeatOff();
reduceTimer(TI_REPEAT,1);
AutofireInitiate(LW_ARROW);

Waitdraw();
//Trace(returnTimer(TI_REPEAT)); //Print value to allegro.log.
//AutofireUpdate(); //Disabled, not needed for this version.

Waitframe();
}
}
}

//Item Scripts

//This item simply triggers the boolean isAutoFire to true, or false. You can expand on this by using a boolean array.

item script repeatingWeapon{
void run(){
if ( isAutofire ){
isAutofire = false;
}
else {
isAutofire = true;
}
}
}

//Functions

void AutofireInitiate(int lType){
if ( isAutofire && !lWeaponExists(lType) && checkTimer(TI_REPEAT) ){
equipmB = GetEquipmentB();
SetItemB(I_REPEAT);
Link->InputB = true;
Waitframe();
if ( GetEquipmentB() == I_REPEAT ) {
SetItemB(equipmB);
}
}
else {
equipmB = GetEquipmentB();
if ( GetEquipmentB() != equipmB ) {
SetItemB(equipmB);
}
}
}

//Initialises automatic firing of a weapon, or automatic use of an item.

void AutofireInitiate(int repeatingItem, bool notLType){
if ( isAutofire && checkTimer(TI_REPEAT) ){
equipmB = GetEquipmentB();
SetItemB(repeatingItem);
Link->InputB = true;
Waitframe();
if ( GetEquipmentB() == repeatingItem ) {
SetItemB(equipmB);
}
}
else {
equipmB = GetEquipmentB();
if ( GetEquipmentB() != equipmB ) {
SetItemB(equipmB);
}
}
}

//Same as above, for use with non-LW items, such as Nayru's Love.

void AutofireUpdate(){
int itemB = GetEquipmentB();
if ( isAutofire && itemB != equipmB ) {
SetItemB(equipmB);
}
}

//Deprecated function, originally meant to work between Waitdraw() and Waitdrame().

void setRepeatOff(){
if ( Link->PressR && isAutofire ){
isAutofire = false;
}
}

//Emergency function to turn boolean off by pressing R.

This entry has no reviews.