Dota 2 Workshop Tools/Scripting/API/Global.LinkLuaModifier: Difference between revisions
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
''' void LinkLuaModifier(string ''modifier_name'', string ''file_path'', int ''motion_controller_type'') ''' | ''' 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文件夹下,文件内容 | 例:我们现在要创造一个Buff,名字叫modifier_evo_buff用来直接给单位加一个Buff,那么我们新建立了一个modifier_evo_buff.lua文件放在hero文件夹下,文件内容 | ||
<source lang="lua"> | <source lang="lua"> | ||
--类名,跟文件名一致 | --类名,跟文件名一致 | ||
modifier_evo_buff = class({}) | modifier_evo_buff = class({}) | ||
-- | --when a modifier created当Modifier被创建时 | ||
function modifier_evo_buff:OnCreated(table) | function modifier_evo_buff:OnCreated(table) | ||
--注意:这些函数是会被服务器和客户端同时执行,所以请判断(一般关键操作在服务器上,提示内容才在客户端上!) | --注意:这些函数是会被服务器和客户端同时执行,所以请判断(一般关键操作在服务器上,提示内容才在客户端上!) | ||
Line 19: | Line 19: | ||
return | return | ||
end | end | ||
--设置计时器间隔 | --set interval of think 设置计时器间隔 | ||
self:StartIntervalThink( 1 ) | self:StartIntervalThink( 1 ) | ||
end | end | ||
--计时器回调函数 | --think callback 计时器回调函数 | ||
function modifier_evo_buff:OnIntervalThink( ) | function modifier_evo_buff:OnIntervalThink( ) | ||
if not IsServer() then | if not IsServer() then | ||
Line 29: | Line 29: | ||
print("modifier_evo_buff:OnIntervalThink") | print("modifier_evo_buff:OnIntervalThink") | ||
end | end | ||
-- | --return modifier's texture name返回该Buff图标资源名(这里用亚巴顿的第一个技能图标) | ||
function modifier_evo_buff:GetTexture( ) | function modifier_evo_buff:GetTexture( ) | ||
return "abaddon_death_coil" | return "abaddon_death_coil" | ||
end | end | ||
--该Buff携带的效果 | --return modifier's effect name 该Buff携带的效果 | ||
function modifier_evo_buff:GetEffectName() | function modifier_evo_buff:GetEffectName() | ||
return "particles/generic_gameplay/generic_stunned.vpcf" | return "particles/generic_gameplay/generic_stunned.vpcf" | ||
end | end | ||
--该Buff效果依附的位置 | --effect attached position 该Buff效果依附的位置 | ||
function modifier_evo_buff:GetEffectAttachType() | function modifier_evo_buff:GetEffectAttachType() | ||
return PATTACH_OVERHEAD_FOLLOW | return PATTACH_OVERHEAD_FOLLOW | ||
end | end | ||
--其他的复写函数请参考 API:CDOTA_Modifier_Lua | --the others ,see API:CDOTA_Modifier_Lua 其他的复写函数请参考 API:CDOTA_Modifier_Lua | ||
</source> | </source> | ||
接下来在调用之前,声明链接(加载)这个Modifier | 接下来在调用之前,声明链接(加载)这个Modifier |
Revision as of 13:28, 7 November 2015

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) |