代码都是从官方的hero_demo中提取出来,只不过是用ts翻译了下

Modifier:

import {BaseModifier, registerModifier} from "../lib/dota_ts_adapter";

@registerModifier()
export class modifier_invincible extends BaseModifier
{
    DeclareFunctions(): modifierfunction[]
    {
        const funcs = [
            modifierfunction.MODIFIER_PROPERTY_ABSOLUTE_NO_DAMAGE_MAGICAL,
            modifierfunction.MODIFIER_PROPERTY_ABSOLUTE_NO_DAMAGE_PHYSICAL,
            modifierfunction.MODIFIER_PROPERTY_ABSOLUTE_NO_DAMAGE_PURE,
        ]

        return funcs
    }

    GetAbsoluteNoDamageMagical(event: ModifierAttackEvent): 0 | 1
    {
        return 1;
    }

    GetAbsoluteNoDamagePure(event: ModifierAttackEvent): 0 | 1
    {
        return 1;
    }

    GetAbsoluteNoDamagePhysical(event: ModifierAttackEvent): 0 | 1
    {
        return 1;
    }
}

因为这个Modifier没有地方引用,直接添加没用哈,需要在addon_game_mode或使用之前require, require("modifiers/modifier_invincible");

然后开关无敌

CustomGameEventManager.RegisterListener("DebugCommand_Invincible", userId => 
        {
            const hero = PlayerResource.GetSelectedHeroEntity(userId - 1 as PlayerID);

            const units = hero.GetAdditionalOwnedUnits();

            units.push(hero);
            
            if (hero.HasModifier("modifier_invincible"))
            {
                for (let unit of units)
                {
                    unit.RemoveModifierByName("modifier_invincible")
                }
            }
            else 
            {
                for (let unit of units)
                {
                    unit.AddNewModifier(hero,undefined, "modifier_invincible", undefined)
                }
            }
        })