Author Topic: Trigger help[Solved]  (Read 1401 times)

Alright guys, I've been working a bit on learning a lot of stuff in Torquescript on my own using a wide variety of resources.

However I've found something that I cannot get the understanding or hang of, triggers.

I'm just trying to learn the basics of how to use them, such as placing a 2x4 creating a trigger around the brick and when a player is standing on/in the brick it will display "hi" in chat every so often until the player moves out of the trigger.

I've seen quite a few examples and rummaged through the coding help section with search but I cannot find a 'tutorial' per say that actually helps me.

If someone could just show me the basics, or post a link to an in depth tutorial I'd appreciate it.
« Last Edit: October 10, 2012, 07:37:31 PM by ¥ola »

I'd like someone to tell me the polygon of a sphere trigger pls


new SimGroup(GROUP NAME) {

//start here
new Trigger(Trigger_TRIGGERNAME) {
      position = "TRIGGERPOS";
      rotation = "DIRECTION OF TRIGGER";
      scale = "SIZE OF TRIGGER";
      dataBlock = "TRIGGERDATABLOCK";
      polyhedron = "SHAPE OF TRIGGER (VERY LONG WITH LOTS OF 1.0000000 0.0000000)";
         goalName = "WHAT HAPPENS WHEN YOU GET THERE";
   };
//end here

};


edit-
That is what a trigger is made of :P

This is how triggers are used in Slayer (for capture points):

Create trigger datablock:
Code: [Select]
datablock TriggerData(Slayer_CPTriggerData)
{
tickPeriodMS = 150; //this is how often Slayer_CPTriggerData::onTickTrigger will be called when an object is in the trigger
};

Create trigger:
Code: [Select]
function fxDtsBrick::createTrigger(%this,%data,%polyhedron)
{
//credits to Space Guy for showing how to create triggers
if(!isObject(%data))
{
Slayer_Support::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);

%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;
}

package deleteBrickTriggers
{
function fxDtsBrick::onRemove(%this) //make sure to clean up your triggers
{
if(isObject(%this.trigger))
%this.trigger.delete();

parent::onRemove(%this);
}
};
activatePackage(deleteBrickTriggers);

Use trigger:
Code: [Select]
function Slayer_CPTriggerData::onEnterTrigger(%this,%trigger,%obj)
{
//called when an object enters the trigger
}

function Slayer_CPTriggerData::onLeaveTrigger(%this,%trigger,%obj)
{
//called when an object leaves the trigger
}

function Slayer_CPTriggerData::onTickTrigger(%this,%trigger,%obj)
{
//called every set amount of milliseconds (set in the datablock)
//only called when an object is in the trigger
}

I'd like someone to tell me the polygon of a sphere trigger pls

polygons in torque can only be rectangular boxes.
You define a corner and the x y and z lengths of the sides, and that's about all you can do.


-snip-
I saw this multiple times and attempted to follow this example and such, but I don't understand a few things about it.

How is the trigger actually created and where is it ?

You would do %brick.createTrigger(%triggerDatablock); and it would create a trigger on top of the brick.

You would do %brick.createTrigger(%triggerDatablock); and it would create a trigger on top of the brick.

Alright, so when a client is on top of the brick it would call the enterTrigger and such?

Does this work with any type of brick?  As in calling it on an 8x8 or a 4x4 would create that size trigger on the top of the brick?

One last question, will the trigger still be there even if the bricks 'rendering' property is off?

Alright, so when a client is on top of the brick it would call the enterTrigger and such?

Does this work with any type of brick?  As in calling it on an 8x8 or a 4x4 would create that size trigger on the top of the brick?

One last question, will the trigger still be there even if the bricks 'rendering' property is off?
Yes, yes, and yes.

Yes, yes, and yes.
Lol, I actually went to testing it and knew the answers before you replied.

Thanks for helping me out!

Thumbs up for not locking the topic after finding a solution.

Thumbs up for not locking the topic after finding a solution.
Actually pretty sure I haven't locked any of my topics since like the first one, but thanks anyway!

How would I get the trigger to take the full shape of the brick?

How would I get the trigger to take the full shape of the brick?

wizardry math.