Jump to content

Weapon lifesteal and lost health

Recommended Posts

Hi I just started to understand lua and I want to get some code advice.

I want to make a weapon that has a fixed lifesteal (5hp) but only for the owners of the tag, and for all the others there was a hp scar per hit (10hp).

I would be very grateful for any help!
(translated by Yandex Translator)

Link to comment
Share on other sites

hello in your weapon.lua file in the "fn" put following code


inst.components.weapon.onattack = onattack

then above "fn" put following code

local function onattack(inst, owner, target)
	if owner:HasTag("this is your character custom tag") then
		owner.components.health:DoDelta(-10) -- Your character with tag is not using weapon so deal DMG to them


Edited by --- -.-
  • Health 1
Link to comment
Share on other sites

4 hours ago, --- -.- said:

здравствуйте, В вашем файле weapon.lua в поле "fn" поставьте следующий код


inst.components.weapon.onattack = onattack

затем над "fn" поставьте следующий код

локальная функция onattack(inst, владелец, цель)
 если owner:HasTag("это пользовательский тег вашего персонажа"), то
владелец.компоненты.здоровье:DoDelta(-10) -- ваш персонаж с тегом не использует оружие, поэтому нанесите им DMG


Thank you very much!!!!!

  • GL Happy 1
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

  • Create New...