Author Topic: What does the trigger class do?  (Read 1943 times)

trinick posted this
Code: [Select]
datablock TriggerData(MyTrigger) {
    tickPeriodMS=100;
};

function MyTrigger::onEnterTrigger(%this, %trigger, %obj)  {
    announce(%obj);
}

function MyTrigger::onLeaveTrigger(%this, %trigger, %obj) {
    announce("!" @ %obj);
}

new Trigger(MyTriggerInst) { datablock = MyTrigger; };
in this topic: http://forum.blockland.us/index.php?topic=238483.0


and I was wondering what do triggers do?

It's used to detect objects inside an area.
When an object enters the trigger area, the onEnterTrigger method is called.
When an object leaves the area, the onLeaveTrigger method called.
There's also an onTickTrigger method, that is called every period defined by tickPeriodMS.

Like in the GameMode_Turtorial, it can be used for other things to happen, like if someone entered a trigger a noise could go off.

In slayer, for the capture points, they use triggers to capture when the player is on it.

Warning - while you were typing a new reply has been posted. You may wish to review your post.
Derp

So how would I define the place where the trigger is placed?

That's where things get tricky. The trigger uses the fields .scale, .polyhedron, .rotation, and .position to figure out how it looks in 3D space.

.scale and .rotation are self-explanatory since they work pretty much as you'd expect in blockland.
.polyhedron is a string of 9 numbers, with the first 3 numbers representing the origin of the trigger and the other 3 sets of 3 representing vectors extending from that origin.
.position is from the origin point of the polyhedron, not the center of the final scaled polyhedron shape. Care must be taken when setting positions.

The easiest thing to do as far as I've been able to figure out is to set the polyhedron to
Code: [Select]
"0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 1.0000000" Which will create a nice rectangle going in the positive directions from the origin with a rotation of "1 0 0 0".
Then set the scale to whatever the dimensions should be, and set the position to where you want the minX/minY/minZ corner to be.

I've found the easiest way to make triggers is with bricks, because you can visually build them rather than entering data

I've found the easiest way to make triggers is with bricks, because you can visually build them rather than entering data
what
How do you define a trigger datablock, define its onEnter, onLeave, and onTick functions, and create the object by planting bricks?
« Last Edit: August 05, 2013, 12:06:55 PM by Headcrab Zombie »

what
How do you define a trigger datablock, define its onEnter, onLeave, and onTick functions, and create the object by planting bricks?
With a function like this!


Code: [Select]
function fxDtsBrick::createTrigger(%this,%data,%polyhedron)
{
if(!isObject(%data))
{
error("ERROR: fxDtsBrick::createTrigger: Trigger datablock not found.");
return 0;
}

if(%polyhedron $= "")
%polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";

if(isObject(%this.trigger))
%this.trigger.delete();

%t = new Trigger()
{
datablock = %data;
polyhedron = %polyhedron;
};
missionCleanup.add(%t);

//space guy
%boxMax = getWords(%this.getWorldBox(), 3, 5);
%boxMin = getWords(%this.getWorldBox(), 0, 2);
%boxDiff = vectorSub(%boxMax,%boxMin);
%boxDiff = vectorAdd(%boxDiff,"0 0 0.2");
%t.setScale(%boxDiff);
%posA = %this.getWorldBoxCenter();
%posB = %t.getWorldBoxCenter();
%posDiff = vectorSub(%posA, %posB);
%posDiff = vectorAdd(%posDiff, "0 0 0.1");
%t.setTransform(%posDiff);

%this.trigger = %t;
%t.brick = %this;

return %t;
}
It creates a trigger directly on top of the brick. By default, it only effects players standing on the brick, but you can change that with ::setScale.

With a function like this!


Code: [Select]
function fxDtsBrick::createTrigger(%this,%data,%polyhedron)
{
if(!isObject(%data))
{
error("ERROR: fxDtsBrick::createTrigger: Trigger datablock not found.");
return 0;
}

if(%polyhedron $= "")
%polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";

if(isObject(%this.trigger))
%this.trigger.delete();

%t = new Trigger()
{
datablock = %data;
polyhedron = %polyhedron;
};
missionCleanup.add(%t);

//space guy
%boxMax = getWords(%this.getWorldBox(), 3, 5);
%boxMin = getWords(%this.getWorldBox(), 0, 2);
%boxDiff = vectorSub(%boxMax,%boxMin);
%boxDiff = vectorAdd(%boxDiff,"0 0 0.2");
%t.setScale(%boxDiff);
%posA = %this.getWorldBoxCenter();
%posB = %t.getWorldBoxCenter();
%posDiff = vectorSub(%posA, %posB);
%posDiff = vectorAdd(%posDiff, "0 0 0.1");
%t.setTransform(%posDiff);

%this.trigger = %t;
%t.brick = %this;

return %t;
}
It creates a trigger directly on top of the brick. By default, it only effects players standing on the brick, but you can change that with ::setScale.
Whoa that's neat, I might use this on something
Thanks Greek

Whoa that's neat, I might use this on something
Thanks Greek
Thank Space Guy.

With a function like this!
Yeah but you still have to write code for the functions.
Idk I guess I was thinking of something different than what he meant