const int CR_BOMLVL=16; //preferedly in another file and imported.
global script BomScript
{
void run()
{
while(true)
{
LockBoom(); //make it happen every frame.
Waitframe();
}
}
void LockBoom()
{
npc tA=Screen->LoadNPC(npcA); //load npcs with 'n' values to be determined later in script.
npc tB=Screen->LoadNPC(npcB);//these two npcs are given values pressing A.
npc tC=Screen->LoadNPC(r);//this one too, but it's the third one.
ffc T=Screen->LoadFFC(28); // The "lock-on" graphic.
T->Data=1; // No graphic. Set this to blank combo.
T->CSet=6; //unimportant personal information.<-optional.
npc oot=Screen->LoadNPC(r); //another npc that will be reassigned multiple times by variable r.
if(UseBoo>=1)
{
if(trigC==0) //Getting started...
{
if(Link->InputB)//Link is holding B.
{
if(Link->InputL)
{
r-=1;
if(r==0)
{r=NumNPCs();}
Waitframes(5);
}
if(Link->InputR)
{
r+=1;
if(r==NumNPCs()+1)
{r=1;}
Waitframes(5);
}
//Since Link pressed L or R, the r variable reassigns NPC "oot."
T->Data=28; //since Link is targeting now, the target ffc is now somthing.
T->X=oot->X; T->Y=oot->Y; //and is centered on the NPC "oot"
if(Link->InputA && oot->isValid() && trigA==0
&& trigB==0)
{T->CSet+=1; trigA=1; npcA=r; Waitframes(5);}
//So when Link presses A, the CSet Flashes, NPC "tA" is assigned the value of r also, until item is used again
if(Link->InputA && oot->isValid() && trigA==1
&& trigB==0)
{T->CSet+=1; trigB=1; npcB=r; Waitframes(5);}
//Same story, but now NPC tB is assigned a value of "r". Link can/could still press L or R to switch NPCs.
if(Link->InputA && oot->isValid() && trigA==1
&& trigB==1)
{T->CSet+=1; T->X=Link->X; T->Y=Link->Y; trigA=0; trigB=0; trigC=1; Waitframes(5);}
//third NPC selection done, moving on to fun fun boom boom
if(Link->InputA && !oot->isValid())
{
trigA=0; trigB=0; trigC=0; npcA=0; npcB=0; r=1;
UseBoo=-1; trigc=0;
} //unless for some reason there isn't a baddie...
}
if(!Link->InputB)
{UseBoo=-1; trigA=0; trigB=0; trigC=0; trigc=0;}
//if Link stopped holding B before he selected with A three times, no Boom Boom.
}
if(trigC==1 && triga==0)
{//Here it is!
trigc=0;
if(Link->InputB)//still holding B, ready to boom boom.
{
T->Y=Link->Y;
T->X=Link->X;
T->Data=28;
//Set this to either blank or a combo that makes sense.
T->CSet=9;
}
if(!Link->InputB)//let go of B.
{
lweapon bom2=CreateLWeaponAt(4, tA->X, tA->Y); bom2->Damage=Game->Counter[16]*4;
lweapon bom3=CreateLWeaponAt(4, tB->X, tB->Y); bom3->Damage=Game->Counter[16]*4;
lweapon bom4=CreateLWeaponAt(4, tC->X, tC->Y); bom4->Damage=Game->Counter[16]*4;
UseBoo=-1; trigA=0; trigB=0; trigC=0; npcA=0; npcB=0; r=1;
}
//BOOM BOOM.
//Oh, and take the Damage=Game->Counter[16]*4 out if you
//like and replace it with Damage=(any multiple of 4).
//I like to use counters for upgradable damage on the
//weapons I script so the player can gain "levels" with the
//items instead of getting an item with a higher level every
//time.
}
}
if(UseBoo<=0)
{return;}
}
}
item script Lock-On Bomb
{
void run()
{
triga=0; trigb=0; trigc=0;
trigA=0; trigB=0; trigC=0;//reset all variables on item use.
npcA=0; npcB=0; npcC=0;
if(UseBoo<=0)
{UseBoo=1; r=1;}
}
}
So, I came up with this in my quest for the perfect lock-on/homing boomerang..
The lock-on feature is the main thing I wanted to share, as this script and function can be modified for use in many other scripts for weapons, movements, etc etc.
On another note, this script, if being combined with other globals, should have the "LockBoom" function at the end of the global main body of script, because it contains Waitframes() that would stop the rest of the global from running if LockBoom() comes before other functions or body of script.
If you can combine globals, you probably already knew that. ;D

