User Tag List

Results 1 to 7 of 7

Thread: Trying to spawn NPCs via scripting.

  1. #1
    Octorok Beta Link's Avatar
    Join Date
    Jan 2007
    Age
    31
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,128
    Level
    11
    vBActivity - Bars
    Lv. Percent
    53.55%

    Trying to spawn NPCs via scripting.

    Well, I'm trying to spawn enemies via scripting. And I'm failing.
    Code:
    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.

  2. #2
    Octorok Elmensajero's Avatar
    Join Date
    May 2008
    Age
    36
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    854
    Level
    10
    vBActivity - Bars
    Lv. Percent
    20.46%

    Re: Trying to spawn NPCs via scripting.

    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...
    Code:
    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;
      }
    }
    Looking for the newest 2.5 content? Check out CZC for quests, demos, scripts, and more!

  3. #3
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,145
    Level
    18
    vBActivity - Bars
    Lv. Percent
    11.32%

    Re: Trying to spawn NPCs via scripting.

    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):

    Code:
    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;
      }
    }
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  4. #4
    On top of the world ShadowTiger's Avatar
    Join Date
    Jun 2002
    Location
    Southeastern New York
    Posts
    12,231
    Mentioned
    31 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    29,582
    Level
    46
    vBActivity - Bars
    Lv. Percent
    60.55%
    Achievements It's over 9000!

    Re: Trying to spawn NPCs via scripting.

    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.

  5. #5
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,145
    Level
    18
    vBActivity - Bars
    Lv. Percent
    11.32%

    Re: Trying to spawn NPCs via scripting.

    "enemy" is the name of the variable. Let me rewrite it for clarity:

    Code:
    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;
      }
    }
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  6. #6
    Octorok Elmensajero's Avatar
    Join Date
    May 2008
    Age
    36
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    854
    Level
    10
    vBActivity - Bars
    Lv. Percent
    20.46%

    Re: Trying to spawn NPCs via scripting.

    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!
    Looking for the newest 2.5 content? Check out CZC for quests, demos, scripts, and more!

  7. #7
    Octorok Beta Link's Avatar
    Join Date
    Jan 2007
    Age
    31
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,128
    Level
    11
    vBActivity - Bars
    Lv. Percent
    53.55%

    Re: Trying to spawn NPCs via scripting.

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social