PDA

View Full Version : Trying to spawn NPCs via scripting.



Beta Link
09-28-2008, 04:36 PM
Well, I'm trying to spawn enemies via scripting. And I'm failing. :(

import "std.zh"
ffc script lv2_boss_pt2{
void run(int e, int x, int y){
npc enemy = Screen->LoadNPC(e);
int enemyx = x;
int enemyy = y;
enemyx = enemy->X;
enemyy = enemy->Y;
}
}
It compiles fine, but it doesn't work. What am I doing wrong? I'm sure it's just some stupid thing I overlooked, but I want to be sure.

Elmensajero
09-28-2008, 07:29 PM
Okay, you first initialized enemyx to the input x. You then overwrote that value with the location of enemy->X. However, enemy->X never changes (which is what is supposed to change in order to move the enemy to another location.) So to fix it all you have to do is reverse the order of the last two statements. However, you don't really need the variables enemyx or enemyy, you can store the input variables x and y into the enemy object directly. So, the code is modified as follows...


import "std.zh"

//spawn enemy e at location (x,y)
ffc script lv2_boss_pt2{
void run(int e, int x, int y){
npc enemy = Screen->LoadNPC(e);
enemy->X=x;
enemy->Y=y;
}
}

pkmnfrk
09-29-2008, 08:56 PM
And, still, that likely doesn't do what's intended. "enemy" is only valid if 1 <= e <= Screen->NumNPCs().

More likely, you want to use Screen->CreateNPC(), since I assume that e is not referencing an existing NPC, but is an ID (like E_ZORA, etc):


import "std.zh"

//spawn enemy e at location (x,y)
ffc script lv2_boss_pt2{
void run(int e, int x, int y){
npc enemy = Screen->CreateNPC(e);
enemy->X=x;
enemy->Y=y;
}
}

ShadowTiger
09-29-2008, 10:49 PM
I'm sorry, may I please interject with a question?

When you say "enemy->X=x;" how does it know which enemy it's referring to, if there are ten enemies possible per screen? Same with the CreateNPC(e). Is that an eleventh enemy, or some unmentioned enemy #1 on the normal list? Or is it something completely different that I haven't wrapped my mortal mind around yet?

Thanks a bunch for the hint.

pkmnfrk
09-29-2008, 11:03 PM
"enemy" is the name of the variable. Let me rewrite it for clarity:


import "std.zh"

//spawn enemy e at location (x,y)
ffc script lv2_boss_pt2{
void run(int e, int x, int y){
npc foobar = Screen->CreateNPC(e);
foobar->X=x;
foobar->Y=y;
}
}

Elmensajero
09-29-2008, 11:43 PM
Hmm, I just assumed he was just trying to spawn an enemy specified in ZQuest with Screen -> Enemies, although looking at it now that wouldn't really make sense since you can already do that with flags:p. Thanks for fixing that pkmnfrk. Is it working now as you wanted it, Beta Link?

EDIT: Yay, 100 posts!

Beta Link
09-30-2008, 12:06 AM
Ah, yes, it's working now. Thanks. And yeah, I had gotten LoadNPC mixed up with CreateNPC. CreateNPC is what I wanted. :) And that's the exact reason I think it wasn't working before. I had put in a D0 variable of... 42, I think. :tongue: