Jump to content

How to make a character immune to projectiles?


Recommended Posts

I want to make a character that can immune to any damages from projectile like blow darts.
I tried to investigate at the onHit trigger but I can't relate it to the component "projectiles".
Also, how can I make a character immune to lightning damage? (i know how to make it immune from fire only so far, but not lightning)
The in game code about projectile (attached) is here but I don't know how to combine it with getting hit component
Thanks!

projectile.lua

Link to comment
Share on other sites

local function isRangedWeapon(weapon)
  		return weapon ~= nil and (
			weapon.components.projectile ~= nil or
			weapon.components.complexprojectile ~= nil or
			weapon.components.weapon:CanRangedAttack()
                    			)
	end

local GetAttacked_old = inst.components.combat.GetAttacked
	function inst.components.combat:GetAttacked(attacker, damage, weapon, stimuli, ...)
  		if isRangedWeapon(weapon) then
    		self.lastwasattackedtime = GetTime()
    			return false --false means damage was blocked
  		end
  		return GetAttacked_old(self, attacker, damage, weapon, stimuli, ...)
	end

Done
Maybe useful to beginner modders with same question

Edited by Aurorance
  • Like 3
Link to comment
Share on other sites

On 5/16/2021 at 1:33 PM, Aurorance said:

ocal function isRangedWeapon(weapon) return weapon ~= nil and ( weapon.components.projectile ~= nil or weapon.components.complexprojectile ~= nil or weapon.components.weapon:CanRangedAttack() ) end local GetAttacked_old = inst.components.combat.GetAttacked function inst.components.combat:GetAttacked(attacker, damage, weapon, stimuli, ...) if isRangedWeapon(weapon) then self.lastwasattackedtime = GetTime() return false --false means damage was blocked end return GetAttacked_old(self, attacker, damage, weapon, stimuli, ...) end

Hello! 
How can I implant your code into a custom character? I would appreciate it if you could give me an answer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...