Dota 2 Workshop Tools/Scripting/API/Global.LinkLuaModifier
January 2024
Contents
Function Description
Chiness :
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)
--If the modifier is located within the root vscript folder
-- call LinkLuaModifier("modifier_evo_buff", LUA_MODIFIER_MOTION_NONE)
声明完就可以为单位添加一个这个Modifier了
--entity为单位句柄
--技能为空
--Modifier名称(上面注册的那个)
--其他参数列表(这里添加了一个永久持续的Modifier)
entity:AddNewModifier(entity, nil, "modifier_evo_buff", { duration = -1})
English (google translation from chiness)
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, Modifier then the second argument (file_path) may be omitted a link with lua script has been defined (class class). If Modifier script in the root directory, and the second parameter (file path) may be omitted 'Example: We are now going to create a Buff, called modifier_evo_buff used to direct units plus a Buff, we established a new file modifier_evo_buff.lua on the hero folder, file contents'
--The class name, the file name is consistent with
modifier_evo_buff = class ({})
--when a modifier created when the Modifier is created
function modifier_evo_buff:OnCreated (table)
--NOTE:These functions will be performed while the server and client, so please judge (usually a key operation on the server, only the prompts on the client!)
if not IsServer () then
return
end
--set interval of think sets the timer interval
self:StartIntervalThink (1)
end
--think callback timer callback function
function modifier_evo_buff:OnIntervalThink ()
if not IsServer () then
return
end
print ( "modifier_evo_buff:OnIntervalThink")
end
--return modifier's texture name returns the Buff icon resource name (here with Abaddon first skill icon)
function modifier_evo_buff:GetTexture ()
return "abaddon_death_coil"
end
--return modifier's effect name carries the Buff effect
function modifier_evo_buff:GetEffectName ()
return "particles / generic_gameplay / generic_stunned.vpcf"
end
--effect attached position the Buff effect attachment position
function modifier_evo_buff:GetEffectAttachType ()
return PATTACH_OVERHEAD_FOLLOW
end
--the others, see API:CDOTA_Modifier_Lua other replication functions refer to the API: CDOTA_Modifier_Lua
Before calling the next, the statement links (load) this Modifier
--1 Modifier parameter name (in the localized resource texts, to move is this, this is also used to add Modifier)
--Location parameter 2 Modifier of lua files are located
--Type of control parameters 3 Modifier
LinkLuaModifier ( "modifier_evo_buff", "hero / modifier_evo_buff", LUA_MODIFIER_MOTION_NONE)
--If The modifier is located within the root vscript folder
-- Call LinkLuaModifier ( "modifier_evo_buff", LUA_MODIFIER_MOTION_NONE)
End statement that can add a unit of the Modifier
--entity units handle
--Skills is empty
--Modifier Name (registered above that)
--Other parameter list (here we add a permanent ongoing 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) |