Template:InstructorLessons

From Valve Developer Community
Jump to: navigation, search

Introductory Lesson "Using your weapon"

First we must open the file scripts / instructor_lessons.txt (That came with the .zip) And at the end of the file (But before the '}' ) we must add the lesson we want.

To begin we must decide what name we will put to this lesson, in itself it will only serve us to be able to identify it at the moment of testing and to give it a unique identification. In this case I'll call it "Using your weapon" so we'll start by writing:

"Using your weapon"
{
}

Now it is necessary to indicate what kind of lesson will be, if it indicates if the lesson can be opened several times on the screen or only once, etc... As we want to show only once we will have to define the value of instance_type 2. In addition it is necessary to adjust the priority of the lesson, for now we will leave it in 0

"Using your weapon"
{
      "priority"         "1"
      "instance_type"    "2"
}

Here the original meaning of each number:

0 = Multiple lessons of same type can be open at once 1 = Only one of each lesson type can be open at once 2 = Replace lesson of the same type 3 = Only one instance will display at a time (but all instances will be open)

After we have to indicate the message we want to give the user, keep in mind that it is possible to use the strings to translate, for example: #Instructor_UseWeapon but in this example we will use a normal message (Do not do it in your mod) , do it with the chains to translate)

"Using your weapon"
{
      "instance_type"    "2"
      "caption"          "Primary Attack"
}

As in if it is a lesson in which we will teach the player how to shoot his weapon will be necessary that the icon is a command / key, for it we will define the value of on_screen_icon as use_binding which in itself means "Use a command / key" which we will define in the field binding:

"Usando tu arma"
{
      "instance_type"    "2"
      "caption"          "Primary Attack"

      "onscreen_icon"    "use_binding"
      "binding"          "+attack"
}

As you can see (and if you have practiced some of this in Source Engine) you will know that the command +attack serves to indicate to the engine that the left mouse button has been pressed, so when this lesson is shown the icon will be a Mouse with the left button in red (Indicating that you must press)

As you can see in this page you can use any command. For example +jump will show the "Space" key (As you can see in the start image) and +use will show the "E" key. Of course, if the player keeps the configuration of the controls intact, if for example change the use key (E) by U the Game Instructor will display the U key.

on_screen_icon is used to indicate the icon that will appear when the target is visible to the player, in this case there is no objective so it will always appear, if there was an object (For example: a button) we should also include the field offscreen_icon which will be the icon that will appear when the target is not in sight (Along with an arrow)

Just as an example / reminder we will:

"Usando tu arma"
{
      "instance_type"    "2"
      "caption"          "Primary Attack"

      "onscreen_icon"    "use_binding"
      "offscreen_icon"   "icon_info"
      "binding"          "+attack"
}

If there was a target, the icon that would be displayed would be:

Hint 002 icon info.jpg

Now it is necessary to indicate how many times maximum it can appear, for this there are 2 forms: For times that it has been shown or For times that it has been fulfilled.

For times shown indicates that when the lesson has been shown a certain number of times the same will no longer appear. It is usually the simplest and is defined with the field display_limit followed by the number of times it can appear.

'Sometimes it has been fulfilled' indicates that when a condition (Generally in the code) the lesson is fulfilled it will be marked as "Met / Learned" and after a number of times "Learned" it will no longer appear . This is the one we will use with this lesson and it is defined with the field success_limit in which we will adjust it 2 times maximum.

"Usando tu arma"
{
      "instance_type"    "2"
      "caption"          "Primary Attack"

      "onscreen_icon"    "use_binding"
      "offscreen_icon"   "icon_info"
      "binding"          "+attack"

      "success_limit"    "2"
      "timeout"          "8"
}

As you can see we have also added the field timeout that simply defines the time in seconds that can remain open, keep in mind that if the time is finished it will be marked as "View" and it will only affect the field display_limit

Now comes the good ... it is necessary to indicate with what event this Lesson will be opened and with what other event will be marked as "Learned". In this case we will use the events: instructor_primaryattack and use_primaryattack (In case you can name them as you wish)

"Usando tu arma"
{
      "instance_type"    "2"
      "caption"          "Primary Attack"

      "onscreen_icon"    "use_binding"
      "offscreen_icon"   "icon_info"
      "binding"          "+attack"

      "success_limit"    "2"
      "timeout"          "8"

      "open"
      {
            "instructor_primaryattack"
            {
            }
      }

      "success"
      {
            "use_primaryattack"
            {
            }
      }
}

Ok, with this we indicate with what event will open and with what event will be marked as "Learned" but now we must tell you what parameters will be received from the event and how to use them. In this case together with the 2 events we will send the parameter userid which will indicate the user that should receive this lesson.

Remember that events are sent from the Server to the Client and these are global ie All players connected to the server will receive it, so with userid we limit the Game Instructor to only I showed it in the player that we indicated.

"Usando tu arma"
{
      "instance_type"    "2"
      "caption"          "Primary Attack"

      "onscreen_icon"    "use_binding"
      "offscreen_icon"   "icon_info"
      "binding"          "+attack"

      "success_limit"    "2"
      "timeout"          "8"

      "open"
      {
            "instructor_primaryattack"
            {
                 "local_player is"   "player userid"
                 "icon_target set"   "player local_player"
            }
      }

      "success"
      {
            "use_primaryattack"
            {
                 "local_player is"   "player userid"
                 "void close"        "void"
            }
      }
}

This is one of the small parts difficult to understand but here we go ...

local_player is

local_player means the "Local Player" or the Client, so with this line we indicate that only show that lesson if the local player is the player that we indicate in the value (player userid)

player userid

This is the value that each condition must have, the first part (player) indicates the type of value that is being received, in this case it is a resource "C_BasePlayer", if it were a text string it would be string instead of player and if it were an entity then it would be entity (C_BaseEntity) instead of player.

The second part (userid) indicates the name of the value, in this case we put it that way but it can be any other that you indicate. You'll see when we get to the part where we send the event from the code.

icon_target set

icon_target is the objective where the icon will be displayed, with this we simply establish (set) the object / player / entity where the icon will go.

player local_player

And with this we only say that the goal is the same player so the result will be only the message and icon showing on the screen of it.

For use_primaryattack it is basically the same only at the end after checking if the local user closes the lesson (The disappears)

And that's all for this lesson, of course there are many more fields and options to create more advanced and interactive lessons. If you have Left 4 Dead 2 I recommend you see your file instructor_lessons.txt to give you an idea. (It is located inside the VPK file: pak01_dir.vpk)

Finally it is necessary to add the events (instructor_primaryattack and use_primaryattack) to the file resource / modevents.res, open it and at the end (But before '}' ) write:

        "instructor_primaryattack"
	{
		"userid" 	"short"
	}
	"use_primaryattack"
	{
		"userid" 	"short"
	}


Feel free to incorporate new lessons into this tutorial!