Shield Generator
by Lucus · in Technical Issues · 07/01/2008 (11:13 pm) · 6 replies
Hello all,
I am trying to regenerate my health/shield bar after 10 seconds of taking damage. My first thought was to make a schedule function. The schedule did not work as the shield generates right after I take damage.
I wrote the schedule function as so
Lucus
I am trying to regenerate my health/shield bar after 10 seconds of taking damage. My first thought was to make a schedule function. The schedule did not work as the shield generates right after I take damage.
I wrote the schedule function as so
schedule(1000,0,%obj.setRepairRate(%this.repairRate);
Lucus
About the author
#2
I assume you're going for the Halo and Call of Duty auto regenerate of health after not taking damage for a length of time. :P
07/01/2008 (11:50 pm)
Yeah as Brian has said you used a timer length value of 1000 milliseconds which is equal to 1 second. So, you want 10000 milliseconds for 10 seconds. Also, you might want to have a variable that equals the return value from schedule() function which is the timer ID so that when your player gets hit again with in that ten seconds it can cancel out that timer and schedule it again.I assume you're going for the Halo and Call of Duty auto regenerate of health after not taking damage for a length of time. :P
#4
Another thing however is that would have to save the Scheduled Obj everytime, and when you get hit the old schedule is deleted and a new one is created.
Not sure where you are doing this exactly, but my guess is in onDamage or Damage. So in there you would have to cancel the old Schedule and Save the new Schedule... something like this:
My point is just... Remember to cancel the previous Schedule.
07/02/2008 (3:12 am)
They are correct with the amount of milliseconds. Another thing however is that would have to save the Scheduled Obj everytime, and when you get hit the old schedule is deleted and a new one is created.
Not sure where you are doing this exactly, but my guess is in onDamage or Damage. So in there you would have to cancel the old Schedule and Save the new Schedule... something like this:
%obj.ShieldScheduler.cancel(); %obj.ShieldScheduler = %obj.schedule(10000 , setRepairRate , %this.repairRate);
My point is just... Remember to cancel the previous Schedule.
#5
Nathan:
I am going for the Halo auto regenerate concept.
James:
I am doing this in the Player.cs in the Armor::damage function.
It works now on the first schedule but like you said James I need to cancel it and call a new schedule. After I get hit a second time it doesn't wait the 10 seconds. I tried placing the schedule before and after the call and I cant get it to work.
Do you have any suggestion on were to put the cancel function?
Thanks for all your help
Lucus
07/02/2008 (9:19 am)
Thanks everyone for replying.Nathan:
I am going for the Halo auto regenerate concept.
James:
I am doing this in the Player.cs in the Armor::damage function.
It works now on the first schedule but like you said James I need to cancel it and call a new schedule. After I get hit a second time it doesn't wait the 10 seconds. I tried placing the schedule before and after the call and I cant get it to work.
Do you have any suggestion on were to put the cancel function?
Thanks for all your help
Lucus
#6
The issue was not with the cancel function. I had to reset the repair rate to 0.
this is the code I am using. Thanks for all your help.
07/02/2008 (11:08 am)
Never mind I fixed the problem.The issue was not with the cancel function. I had to reset the repair rate to 0.
this is the code I am using. Thanks for all your help.
%this.repairRate = 0;
%obj.setRepairRate(%this.repairRate);
if (%obj.isbot == false)
{
%this.repairRate = 0.33;
cancel(%obj.shieldScheduler);
%obj.ShieldScheduler = %obj.schedule(10000 , setRepairRate , %this.repairRate);
}
Torque Owner Brian Wilson
When you say the shield generates "right after I take damage", do you mean when you take damage, or 1 second after. If it's 1 second after, then the schedule is right on time.