Page 1 of 1
Self - Recharging
Posted: Wed Jul 08, 2009 8:47 pm
by metal_head
This requires Low level, so my idea is to make a script that recharges your health (in my case shield attribute) to full if the player's health attribute has stayed at one value for some time.
OK, so for this I'll need a variable that get's the value of the player's health attribute, let's call it
health_watch
so this variable has to get the health attribute:
Code: Select all
health_watch = GetAttribute("health","Player");
than the script has to check if the health has lowered
Code: Select all
if (GetAttribute("health", "Player") < health_watch)
{
}
...ok, that actually was stupid, the whole thing could be done with just
Code: Select all
if (GetAttribute("health", "Player") <100)
{
}
Than goes to another order, which would be something like this:
Code: Select all
ModifyAttribute("health", 1, "Player");
if (GetAttribute("health", "Player") >= health_watch)
{
}
And goes back to the begining, but how can I make a timer order,that will check if several seconds have passed since the last injury and check if the health has lowered (the one with the health and the lowering actually I did first, so I know how to do it, but how about a timer?). I want if the player recieves an injury during the delat befor the health/shield starts refilling, the timer to start again, but how to make the timer? Would Jay's timer thing be a good idea?
http://www.realityfactory.info/forum/vi ... fdf#p28715
Re: Self - Recharging
Posted: Wed Jul 08, 2009 9:34 pm
by Juutis
Would something like this be useful?
Code: Select all
if (GetAttribute("health", "Player") < health_watch)
{
DAMAGETIMER = self.time + DELAY;
}
health_watch = GetAttribute("health","Player");
if(DAMAGETIMER < self.time)
{
ModifyAttribute("health", 1, "Player");
//might wanna add something like DAMAGETIMER = self.time + 0.1;
//to make the attribute recharge at a certain rate. X per second.
}
Basically it's just a timer that resets each time you receive damage and starts healing you after a delay determined by the DELAY variable.
Re: Self - Recharging
Posted: Fri Jul 10, 2009 1:44 pm
by metal_head
Thanks, I'm on a holiday now so I don't have internet all the time, but looking at it, I think that it's just the thing I needed.
Amm, sorry to bother, but how does this work actually:
I see there are 2 variables, but I don't quite get the equation and the if statement for it after that, the equation is all summing and no subtracting, why in the if statement there is "<"
I see that the variable gets the value self.time + DELAY only if the if the condition in the if statement is met, but still I don't get that part

Re: Self - Recharging
Posted: Fri Jul 10, 2009 8:46 pm
by Juutis
The point is to use the self.time variable which counts how many seconds the script has been in low level.
An example:
Let's assume the value of our DELAY variable is 5 and say, 10 seconds have passed since the script went low level ( self.time = 10 ). Now, if the player gets damaged ( if(GetAttribute("health","Player") < health_watch) ) DAMAGETIMER gets set to self.time + DELAY (10 + 5 = 15). The recharging won't start immediately since obviously self.time (10) is less than DAMAGETIMER (15), but after the 5 second delay self.time will be greater than DAMAGETIMER and the ModifyAttribute() command kicks in. If the player is damaged during or after the 5 second delay, DAMAGETIMER will just reset and take another 5 seconds until starting the recharge.
Re: Self - Recharging
Posted: Sat Jul 11, 2009 4:22 pm
by metal_head
I understood how the script works while I was using the toilet

but since I'm on a holiday now and I don't have access to the internet all the time, I couldn't tell you that there's no need to explain it, thanks man that will do the job!
Re: Self - Recharging
Posted: Mon Jul 13, 2009 2:08 pm
by metal_head
Got a question about sound.
Here's the script:
Code: Select all
{
WATCH [100]
DAMAGETIMER [0]
DELAY [7]
Spawn[ ()
{
Console(true);
LowLevel("DoIt");
} ]
DoIt[ ()
{
self.ThinkTime = 0.0;
PositionToPlayer(0, 0, 0);
if (GetAttribute("armor", "Player") <100)
{
self.think = "Charge";
}
} ]
Charge[ ()
{
self.ThinkTime = 0.0;
if (GetAttribute("armor", "Player") < WATCH)
{
DAMAGETIMER = self.time + DELAY;
}
WATCH = GetAttribute("armor","Player");
if(DAMAGETIMER < self.time)
{
PlaySound("pickup/recharge.wav");
}
if(DAMAGETIMER < self.time)
{
self.ThinkTime = 0.05;
ModifyAttribute("armor", 1, "Player");
}
if (GetAttribute("armor", "Player") = 100)
{
self.think = "DoIt";
}
} ]
}
When the counter runs out, a sound is played:
Code: Select all
if(DAMAGETIMER < self.time)
{
PlaySound("pickup/recharge.wav");
}
The sound is long about 5 secs., but how can I make it stop when the shield is fully recharged? My script detects if the shield is fully recharged and get's the script back to where it startet if the shiled is = 100, I can also use this to put the command StopAllAoudioStreams(); but then the script will stop everything, not just the sound that is played by the script how can I stop the sound that is only played by this pawn?
Re: Self - Recharging
Posted: Mon Jul 13, 2009 6:18 pm
by Juutis
You could attach an AudioSource3D to the player (or if that's impossible, to a pawn that follows the player) and then turn the trigger for it on when you want the sound to be played:
Code: Select all
Charge[ ()
{
self.ThinkTime = 0.0;
if (GetAttribute("armor", "Player") < WATCH)
{
SetEventState("sound",false);
DAMAGETIMER = self.time + DELAY;
}
WATCH = GetAttribute("armor","Player");
if(DAMAGETIMER < self.time)
{
self.ThinkTime = 0.05;
ModifyAttribute("armor", 1, "Player");
SetEventState("sound",true);
}
if (GetAttribute("armor", "Player") = 100)
{
SetEventState("sound",false);
self.think = "DoIt";
}
} ]
Re: Self - Recharging
Posted: Mon Jul 13, 2009 8:09 pm
by metal_head
But if the trigger goes off, will the AudioSource3D entity continue to play?
Re: Self - Recharging
Posted: Mon Jul 13, 2009 8:14 pm
by Juutis
No. It will stop.
Re: Self - Recharging
Posted: Mon Jul 13, 2009 8:21 pm
by metal_head
Thanks, I'll try it.
