self.health bug?

Discuss programming in the QuakeC language.
Post Reply
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

self.health bug?

Post by drm_wayne »

hey guys,

I found a small bug in my mod..
I noticed that when you have exactly 0 health you are kinda "half-dead"...
You still can shoot weapons and fire impulses..
After that i tested it with a base 1.06 qc too, same result..
Is there a way to avoid this?

Code: Select all

	if (self.impulse == 203)
		self.health = 0;
I used this impulse to test it, and im always "half-dead" :/
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: self.health bug?

Post by frag.machine »

drm_wayne wrote:hey guys,

I found a small bug in my mod..
I noticed that when you have exactly 0 health you are kinda "half-dead"...
You still can shoot weapons and fire impulses..
After that i tested it with a base 1.06 qc too, same result..
Is there a way to avoid this?

Code: Select all

	if (self.impulse == 203)
		self.health = 0;
I used this impulse to test it, and im always "half-dead" :/
The problem here is you're setting health directly, and this is a big no-no, because the QC code checks some entity flags besides the health to determine if the player is dead. Try using T_Damage(self, self, self.health+1) instead (pretty sure this isn't the correct call to the function, can't check it right now).

BTW, there's already a "kill" command to suicide that you can easily bind to a key, so no need to reinvent the wheel. :)
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: self.health bug?

Post by drm_wayne »

i just added the impulse for testing, i noticed when i get killed by an enemy and have self.health 0 i am "half-dead"...
i can still shoot weapons, kill command doesnt work (says im already dead)...
this is kinda annoying..
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: self.health bug?

Post by Spike »

the client sees rounded values. any health less than 1 is thus considered dead by the client.
the qc code goes off other fields instead of just health.

it is thus good practise to detect death by < 1, to set it to 0 if its > 0, and to update the .deadflag field at the same time.
you cannot trivially just set health = 0, if only because that won't do the right player animations etc.
Post Reply