Post tutorial Report RSS UnrealScripter #1

UDK is a powerful tool that allows making all types of games. The problem is that we need to be able to program it ! This tutorial has a simple aim : helping to understand the UnrealScript programming.

Posted by on - Intermediate Client Side Coding

UDK is a powerful tool that allows making all types of games. The problem is that we need to be able to program it ! This tutorial has a simple aim : helping to understand the UnrealScript programming.

All I will explain here is for solo games only. But this will maybe and often work for multiplayer games. This first tutorial will allow you to create a SequenceAction useable in Kismet. This SequenceAction will display a message (subtitles for example) when we want to. You can use UIScenes for this, but using a SequenceAction will be simpler later.

First thing to do : create a blank SequenceAction :

class TT_SeqAct_Message extends SequenceAction;

defaultproperties
{
}

We save the file with the name : TT_SeqAct_Message.uc. As this name say it, a SequenceAction make something. We will use the event Activated() to put in what we want to do (here, displaying a message).

To display a message, we will use the function BroadcastLocalizedMessage() that send messages to all players. As we are in a solo game, we are sure to receive it! (you can use the ReceiveLocalizedMessage() to send a message to a single player or a particular group of players). The function BroadcastLocalizedMessage() is defined in the Actor.uc class. We have to use WorldInfo to use this function (look at the Actor.uc file to understand why).

class TT_SeqAct_Message extends SequenceAction;

event Activated()
{
local WorldInfo WI; 
WI = GetWorldInfo(); 
WI.BroadcastLocalizedMessage(class'TT_Message');
}

defaultproperties
{
}

We introduce here the variable WI, that corredpond to the WorldInfo. Then, we define it with the function GetWorldInfo(). And finally we can send our message ! All the actions here have to be known, because they are reused in a lot of cases :

1 – define a variable
2 – give a value to this variable
3 – exploite this variable

The next step is to create the TT_Message class. We create a file named TT_Message.uc with the classic structure :

class TT_Message extends LocalMessage;

static function string GetString(
optional int Switch,
optional bool bPRI1HUD,
optional PlayerReplicationInfo RelatedPRI_1,
optional PlayerReplicationInfo RelatedPRI_2,
optional Object OptionalObject
)
{
Return "Trash Team !"
}

defaultproperties
{
Lifetime=5
DrawColor=(G=255,R=255,B=255)
PosY=0.9
FontSize=2
}

The GetString() function is the most imporant in the LocalMessage class. It defines what will be displayed. Some options can be used. Some of them use the PlayerReplicationInfo (informations
about the player as health, armor, speed…). We just want to display a simple sentence. In the class properties, some little things can be used to customize our message :

Lifetime : the time the message will be displayed (here : 5 secondes)
DrawColor : the color of the text (here : blank)
PosY : Vertical position of the message (here : on the bottom of the screen)
FontSize : Size of the font (here : middle size)

We will optimize our sequence. We will make a sequence that will be used to display many different messages. We consider a game with two races of characters. We can choose to be a troll or an human. Each race has a number. For example:

Human = 0
Troll = 1

We will display two different messages by races. We will use the switch option of the GetString() function of the LocalMessage() class. When I send a message to a player, I can define what message is sent. For example, BroadcastLocalizedMessage(class’TT_Message’,2) send the second message of the TT_Message class. To define the message :

class TT_Message extends LocalMessage;

static function string GetString(
optional int Switch,
optional bool bPRI1HUD,
optional PlayerReplicationInfo RelatedPRI_1,
optional PlayerReplicationInfo RelatedPRI_2,
optional Object OptionalObject
)
{
if (switch == 0)
{
return "You are an human !"
}
else if (switch == 1)
{
return "You are a troll !"
}
else
{
}
}

defaultproperties
{
Lifetime=5
DrawColor=(G=255,R=255,B=255)
PosY=0.9
FontSize=2
}

Now we will define in our sequence what message to send. The aim is to be able to define it in
Kismet what race have to receive this message (race 0 or race 1). We add a node to our class TT_SeqAct_Message with the line :


<span>VariableLinks.Add((ExpectedType=class'SeqVar_Int',LinkDesc="Race",PropertyName=Race,bWriteable=True))
</span>


VariableLinks.Add : add a node
ExpectedType : what type of variable is needed (here : integer)
LinkDesc : name of the variable (here : race)
PropertyName : name that will be display in Kismet for the node (here : race)

We have to define the variable race as an integer :

Var() int Race ;

The Race variable will be defined by Kismet by connecting an integer to the node Race of our sequence. To call the message, we will use the command :

WI.BroadcastLocalizedMessage(class'TT_Message', Race) ;

So finally, the entire class :

<span>class TT_SeqActMessage extends SequenceAction;

var() int Race;

event Activated()
{
local WorldInfo WI;
WI = GetWorldInfo();
WI.BroadcastLocalizedMessage(class'TT_Message', Race);
}

defaultproperties
{
bCallHandler=false
ObjName="Play Message"
ObjCategory="Trash Team"
VariableLinks.Add((ExpectedType=class'SeqVar_Int',LinkDesc="Message",PropertyName=Message,bWriteable=True))
}
</span>

ObjName : name of the sequence that will be shown in Kismet
ObjCategory : the folder of the sequence

Here is the principle of our sequence:

UnrealScripter #1

You can use the same principle to make SequenceCondition for example. You just need to open an existing SequenceCondition to see what is different.

Here is the result in Kismet :

UnrealScripter #1

In the next tutorial, we will learn how to define the player race and use it in our SequenceAction !

Comments
Picklock
Picklock

cool, thanks!

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Tutorial
Browse
Tutorials
Report
Report
Share
Related Groups
Indie Devs
Indie Devs Hobbies & Interests with 1,440 members
UDK Developer's Group
UDK Developer's Group Hardware & Tech with 704 members