nib's Mapper Resource Center
     

Basic Script Mover

by nib


Scripting. At first, you'll hate it. You'll think it was put in the game just to make your life miserable. Well, at least that's how I felt...until I understood it. Now, I love it, and so will you (well, maybe). Once you understand scripting, you'll see its power and flexibility (along with some of its nasty limitations). So, there are two scripting tutorials on my site. One, is a very basic scripting tutorial that basically shows you how to do the bare minimum to get a platform moving. This is a good place to start just to get your feet wet. The second tutorial is a bit more complex and is broken into three parts. That tutorial goes into more detail and will show you how to create mulitple moving brushes along with using variables in your script.


Assumptions:

The only thing you should know how to do to use this tutorial is to create a room and compile your map.

Step 1:

Create a basic room with an additional brush that will act as your moving platform. Don't forget to put in your info_player_start entity!

Small Image of map

Step 2:

Moving a platform in RtCW requires several different entities to work together, along with a script file. A script file is just a text document that has the same name as your map with a .script extension (and it is stored in your maps folder with your map). So, in this example, my map is called basic_script_mover.map so my script file will be called basic_script_mover.script. Don't worry about what's in the script file just yet, lets just worry about getting your map setup. There are four basic entities that you have to use to move a brush, they are:

  • func_invisible_user: Used to start the whole process
  • target_script_trigger: Called by func_invisible_user, defines what script function to call
  • script_mover: use this entity on the brush you want to move
  • path_corner: defines various locations to move your brush to

Ok, lets start adding this entities to your map. First, the func_invisible_user acts as your "button". You'll see in the below screenshot that I added a normal brush to act as the visible marker of a "button" that will launch our platform. For this tutorial we aren't going to actually make a button since that adds another layer of complexity. That is covered in the advanced tutorial.

To create your func_invisible_user brush that will trigger our platform, do the following:

  • Create a brush in front of the brush at acts as your button
  • Apply the common/trigger texture to the brush
  • Make sure the brush is highlighted, then right-click in the 2D window and choose func->func_invisible_user
  • Next, again with the brush highlighted, press N to bring up the properties window

There are two keys you have to add in the properies window.
cursorhint = hint_button and target = button_01
cursorhint allows you to define what hint icon shows up on the players screen. Since we're wanting this bursh to act like a button, use the hint_button. The target key is used to tell func_invisible_user what target to trigger when its activiated.

Create a second func_invisible_user brush where you're platform will end up, this one will be used to trigger the platform to return the the original starting position. Make that brush have a target = button_02.

Small Image of map

Step 3:

Now we need to add the entity that will control our scripting. This entity is called target_script_trigger. Place this entity anywhere in your map (preferably near the func_invisible_user brush you just created). Then, make sure the entity is highlighted and press 'N'. We need to add the following keys to the entity's properties:

  • targetname: button_01 - This is the name that your func_invisible_user entity points to
  • scriptname: move_platform - This is the name of the function in your scripot file that this entity calls
  • target: move_to_destination - This is the name of the trigger within your function (named above) that is called by this entity


Also create a second target_script_trigger at the destination of your platform, this will trigger the code to return your platform to its original location. It should have the following values:

  • targetname: button_02
  • scriptname: move_platform
  • target: move_to_start

Small Image of map

Step 4:

Next, we have to layout the pathing points for our brush to follow. This is actually quite easy. Right-click in the 2D window and choose path->path_corner. This will create an entity in your map. Place this exactly where you want your platform to move to. Repeat this to create a path you want your plaform to follow. The only key you need for your pathing points is targetname, which you use to identify the path_corner within your script file. In my map, I named them point_00 through point_03.

Small Image of map

Step 5:

Now, one last thing to do in the map. We need to setup our platform so a) be movable and b) have an origin. Creating the origin is a very important. The origin will be used as the center of your movable brush (or brushes) in conjuntion with your path_corners. An origin is nothing more than a brush with the common/origin texture on it. The important thing is to place your origin in the optimal location of your brush (or brushes). So, in my map, I placed the origin brush in the center of my platform and I made it 1 grid line higher than the platform (I use the 8 point grid). Once you've placed your origin brush within your platform, select all the various brushes that are going to make up your moving platform, then right-click in the 2D window and choose script->script_mover. Then, highlight the script_mover that was just created and press 'N'. Now, click the "solid" spawnflag and add a single key scriptname: platform. The name "platform" is used to reference the function block within the script file (which we finally get to in the next step).

Small Image of map

Step 6:

Finally! We're not only at the part where I explain the script file, but we're also on the last step! So, again, the script file is nothing more than a text file with the same name as your map and an extension of .script.

The script file is what actually controls the movement of your brush. A script file can be very basic (like for this tutorial), or it can be quite complex, depending on what you're doing. Our script file is only going to have two functions, each with two triggers. A function is a block of code that contains triggers. It looks like this:

functionname {
   trigger trigger_name
   {
   // Your code goes here
   }
}

So, here's the full script file:

// This is the scriptname of your target_script_trigger entity
move_platform		
{
	// This is the target name of your target_script_trigger 
	trigger move_to_destination		
	{
		// Calls move_dest trigger within platform function block
		trigger platform move_dest	
	}
	
	// Same as above
	trigger move_to_start
	{
		trigger platform move_start	
	}
}


// Function block. This is the scriptname used on your script_mover brush
platform
{
	
	// Called by your move_platform trigger move_to_destination
	trigger move_dest		
	{
	// move the script_mover defined by scriptname "platform" to path_corder 
	// with a targetname of "point_01" 32 is the speed of the movement
	gotomarker point_01 32		
	
	// Wait 12 seconds (12000 milliseconds) before going to next statemnt.
	// You have to do this to wait for your platofrm to reach point_01, 
	// otherwise your platform will move on to the next statement before 
	// its time
	wait 12000				
		
	// Turn the platform to face the 90 degree point on the Y axis
	// The 1500 means that it should take 1.5 seconds to complete the turn
	faceangles 0 90 0 1500		
	
	// Move to point_02
	gotomarker point_02 32		
	// Wait 6 seconds
	wait 6000						

	// Turn the platform to face the 180 degree mark. 
	// Note, this doesn't mean to turn the platform 180 
	// degrees from its current position, it means face the world
	// 180 degree angle
	faceangles 0 180 0 1500		
		
	// Move to point_03
	gotomarker point_03 32		
		
	}
	
	trigger move_start
	{
	// Face angle 0. Problem: The platform currently always turns 
	// counter clock-wise this causes a problem because the platform 
	// collides with another brush.
	// Not sure how to fix this, if you know, email me at nib@nibsworld.com
	faceangles 0 -0 0 1500		
	
	// Move back to the starting marker
	gotomarker point_00 32		
	}
	

}

Well, that's about it. Seems long and complex but I promise you it isn't, there is just a lot of information to get across. Once you've digested this, move on to the advanced tutorial done by BOlty BOy. It shows you how to create a draw bridge with 2 levers.

Conclusion:

Files:

basic_script_mover_tut.zip