Jump to content
Einlander

Fpsplayer.lua TakeDamage() and Hurt() treat death differently

Recommended Posts

I was updating a pain trigger and noticed that in the fpsplayer.lua file that the functions:

Script:Hurt(damage,distributorOfPain)
and
Script:TakeDamage(damage)
 

 

Script:Hurt will lower your health and when dead initiate the death sequence by calling Script:Kill(), BUT it will NOT set the players self.alive to false, call Script:OnHit() or Script:OnDead()

 

Script:TakeDamage will lower your health, set your self.alive to false, call the self:OnHit() and self:OnDead() outputs but will not start the death sequence by calling Script:Kill()

 

Fixed functions:

 

function Script:Hurt(damage,distributorOfPain)
	if self.health>0 then
		self.sound.damage[math.random(#self.sound.damage)]:Play()
		self.health = self.health - damage
		self.hurtoffset = Vec3(math.random(-1,1),math.random(-1,1),0):Normalize()*30
		local blood = {}
		local n=1
		blood.texture=self.image.blood[math.random(1,4)]
		blood.intensity=1
		table.insert(self.bloodoverlay,blood)
		if self.bloodindex>4 then self.bloodindex=1 end
		self:OnHit()
		if self.health<=0 then
			self.alive = false
			self:Kill()
			self:OnDead()
		end
	end
end



function Script:TakeDamage(damage)
	-- Decrease health
	self.health = self.health - damage;
	-- Call OnHit output
	self:OnHit()
	-- If health lower or equal to zero, the player is dead
	if self.health <= 0 then
		self.alive = false
		-- Call the OnDead output
		self:OnDead()
		self:Kill()
	end
end

 

 

Share this post


Link to post

thanks, got into some trouble with that when I tried to make my character hurt to death when he has no oxygen or hunger left.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...