Regeneration trigger
by Very Interactive Person · in Torque Game Engine · 06/30/2003 (6:02 am) · 11 replies
I made this trigger:
What does it do?: It regerates the player health on entering the trigger.
What do I want it to do?: Regenerating the player health as long as he is in the trigger.
This may sound easy to make... but for me figuring this out was already quit a task. Altough I have played with the scripts before, I only started scripting seriously yesterday and there's so much I don't understand yet. So, can someone please help me and tell me what I should change and add to make it execute the code that is in onEnterTrigger every second until the player leaves the trigger?
datablock TriggerData(Regeneration)
{
tickPeriodMS = 100;
};
function Regeneration::onEnterTrigger( %this, %trigger, %obj )
{
if (%obj.getDamageLevel() != 0 && %obj.getState() !$= "Dead" ) {
%obj.applyRepair(10);
serverPlay3D(regen,%obj.getTransform());
if (%obj.client)
messageClient(%obj.client, 'MsgRegenerating', '\c2Regenerating');
}
}
datablock AudioProfile(regen)
{
filename = "~/data/sound/regenerate.wav";
description = "AudioClose3d";
preload = false;
};What does it do?: It regerates the player health on entering the trigger.
What do I want it to do?: Regenerating the player health as long as he is in the trigger.
This may sound easy to make... but for me figuring this out was already quit a task. Altough I have played with the scripts before, I only started scripting seriously yesterday and there's so much I don't understand yet. So, can someone please help me and tell me what I should change and add to make it execute the code that is in onEnterTrigger every second until the player leaves the trigger?
#2
06/30/2003 (6:14 am)
Yeh, I know that. And dumb as I am, I just tried to put the code in the tick function. Didn't do a thing ;)
#3
That's what you ment right? Just use the tick function. But this doesn't do anything ingame, only the enter trigger function works. I'm doing something wrong... I just don't know what ;)
06/30/2003 (6:32 am)
Here's what I did:function Regeneration::onTickTrigger(%this, %trigger, %obj){
if (%obj.getDamageLevel() != 0 && %obj.getState() !$= "Dead" ) {
%obj.applyRepair(10);
serverPlay3D(regen,%obj.getTransform());
if (%obj.client)
messageClient(%obj.client, 'MsgRegenerating', '\c2Regenerating');
}
}That's what you ment right? Just use the tick function. But this doesn't do anything ingame, only the enter trigger function works. I'm doing something wrong... I just don't know what ;)
#4
i hope the script can help u.
datablock TriggerData(HealTrigger)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
function HealTrigger::OnEnterTrigger(%this,%trigger,%obj) {
%checkname = %trigger.getName();
%client = %obj.client;
if(!%client)
{
echo("not a client!");
return;
}
%client.player.healpointing = 1;
CommandToClient(%client,'bottomprint',"\nHealing process activated...",5,2);
HealSched(%trigger,%client);
}
function HealSched(%trigger,%client) {
if (%client.player.getDamageLevel() > 0) {
%client.player.setDamageLevel(%client.player.getDamageLevel() - 0.2);
%client.player.healsched = schedule(50,0,"HealSched",%trigger,%client);
} else {
CommandToClient(%client,'bottomprint',"\nHealing Complete...",5,2);
%client.player.healpointing = 0;
}
}
function HealTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
%checkname = %trigger.getName();
%client = %obj.client;
if(!%client)
{
return;
}
if (%client.player.healpointing == 1) {
cancel(%client.player.healsched);
CommandToClient(%client,'bottomprint',"\nHealing stopped...",5,2);
%client.player.healpointing = 0;
} else
%client.player.healpointing = 0;
}
datablock ParticleData(HealpointBeam)
{
textureName = "~/data/shapes/particles/smoke";
dragCoeffiecient = 0.0;
gravityCoefficient = -0.2; // rises slowly
inheritedVelFactor = -1;
lifetimeMS = 2500;
lifetimeVarianceMS = 1;
useInvAlpha = false;
spinRandomMin = 0.0;
spinRandomMax = 0.0;
colors[0] = "1.0 0.0 0.0 0.5";
colors[1] = "1.0 0.0 0.0 0.5";
colors[2] = "1.0 0.0 0.0 1.0";
sizes[0] = 3.0;
sizes[1] = 3.0;
sizes[2] = 3.0;
times[0] = 0.5;
times[1] = 0.5;
times[2] = 1.0;
};
datablock ParticleEmitterData(HealpointEmitter)
{
ejectionPeriodMS = 50;
periodVarianceMS = 0;
ejectionVelocity = 0.0;
velocityVariance = 0.0;
thetaMin = 0.0;
thetaMax = 10.0;
particles = HealpointBeam;
};
datablock ParticleEmitterNodeData(HealpointEmitterNode)
{
timeMultiple = 1;
};
06/30/2003 (7:47 am)
Now, i dont know if i can help, but we are (german community) have made a "helthshower" trigger. the script works fine (have run a little server to play Multiplayer online)i hope the script can help u.
datablock TriggerData(HealTrigger)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
function HealTrigger::OnEnterTrigger(%this,%trigger,%obj) {
%checkname = %trigger.getName();
%client = %obj.client;
if(!%client)
{
echo("not a client!");
return;
}
%client.player.healpointing = 1;
CommandToClient(%client,'bottomprint',"\nHealing process activated...",5,2);
HealSched(%trigger,%client);
}
function HealSched(%trigger,%client) {
if (%client.player.getDamageLevel() > 0) {
%client.player.setDamageLevel(%client.player.getDamageLevel() - 0.2);
%client.player.healsched = schedule(50,0,"HealSched",%trigger,%client);
} else {
CommandToClient(%client,'bottomprint',"\nHealing Complete...",5,2);
%client.player.healpointing = 0;
}
}
function HealTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
%checkname = %trigger.getName();
%client = %obj.client;
if(!%client)
{
return;
}
if (%client.player.healpointing == 1) {
cancel(%client.player.healsched);
CommandToClient(%client,'bottomprint',"\nHealing stopped...",5,2);
%client.player.healpointing = 0;
} else
%client.player.healpointing = 0;
}
datablock ParticleData(HealpointBeam)
{
textureName = "~/data/shapes/particles/smoke";
dragCoeffiecient = 0.0;
gravityCoefficient = -0.2; // rises slowly
inheritedVelFactor = -1;
lifetimeMS = 2500;
lifetimeVarianceMS = 1;
useInvAlpha = false;
spinRandomMin = 0.0;
spinRandomMax = 0.0;
colors[0] = "1.0 0.0 0.0 0.5";
colors[1] = "1.0 0.0 0.0 0.5";
colors[2] = "1.0 0.0 0.0 1.0";
sizes[0] = 3.0;
sizes[1] = 3.0;
sizes[2] = 3.0;
times[0] = 0.5;
times[1] = 0.5;
times[2] = 1.0;
};
datablock ParticleEmitterData(HealpointEmitter)
{
ejectionPeriodMS = 50;
periodVarianceMS = 0;
ejectionVelocity = 0.0;
velocityVariance = 0.0;
thetaMin = 0.0;
thetaMax = 10.0;
particles = HealpointBeam;
};
datablock ParticleEmitterNodeData(HealpointEmitterNode)
{
timeMultiple = 1;
};
#5
I suppose you just placed the particle effect in the map on the position of the trigger? Wouldn't it be cool to only activitate the effect when someone is in the trigger (I know learn how to walk before you can run... so I'll implement that regenerator first... )
06/30/2003 (8:08 am)
As a matter of fact this is very helpfull.I suppose you just placed the particle effect in the map on the position of the trigger? Wouldn't it be cool to only activitate the effect when someone is in the trigger (I know learn how to walk before you can run... so I'll implement that regenerator first... )
#6
The trigger is a bit strange.
There are 3 trigger functions exposed to the console that can be used to tap into the trigger events, and 2 more that are pure script functions that are the final callbacks.
These two callback functions are odd, Tribes 2 did not have any examples where they were used, so your mileage may vary
06/30/2003 (10:00 am)
Try doing this instead:function Regeneration::onTickTrigger(%this, %obj)
{
if (%obj.getDamageLevel() != 0 && %obj.getState()!$= "Dead" )
{
%obj.applyRepair(10);
serverPlay3D(regen,%obj.getTransform());
if (%obj.client)
messageClient(%obj.client, MsgRegenerating, "\c2Regenerating");
}
}The trigger is a bit strange.
There are 3 trigger functions exposed to the console that can be used to tap into the trigger events, and 2 more that are pure script functions that are the final callbacks.
[TriggerData].onEnterTrigger(This, Trigger, ObjectId)
[TriggerData].onLeaveTrigger(This, Trigger, ObjectId)
[TriggerData].onTickTrigger(This, Object)These two callback functions are odd, Tribes 2 did not have any examples where they were used, so your mileage may vary
[TriggerData].onTrigger(%this, %arg)
[TriggerData].onTriggerTick(%this)
#7
I'm now using a mix between my code and what Micheal just posted. So thanks a lot, all of you!
06/30/2003 (10:29 am)
Saw your post too late ;) I already have it working, but thanks anyway. I'm now using a mix between my code and what Micheal just posted. So thanks a lot, all of you!
#8
And it's a lot cleaner... and that's what It was supposed to be for anyway.
@Labrat: So... the onTriggerTick always ticks no matter if an object is or isn't inside it? I'm guessing that since it has no object parameter. Weird names they chose for those 2 functions :)
06/30/2003 (2:39 pm)
I would recommend doing what LabRat posted, since that's what I meant :)And it's a lot cleaner... and that's what It was supposed to be for anyway.
@Labrat: So... the onTriggerTick always ticks no matter if an object is or isn't inside it? I'm guessing that since it has no object parameter. Weird names they chose for those 2 functions :)
#9
06/30/2003 (4:21 pm)
I'm not even sure if the onTriggerTick calls back to the TriggerData I'd have to run a trigger through debug to fund out.
#10
Anyway, I'm working on another trigger, and tried the ontick approach.... but it looks like I'm missing something here:
Why does this work:
If I put both functions in my trigger, then watch the console as I drive into it with a vehcile with the name "test" set in the datablock... I get to see "test" once in the console window,... then every half second a blank line is printed (so I assume in the onticktrigger the getdatablock().name results in NULL).
07/02/2003 (10:12 am)
I'll probably change it, I was just lazy after a day of scripting ;)Anyway, I'm working on another trigger, and tried the ontick approach.... but it looks like I'm missing something here:
Why does this work:
function TestTrigger::OnEnterTrigger(%this,%trigger,%obj){
echo(%obj.getDatablock().name);
}and this not:function TestTrigger::onTickTrigger(%this, %obj){
echo(%obj.getDatablock().name);
}If I put both functions in my trigger, then watch the console as I drive into it with a vehcile with the name "test" set in the datablock... I get to see "test" once in the console window,... then every half second a blank line is printed (so I assume in the onticktrigger the getdatablock().name results in NULL).
Torque 3D Owner Xavier "eXoDuS" Amado
Default Studio Name