Lesson 2 - Your first trigger

Lessons and tutorials about mods and maps
Post Reply
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Lesson 2 - Your first trigger

Post by Feralidragon »

In this lesson, it's assumed that you already know the basic steps to create and compile a package.
If you don't know how to do this, check the previous lesson here: Lesson 1 - Your first mutator

________________________________________________________________________________________________________________________


In this lesson we're going to make a new custom simple trigger that can be used in your maps:
- When it's triggered, it will broadcast a message to all players;
- This message can be customized by the mapper in the Unreal Editor.


1 - Start by creating a new package (the same way you did in the previous lesson), but this time we're going to name it MyFirstTrigger.


2 - Next create a new .uc file in the Classes folder. We're going to call it MyTrigger.


3 - Since it's a trigger, the class declaration will be written as follows:

Code: Select all

class MyTrigger extends Triggers;

4 - Next, we create the property the mapper will be able to see and change, in order to write his/her own custom message, as:

Code: Select all

var() string MyMessage;
var indicates that we're declaring a new variable for this class.
() next to var indicates that this property can be seen and edited from Unreal Editor, or in other words, it can be seen and edited by the mapper once placed in the map.
string indicates that this property will store text in it (since a message is text after all).
MyMessage is the name we chose to call this new variable. Therefore this property will be seen as MyMessage in the Unreal Editor.


5 - When actors are triggered, the function Trigger(Actor Other, Pawn EventInstigator) is called, therefore this is the function you're going to use for every custom actor you want to have a custom behavior when triggered.
In this case, when triggered we want to broadcast the message stored in the MyMessage property we created above:

Code: Select all

function Trigger(Actor Other, Pawn EventInstigator)
{
   BroadcastMessage(MyMessage);
}

6 - Since you created a new property, it's good practice (sometimes necessary) to define its default value, or in other words, the text it will have if the mapper does not edit this property.
In this case, the default text will be "Put your message here.".
To do so you must create a defaultproperties block at the end of the file, as:

Code: Select all

defaultproperties
{
   MyMessage="Put your message here."
}
NOTE: In the defaultproperties block, you cannot have spaces or new lines in the expression, therefore:
var = value is wrong;
var=value is correct.
The value however can have spaces only if it's a string/text, but not new lines, just like in this case.


7 - In the end your class should look like this:
Image



8 - Save and compile the package, so in the end you get a MyFirstTrigger.u file in your System folder in your Unreal Tournament install.
Image



9 - Unlike the previous lesson, in this case we do not need to create a .int file, since a trigger is something that is only used in a map.
Therefore, the map itself will tell the game to load up the package when needed.



10 - From here, just open Unreal Editor and open an existing map or create your own, and load up the MyFirstTrigger.u package into the editor.
Image



11 - Now, just add this MyTrigger somewhere in your map, and another standard trigger too.
The standard trigger will activate your MyTrigger, therefore set the standard trigger Event to the Tag of MyTrigger.
Image

Image



12 - After that, you need to setup the message your want to display, therefore open the MyTrigger properties, look for the category also called MyTrigger, and find the property MyMessage that we defined.
Just write there anything you want. In this example I chose "My trigger works!".
Image



13 - Save the map, play it and try it out.
NOTE: If you opened an existing map just for testing purposes, save it with another name: for example, if you open CTF-Face to do this experiment, save it as CTF-Face_MyTrigger or something else.
Image

Image



________________________________________________________________________________________________________________________


You can download the source and compiled package used in this lesson here:

Source: http://www.mediafire.com/?hnzrwrrwzgnn38z

Package: http://www.mediafire.com/?733g4asu3bbt29u

________________________________________________________________________________________________________________________

User avatar
Cronoloop
Skilled
Posts: 223
Joined: Sat Feb 16, 2013 10:16 am

Re: Lesson 2 - Your first trigger

Post by Cronoloop »

This is pretty cool.
By "triggering" you mean activating it, or just walking near/on it?

We need a trap tutorial a-la Pressure! Would be awesome :mrgreen:

Nice tut :thuup:
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Lesson 2 - Your first trigger

Post by Chamberly »

So I'm stuck here, starting from #11. According to your picture you have the trigger box. Mine doesn't show up in the editor or the map being played. What am I missing here? I'm not very good at map editing (lack of knowledge).
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Lesson 2 - Your first trigger

Post by Feralidragon »

That trigger box is from a normal trigger.
You can add one by going to Triggers > Trigger (basically in the same branch as MyTrigger).

