PDA

View Full Version : Real NPC script modification



Joe123
09-19-2007, 11:32 AM
Can someone edit this script by Pkmnfrk for me so that after you read the string, you are warped like a direct warp (I want it to take me to a duplicate screen)

ffc script real_npc {
void run(int m, int s, int f, int d, int def_dir) {
int d_x;
int d_y;
int a_x;
int a_y;
int orig_d = this->Data;

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(f != 0) {
if(a_x < d && a_y < d) {
if(a_x <= a_y) {
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;
Screen->Message(m);
}
Waitframe();
}
}
}

ShadowMancer
09-20-2007, 04:24 PM
Humm, it does not look like we have a direct warp function in ZScript right now. Although I don't know if side warp looks like a direct warp or not


void Warp(int dmap, int screen)
* Warps link to the given screen in the given dmap, just like if he'd
* triggered a side warp.


But if that would work for you it would be as simple as:



//add two extra vars to void run
void run(int m, int s, int f, int d, int def_dir,int map,int scr) {
//the rest of the code remains unchanged...
//add the warp command
if(Link->InputA && a_x < 24 && a_y < 24) {
if(s != 0) Game->PlaySound(s);
Link->InputA = false;
Screen->Message(m);
Link->Warp(map,scr)

Just put the DMap and Screen in the 6th and 7th argument of the FFC and it will warp you after the message is displayed.
I think you need the 'messages freeze all action' rule otherwise you will warp before you get to see the message.

Joe123
09-20-2007, 05:48 PM
void PitWarp(int dmap, int screen)
* Warps link to the given screen in the given dmap, just like if he'd
* triggered a pit warp.

'Pit' combos were the old name for direct warp. Where exactly do I put your addition in the script however?

EDIT: after reading what you'd written in the script box it makes more sense. I think I'd tried that already, but I'll try it again your way.

EDIT: Nope, doesn't work. Warps me before the string is displayed.

ShadowMancer
09-24-2007, 08:32 PM
Try this:


//add two extra vars to void run
void run(int m, int s, int f, int d, int def_dir,int map,int scr) {
//the rest of the code remains unchanged...
//add the warp command
if(Link->InputA && a_x < 24 && a_y < 24) {
if(s != 0) Game->PlaySound(s);
Link->InputA = false;
Screen->Message(m);
While (!Link->InputUp && !Link->InputDown && !Link->InputLeft && !Link->InputRight) {Waitframe();}
Link->Warp(map,scr)


Its not perfect but basically as soon as you press any direction key you will warp, as far as I know there is no real way to detect if the message is bieng displayed at the moment so this will have to do for now.

Gleeok
09-24-2007, 09:05 PM
Well how about giving a variable to Waitframe(wait);
Use that with short strings and it should seem transparent to the player.

ShadowMancer
09-24-2007, 09:15 PM
Well how about giving a variable to Waitframe(wait);
Use that with short strings and it should seem transparent to the player.
I was thinking of that myself, only problem is mutiple strings. You could say count the number of times the user presses A but you would have to know how many strings there are. Question Joe123, do you have the 'messages freeze all action' rule checked? I think it should work if that rule is on but I have not tested it.

Gleeok
09-25-2007, 12:22 AM
I think the script runs regardless of that rule. Bes not to make the string too long. Although a quick fix might be:

warp to a mock screen, then to another mock screen with the script again.

...workarounds suck.

ShadowMancer
09-25-2007, 01:04 AM
Workarounds:gavel:

But yea that would work, or I was also thinking don't link the strings but rather have the script show each message seperatly and count the number of messages and the number of times A is pressed.
if (pressA == numbMsg) {Link->Warp(map,scr);}
only proble with that is setting up a system of what string to display next, the script is already useing 7 out of 8 arguments, the 8th argument can be number of strings then just use consecutive strings, so if int m = 6 and int numbMsg = 3 then it would show in order string#6, #7, #8 then warp. This seems like it may work although still a minor workaround because you need to setup your strings in order (can be done with proper planning, I personally write almost everything on paper before ZQ is even opened. Except mabye scripts but I've been writeng code for so long its like 2nd nature :p )

EDIT: I just had a crazy idea...

I think the script runs regardless of that rule
This may be because there is no Waitframe(); in between the message and the warp, ZC executes scripts up until the waitframe call, then resumes 'normal' game action for one frame then goes back to the script... so try:



//add two extra vars to void run
void run(int m, int s, int f, int d, int def_dir,int map,int scr) {
//the rest of the code remains unchanged...
//add the warp command
if(Link->InputA && a_x < 24 && a_y < 24) {
if(s != 0) Game->PlaySound(s);
Link->InputA = false;
Screen->Message(m);
Waitframe();
Link->Warp(map,scr)

Joe123
09-25-2007, 03:03 AM
:scared: I look away for 5 minutes and suddenly I get lots of help :P

Thanks you two, but I already made do with the script that just warps you instead of diplaying the message. So you go out to the NPC, talk to him and get warped to a duplicate screen with the string, where you then activate a Perm. Trigger with the RSCs I needed. Works almost perfectly, except the NPC makes the crappy bleep noise instead of saying hello like the rest of them do. Ah well.

EDIT: Although yes I do have that rule checked. Will that addition of the waiframe make it run properly?

EDIT2: No, doesn't work.