Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
UScript Tutorial.doc
Скачиваний:
4
Добавлен:
01.09.2019
Размер:
634.37 Кб
Скачать

The Weapon Idle State

state Idle

{

function AnimEnd()

{

PlayIdleAnim();

}

function bool PutDown()

{

GotoState('DownWeapon');

return True;

}

Begin:

bPointing=False;

if ( (AmmoType != None)

&& (AmmoType.AmmoAmount<=0) )

Pawn(Owner).SwitchToBestWeapon();

if ( Pawn(Owner).bFire!=0 ) Fire(0.0);

if ( Pawn(Owner).bAltFire!=0 ) AltFire(0.0);

Disable('AnimEnd');

PlayIdleAnim();

}

Code in states can be written either within functions, or under labels. Begin is by far the most common label, and any code written under it is executed as soon as the class enters that state. Another cool thing about states is that you can use them to override functions within a particular class. For instance, say you had a Timer() function defined outside of a state. If you defined another Timer() function within a state, then that Timer() function would override the global one if the class was in that state. Another useful thing you can do with a state is to stop certain functions from executing while the class is in that state. For example, if you wanted to make it so the player couldn't fire while his gun was reloading (usually a good idea), you could add this line just after the definition of your reload state:

The Ignore Statement

ignores Fire, AltFire;

This makes it so neither the Fire() or AltFire() function can be executed while the class is in this state. To make an object enter a state, use the syntax: "GoToState('State');".

D e f a u l t P r o p e r t i e s

Default properties are simply a means by which you, as the programmer, or someone else, such as a mapper, can set default values for certain variables in a class. Default properties are used to control many things, such as how to display a class, what mesh or texture to use, and what sounds to use. If you want a variable to be displayed in the default properties of a class, you have to declare it in a special way:

Default Properties Variable

var([defaultgroup]) [vartype] [varname];

The part in the parenthesis, defaultgroup, tells Unreal what section of the default properties you want the variable to be displayed in. If you don't supply anything for this parameter, it will be displayed in a section with the same name as the class. You can look at and change the default properties of a class by selecting it in the class browser, and clicking the "Defaults" button.

Y o u r F i r s t C l a s s

Here it is. The moment you've been waiting for since... since... well, since you started reading this sentence, I suppose. It's time to create your first new UnrealScript class. To be specific, you're going to make a new type of FlakCannon that randomly alternates between firing a flakshell, a grenade, or an energy ball in alt-fire. Not the most exciting weapon there ever was, but hey, this is a tutorial for beginners. To start off, I suppose I should explain a little something about the way Unreal is organized. All classes, sounds, textures, and models are stored in special files called packages. Most of the code and models, and some of the textures and sounds for Unreal are stored in two files: unreali.u, and unrealshare.u (as of 220, anyway). These files are found in your Unreal\System directory, as are all .u files. When you create a new class in UnrealScript, you store that class in a new .u file. It's not a good idea to store a new class in an existing .u file, since you would then have to pass around the entire file if you wanted to distribute your class. With that out of the way, let's get ready to rumble. Open up UnrealEd (if you don't already have it open), and get to the class browser. Open up the Inventory and Weapon threads, and select the FlakCannon class. Now, hit the "New..." button, which can be found down below the browser. You'll get a window asking you to enter a class name, and a package name. Enter "MultiCannon" in both fields, and press the "Create this actor class" button. You'll see that your MultiCannon class will appear under FlakCannon in the class tree, and an editor window will appear, complete with the class declaration. The next thing to do is copy the AltFire() function from the FlakCannon class, since we want to modify what the weapon shoots in alt-fire. AltFire() is simply a function which is called by the engine when the player presses the alt-fire button. It's used to control what happens when a weapon alt-fires. The same goes for the Fire() function, but we're not modifying primary fire here, so we don't need Fire(). Anyway, double-click on FlakCannon in the class browser to open it up. Scroll through the code until you find the AltFire() function, and copy it into your MultiCannon class. You'll notice that the new code appears as all green when you first copy it. This is because UnrealEd doesn't apply the proper coloring to code until you compile it. So, let's compile it. Compiling in UnrealEd couldn't be easier. Simply hit the F7 key to compile all modified classes. Now, add the following local variable declarations to your new AltFire() function:

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]