Kill Triggers
by Josiah Trumpower · in Torque Game Engine Advanced · 11/05/2009 (6:37 pm) · 8 replies
I am trying to make a trigger kill the player but it is not working. Can someone please shed some light as to why? and if you have working code for it could you please share? Here is my current code that doesn't work. I only have a thousand health so this is overkill but still it should work i think.
datablock TriggerData(killPlayer)
{
tickPeriodMS = 500;
damage = 5000;
};
function killPlayer::onEnterTrigger(%this, %data, %obj, %colObj)
{
%checkname = %obj.getName();
%client = %colObj.client;
if (%colObj.client)
%colObj.applydamage(%this.damage);
if(!%client)
{
echo("not a client!");
return;
}
}
datablock TriggerData(killPlayer)
{
tickPeriodMS = 500;
damage = 5000;
};
function killPlayer::onEnterTrigger(%this, %data, %obj, %colObj)
{
%checkname = %obj.getName();
%client = %colObj.client;
if (%colObj.client)
%colObj.applydamage(%this.damage);
if(!%client)
{
echo("not a client!");
return;
}
}
About the author
#2
11/05/2009 (10:06 pm)
%colObl works fine when trying to play a sound on trigger enter. It also works fine when trying to do level transitions but not to kill the player for some odd reason. I can't seem to make the trigger work.
#3
11/05/2009 (10:10 pm)
Here's how I get the player in a trigger - try this and see if it worksdatablock TriggerData(mytrigger)
{
tickPeriodMS = 500;
};
function mytrigger::onEnterTrigger(%this,%trigger,%obj)
{
%checkclass = %obj.getclassname();
if(%checkclass $= "player")
{
echo("Player in Trigger");
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this,%trigger,%obj);
}
#4
11/05/2009 (10:38 pm)
Thanks! that works completely perfect. How come yours works but my code doesn't? Is their an error in my code? Or was it the way i was referencing the client?
#5
11/05/2009 (10:44 pm)
I think it was client referencing which was the problem - I didn't see anyway for the trigger to "get" the client.
#6
11/05/2009 (11:48 pm)
Oh ok, well thank you very much. And thank you for the fast replies
#7
11/19/2009 (4:32 pm)
Thanks Steve
#8
FWIW you should in fact be able to find the client given a Player object. That is assuming that the Player has a client. In the case of starter.fps, it looks as though the AIPlayers are not assigned a client. But for human players, the client can be found easily enough:
Looks like that didn't work in the OP's code because the argument list for onEnterTrigger was incorrect. onEnterTrigger has three arguments: the trigger datablock, the trigger instance, and the colliding object.
11/19/2009 (5:24 pm)
Quote:I didn't see anyway for the trigger to "get" the client.
FWIW you should in fact be able to find the client given a Player object. That is assuming that the Player has a client. In the case of starter.fps, it looks as though the AIPlayers are not assigned a client. But for human players, the client can be found easily enough:
function mytrigger::onEnterTrigger(%this,%trigger,%obj)
{
if (%obj.getType() & $TypeMasks::PlayerObjectType)
{
%client = %obj.client;
if (isObject(%client))
... etc
}
}This is because the client parameter of the player object is assigned when the (human's) player is created in GameConnection::spawnPlayer() in server/game.cc:// Create the player object
%player = new Player() {
dataBlock = PlayerBody;
client = %this; // <--
};So the GameConnection instance that was %this can later be referenced by the "client" parameter of the Player object instance it just created.Looks like that didn't work in the OP's code because the argument list for onEnterTrigger was incorrect. onEnterTrigger has three arguments: the trigger datablock, the trigger instance, and the colliding object.
Associate Steve Acaster
[YorkshireRifles.com]
%colObj.applydamage(%damage);
But you might need to pass that info to the onEnterTrigger((%this, %data, %obj, %colObj, %damage) to get it to fire correctly - or just put it in the onEnterTrigger() function.
There is also a built in kill(); function, which does pretty much the same thing and can be called on player/AI. %colObj.kill();
Actually does %colObj work? It's not stock trigger script and you'd need some extra code/function to utilize it.
Try echo("colObj is " @ %colObj.getshapename()); inside onEnterTrigger and see if it gives the text above your model/avatar's head - as long as it's got one obviously.