Regenarating Armor?
Moderator: InsideQC Admins
23 posts
• Page 1 of 2 • 1, 2
Regenarating Armor?
I have somewhat of an idea on how to do this, but i need a little bit of help...
PlayerPreThink:
if(self.armorvalue < 100)
{
self.armorvalue = self.armorvalue+1;
}
else if(self.armorvalue = 100)
{
self.armorvalue = self.armorvalue+0;
}
I've been told that i need to create a float to store the old health value, and increase that value until it reaches the limit.
Which will work better?
PlayerPreThink:
if(self.armorvalue < 100)
{
self.armorvalue = self.armorvalue+1;
}
else if(self.armorvalue = 100)
{
self.armorvalue = self.armorvalue+0;
}
I've been told that i need to create a float to store the old health value, and increase that value until it reaches the limit.
Which will work better?
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Regenarating Armor?
DusterdooSmock wrote:I have somewhat of an idea on how to do this, but i need a little bit of help...
PlayerPreThink:
if(self.armorvalue < 100)
{
self.armorvalue = self.armorvalue+1;
}
else if(self.armorvalue = 100)
{
self.armorvalue = self.armorvalue+0;
}
I've been told that i need to create a float to store the old health value, and increase that value until it reaches the limit.
Which will work better?
If you're regenerating armor, you shouldn't mess with the health values. They are different things.
There are some problems with this solution:
a) players without any armor will "grow it up" magically, and this may not be what you desire, so you should check if the player has any armor first;
b) the "else" portion is useless and can be safely discarded (also, the syntax is wrong: "self.armorvalue = 100" means attribution, and what you should use here is "self.armorvalue == 100");
c) this will make the armor regenerate to the same value, regardless of the armor type, and again this may not be what you have in mind, so maybe you should check the armortype to determine the upper limit;
d) simply calling this code in PlayerPreThink () will make the armor regenerate at the same rate this function is called (usually, 20 times per second, translating to the same regen points/second). This is really fast, and may not be what you want. To solve this, I suggest you to add a float to the entity fields to store the last time you regenerated armor and test it before adding to the armor value.
But you are in the right direction, which is a good thing.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
This is something I coded simply for CTF once apon a time...
regen_time is a global variable that you have to create in defs.qc, it keeps track of when to update the regen, ie
.float regen_time
- Code: Select all
if ((self.regen_time < time)) //has enough time elapsed?
{
self.regen_time = time + 1; // update our regen to happen once per second.
//you could even change this to exponentially (time + (2 - self.armorvalue/200)), so it starts out slow then gets faster.
if (self.armortype) //do we have armor at all?
{
if ((self.armortype == 0.3) && (self.armorvalue < 100)) //yellow armor
{
self.armorvalue += 5;
if (self.armorvalue > 100) self.armorvalue = 100;
}
else
{
if ((self.armortype == 0.6) && (self.armorvalue < 150)) // green armor
{
self.armorvalue += 5;
if (self.armorvalue > 150) self.armorvalue = 150;
}
else
{
if ((self.armortype == 0.8) && (self.armorvalue < 200)) //red armor
{
self.armorvalue += 5;
if (self.armorvalue > 200) self.armorvalue = 200;
}
}
}
}
}
regen_time is a global variable that you have to create in defs.qc, it keeps track of when to update the regen, ie
.float regen_time
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
if it was global wouldnt it just be
- Code: Select all
float
- Code: Select all
.float
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
qc has 4 types of variables...
global fields
global values
local fields
local values
note that fields are values too. :s
note that local fields are not given space, so they can only be used as pointers (kinda like the find builtin).
But yeah, global or variable generally implies non-field, though fields can potentially be variables too, which is fun (see local fields).
PlayerPreThink is called per-player, so a global field (.float) is correct in this case.
If you were to use a single regen_time, only the first player would regen.
Alternatively you can use a global non-field (float) and place your regen logic in StartFrame, though I can't recommend doing so.
Or you can use the frametime global. mneh
global fields
global values
local fields
local values
note that fields are values too. :s
note that local fields are not given space, so they can only be used as pointers (kinda like the find builtin).
But yeah, global or variable generally implies non-field, though fields can potentially be variables too, which is fun (see local fields).
PlayerPreThink is called per-player, so a global field (.float) is correct in this case.
If you were to use a single regen_time, only the first player would regen.
Alternatively you can use a global non-field (float) and place your regen logic in StartFrame, though I can't recommend doing so.
Or you can use the frametime global. mneh
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
ceriux wrote:i think hes thinking similar to halo.
Yes exactly, in my mod im using elements from almost every big name first person shooter.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
DusterdooSmock wrote:ceriux wrote:i think hes thinking similar to halo.
Yes exactly, in my mod im using elements from almost every big name first person shooter.
Then you should skip completely Halo
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
frag.machine wrote:DusterdooSmock wrote:ceriux wrote:i think hes thinking similar to halo.
Yes exactly, in my mod im using elements from almost every big name first person shooter.
Then you should skip completely Halo
The only thing that i'm doing that's in halo is the regenerating armor.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
OK, sorry for the double-post, but how's this?
- Code: Select all
Bottom of "defs.qc":
.float regen_time
PutClientInServer in "client.qc":
self.armorvalue = 100;
PlayerPreThink in "client.qc":
if ((self.regen_time < time))
{
self.regen_time = time + 1;
if(self.armorvalue < 100)
{
self.armorvalue = self.armorvalue +1;
}
else if(self.armorvalue > 100)
{
self.armorvalue = 100;
}
}
Last edited by DusterdooSmock on Thu Sep 16, 2010 2:11 am, edited 1 time in total.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
You missed a "}" at the end, but looks like it should work to me.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
why regenerate armor instead of health? It would make sense in a game where armor protected 80-100% of damage, but in quake the percentages are rather low, so you end up losing a lot of health even when you do have armor.
So if you do this i recommend making armor absorb close to 100% of damage, and remove most health pickups from the game (maybe just restore health between missions or something.)
So if you do this i recommend making armor absorb close to 100% of damage, and remove most health pickups from the game (maybe just restore health between missions or something.)
- metlslime
- Posts: 316
- Joined: Tue Feb 05, 2008 11:03 pm
metlslime wrote:why regenerate armor instead of health?
<leileilol>
BECAUSE HALO HAS IT OMG WHAT A N00B U ARE!!!!ONE1!
</leileilol>
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
23 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest