Jump to content

Weapon that heals enemies


Recommended Posts

Hello, 

I'm currently trying to mod a weapon that doesn't deal damage and heals with each hit the target.

THe no damage part is no problem, I just need help with the healing.

This is the section where i tried to add the healing, but when I'm trying it, nothing happens. 

local function onattack(target)
	if target.components.health then
		target.components.health:DoDelta(5)
	end
end

inst.components.weapon:SetOnAttack(onattack)

This my first try at modding, I tried searching for a solution, but didn't find anything.

Any help is welcome!
 

  • Like 1
Link to comment
Share on other sites

inst.components.weapon:SetOnAttack(onattack)

This code means when this weapon attacks, weapon will call function 'onattack(inst, attacker, target)'

This means you have to give value (inst, attacker, target) but you give only one value, so instead of target, the first value - inst(weapon itself) will go to function onattack,

local function onattack(target)
	if target.components.health then
		target.components.health:DoDelta(5)
	end
end

So this code, will be

local function onattack('your weapon')
	if 'your weapon'.components.health then
		'your weapon'.target.components.health:DoDelta(5)
		--your weapon has no health components for sure so it will do nothing
	end
end

this one, of course you'll not want.

To edit code, just add more value:

local function onattack(inst, attacker, target)
	if target.components.health then
		target.components.health:DoDelta(5)
	end
end

This should work without problem.

Edited by Combustiblemon
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...