Game Development Community

Trigger Teleporter for TGEA

by DreamPharaoh · in Technical Issues · 02/12/2008 (3:43 pm) · 2 replies

I am atempting to make a simple teleport trigger so that I can make caves in TGEA (can't put holes in terrain) . I have been messing with this code. It echoes all of the info in the console but has no effect on the character. Any ideas to what may be wrong? Thank you for any help on this.

datablock TriggerData( TempleOfEvilTrigger )
{
// tickPeriodMS is a value is used to control how often the //console
// onTriggerTick callback is called while there are any //objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};

function TempleOfEvilTrigger::onEnterTrigger( %this, %trigger, %obj )
{
echo( "The player has just entered the Temple of Evil! - Not the smartest move!");
%oldTransform = %Obj.getTransform();
echo(%oldTransform);
echo(%this);
echo(%trigger);
echo(%obj);

//%obj.setTransform(604.05 829.889 -241.34 -0.250 3 6);
%newPos = %obj.getWorldBoxCenter();
%newPos = vectorAdd( "10 0 0", %newPos );

//604.05 829.889 -241.34 -0.25
%newTransform = %newPos SPC getWords( %oldTransform, 3 , 6);

// This method is called whenever an object enters the //%trigger
// area, the object is passed as %obj. The default //onEnterTrigger
// method (in the C++ code) invokes the //::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the //trigger.
//Parent::onEnterTrigger( %this, %trigger, %obj );
}

function TempleOfEvilTrigger::onLeaveTrigger( %this, %trigger, %obj )
{
echo( "The player has just left the Temple of Evil! - The player lives to fight another day!");

// This method is called whenever an object leaves the //%trigger
// area, the object is passed as %obj. The default //onLeaveTrigger
// method (in the C++ code) invokes the //::onTrigger(%trigger,0) method on
// every object (whatever it's type) in the same group as the //trigger.
Parent::onLeaveTrigger( %this, %trigger, %obj );
}

function TempleOfEvilTrigger::onTickTrigger( %this, %trigger )
{
echo( "The player is still in the Temple of Evil! - Calling all monsters!");

// This method is called every tickPerioMS, as long as any
// objects intersect the trigger. The default onTriggerTick
// method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
// every object (whatever it's type) in the same group as the trigger.

// You can iterate through the objects in the list by using //these
// methods:
// %this.getNumObjects();
// %this.getObject(n);
Parent::onTickTrigger( %this, %trigger );
}

#1
02/12/2008 (5:31 pm)
This code came from someone else, sorry I can't remember who it was. I know Orion Elenzil was involved at some point. I just tested it in TGEA 1.0.3 and it works fine.

This is my Trigger.cs Script:
//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// DefaultTrigger is used by the mission editor.  This is also an example
// of trigger methods and callbacks.

datablock TriggerData(DefaultTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};


//-----------------------------------------------------------------------------

function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object enters the %trigger
   // area, the object is passed as %obj.  The default onEnterTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onEnterTrigger(%this,%trigger,%obj);
}

function DefaultTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object leaves the %trigger
   // area, the object is passed as %obj.  The default onLeaveTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onLeaveTrigger(%this,%trigger,%obj);
}

function DefaultTrigger::onTickTrigger(%this,%trigger)
{
   // This method is called every tickPerioMS, as long as any
   // objects intersect the trigger. The default onTriggerTick
   // method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
   // every object (whatever it's type) in the same group as the trigger.

   // You can iterate through the objects in the list by using these
   // methods:
   //    %this.getNumObjects();
   //    %this.getObject(n);
   Parent::onTickTrigger(%this,%trigger);
}

datablock TriggerData(Teleporter)
{
tickPeriodMS = 100; 
};

//-----------------------------------------------------------------------------
function Teleporter::onEnterTrigger(%this,%trigger,%obj)
{
echo("Teleporter::onEnterTrigger --IN");
Parent::onEnterTrigger(%this,%trigger,%obj);
   
   // Print out some debug info ;)
   // Get the number of dynamic field in the trigger
echo("# Of Indx : " @ %trigger.getDynamicFieldCount());
   // in my case I just have one so I use the first index
   echo("Index 0   : " @ %trigger.getDynamicField(0));
   
   // here is where we do the real work
   //%str = %trigger.getDynamicField(0);
   // it should remove the name of the dynamic field and leave the coordinates
   //%coords = removeField(%str, 0);

%coords = %trigger.coords;   // Updated, thx Orion Elenzil

   // for educational purposes print out the string and the coordinates
echo("The String   : " @ %str);
   echo("Coordinates  : " @ %coords);
   
   // this transform will take you to the place that you want!!
%obj.setTransform(%coords);
}
//-----------------------------------------------------------------------------

function Teleporter::onLeaveTrigger(%this,%trigger,%obj)
{
Parent::onLeaveTrigger(%this,%trigger,%obj);
}

function Teleporter::onTickTrigger(%this,%trigger)
{
   
Parent::onTickTrigger(%this,%trigger);
}

Then just add this to a mission file:

new Trigger(TestTrigger2) {
      canSaveDynamicFields = "1";
      position = "-405.268 -687.6 84.8636";
      rotation = "1 0 0 0";
      scale = "4 4 4";
      dataBlock = "Teleporter";
      polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         coords = "-847.692 159.735 93.6533";
   };

The position is the location of the trigger, the coords is the location of the destination.

Hope it helps.

.
#2
02/12/2008 (5:46 pm)
Thank you so much!!! This works beautifully, alot better than what the book suggested.