Вы находитесь на странице: 1из 7

Unreal Script Lesson 1

*Notepad++ has a custom Unreal Script highlighter that can be found at:
http://www.mediafire.com/download/c8v5aj2j3jt32c9/Unrealscript+Highlighter.zip To Install:

1) Find the Notepad++ settings folder (on Win7 this should be C:\Users\[UserName]\AppData\Roaming\Notepad++). 2) Put the downloaded file in there. 3) Rename the file to userDefineLang.xml 4) Open Notepad++. Lesson 1-Part 1: Setting up the engine for a custom game.
Unreal Script is a very powerful tool that gives the developer a full command of their assets. In this lesson, the campers will learn how to configure UDK to compile their own code, and set up their own Game, Player, and HUD. Setting up UDK for custom code can be done in a few simple steps. 1) 2) 3) 4) Open the UDK directory in the C:\ Choose the installation directory you are going to customize Open the Development\Src directory Inside the Src directory, make a new folder. Lets call it EGG.(Who doesnt like eggs?)

5) Inside the EGG directory, create a new folder named Classes. 6) Inside the DefaultEngine.ini file under [UnrealEd.EditorEngine], put +=EGG 7) Run UDK. A window like this should pop up.

Dont have the campers click Yes, instead have them click Cancel. They have successfully set up a

custom package to compile code in.

Now we will create a custom Game in Unreal Script. Explain that Unreal Script is an OOP. This means that we derive new classes from pre-made classes already in the engine. These classes have built in methods that we can use to our advantage. Have the campers open Notepad++ and create a new file. Have them write down the code below. Explain that they are creating a new class that uses the properties and methods of the SimpleGame class. Inside this class there is a method called PostLogin(). UDK treats assets as members of a server, regardless of the type of game being built. The PostLogin() method is called after the user is fully connected. Once they are connected, the StartMatch() method is called. The SetGameType() method returns the class of GameInfo to spawn for the game on the specified map and the specified options this function should include any fallbacks in case the desired class can't be found. For our purposes, these should be declared as the default. The defaultproperties hold the objects that are always associated with the class. Have each camper notice we will be setting up a HUD, Pawn, and PlayerController.

class EGG_test_game extends SimpleGame; event PostLogin( PlayerController NewPlayer ) { super.PostLogin( NewPlayer ); } simulated function StartMatch() { super.StartMatch(); } static event class<GameInfo> SetGameType(string MapName, string Options, string Portal) { return Default.class; } defaultproperties { PlayerControllerClass=class'EGG.EGG_test_controller' DefaultPawnClass=class'EGG.EGG_test_pawn' HUDType=class'EGG.EGG_test_hud' bDelayedStart=false }

Lesson 1-Part 2: The Pawn, PlayerController, and the HUD.

Now that we have a working game, let us create a character. The following code will set up a simple Pawn.
class EGG_test_pawn extends Pawn; simulated function PostBeginPlay() { Super.PostBeginPlay(); } defaultproperties { bPostRenderIfNotVisible=true }

This pawn has no properties yet, but thats fine for now. We gave this Pawn its own PlayerController in our Game so lets make that next. This code sets up our PlayerController. Notice that it has an event that gives it a Pawn, and an ability to use vehicles. The inPawn will be our Pawn as defined in our game.

class EGG_test_controller extends PlayerController; event Possess(Pawn inPawn, bool bVehicleTransition) { super.Possess(inPawn, bVehicleTransition); } defaultproperties { }

Finally we need to set up a HUD. The HUD in UDK is very powerful and can be utilized in many ways. UDK allows for .swf importation from flash to utilize high quality movies and animations, has its own object creation, and has a canvas that can draw directly to a HUD. For now, we are going to set up a simple crosshair and draw some text to the screen.
class EGG_test_hud extends HUD; var Font Player_Font; function PostRender() { local float CrosshairSize; super.PostRender(); CrosshairSize = 4; Canvas.SetDrawColor(0,255,0,255); Canvas.SetPos(CenterX - CrosshairSize, CenterY); Canvas.DrawRect(2*CrosshairSize + 1, 1); Canvas.SetPos(CenterX, CenterY - CrosshairSize); Canvas.DrawRect(1, 2*CrosshairSize + 1); Canvas.Font = Player_Font; Canvas.SetPos(70, 100); Canvas.DrawText("EGG_HUD"); } defaultproperties { Player_Font= "UI_Fonts.MultiFonts.MF_HudSmall" }

The canvas has a lot of built in member functions. These include the SetDrawColor(),SetPos(),DrawText(),DrawRect(), and Font(). Most of these are fairly straightforward, but make sure you explain what each do to clarify. Have each camper notice the font is set up in our defaultproperties using a pre-existing package font. UDK comes with many fonts and also supports custom fonts. The canvas also has some different ways of defining positions on the screen. In the code we hardcode the pixels, and go off the center of

the screen. SizeX and SizeY can be used as well. These are set to the size of the screen. For example a 1280x720 display would have a SizeX of 1280, and a SizeY of 720.

Lesson 1-Part 3: Testing it all out. Now that we have set up our game, lets compile and run it. Open UDK and when prompted to compile scripts press Yes. A screen like this should appear.

Notice that the compiler say Package EGG changed, recompiling. This is a good thing. It means we successfully made our new game class. Now have the campers open the editor. Have them click on View -> World Properties. Inside the window, have them pull down the Game Type tab. Change Default Game Type, Game Types Supported On This Map, and Game Type For PIE to our

EGG_game_test class.

Finally, click the play button and you should get something like this.

With that this lesson is over. Next lesson will we move onto learning how to implement a Trigger in Unreal Script.