Dota 2 Workshop Tools/Scripting/API/Global.LinkLuaModifier

From Valve Developer Community
Jump to navigation Jump to search
Note.pngNote: This page is automatically generated. Any changes may be overwritten

Function Description

void LinkLuaModifier(string modifier_name, string file_path, int motion_controller_type)

Link a lua-defined modifier with the associated class. If the modifier is located within the root vscript folder, then the second argument (file_path) may be omitted链接一个已经用lua脚本定义的Modifier(类class)。如果这个Modifier脚本在根目录,第二个参数(文件路径)可以省略' 例:我们现在要创造一个Buff,名字叫modifier_evo_buff用来直接给单位加一个Buff,那么我们新建立了一个modifier_evo_buff.lua文件放在hero文件夹下,文件内容

--类名,跟文件名一致
modifier_evo_buff = class({})
--when a modifier created当Modifier被创建时
function modifier_evo_buff:OnCreated(table)
    --注意:这些函数是会被服务器和客户端同时执行,所以请判断(一般关键操作在服务器上,提示内容才在客户端上!)
    if not IsServer() then
        return
    end
   --set interval of think 设置计时器间隔
   self:StartIntervalThink( 1 )
end
--think callback 计时器回调函数
function modifier_evo_buff:OnIntervalThink(  ) 
    if not IsServer() then
        return
    end
    print("modifier_evo_buff:OnIntervalThink")
end
--return modifier's texture name返回该Buff图标资源名(这里用亚巴顿的第一个技能图标)
function modifier_evo_buff:GetTexture(  )
    return "abaddon_death_coil" 
end
--return modifier's effect name 该Buff携带的效果
function modifier_evo_buff:GetEffectName()
    return "particles/generic_gameplay/generic_stunned.vpcf"
end
--effect attached position 该Buff效果依附的位置
function modifier_evo_buff:GetEffectAttachType()
    return PATTACH_OVERHEAD_FOLLOW
end

--the others ,see API:CDOTA_Modifier_Lua 其他的复写函数请参考 API:CDOTA_Modifier_Lua

接下来在调用之前,声明链接(加载)这个Modifier

--参数1 Modifier名称(在本地化资源文本里,引动的就是这个,添加Modifier用的也是这个)
--参数2 Modifier的lua文件所在的位置
--参数3 Modifier控制类型
LinkLuaModifier("modifier_evo_buff","hero/modifier_evo_buff", LUA_MODIFIER_MOTION_NONE)

声明完就可以为单位添加一个这个Modifier了

--entity为单位句柄
--技能为空
--Modifier名称(上面注册的那个)
--其他参数列表(这里添加了一个永久持续的Modifier)
entity:AddNewModifier(entity, nil, "modifier_evo_buff", { duration = -1})

Parameters

Type Name Description
string modifier_name 注册Modifier所使用的名称
string file_path lua文件所处的位置
int motion_controller_type Modifier控制类型(一般为LUA_MODIFIER_MOTION_NONE)