From there, as I explain above, you just need to set that normal trigger Event to the MyTrigger Tag you placed in the map.
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Lesson 2 - Your first trigger

Post by Chamberly »

That works. Thanks! :mrgreen:
redgrape404
Average
Posts: 43
Joined: Wed Nov 25, 2015 2:51 am
Personal rank: High School graduate
Location: Vancouver, Washington, United States

Re: Lesson 2 - Your first trigger

Post by redgrape404 »

I'm haveing trouble UMake won't let me compile
ShaiHulud
Adept
Posts: 459
Joined: Sat Dec 22, 2012 6:37 am

Re: Lesson 2 - Your first trigger

Post by ShaiHulud »

I always use ucc from the command line (that's not supposed to sound like some kind of geeky boast, I'm just too lazy to learn how to use yet another tool), but presumably UMake forward error messages from ucc - so what error message are you seeing?
User avatar
UnrealGGecko
Godlike
Posts: 2894
Joined: Wed Feb 01, 2012 11:26 am
Personal rank: GEx the Gecko
Location: Kaunas, Lithuania
Contact:

Re: Lesson 2 - Your first trigger

Post by UnrealGGecko »

Check for any spelling and symbol placing mistakes in your code. When I started learning C++ in school I made a ton of those and was wondering why the hell my simple ''type 2 numbers in so they get added'' oops :P
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Lesson 2 - Your first trigger

Post by JackGriffin »

Grab my coding school zip file, it has a standalone one-click compiler in it. It's on here somewhere or I'm sure someone has it to post. It's not better than UMake, just simpler to use. There's also some coding tools, etc in the zip as well as information on setup. Hope that helps.
So long, and thanks for all the fish
User avatar
sektor2111
Godlike
Posts: 6402
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Lesson 2 - Your first trigger

Post by sektor2111 »

UMake make things faster and easier without editing ini files, just click here and there, compile, test, compile, test. You can do in a mod with some values having 5 options all tests in less than 10 minutes.

To not forget that in any case an ucc.log file is being generated and then after compiling or failing you can inspect that log file for errors if they do exist. Usually if script is bad written line in cause is mentioned, later by using a smart text editor as NotePad++ you can figure the bad line and look for:
- syntax problem - wrong code - brackets not closed, etc.;
- variable not defined;
- some class mentioned is not loaded in dependencies chain;
- attempting to assign a constant;
- redundant cast Pawn to Pawn or such;
- strings problems, etc.
Any of these rejections is located in log file even if you are using UMake or not, because UMake allows compiling if things are properly done. I was using UMake for years with no issues.
nogardilaref
Masterful
Posts: 577
Joined: Tue Jun 20, 2017 1:00 pm
Personal rank: ⚋⚊⚌☰⚞⌖⚟☰⚌⚊⚋

Re: Lesson 2 - Your first trigger

Post by nogardilaref »

These days what you really want is a full fledged IDE where you can setup your project, compile it and use version control as well.
That's the simplest and most productive way to do any programming at all (be it a mod or something else).

There was a project some years ago where someone was trying to create an UnrealScript plugin for Eclipse.
But the project was abandoned, and generally old plugins do not work in newer versions of Eclipse (at least not very well), but it had a really good premise going on.

But I think as long you have syntax highlighting and an easy way to compile and push it to git or so, anything of the sort would be really great.
Furthermore these things are followed by repositories and dependency managers, which would be the cherry on top.
redgrape404
Average
Posts: 43
Joined: Wed Nov 25, 2015 2:51 am
Personal rank: High School graduate
Location: Vancouver, Washington, United States

Re: Lesson 2 - Your first trigger

Post by redgrape404 »

I'll take note on that.

Also is there a compiler that points out the errors in your code.
redgrape404
Average
Posts: 43
Joined: Wed Nov 25, 2015 2:51 am
Personal rank: High School graduate
Location: Vancouver, Washington, United States

Re: Lesson 2 - Your first trigger

Post by redgrape404 »

O.K I have found the problem

UnrealScript project directories must be located directly below the game base directory

What does that mean to me?
nogardilaref
Masterful
Posts: 577
Joined: Tue Jun 20, 2017 1:00 pm
Personal rank: ⚋⚊⚌☰⚞⌖⚟☰⚌⚊⚋

Re: Lesson 2 - Your first trigger

Post by nogardilaref »

It means that, if your UT directory is, let's say:
C:\UnrealTournament
then the folder with all your stuff should be directly in that directory.
Post Reply