Game Development Community

HOW2 get FlyingVehicle Energy Replenish with Triggers

by ebee t · in Torque Game Engine · 04/29/2006 (12:18 am) · 8 replies

How can you get trigger *onTickTrigger* to replenish objects "WheeledflyingVehicle" health and energy over time?, I have played around with this but I can seem to get it to effect anything, all I know is the trigger event is working, just I cant understand how to add the effect the health/energy for triggers.
Thanks in Advance
----------------------------------------------------------------------------------------------------------------------------------------

function DefaultTrigger::onTickTrigger(%this,%trigger)
{

echo( "The Aircraft is recharging");

//%obj.setEnergyLevel(%this.MaxEnergy);

??what could go here to work??

Parent::onTickTrigger(%this,%trigger);
}

#1
04/29/2006 (12:51 am)
Here's an example of how it works in my game. I attached a trigger to a flying vehicle (a so called repair ship).

When a client enters the trigger I send him a command to show a repair icon in the gui (just a command to make a gui element visible):
function AIDropshipTriggerData::onEnterTrigger(%this,%trigger,%obj)
{
	//echo("\c2 -> onEnterTrigger");
	if (%trigger.ship != %obj)
	{
		if (isObject(%obj.client))
		{
			commandToClient(%obj.client, 'RepairIcon', 1); // switch the repair icon on at the client
		}
	}
	Parent::onEnterTrigger(%this,%trigger,%obj);
}

When the client leaves the trigger, the repair icon on the clients playgui gets again invisible.
function AIDropshipTriggerData::onLeaveTrigger(%this,%trigger,%obj)
{
	//echo("\c2 onLeaveTrigger");
	if (%trigger.ship != %obj)
	{
		if (isObject(%obj.client))
		{
			commandToClient(%obj.client, 'RepairIcon', 0); // switch the repair icon off at the client
		}
	}	
	Parent::onLeaveTrigger(%this,%trigger,%obj);
}

And now the magic repair over time function. The longer the client's player is staying in the trigger, the more it gets repaired. Note that ALL players get repaired that stay in the trigger.
function AIDropshipTriggerData::onTickTrigger(%this,%trigger)
{
	%numInRange = %trigger.getNumObjects();
	for (%i = 0; %i < %numInRange; %i++)
	{
		%obj = %trigger.getObject(%i);
		if (%trigger.ship != %obj) // don't heal ourself, only others.
		{
			// a ship other than our own entered the trigger
			// and wants to get some healing and ammo (ammo = later).
			 %obj.setDamageLevel(%obj.getDamageLevel() - %trigger.ship.repairRate);
		}
	}
   Parent::onTickTrigger(%this,%trigger);
}

I need to mention that %trigger.ship.repairRate is a value of how much to repair at a time and the value is stored as variable in the ship itself. You could substitue it by "0.7" for example.

Is that what you were looking for?

Martin
#2
04/29/2006 (1:59 am)
Yes Thank you thats more than I could have hoped for, excellent idea with the commandToClient.
I havent got to the health part as of yet, but it looks like you have saved me much time, I thank you again...

Mean while I have been just trying to get the energy replenish script worked out so far I have only this, but for some reason once the WheeledFlyingV leaves the area, it no longer, drains the Jet energy I had implimented previously... any ideas?? Thanks again.

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


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

function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{
echo( "The AIRCRAFT HAS ENTERED AIRPORT");
Parent::onEnterTrigger(%this,%trigger,%obj);
}

function DefaultTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
echo( "The aircraft has left the airport");
Parent::onLeaveTrigger(%this,%trigger,%obj);
for(%i = 0; %i < %trigger.getNumObjects();%i++)
{
%trigger.getObject(%i).setRechargeRate(0.05);

}
}

function DefaultTrigger::onTickTrigger(%this,%trigger,%obj)
{
Parent::onTickTrigger(%this,%trigger);
echo( "The AIRCRAFT IS STANDING BY");
for(%i = 0; %i < %trigger.getNumObjects();%i++)
{
//%trigger.getObject(%i).client.incScore(1);
%trigger.getObject(%i).setRechargeRate(1.0);
}
}
#3
04/29/2006 (2:15 am)
To give you some insight - I had better post some data here,

in my Aircraft.cs datablock I have,

// Turbo Jet
jetForce = 800;
minJetEnergy= 0.0;
jetEnergyDrain= 0.5;
RechargeRate= 0.0;
--------------------------------
In the - function WheeledFlyingVehicleData::create(%block) I have
//add energy to hud
%obj.setEnergyLevel(%this.MaxEnergy);
%obj.setRechargeRate(%this.rechargeRate);
%obj.setjetEnergyDrain(%this.jetEnergyDrain);
----------------------------------------------------------------------------------------
and I have edited WheeledFyingVehicl.cc to take energy from jetforceEnergy, also thottle to 0, when jetforceEnergy hits 0....
#4
04/29/2006 (3:03 am)
Hmm, it's hard to do remote debugging, but in your onLeaveTrigger(..) you still do a "setRechargeRate" call. Maybe you should there set the recharging to "0.0". Just a guess. I'm not pretty about this recharge thing as I don't use it very much.

On the other hand you could do the energy reloading in the same manner as I did for the health stuff. You could use the setEnergyLevel() method of the player object to do some step-by-step recharging.

Martin
#5
04/29/2006 (3:13 am)
Thanks Martin your input has been great. , I will mess with this some more, Your code works like a charm I have implimented this

function DefaultTrigger::onTickTrigger(%this,%trigger,%obj)
{
echo( "The Aircraft is re-fueling");

%numInRange = %trigger.getNumObjects();
for (%i = 0; %i < %numInRange; %i++) {
%obj = %trigger.getObject(%i);
if (%trigger.AirCraft != %obj)//
{
%obj.setRechargeRate(1.0);
}
}

Thankyou again.
Parent::onTickTrigger(%this,%trigger);
}
#6
04/29/2006 (4:04 am)
Glad to hear it works :-)

Martin
#7
05/09/2006 (3:55 am)
Great... I will be able to use this too :-D

Martin... Is there anywhere that I can get info, screens, etc on your project?
#8
05/09/2006 (4:24 am)
@Burning: Yes, but the screens are very old (except the newer TSE terrain test screenshots) and the game information is not up2date.

http://www.decane.net/subsonic

http://www.decane.net/component/option,com_zoom/Itemid,45/catid,1/

Well, while writing this I think I need to update my website... :-)
If you need more information, please drop me a mail.