Main
Projects
Art
Music
Scripting
LiveJournal
Forum
Links
Lesson 2
NPCs: Why you need to know Fake Plotscripting

"What? Why do I need to know fake plotscripting when I have the real thing?"
The truth is that fake plotscripting is not dead. The same ingenuity that allowed Vidual to make fantastic cutscenes in Origin will help you make professional plotscripting now.


Fake Plotscripting - What is it?

Fake Plotscripting is the term for the use of NPCs to simulate plotscripting. This often involves invisible NPCs set to activate without the player knowing or to block visible NPCs.
So what? While you don't need to use fake plotscripting anymore, you do need to know how to use NPCs -- and the hero -- skillfully. Since this is so closely related to CUSTOM, I can't do as much as I'd like to here. My advice: practice. Practice a lot. Here's some examples of what you can do with NPCs:


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

define script(1,dance,none)

script,dance,begin
 walk npc(1,west,3)
 wait for npc(1)
 walk npc(1,north,3)
 wait for npc(1)
 walk npc(1,east,3)
 wait for npc(1)
 walk npc(1,south,3)
 wait for npc(1)
end


This script will make NPC 1 "dance" -- actually just walk in a square. Taking out every other wait for npc will make him walk diagonally: you can do that with plotscripting.
It's a simple script, but I notice an excellent opportunity to demonstrate arguments. An argument is what happens when you get mad at your script for not compiling... just kidding. It's a local variable that is given to the script from something outside the script, usually another script or the game itself. Let's put an argument into "dance" and see how it changes.


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

define script(1,dance,1,1)

script,dance,who,begin
 walk npc(who,west,3)
 wait for npc(who)
 walk npc(who,north,3)
 wait for npc(who)
 walk npc(who,east,3)
 wait for npc(who)
 walk npc(who,south,3)
 wait for npc(who)
end

The effect of this script is just like before, but this time you can choose which NPC will dance. The important changes:

  • In the define script, "none" was replaced by the number of arguments (1) and the default value for those arguments (in this case, also 1).
  • In the script, the variable "who" was added. Then, each time the script used the NPC number, the variable was substituted.

  • Do you understand? Don't move on until you do, because now it gets tricky! Let's try putting another argument in.


    include, plotscr.hsd
    include, game.hsi #replace "game" with your filename
    
    define script(1,dance,2,1,3)
    
    script,dance,who,dist,begin
     walk npc(who,west,dist)
     wait for npc(who)
     walk npc(who,north,dist)
     wait for npc(who)
     walk npc(who,east,dist)
     wait for npc(who)
     walk npc(who,south,dist)
     wait for npc(who)
    end
    

    Can you guess what I just did? Make a guess and highlight the blank area below to see if you're right.
    <The new argument tells how far the NPC should walk. Its default value is 3.>

    Did you get it? I hope so, because it's time for a new example.


    include, plotscr.hsd
    include, game.hsi #replace "game" with your filename
    
    define script(1,watch,1,1)
    
    script,watch,who,begin
     if (herox(me) << npcx(who)) then (set npc direction(who,west))
     if (herox(me) >> npcx(who)) then (set npc direction(who,east))
     if (heroy(me) << npcy(who)) then (set npc direction(who,north))
     if (heroy(me) >> npcy(who)) then (set npc direction(who,south))
    end
    

    This is a little more complex: when the script is run, NPC "who" will turn to face the hero. You can run the script when the hero steps on a squeaky board, or talks to someone else, or whatever you want. The nice part of this script is that it works no matter who the NPC is or where the hero is.
    Now it's your turn: try making a script that makes an NPC chase you, using the alter npc command. (Click on the link for the glossary's help on usage.) Try making an invisible "Step On" NPC that calls it -- you could make a spy game using your new plotscript!

    But, alas, that's all for this lesson. Your homework is to play Beyond Destiny and Origin if you haven't played them (and, indeed, if you can find them).

    Return to Main Menu

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