oikawa Posted March 24, 2021 Share Posted March 24, 2021 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 More sharing options...
. . . Posted March 25, 2021 Share Posted March 25, 2021 (edited) hello in your weapon.lua file in the "fn" put following code inst:AddComponent("weapon") inst.components.weapon:SetDamage(9999999999) 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(5) else owner.components.health:DoDelta(-10) -- Your character with tag is not using weapon so deal DMG to them end end Edited March 25, 2021 by --- -.- 1 Link to comment Share on other sites More sharing options...
oikawa Posted March 26, 2021 Author Share Posted March 26, 2021 4 hours ago, --- -.- said: здравствуйте, В вашем файле weapon.lua в поле "fn" поставьте следующий код inst:AddComponent("оружие") inst.components.weapon:SetDamage(9999999999) inst.components.weapon.onattack = onattack затем над "fn" поставьте следующий код локальная функция onattack(inst, владелец, цель) если owner:HasTag("это пользовательский тег вашего персонажа"), то owner.components.здоровье:Додельта(5) еще владелец.компоненты.здоровье:DoDelta(-10) -- ваш персонаж с тегом не использует оружие, поэтому нанесите им DMG end end Thank you very much!!!!! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now