Intro To Scripting

From CoDWWModWiki

Jump to: navigation, search

Contents

Create A Map Script File

1: Create a new Notepad or TextPad file and open it.
2: Copy the following into the file.

main()
{
	//maps\mp\mp_yourmapname_fx::main();		
	maps\mp\_load::main();
	
	//maps\mp\_compass::setupMiniMap("compass_map_mp_yourmapname");

	// If the team nationalites change in this file,
	// you must update the team nationality in the level's csc file as well!
	game["allies"] = "marines";
	game["axis"] = "german";
	game["attackers"] = "axis";
	game["defenders"] = "allies";
	game["allies_soldiertype"] = "german";
	game["axis_soldiertype"] = "german";

	setdvar( "r_specularcolorscale", "1" );
	setdvar("compassmaxrange","2100");

}


3: Save the file in raw\maps\mp\mp_yourmapname.gsc

  • Remember that when saving you may have to select "All Files" as it night save your file as "mp_yourmapname.gsc.txt" and that's no good.



Editing Your Script File

  • maps\mp\mp_yourmapname_fx::main();
    • Calls the main() function of maps\mp\mp_yourmapname_fx.gsc, this is used for FX.
  • maps\mp\_load::main();
    • Calls the main() function of maps\mp\_load.gsc
    • Required for just about everything, always leave alone.
  • maps\mp\_compass::setupMiniMap("compass_map_mp_yourname);
    • Change it to the material name of you minimap texture.
  • game["allies"] = "marines";
  • game["axis"] = "german";
    • Change the nationality at the end to change the respective team nationality.
      • "marines", "russian", "german", "japanese"
  • game["attackers"] = "axis";
  • game["defenders"] = "allies";
    • Change to what role you want each team to play.
  • game["allies_soldiertype"] = "german";
  • game["axis_soldiertype"] = "german";
    • This sets the clothing for each team.
      • "german" or "pacific"



Combining With Your Map

1: Make sure your file is properly saved and updated in "\raw\maps\mp\mp_yourmapname.gsc".
2: Open the CoDWaW Compile Tools application and go to the "Level Compiling" tab.
3: Build your Fast File then click on "Update Zone File".
4: Look for "rawfile,maps/mp/mp_yourmapname.gsc" on the right. If its missing then create the entry.
5: Rebuild your Fast File and test the map.


Moving Objects

While there are hundreds of ways to do one thing in programming, this uses the easiest to understand scripts that get it done.

1. In your map create a script_brushmodel or script_model that you want to move or rotate.

  • Give that object the "Key / value" of "targetname / move".
  • Save the map and recompile, your done in Radiant.

2. Open your map's script file.
3. In main() add the line "thread move();" 4. Then add this block of code past the bottom of the file.

move() {

    // Assign any script object in the map with "targetname / move" to "moveEntity"
    moveEntity = getEntArray( "move" , "targetname" );

    //Always going, "while true" and 1 = true, 0 = false
    while (1)
    {
        //Rotating moveEntity 360 degrees in 5 seconds with 0 speed up time and 0 slowdown time
        moveEntity rotateyaw( 360, 5, 0, 0 );
        
        //Move moveEntity along the X axis 512 units in 5 seconds with a 1 second acceleration time and a .5 second deceleration time.
        moveEntity moveX( 512, 5, 1, .5 );

        //Having a slightly shorter wait time than move time assures us there are no hitches.
        wait 4.9;
    }
}


Double Check: Make sure your .gsc looks like the one below, this is how it should be setup but you may have your own changes.


main()
{
	//maps\mp\mp_yourmapname_fx::main();		
	maps\mp\_load::main();
	
	//maps\mp\_compass::setupMiniMap("compass_map_mp_yourmapname");

	// If the team nationalites change in this file,
	// you must update the team nationality in the level's csc file as well!
	game["allies"] = "marines";
	game["axis"] = "german";
	game["attackers"] = "axis";
	game["defenders"] = "allies";
	game["allies_soldiertype"] = "german";
	game["axis_soldiertype"] = "german";

	setdvar( "r_specularcolorscale", "1" );
	setdvar("compassmaxrange","2100");

}

move() {

    // Assign any script object in the map with "targetname / move" to "moveEntity"
    moveEntity = getEntArray( "move" , "targetname" );

    //Always going, "while true" and 1 = true, 0 = false
    while (1)
    {
        //Rotating moveEntity 360 degrees in 5 seconds with 0 speed up time and 0 slowdown time
        moveEntity rotateyaw( 360, 5, 0, 0 );
        
        //Move moveEntity along the X axis 512 units in 5 seconds with a 1 second acceleration time and a .5 second deceleration time.
        moveEntity moveX( 512, 5, 1, .5 );

        //Having a slightly shorter wait time than move time assures us there are no hitches.
        wait 4.9;
    }
}

5: Load your map and see if your object is now going all over the place.

Personal tools