Jump to content

Recommended Posts

Kind of late, but in order to do that you have to modify a lot of stuff. I tried setting the players stun value to be STUNNABLE.NEVER but I got inconsistent results, so I overwrote the attacked event instead. Not sure what you need this for but it's probably easy to modify since it only depends on a tag.

Spoiler
local _G = GLOBAL
local statetag = "invulnerable" -- In case it needs to be changed later

local function OverlayDisable(self, owner) 
	local Flash_old = self.Flash
	self.Flash = function(self, ...)
		if owner:HasTag(statetag) then return end -- No red pulses
		Flash_old(self, ...)
	end
end
AddClassPostConstruct("widgets/bloodover", OverlayDisable)

AddStategraphPostInit("wilson", function(sg) -- No AddStategraphPostInitAny, so I'm not sure how to make any inst unstunnable?
	if not sg.events.attacked.fn then return end
	local attacked_old = sg.events.attacked.fn
	sg.events.attacked.fn = function(inst, data)
		if inst:HasTag(statetag) then return end -- No stun
		attacked_old(inst, data)
	end
end)

local function invulnerableOn(inst)
	if not inst:HasTag(statetag) then
		print(inst, "invuln on")
		inst:AddTag(statetag)
		inst.components.health.externalabsorbmodifiers = _G.SourceModifierList(inst, 1, _G.SourceModifierList.additive) -- No damage delta
	else
		print(inst, "invuln already on")
	end
end

local function invulnerableOff(inst)
	if inst:HasTag(statetag) then
		print(inst, "invuln off")
		inst:RemoveTag(statetag)
		inst.components.health.externalabsorbmodifiers = _G.SourceModifierList(inst, -1, _G.SourceModifierList.additive)
	else
		print(inst, "invuln already off")
	end
end

local function c_invulnerable(toggle, inst)
	local inst = inst or _G.ConsoleCommandPlayer() or _G.ThePlayer
	if type(toggle) == "boolean" then
		if toggle then
			invulnerableOn(inst)
		else
			invulnerableOff(inst)
		end
	elseif inst:HasTag(statetag) then
		invulnerableOff(inst)
	else
		invulnerableOn(inst)
	end
end
GLOBAL.c_invulnerable = c_invulnerable

 

 

Edited by oregu

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
×
  • Create New...