onEnterTrigger only activated by Players?
by Chris · in Torque Game Engine · 05/04/2009 (7:44 pm) · 14 replies
Hey guys, I'm trying to get it so that only the Player can set off this onEnterTrigger and not AI players. I'm not sure how to do this. Any time I try to mess with the trigger data in the data block it makes the whole trigger area disappear. Here's what I've got so far, but the if statement just doesn't allow anything to happen:
function RestrictedRoom::onEnterTrigger(%this, %trigger, %client)
{
if(%client == %client.player)
{
$restrictedflag = true;
echo("I'm in the nursing station! Yipee!");
//commandToServer(messageClient(%client, '', 'Hey you're not supposed to be in there!'));
//error("Hey you're not allowed in there!");
//FontRenderer.Instance.DrawString(spriteFont, new Vector2(975,100), Color.White, "Hey you're not allowed in there!", "");
serverConnection.setBlackout( 1 , 3000 );
//%posFinal = 140.359 -425.215 32.9063 0 0 1 1;
//%obj.setTransform(%posFinal);
serverConnection.schedule( 5000, %client.setTransform( 143.013 SPC -430.025 SPC 33.8565 SPC 0 SPC 0 SPC 0 SPC 0 ));
serverConnection.schedule( 3000, setBlackout , 0 , 3000 );
}
else
{
%restrictedflag = false;
}
}
#2
maybe?
If you don't want to create a GUI for a message, you could try using the centerprint/bottomprint messaging functionality.
05/04/2009 (10:19 pm)
if (!%client.isAiControlled())maybe?
If you don't want to create a GUI for a message, you could try using the centerprint/bottomprint messaging functionality.
#3
The third argument is not %client as in the GameClientConnection it's %intruder or the SimObject that entered the trigger.
This should work any time a player walks through the trigger. A class name of "AIPlayer" would be the AI.
The other thing to remember is that triggers are only called on the server side. The client does not even know they exist because they are not ghosted.
05/06/2009 (10:33 am)
I assume RestrictedRoom is your trigger datablock.The third argument is not %client as in the GameClientConnection it's %intruder or the SimObject that entered the trigger.
This should work any time a player walks through the trigger. A class name of "AIPlayer" would be the AI.
function RestrictedRoom::onEnterTrigger(%this, %trigger, %intruder)
{
if (%intruder.getClassName() $= "Player")
{
}
}The other thing to remember is that triggers are only called on the server side. The client does not even know they exist because they are not ghosted.
#4
you can also test whether a server-side object is a real player or not by testing isObject(%intruder.client).
05/06/2009 (10:41 am)
Wes is spot-on.you can also test whether a server-side object is a real player or not by testing isObject(%intruder.client).
#5
I'm trying to make it so that the Player teleports when he enters this area to another room, but I don't want it to happen instantly. I'm trying to make it so the screen fades to black, then a second or so later he teleports into the room, then a second or so after that he fades back into reality. The problem is, for some reason the serverConnection.schedule isn't making a delay, everything just happens instantly (except the fade-in doesn't happen until the fade-out is done), maybe I have it coded wrong? Let me know what you guys think:
05/08/2009 (2:19 pm)
Wes, thank you very much, that worked great! I have another question since you all have been very helpful:I'm trying to make it so that the Player teleports when he enters this area to another room, but I don't want it to happen instantly. I'm trying to make it so the screen fades to black, then a second or so later he teleports into the room, then a second or so after that he fades back into reality. The problem is, for some reason the serverConnection.schedule isn't making a delay, everything just happens instantly (except the fade-in doesn't happen until the fade-out is done), maybe I have it coded wrong? Let me know what you guys think:
serverConnection.setBlackout( 1 , 3000 ); serverConnection.schedule( 5000, %intruder.setTransform( 143.013 SPC -430.025 SPC 33.8565 SPC 0 SPC 0 SPC 0 SPC 0 )); serverConnection.schedule( 3000, setBlackout , 0 , 3000 );
#6
05/08/2009 (2:55 pm)
your "%intruder.setTransform()" line is being executed when you call schedule, and the return value from setTransform (which is empty) ends up being the command which gets scheduled. try replacing that schedule with this one:%intruder.schedule(5000, "setTransform", "143 -430 34 0 0 1 0");
#7
05/08/2009 (11:16 pm)
Orion that worked great! Thanks a lot guys, you're life savers :)
#8
However, I only want him to be teleported when an AI player enters the same room. So how would you program it so once the player has entered the trigger area, it waits until the AI player enters also to be teleported?
Thanks for any help!
05/11/2009 (11:30 am)
Ok, one more question about this guys. I'm trying to make it so there can be multiple intruders in the same space, but only the Player is the one who is teleported to another room, not the AI players.However, I only want him to be teleported when an AI player enters the same room. So how would you program it so once the player has entered the trigger area, it waits until the AI player enters also to be teleported?
Thanks for any help!
#9
but it doesn't seem to work.
05/11/2009 (11:32 am)
Basically what I need to know is how to specify WHAT intruder to teleport. I've tried doing:%intruder.Player.schedule(5000, "setTransform", "143 -430 34 0 0 1 0");
but it doesn't seem to work.
#10
05/11/2009 (11:40 am)
Try something like:if (%intruder.getClassName() $= "Player")
{
%intruder.setTransform(142 -430 0);
}
#11
you have a trigger area T and you want it so that if there is a real player and an AIPlayer in the trigger then the player is teleported somewhere else ?
a diagram might help.
the approach i would probably take would be to use the getNumObjects() and getObject() methods of triggers. these let you walk through the list of what's in the trigger. so you could do something like
05/11/2009 (11:41 am)
let me repeat the Q to make sure i understand.you have a trigger area T and you want it so that if there is a real player and an AIPlayer in the trigger then the player is teleported somewhere else ?
a diagram might help.
the approach i would probably take would be to use the getNumObjects() and getObject() methods of triggers. these let you walk through the list of what's in the trigger. so you could do something like
// run this code whenever anyone enters the trigger.
// note that getNumObjects() and getObject() are methods of the trigger, not the trigger datablock.
// first walk through and see if there are any AIPlayers in the trigger
%hasAIPlayer = false;
for (%n = %theTrigger.getNumObjects() - 1; %n >= 0 && !%hasAIPlayer; %n--)
{
%obj = %theTrigger.getObject(%n);
%hasAIPlayer |= (%obj.getClassName() $= "AIPlayer");
}
if (!%hasAIPlayer)
{
return;
}
// then walk through and teleport any real players
for (%n = %theTrigger.getNumObjects() - 1; %n >= 0 && !%hasAIPlayer; %n--)
{
%obj = %theTrigger.getObject(%n);
if (%obj.getClassName $= "Player")
{
// teleport the object. eg %obj.setTransform()
}
}
#12
05/11/2009 (11:47 am)
woops, edited previous post. forgot to early-out if there are no AIPlayers.
#13
05/11/2009 (1:34 pm)
So I've implemented your code into my function, but it doesn't seem to do anything. None of the effects are triggered, here's what I've got:function RestrictedRoom::onEnterTrigger(%this, %trigger, %obj)
{
for (%n = %trigger.getNumObjects() - 1; %n >= 0 && !%hasAIPlayer; %n--)
{
%obj = %trigger.getObject(%n);
%hasAIPlayer |= (%obj.getClassName() $= "AIPlayer");
}
if (!%hasAIPlayer)
{
return;
}
// then walk through and teleport any real players
for (%n = %trigger.getNumObjects() - 1; %n >= 0 && !%hasAIPlayer; %n--)
{
%obj = %trigger.getObject(%n);
if (%obj.getClassName $= "Player")
{
serverConnection.setBlackout( 1 , 3000 );
%obj.schedule(3000, "setTransform", "143 -430 34 0 0 1 0");
serverConnection.schedule( 4000, setBlackout , 0 , 3000 );
}
}
}
#14
are you sure you understand what the code sample is intended to do ?
does that match what want to happen ?
try putting some debug prints in there to make sure stuff is happening how you expect.
eg echo("RestrictedRoom::onEnterTrigger() -" SPC %this SPC %trigger SPC %object);
put an echo inside the various loops printing out each object in the trigger, etc.
05/11/2009 (1:37 pm)
well, this is what being a programmer is all about.are you sure you understand what the code sample is intended to do ?
does that match what want to happen ?
try putting some debug prints in there to make sure stuff is happening how you expect.
eg echo("RestrictedRoom::onEnterTrigger() -" SPC %this SPC %trigger SPC %object);
put an echo inside the various loops printing out each object in the trigger, etc.
Chris