Difference between revisions of "Create story script"

From XStoryPlayer Wiki
Jump to: navigation, search
Line 1: Line 1:
In this tutorial we will add some scripting: Give feedback to player, make the doors open when a specific event occurs, let female alien walk by.
+
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.
  
 
<ol>
 
<ol>

Revision as of 15:40, 12 January 2015

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 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.