Game Development Community

Applying Damage

by Jonathan Paprocki · in Torque 3D Professional · 10/18/2009 (11:57 pm) · 5 replies

I have to make a basic trigger that echoes when the player has walked through the trigger, transform the player a few game world units and then apply 50 damage to the player. I have gotten the the trigger to echo and then transform the player but I can't seem to get it to apply the damage to them. Thanks in advance!!!

#1
10/19/2009 (12:06 am)
//Where the %obj is the player.
%obj.applyDamage(%damage);

Look in scripts/server for player.cs, there's the functions that the player usual uses there, also call a playerID/name.dump(); in-game to get a list of related functions to that object/class.
#2
10/19/2009 (12:54 am)
function MyTrigger::onEnterTrigger(%this,%trigger,%obj)
{
echo("MyTrigger FIRED by ID# ", %obj);

%objLocation = %obj.getTransform();
%loc_X = getword(%objLocation,0);
%loc_Y = getword(%objLocation,1);
%loc_Z = getword(%objLocation,2);
%loc_X += 10;
%obj.setTransform(%loc_X SPC %loc_Y SPC
%loc_Z SPC "0 0 1 0");

%obj.applyDamage(%damage);
}

now in the scripts/server/player.cs
would I just do %damage = 50; ?

#3
10/19/2009 (4:39 am)
Your onEnterTrigger() function doesn't have a value for %damage which results in 0 damage being applied.
#4
10/19/2009 (10:18 am)
As Michael points out, you've got to decalre how much damage you want.
Quote:
would I just do %damage = 50; ?
%damage = 50; is all you need, stick it in the trigger.

Here's a couple of useful examples, including making sure that this only happens to human players.

function MyTrigger::onEnterTrigger(%this,%trigger,%obj)
{
%checkclass = %obj.getclassname();
   if(%checkclass $= "player")
	{
        echo("MyTrigger FIRED by ID# ", %obj);

        %objLocation = %obj.getTransform();
        %loc_X = getword(%objLocation,0);
        %loc_Y = getword(%objLocation,1);
        %loc_Z = getword(%objLocation,2);
        %loc_X += 10;
        %obj.setTransform(%loc_X SPC %loc_Y SPC
        %loc_Z SPC "0 0 1 0");

        %damage = 50;

        %obj.applyDamage(%damage);

	}
	else
	{
//echo("NOT player in trigger");
	}
   Parent::onEnterTrigger(%this,%trigger,%obj);
}

Obviously if you're using some 3rd person RTS style situation, player class won't return anything valid because you'll have an AIplayer class object under control.
#5
10/19/2009 (10:54 am)
Thanks you guys, I wasn't sure if it was supposed to be set locally or globally in the player.cs, I thought it didn't work just didn't get the health to update correctly.