Forum

self.health bug?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

self.health bug?

Postby drm_wayne » Tue Dec 31, 2013 8:12 am

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" :/
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: self.health bug?

Postby frag.machine » Tue Dec 31, 2013 11:26 am

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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Re: self.health bug?

Postby drm_wayne » Tue Dec 31, 2013 1:02 pm

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..
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: self.health bug?

Postby Spike » Tue Dec 31, 2013 1:41 pm

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.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest