Why do you need a
second script here? You can use one ffc, and do:
this->X = n->X; this->Y = n->Y;
Here is a method to do what you want, but it doesn't have a perfect 'failsafe' method. You could look for an n->Attributes[] value on top of other checks if you wish.
This ffc will be kept at the coordinates of the npc that it finds, and if it fails to find one, it closes. The ffc closes when the npc dies, too.
D0: A positive number here will follow the first instance of an npc with this ID.
D0: A negative number will follow an npc that spawns on a flag equal to this * -1 (so, -16 is flag 16)
D1: If you want to mark the npc so that other scripts know that this is following it, select a Misc index from 1 to 15 and use it in this arg.
The script will mark that index with the value '45678.9012 + nmisc', so that you can scan for that npc.
D2: If you want to cause the ffc to wait before closing when the npc dies, this is how many frames it will wait before clearing and exiting.
D3: The ID of another ffc. If set between 1 and 32, the corresponding ffc will also move with this one.
/////////////////////////////////
/// FFC Follows NPC for Zagut ///
/// By: ZoriaRPG ///
/// 31st march, 2017 ///
/////////////////////////////////
ffc script follownpc{
void run(int nid, int nmisc, int death_frames, int otherffc){
int q[5]; int loc = -1; npc n;
//find the npc that spawns at a specific location (flag) if D0 is negative
if ( nid == 0 ) {
int ss[]="The ffc using script 'follownpc' cannot run with its D0 arg set to '0'.";
TraceS(ss);
this->Data = 0; this->Script = 0; Quit();
}
if ( nid < 0 ) {
nid = nid * -1; //convert to a positive value,
//scan for the screen flag
for ( q[0] = 0; q[0] < 176; q[0]++ ) {
if ( ComboFI(q[0], nid ) {
loc = q[0];
break;
}
}
//if there is no flag, then it is an error, so quit.
if ( loc < 0 ) {
this->Data = 0; this->Script = 0; Quit();
}
else {
Waitframes(5); //Wait for npcs to spawn.
//scan to find the npc at the coordinates
q[4] = Screen->NumNPCs();
for ( q[0] = 1; q[0] <= q[4]; q[0]++ ) {
n = Screen->LoadNPC(q[0]);
//Check to see if the npc is on the flag tile.
if ( ComboAt(n->X, n->Y) == loc ) {
q[1] = n->X; //store its coordinaes.
q[2] = n->Y;
q[3] = 1; //mark it found.
if ( nmisc > 0 ) n->Misc[nmisc] = nmisc + 45678.9012;
//Mark a Misc index if desired to flag the enemy we are following.
break;
}
}
if ( q[3] != 1 ) {
//We didn;t find the npc, so quit.
this->Data = 0; this->Script - 0; Quit();
}
}
}
//otherwise, find an npc with this ID
//check them in list order, so that the user may utilise the first on the list
//with relative surety.
else {
//Wait for npcs to spawn.
Waitframes(5);
//scan the npcs.
q[4] = Screen->NumNPCs();
for ( q[0] = 1; q[0] <= q[4]; q[0]++ ) {
n = Screen->LoadNPC(q[0]);
if ( n->ID == nid ) {
q[1] = n->X; //store its coordinaes.
q[2] = n->Y;
q[3] = 1; //mark it found.
if ( nmisc > 0 ) n->Misc[nmisc] = nmisc + 45678.9012;
//Mark a Misc index if desired to flag the enemy we are following.
break;
}
}
if ( q[3] != 1 ) {
//We didn;t find the npc, so quit.
this->Data = 0; this->Script - 0; Quit();
}
//or a specific npc type, if D0 is positive
while(n->isValid()){
this->X = n->X;
this->Y = n->Y;
if ( otherffc > 0 && otherffc < 33 ) {
ffc f = Screen->LoadFFC(otherffc);
f->X = this->X;
f->Y = this->Y;
}
Waitframe();
}
//The enemy is dead.
//Wait for death anim.
if ( death_frames ) Waitframes(death_frames);
//Clean up the ffc.
this->Data = 0; this->Script = 0; Quit();
}
}
Difficult no, problematic maybe.
The issue is the number given to enemies, the UID, is not always the same number nor does it always match the enemies position in the editor. As an example if you assign a stalfos to slot 0 and a Gel to slot 1 in the editor, in game the Stalfos could be enemy 1 while the Gel is enemy 0. The result would be the ffc assigning the target ffc to the wrong npc.
It would be helpful if you could tell us what the goal is of having a ffc stick another ffc to an npc.
I do not believe that is precisely true, or valid.
NPC 0, or 'first on the list', should be the first one spawned. In fact, my script would work better using a positive loop--I changed it, to reflect this benefit--if the enemy that does this will always be the first on the list.
As I recall, npcs are spawned in order, so the screen index, and the editor index, will always match for the first npc. Later nocs on the list, may change, when npcs in the middle of the list are killed.
Edited by ZoriaRPG, 31 March 2017 - 02:15 AM.