Create story script

From XStoryPlayer Wiki
Revision as of 16:13, 12 January 2015 by Xwikip (Talk | contribs)

Jump to: navigation, search

In this tutorial we will add some scripting: Make the doors open when a specific event occurs, Give feedback to player, let female alien walk by.

  1. We don't want the doors to open automatically. We need to make the doors into objects that can be driven by the script.
    Open the /init/story/scenes.dat file and add under data {...} :
    door_objecti CELL1
    {
      rotate   = false; // Door translates
     
      q        = 4.5;  // Open height
      q_min    = 0.0;  // Min height
      q_max    = 6.0;  // Max height
      q_spring = 30.0; // Spring used for opening door
     
      open = true; // Door status
     
      obj_name = "cell1"; // Object in scene that is the door
    }
     
    door_objecti CELL2
    {
      rotate   = false;
     
      q        = 4.5;
      q_min    = 0.0;
      q_max    = 6.0;
      q_spring = 30.0;
     
      open = false;
     
      obj_name = "cell2";
    }

    This will make a door object from the scene object. Now we can also open the door using a script.

  2. Now lets test the doors. Open the /init/story/player/brain/run.dat. This file contains the state code of the player.
    Change the code to this:
    #include "init/std/base/main/brain/code/run.dat"
     
    //-------------------------------------------
     
    <state_run>
     
    case (state.dyn.me.do.state)
    {
      [RUN0] state_run0();
    }
     
    </state_run>
     
    //-------------------------------------------
     
    <state_run0>
     
    case (state.dyn.me.do.state2)
    {
      [NONE]
      {
        // Set timer to 3 seconds
        do_set_timer(3);
     
        state.dyn.me.do.state2 = START;
      }
     
      [START]
      {
        // Wait for timeout
        loc.ts = GetTs();  
        [loc.ts < state.dyn.me.do.ts] return;
     
        // Open doors	
        loc.so.obj = SPACESHIP1:CELL1;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_OPEN;	    
        SetObject(loc.so);
     
        loc.so.obj = SPACESHIP1:CELL2;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_OPEN;	    
        SetObject(loc.so);
     
        // Set timer to 6 seconds
        do_set_timer(6);
     
        state.dyn.me.do.state2 = OPEN;
      }
     
      [OPEN]
      {
        // Wait for timeout
        loc.ts = GetTs();  
        [loc.ts < state.dyn.me.do.ts] return;
     
        // Close doors	
        loc.so.obj = SPACESHIP1:CELL1;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_CLOSE;	    
        SetObject(loc.so);
     
        loc.so.obj = SPACESHIP1:CELL2;
        loc.so.par = DOOR_SET_STATUS;
        loc.so.val = DOOR_SETVAL_STATUS_CLOSE;	    
        SetObject(loc.so);
     
        // Set timer to 6 seconds
        do_set_timer(6);
     
        state.dyn.me.do.state2 = START;    
      }
    }
     
    </state_run0>

    This code opens the doors and then closes them again.

  3. Start the abducted scene and check if the doors open and close in a continuous loop.
  4. Now add a sound to the doors. Copy the unlock2.wav to the /scenes/sounds/door directory.
    Open the /sources/scenes/spaceship/scene.ini file and add this code to both cell door objects:
    rb "cell1Shape"
    {
      ...
     
      media
      {
        elem[0]
        {
          filename = "scenes/sounds/door/unlock2.wav";
     
          type      = AUDIO;
          stream    = false;
          pos3d     = true;
          pos3d_min = 1.0;
          start     = false;
          loop      = false;
          volume    = 1.0;
        }
      }
    }

    Run the filemaker and create the objects.

  5. Run the abducted story, because the cell objects are door objects the sound in the object is automatically used for the door sounds.
  6. Now let us make a start with the story. Open the /init/story/player/brain/run.dat again.
    Change the state_run0 function to this:
    <state_run0>
     
    case (state.dyn.me.do.state2)
    {
      [NONE]
      {
        do_set_timer(10);
     
        state.dyn.me.do.state2 = START;
      }
     
      [START]
      {
        loc.ts = GetTs();  
        [loc.ts < state.dyn.me.do.ts] return;
     
        // Give feedback to player
        feedback.s         = "What happened to me? I remember waking up from a bright light.";
        feedback.dur       = 6.0; // Show feedback for 6 seconds
        feedback.rem.delay = 5.0; // Wait 5 seconds
        feedback.rem.s     = "And now I am stuck in this strange place."; // Then show this feedback
     
        do_set_timer(30);
     
        state.dyn.me.do.state2 = START2;
      }
     
      [START2]
      {
        loc.ts = GetTs();  
        [loc.ts < state.dyn.me.do.ts] return;
     
        feedback.s = "Wait, I believe I hear someone coming...";
     
        do_set_timer(15);
     
        state.dyn.me.do.state2 = START3;
      }
    }
     
    </state_run0>

    This code shows some feedback to the player starting the story off.