Jump to content

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

 

 

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...