Lesson 3
Finding the Lost Sheep

If you haven't played Sheep Rancher, now is an excellent time to do so, because today's lesson is all about the type of NPC usage used in Sheep Rancher. This goes back to last lesson -- you'll learn a little bit of fake plotscripting (maybe without knowing it) if you listen carefully.
A little quiz -- in Sheep Rancher, what makes it so that Sam can step on the puddles but the sheep can't? The answer: an invisible NPC. By making an invisible "Step On" NPC, you've made a space that NPCs are blocked by, but that your hero isn't.
That's really incidental to today's lesson, though. We're going to focus on NPC location.

include, plotscr.hsd
include, game.hsi #replace "game" with your filename

define script(1,zap,none)

 if (herodirection(me)==west) then
  set npc position(35,herox(me)--1,heroy(me))
 if (herodirection(me)==north) then
  set npc position(35,herox(me),heroy(me)--1)
 if (herodirection(me)==east) then
  set npc position(35,herox(me)+1,heroy(me))
 if (herodirection(me)==south) then
  set npc position(35,herox(me),heroy(me)+1)

This "zap" script is similar to scripts used in both Sheep Rancher and Way of the Wizard. It makes NPC 35 appear just in front of the hero. This is very useful. What can you do with this?

  • In Sheep Rancher, it's used to make a crate or puddle that blocks the sheep.
  • In Way of the Wizard, it's used to make an attack.
  • Basically, you use this script when you need to put something in front of the player.
  • What do X and Y mean? These refers to the NPC's on-screen location. The lower the NPC is, the higher his Y is. The further to the right the NPC is, the higher his X is.
    Let's go back to the for loop from Lesson 1. Now is a good time to do this, because we're using Sheep Rancher to learn. Sheep Rancher uses for loops to find out whether a group of sheep is in the Star Area. For my convenience, the Star Area was in the same position in each level: the coordinate Y:10 and below.

    script,sheep,num,begin #num is the number of sheep
     variable (ctr) #a counter variable
     while (check tag(tag:Win)==false) do
      set tag(tag:Win,true)
      for (ctr,0,num,1) do
       if (npc y(ctr) << 10) then (set tag(tag:Win,false))

    I used another type of loop in this script: the while loop. This loop will keep repeating until its condition is true. The script "sheep" keeps repeating until the tag "Win" is on, and the tag turns on when all the sheep are below Y:10.
    By the way, you may have noticed that I use parentheses -- ( and ) -- instead of begin and end. They're the same, but I like my way better. Use whichever one you prefer.

    NPC location is powerful stuff, and there's more to it than it seems. Don't be afraid to use your NPCs "non-traditionally." For example, in Sheep Rancher, the animation of the Vanish spell is created by rotating the NPC. After its animation, it is removed. In this case, the "facing left" frame isn't actually facing left; it's just another frame in the NPC's animation.

    That's the end of this lesson. Your homework is to use the alter npc command in a for loop with arguments. If you can do that, you're on par with the course.

    Return to Main Menu

    Site layout (c)2000 Jennifer Raby. Used by permission.