King of Dwythia
11-09-2007, 06:56 PM
This is a simple modification of the NPC script by pkmnfrk found at http://www.armageddongames.net/forums/showthread.php?t=98097.
This modification does two things. First, it prevents link from reading the string more than once without first leaving the screen (which prevents the string from starting over when you press 'a' to speed up the script or to attack an enemy sneaking up on you). Second, it allows you to search the screen for a combo, and if the combo exist, play an alternate string.
//real_npc by pkmnfrk and modified by King of Dwythia
ffc script real_npc {
void run(int m, int s, int f, int d, int def_dir, int newcombo, int m2) {
int d_x;
int d_y;
int a_x;
int a_y;
int orig_d = this->Data;
int CheckCombo = 0;
int alreadydone1 = 0;
int alreadydone2 = 0;
if(d == 0) d = 48;
while(true) {
d_x = this->X - Link->X;
d_y = this->Y - Link->Y;
a_x = Abs(d_x);
a_y = Abs(d_y);
if(newcombo != 0) {
for (int i = 0; i <= 176;i++) {
if (Screen->ComboD[i] == newcombo) {CheckCombo = 1;}
}
}
if(f != 0) {
if(a_x < d && a_y < d) {
if(d_y >= 0) {
this->Data = orig_d + DIR_UP;
} else {
this->Data = orig_d + DIR_DOWN;
}
} else {
if(d_x >= 0) {
this->Data = orig_d + DIR_LEFT;
} else {
this->Data = orig_d + DIR_RIGHT;
}
}
} else {
this->Data = orig_d + def_dir;
}
}
if(Link->InputA && a_x < 24 && a_y < 24) {
if(s != 0) Game->PlaySound(s);
Link->InputA = false;
if(CheckCombo==0 && alreadydone1 == 0) {Screen->Message(m); alreadydone1 = 1;}
else if (CheckCombo == 1 && alreadydone2 == 0) {Screen->Message(m2); alreadydone2 = 1;}
}
Waitframe();
}
}
}
Takes 5 parameters (!!):
0: The message. Same as the sign post.
1: S sound to play when activated.
2: Whether to have the NPC turn to face Link when he's near. See below for details. (0 is off, anything else is on)
3: If #2 is on, how close Link must be for the NPC to turn, in pixels (+ 16, because that's how wide Link is) (default is 48)
4: If #2 is on, which direction is the "default" direction, when Link is far away (0 - Up, 1 - Down, 2 - Left, 3 - Right)
To have an NPC that faces Link, you must put the combos for each direction in a certain order: Up, Down, Left, Right, AND! You must set the FFC to the UP facing combo. If you do that, you'll be fine.
Tips:
Like the Sign post, you should put a solid combo on the same square as the NPC, so Link can't move through it.
If you use the facing feature, then you must use the FFC as a sprite, you can't have it invisible on top of an NPC combo. If you're just using a plain NPC, then it doesn't matter which you do.
It works best with the "Messages freeze all action" and "Messages disappear" rules.
I have added two more parameters:
5: The number of the combo to look for
6: The number of the alternate string to display
I can see several uses for this script. Here's the scenario that I wrote it for: Link needs to cross a bridge, but it is broken. There is a person sitting next to an unlit campfire. When link talks to him, he says "I'm cold, light my fire and I will repair the bridge". Link lights the fire, the bridge is repaired. The lit fire happens to be the combo the script is looking for, and now that it is on the screen, the guy, when talked to, will now say "Thanks".
This modification does two things. First, it prevents link from reading the string more than once without first leaving the screen (which prevents the string from starting over when you press 'a' to speed up the script or to attack an enemy sneaking up on you). Second, it allows you to search the screen for a combo, and if the combo exist, play an alternate string.
//real_npc by pkmnfrk and modified by King of Dwythia
ffc script real_npc {
void run(int m, int s, int f, int d, int def_dir, int newcombo, int m2) {
int d_x;
int d_y;
int a_x;
int a_y;
int orig_d = this->Data;
int CheckCombo = 0;
int alreadydone1 = 0;
int alreadydone2 = 0;
if(d == 0) d = 48;
while(true) {
d_x = this->X - Link->X;
d_y = this->Y - Link->Y;
a_x = Abs(d_x);
a_y = Abs(d_y);
if(newcombo != 0) {
for (int i = 0; i <= 176;i++) {
if (Screen->ComboD[i] == newcombo) {CheckCombo = 1;}
}
}
if(f != 0) {
if(a_x < d && a_y < d) {
if(d_y >= 0) {
this->Data = orig_d + DIR_UP;
} else {
this->Data = orig_d + DIR_DOWN;
}
} else {
if(d_x >= 0) {
this->Data = orig_d + DIR_LEFT;
} else {
this->Data = orig_d + DIR_RIGHT;
}
}
} else {
this->Data = orig_d + def_dir;
}
}
if(Link->InputA && a_x < 24 && a_y < 24) {
if(s != 0) Game->PlaySound(s);
Link->InputA = false;
if(CheckCombo==0 && alreadydone1 == 0) {Screen->Message(m); alreadydone1 = 1;}
else if (CheckCombo == 1 && alreadydone2 == 0) {Screen->Message(m2); alreadydone2 = 1;}
}
Waitframe();
}
}
}
Takes 5 parameters (!!):
0: The message. Same as the sign post.
1: S sound to play when activated.
2: Whether to have the NPC turn to face Link when he's near. See below for details. (0 is off, anything else is on)
3: If #2 is on, how close Link must be for the NPC to turn, in pixels (+ 16, because that's how wide Link is) (default is 48)
4: If #2 is on, which direction is the "default" direction, when Link is far away (0 - Up, 1 - Down, 2 - Left, 3 - Right)
To have an NPC that faces Link, you must put the combos for each direction in a certain order: Up, Down, Left, Right, AND! You must set the FFC to the UP facing combo. If you do that, you'll be fine.
Tips:
Like the Sign post, you should put a solid combo on the same square as the NPC, so Link can't move through it.
If you use the facing feature, then you must use the FFC as a sprite, you can't have it invisible on top of an NPC combo. If you're just using a plain NPC, then it doesn't matter which you do.
It works best with the "Messages freeze all action" and "Messages disappear" rules.
I have added two more parameters:
5: The number of the combo to look for
6: The number of the alternate string to display
I can see several uses for this script. Here's the scenario that I wrote it for: Link needs to cross a bridge, but it is broken. There is a person sitting next to an unlit campfire. When link talks to him, he says "I'm cold, light my fire and I will repair the bridge". Link lights the fire, the bridge is repaired. The lit fire happens to be the combo the script is looking for, and now that it is on the screen, the guy, when talked to, will now say "Thanks".