Game Development Community

Trigger

by Taylor Wiebe · in Torque Game Engine · 04/06/2007 (8:27 pm) · 11 replies

How would I make it so that if I add a trigger over some water, when you fall in you would be sent back to a specific "spawn point"?

#1
04/06/2007 (8:49 pm)
1. Create a databask for your triggers ...

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


2. Draw your trigger over the water from your datablock


3. Test for the trigger and setTransform your player somewhere.

function YourLevel::onEnterTrigger(%this,%trigger,%obj)
{
if (%obj != LocalClientConnection.player) return;

switch$(strupr(%trigger.getName()))
{

case "OVERWATER":
LocalClientConnection.Player.setTransform(markSpawnPoint.getTransform());

....

Cheers.
#2
04/07/2007 (9:00 am)
I got the first and second part to work but when I add the third into the console it says Parse Error.
#3
04/07/2007 (9:51 am)
It works ... You have to remove the carriage returns first ... or run it from a .cs
I have a sys_function.cs that is executed ... I just add new functions to it for testing.
p.s. don't forget the closing brackets for the above! }}

Randy
#4
04/07/2007 (10:11 am)
Sorry for all of these questions, I am just learning to script. how exactly do you run it from a .cs file? I created a new .cs file called overwater.cs and now how do I get it tow work in the game. I just pasted this script into it (just want to make sure this is right):

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


function YourLevel::onEnterTrigger(%this,%trigger,%obj)
{
if (%obj != LocalClientConnection.player) return;

switch$(strupr(%trigger.getName()))
{

case "OVERWATER":
LocalClientConnection.Player.setTransform(markSpawnPoint.getTransform());

}}
#5
04/07/2007 (11:17 am)
datablock TriggerData(waterOverTrigger)
{
   tickPeriodMS = 100;
};

function waterOverTrigger::onEnterTrigger(%this, %trigger , %obj)
{
   %spawnPoint = pickSpawnPoint();
   %player.setVelocity("0 0 0");
   %player.setTransform(%spawnPoint);

}

try that

TomFeni
#6
04/09/2007 (7:54 am)
Could someone answer my second question too? on how to use the .cs file in torque.
#7
04/09/2007 (8:05 am)
Scripts need to be executed. There are two types of scripts, server scripts and client scripts. Where they need to be executed from will depend on what type of script they are.

In your case, you have a server script and will want to store and execute it from the server. Typically, this is done from server/scripts/game.cs

Example:
exec("./audioProfiles.cs");
   exec("./camera.cs");
   exec("./markers.cs");
   exec("./triggers.cs");

So you will need to place your script in the server/scripts directory as well as adding this line to the "onServerCreated" function at the top of game.cs
exec("./overwater.cs");

The order in which scripts are executed DOES matter however in your case you'd be adding your "exec" command to the bottom of the list.
#8
04/09/2007 (8:06 am)
Did you exec the .cs file after you made it?
#9
04/09/2007 (8:18 am)
You need to exec the script file e.g:

exec( "./overwater.cs" );

Add the code in (e.g. /client/init.cs) and change the path if overwater.cs is not in the same directory as the script doing the exec etc.
#10
04/09/2007 (8:20 am)
Heh, Tim was too quick for me (and better at explaining it too ;p)
#11
04/09/2007 (8:47 am)
Man. And I didn't even read his before I posted my question!