|
发表于 2009-7-21 07:14:44
|
显示全部楼层
帮LZ把代码贴上:
[jass]//***************************************************************************
//* Damage Show System Functions *
//* Edit by feelerly *
//* 2008.02.20 *
//* Welcome to visit us and discuss with in http://bbs.wow8.org *
//***************************************************************************
// 这些功能是支持伤害显示系统的一些其他函数,可以删除.但为了完整,建议保留这些函数.
// 本套函数基于前一次发布的显示系统, 现在已经完美了,设置附加伤害方面也人性化了.
// ---->> 最完美的伤害显示系统,无泄漏,绿色环保,随心所欲设置伤害!
// ---->> 为什么是完美的呢?因为可以实现单位受伤害时,任意加成或减少伤害,由于引入了"伤害加成因素"这个概念
// 使得加成伤害变量随心所欲,便于控制.那什么是伤害加成因素呢?就是伤害来源所拥有的一个条件,现在只
// 添加了单位,物品,单位组,玩家,玩家组,地区,区域六个因素,也就是说,伤害来源拥有以上六个因素之一,就可以对
// 目标单位造成伤害加成,反之则不加成.如果开启伤害显示时,没有设置伤害加成因素,那么会默认为受到任何
// 伤害都会对目标进行伤害加成触发.加成伤害有两种运算方式: 加法运算和乘法运算.0为加法,1为乘法.将负
// 数带入运算会加成伤害的值小于0,这时会自动调整为目标减少伤害,当然,这个也要因素满足条件才行.
// 目前,这个系统应该是最完美的伤害显示系统了,经过偶的排泄处理,在地图中对于游戏不会有什么影响.而且
// 还可以随意添加和修改脚本中的一些数据以达到想要的各种伤害效果.
// 建议: 使用ReturnBugSystem数据转换函数做为支撑函数,这套系统需要ReturnBugSystem数据转换函数的支持
//===========================================================================
// 数据转换系统功能函数
//===========================================================================
// ==========>> 数据转换系统 <<==========
function CacheValue takes nothing returns gamecache
// CacheValue 缓存函数,这个函数是用来设置储存的缓存文件的.一般不需要更改
// 如果你想使用自定义函数,可以用bj_lastCreatedGameCache来设定缓存.系统会自
// 动识别的(要在初始化地图时就设置,不然会出错的.)
if bj_lastCreatedGameCache == null then
call FlushGameCache( bj_lastCreatedGameCache )
set bj_lastCreatedGameCache = InitGameCache( "ReturnBugSystem.w3v")
endif
return bj_lastCreatedGameCache
endfunction
constant function ConvertHandleInt takes handle h returns integer
return h // 将句柄值转换为整数值
return 0 // return 0 实际是不会运行的,做为欺骗Jass语法检查用的
endfunction
constant function ConvertHandle takes integer i returns handle
return i // 将整数值转换为句柄值.转换单位玩家之类的同理.
return null
endfunction
constant function ConvertUnit takes integer i returns unit
return i
return null
endfunction
constant function ConvertItem takes integer i returns item
return i
return null
endfunction
constant function ConvertForce takes integer i returns force
return i
return null
endfunction
constant function ConvertGroup takes integer i returns group
return i
return null
endfunction
constant function ConvertPlayer takes integer i returns player
return i
return null
endfunction
constant function ConvertRect takes integer i returns rect
return i
return null
endfunction
constant function ConvertRegion takes integer i returns region
return i
return null
endfunction
constant function ConvertTrigger takes integer i returns trigger
return i
return null
endfunction
constant function ConvertAction takes integer i returns triggeraction
return i
return null
endfunction
function HandleName takes handle h returns string
return I2S( ConvertHandleInt( h ) )
endfunction
function Debug takes string s returns nothing
local integer a = 0
loop
call DisplayTimedTextToPlayer( Player(a), 0, 0, 60.00, s )
set a = a + 1
exitwhen a == 11
endloop
set a = 0
endfunction
//===========================================================================
// Convert Data end
//===========================================================================
function RandomColor takes string s returns string
// 随机文字颜色处理,创造多彩文字,让游戏显得更有个性!
local string hex = "0123456789abcdef"
local string color = null
local string id = null
local integer a = 0
local integer b = 0
loop
set b = GetRandomInt(1,16)
set id = SubString( hex, b - 1, b )
set color = color + id
set a = a + 1
exitwhen a == 6
endloop
set id = null
return "|cff" + color + s + "|r"
endfunction
// ---->判断handle值的类型!有的时候可以起来防止数据混乱的情况.
// !完美无泄漏. 一般判断handle的用户类型是没有必要的,但可以做为判断一些数据的依据.
// 这个也是以上所以伤害加成因素判断的函数,因些不能删除.
function IsHandleUnit takes integer i returns boolean
local unit u = ConvertUnit( i )
local boolean b = false
if GetUnitState( u, UNIT_STATE_LIFE ) > 0.00 then
set b = true
endif
set u = null
return b
endfunction
function IsHandleItem takes integer i returns boolean
local item it = ConvertItem( i )
local integer ud = GetItemUserData( it )
local boolean b = false
call SetItemUserData( it, ud + 1 )
if GetItemUserData( it ) > 0 then
set b = true
endif
call SetItemUserData( it, ud )
set it = null
return b
endfunction
function IsHandleGroup takes integer i returns boolean
local group g = ConvertGroup( i )
local unit u = CreateUnit( Player(12), 'ewsp', 0, 0, 0 )
local boolean b = false
call GroupAddUnit( g, u )
if IsUnitInGroup( u, g ) == true then
set b = true
endif
call GroupRemoveUnit( g, u )
call RemoveUnit( u )
set g = null
set u = null
return b
endfunction
function IsHandlePlayer takes integer i returns boolean
local player p = ConvertPlayer( i )
local boolean b = false
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then
set b = true
endif
set p = null
return b
endfunction
function IsHandleForce takes integer i returns boolean
local force f = ConvertForce( i )
local boolean b = false
if IsPlayerInForce( Player(12), f ) == false then
call ForceAddPlayer( f, Player(12) )
endif
if IsPlayerInForce( Player(12), f ) == true then
set b = true
endif
set f = null
return b
endfunction
function IsHandleRect takes integer i returns boolean
local rect r = ConvertRect( i )
local real rx = GetRandomReal( GetRectMinX(r), GetRectMaxX(r) )
local real ry = GetRandomReal( GetRectMinY(r), GetRectMaxY(r) )
local boolean b = false
if rx != 0.00 and ry != 0.00 then
if GetRectMinX(r) < rx and GetRectMaxX(r) > rx and GetRectMinY(r) < ry and GetRectMaxY(r) > ry then
set b = true
endif
endif
set r = null
return b
endfunction
function IsHandleRegion takes integer i returns boolean
local region r = ConvertRegion( i )
local boolean b = false
call RegionAddCell( r, 0, 0 )
if IsPointInRegion( r, 0, 0) then
set b = true
endif
set r = null
return b
endfunction
// ----> 判断伤害来源是否满足伤害目标所提供的伤害加成因素,如果满足则进行伤害加成.
function AddSourceIsExist takes unit u, unit s returns boolean
// 检查附加伤害因素是否存在, 目前可以支持单位,物品,单位组,玩家,势力,地区,区域
// 单位就是伤害源为指定的单位, 单位组是指伤害源在指定单位组中, 玩家是指伤害源属于某个指定玩家
// 而势力是指伤害源所属玩家组, 地区是指伤害源在某个地区内, 区域与地区的效果相同.
// 物品是指伤害来源是否拥有这个物品.
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local integer h = 0
local boolean b = false
local string name = I2S( ConvertHandleInt(u) )
if HaveStoredInteger(CacheValue(), name, "NoSource") then
set b = true
elseif HaveStoredInteger(CacheValue(), name, "AddUnitSource" ) then
set b = true
elseif HaveStoredInteger(CacheValue(), name, "AddItemSource" ) then
if UnitHasItem( s, ConvertItem(GetStoredInteger(CacheValue(), name, "AddItemSource" )) ) then
set b = true
endif
elseif HaveStoredInteger(CacheValue(), name, "AddGroupSource" ) then
if IsUnitInGroup( s, ConvertGroup(GetStoredInteger(CacheValue(), name, "AddGroupSource" )) ) then
set b = true
endif
elseif HaveStoredInteger(CacheValue(), name, "AddPlayerSource" ) then
if GetOwningPlayer( s ) == ConvertPlayer(GetStoredInteger(CacheValue(), name, "AddPlayerSource" )) then
set b = true
endif
elseif HaveStoredInteger(CacheValue(), name, "AddForceSource" ) then
if IsPlayerInForce( GetOwningPlayer( s ), ConvertForce(GetStoredInteger(CacheValue(), name, "AddForceSource" ))) then
set b = true
endif
elseif HaveStoredInteger(CacheValue(), name, "AddRectSource" ) then
set h = GetStoredInteger(CacheValue(), name, "AddRectSource" )
if RectContainsCoords( ConvertRect(h), x, y ) then
set b = true
endif
elseif HaveStoredInteger(CacheValue(), name, "AddRegionSource" ) then
set h = GetStoredInteger(CacheValue(), name, "AddRegionSource" )
if IsPointInRegion( ConvertRegion(h), x, y ) then
set b = true
endif
endif
return b
endfunction
// - -||| 一个附加效果, 可以改变伤害来源的生命值, 做为测试来用, 建议在添加时禁用这个功能.
function AddLifeValueOfSource takes real life returns nothing
// 改变伤害来源生命,以实现传说中的"吸血伤害"或者"反弹伤害"效果.
local effect e = null
if life > 0.00 and GetUnitState( GetEventDamageSource() ,UNIT_STATE_LIFE ) > 0.00 and GetTriggerUnit() != GetEventDamageSource() then
if GetUnitState( GetEventDamageSource() ,UNIT_STATE_LIFE ) - life <= 0.00 then
set life = GetUnitState( GetEventDamageSource() ,UNIT_STATE_LIFE ) - 2.00
endif
set e = AddSpecialEffectTarget("Abilities\\\\Spells\\\\Undead\\\\VampiricAura\\\\VampiricAuraTarget.mdl", GetEventDamageSource(), "origin")
elseif life == 0.00 and GetUnitState( GetEventDamageSource() ,UNIT_STATE_LIFE ) > 0.00 and GetTriggerUnit() != GetEventDamageSource() then
set e = AddSpecialEffectTarget("Abilities\\\\Spells\\\\Human\\\\Slow\\\\SlowCaster.mdl", GetEventDamageSource(), "origin")
elseif life < 0.00 and GetUnitState( GetEventDamageSource() ,UNIT_STATE_LIFE ) > 0.00 and GetTriggerUnit() != GetEventDamageSource() then
set e = AddSpecialEffectTarget("Abilities\\\\Weapons\\\\FlyingMachine\\\\FlyingMachineImpact.mdl", GetEventDamageSource(), "chest")
endif
call DestroyEffect( e )
call SetUnitState( GetEventDamageSource(), UNIT_STATE_LIFE, GetUnitState( GetEventDamageSource() ,UNIT_STATE_LIFE ) + life )
set e = null
endfunction
// - -||| END!
// ----> 单位受伤害时,显示所受的伤害值 <----
function ShowDamageForUnitActions takes nothing returns nothing
local texttag tt = CreateTextTag()
local unit u = GetTriggerUnit()
local unit s = GetEventDamageSource()
local integer mtd = GetStoredInteger( CacheValue(), I2S(ConvertHandleInt(u)), "AddMethod" )
local real admg = GetStoredReal( CacheValue(), I2S(ConvertHandleInt(u)), "AddDamage" )
local real dmg = GetEventDamage()
local real life = 0.00
local string text = null
//call Debug( "伤害计算: "+R2S(dmg) + " || " + R2S(admg) + " ? " + I2S(mtd))
if dmg <= 0.00 then
call DestroyTextTag( tt )
else
// 如果单位所受伤害大于单位当前生命,即单位被秒杀,则不进行伤害的加成判断.
if dmg >= GetUnitState( u ,UNIT_STATE_LIFE ) then
set dmg = GetUnitState( u ,UNIT_STATE_LIFE )
else
// ----> 实际所受伤害值
set life = GetUnitState( u ,UNIT_STATE_LIFE )
if AddSourceIsExist( u, s ) then
if mtd == 0 then // 0 为加减运算
// 根据运算方式, 来决定单位最终所受附加伤害.
set dmg = admg
elseif mtd == 1 then // 1 为乘法运算
set dmg = dmg*admg - dmg
//if admg < 1 and admg >= 0.00 then
// 乘法运算时, 0 - 1 之间的加成按照(事件伤害*加成伤害) 来计算
//endif
endif
//call Debug( "伤害加成: " + R2S(GetEventDamage()) + " || " + R2S(dmg) )
// ----> 修正所受伤害值, dmg 为负则减伤, 为正则加伤
// 算法上可能有一些出入,但实际单位所伤害的应该是符合计算结果的.
if dmg > 0.00 then
if GetUnitState( u ,UNIT_STATE_LIFE ) - dmg <= 0.00 then
call SetUnitState( u, UNIT_STATE_LIFE, 1.00 )
else
call SetUnitState( u, UNIT_STATE_LIFE, GetUnitState( u ,UNIT_STATE_LIFE ) - dmg )
endif
elseif dmg < 0.00 then
if GetUnitState( u ,UNIT_STATE_LIFE ) - dmg >= life + GetEventDamage() then
call SetUnitState( u, UNIT_STATE_LIFE, life + GetEventDamage() )
else
call SetUnitState( u, UNIT_STATE_LIFE, GetUnitState( u ,UNIT_STATE_LIFE ) + (-dmg) )
endif
endif
set life = life - GetUnitState( u ,UNIT_STATE_LIFE )
//call Debug( "所受加成: " + R2S(GetEventDamage()) + " || " + R2S(life) )
endif
set dmg = GetEventDamage() + life
//call Debug( "最终伤害: " + R2S(GetEventDamage()) + " || " + R2S(life) )
// ----> 选择附加的效果,这些效果可以自己定义, 因此不在参数中设置了,可以用条件来设置是否执行附加的效果.
// ----> 如果没有条件限制, 则是直接执行附加效果.不过如果要加附加的效果,必须在这个位置以下添加.
call AddLifeValueOfSource( (dmg * 0.50) ) // 改变伤害来源的生命值.带入负数则是减少生命.
// ----> 附加效果自己可以创建的, 比如反弹魔法, 或者是其他的触发.
// ----> 所显示计算后的伤害值
if dmg <= 0.04999 then
set text = RandomColor("Miss!")
else
set text = RandomColor("-" + R2SW(dmg,-1,1) )
endif
endif
// -> 以下是漂浮文字的设定,颜色是随机的,自己可以添加颜色.
call SetTextTagText( tt, text, TextTagSize2Height(11) )
call SetTextTagPos( tt, GetUnitX(u),GetUnitY(u), 16+GetUnitFlyHeight(u) )
call SetTextTagColor( tt, 255, 255, 255, 157 )
call SetTextTagVelocityBJ( tt, GetRandomReal(100,161.8), GetRandomReal(60,120) )
call SetTextTagPermanent( tt, false )
call SetTextTagLifespan( tt, 1.618 )
call SetTextTagFadepoint( tt, 0.618 )
endif
set dmg = 0.00
set tt = null
set s = null
set u = null
endfunction
function ResetAddSource takes unit u returns nothing
// 清理附加伤害因素, 在重新选定伤害因素时, 必须清空以前所注入的数据.
local string name = I2S(ConvertHandleInt(u))
call FlushStoredInteger( CacheValue(), name, "NoSource" )
call FlushStoredInteger( CacheValue(), name, "AddUnitSource" )
call FlushStoredInteger( CacheValue(), name, "AddItemSource" )
call FlushStoredInteger( CacheValue(), name, "AddGroupSource" )
call FlushStoredInteger( CacheValue(), name, "AddForceSource" )
call FlushStoredInteger( CacheValue(), name, "AddPlayerSource" )
call FlushStoredInteger( CacheValue(), name, "AddRectSource" )
call FlushStoredInteger( CacheValue(), name, "AddRegionSource" )
endfunction
function ShowDamageForUnit takes unit u, boolean b, real admg, integer method, handle h returns nothing
// -> 如果 b 等于 true 时,则认为单位开启了伤害显示与伤害加成,b 为 false 时,则认为是关闭了伤害显示与伤害加成.
local string name = I2S(ConvertHandleInt(u))
local trigger trig = null
local triggeraction ta = null
local boolean flag = GetStoredBoolean( CacheValue(), I2S(ConvertHandleInt(u)), "HasShowedDamage" )
if b == true then
if flag == false and GetStoredInteger( CacheValue(), name, "UnitDamageTrigger" ) == 0 then
set trig = CreateTrigger() // 如果单位没有开启过伤害显示, 则创建相关的触发, 开启单位的伤害显示.
call TriggerRegisterUnitEvent( trig, u, EVENT_UNIT_DAMAGED )
set ta = TriggerAddAction( trig, function ShowDamageForUnitActions )
call StoreInteger( CacheValue(), name, "UnitDamageTrigger", ConvertHandleInt(trig) )
call StoreInteger( CacheValue(), I2S(ConvertHandleInt(trig)), "TriggerAction", ConvertHandleInt(ta) )
elseif flag == true then // 如果开启的伤害显示被关闭,则打开.
set trig = ConvertTrigger( GetStoredInteger( CacheValue(), name, "UnitDamageTrigger" ) )
if IsTriggerEnabled( trig ) == false then
call EnableTrigger( trig )
endif
endif
call ExecuteFunc( "TriggerCheckUnitDamageShow" ) // 运行触发检查单位是否死亡,如果死亡则清除相关伤害显示
call ResetAddSource( u ) // 清空以前设置的附加伤害来源
call StoreInteger( CacheValue(), name, "AddMethod", method ) // 附加伤害的计算方法
call StoreReal( CacheValue(), name, "AddDamage", admg ) // 所附加的伤害
// ----> 设置附加伤害因素,在单位受到伤害时,会检查所注入的数据.以此来判断一个单位接受的伤害加成.
if ConvertHandleInt(h) <= 0 then // 如果没有设置因素,则默认为因素不存在,所有对该单位造成的伤害都会进行加成.
call StoreInteger( CacheValue(), name, "NoSource", ConvertHandleInt(h) )
elseif IsHandleUnit(ConvertHandleInt(h)) then // 设置单位因素,只有这个指定单位对该单位伤害时具有伤害加成效果
call StoreInteger( CacheValue(), name, "AddUnitSource", ConvertHandleInt(h) )
elseif IsHandleItem(ConvertHandleInt(h)) then // 设置物品因素,只有持有指定物品的单位对该单位伤害时具有伤害加成效果
call StoreInteger( CacheValue(), name, "AddItemSource", ConvertHandleInt(h) )
elseif IsHandleGroup(ConvertHandleInt(h)) then // 设置单位组因素, 只有这个单位组中的单位对该单位造成伤害时有加成效果
call StoreInteger( CacheValue(), name, "AddGroupSource", ConvertHandleInt(h) )
elseif IsHandlePlayer(ConvertHandleInt(h)) then // 设置玩家因素
call StoreInteger( CacheValue(), name, "AddPlayerSource", ConvertHandleInt(h) )
elseif IsHandleForce(ConvertHandleInt(h)) then // 设置玩家组(势力)因素
call StoreInteger( CacheValue(), name, "AddForceSource", ConvertHandleInt(h) )
elseif IsHandleRect( ConvertHandleInt(h) ) then // 设置地区因素
call StoreInteger( CacheValue(), name, "AddRectSource", ConvertHandleInt(h) )
elseif IsHandleRegion( ConvertHandleInt(h) ) then // 设置区域因素
call StoreInteger( CacheValue(), name, "AddRetionSource", ConvertHandleInt(h) )
endif
elseif flag == true then
set trig = ConvertTrigger( GetStoredInteger( CacheValue(), name, "UnitDamageTrigger" ) )
call DisableTrigger( trig )
endif
call StoreBoolean( CacheValue(), I2S(ConvertHandleInt(u)), "HasShowedDamage", b )
set trig = null
set ta = null
endfunction
// ----> END <----
// ----> 触发检查单位伤害显示状态 <----
function TriggerCheckUnitDamageShowActions takes nothing returns nothing
// 触发检查单位伤害显示状态,如果单位死亡则清除单位的伤害显示.
local string name = I2S(ConvertHandleInt(GetTriggerUnit()))
local trigger trig = null
local triggeraction ta = null
if GetStoredBoolean( CacheValue(), name, "HasShowedDamage" ) == true then
call FlushStoredBoolean( CacheValue(), name, "HasShowedDamage" )
call ResetAddSource( GetTriggerUnit() )
set trig = ConvertTrigger( GetStoredInteger( CacheValue(), name, "UnitDamageTrigger" ) )
set ta = ConvertAction( GetStoredInteger( CacheValue(), I2S(ConvertHandleInt(trig)), "TriggerAction" ) )
call FlushStoredInteger( CacheValue(), name, "UnitDamageTrigger" )
call FlushStoredReal( CacheValue(), name, "AddDamage" )
call TriggerRemoveAction( trig, ta )
call FlushStoredMission( CacheValue(), I2S(ConvertHandleInt(trig)) )
call DestroyTrigger( trig )
endif
set trig = null
set ta = null
endfunction
function TriggerCheckUnitDamageShow takes nothing returns nothing
// 触发检查单位伤害显示的设置状态,如果单位死亡,则清除单位的伤害显示内容,包括英雄在内.
// ----> 这个检查针对所有玩家的包括中立的玩家.这个不能被关闭,一旦关闭了,很可能造成数据泄漏.
local boolexpr f = null
local trigger trig = null
local triggeraction ta = null
local integer i = 0
if GetStoredBoolean( CacheValue(), "Maps", "CheckDamageEnable" ) == false then
set trig = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent( trig, Player(i), EVENT_PLAYER_UNIT_DEATH, f )
set i = i + 1
exitwhen i == 14
endloop
set ta = TriggerAddAction( trig, function TriggerCheckUnitDamageShowActions )
call StoreInteger( CacheValue(), "Maps", "DamageShowCheck", ConvertHandleInt(trig) )
call StoreInteger( CacheValue(), I2S(ConvertHandleInt(trig)), "TriggerAction", ConvertHandleInt(ta) )
call StoreBoolean( CacheValue(), "Maps", "CheckDamageEnable", true )
endif
call DestroyBoolExpr( f )
set trig = null
set ta = null
set f = null
endfunction
// ----> END <----
// ----> 计时检查地图上所有单位伤害显示状态 <----
function ShowDamageForPlayerUnitActionsFunc takes unit u returns nothing
local string pname = I2S(ConvertHandleInt(GetOwningPlayer(u)))
local string uname = I2S(ConvertHandleInt(u))
local integer method = GetStoredInteger( CacheValue(), pname, "AddMethod" )
local integer source = GetStoredInteger( CacheValue(), pname, "AddSource" )
local real admg = GetStoredReal( CacheValue(), pname, "AddDamage" )
if GetStoredBoolean( CacheValue(), pname, "HasShowedDamage" ) == true then
if GetStoredBoolean( CacheValue(), uname, "HasShowedDamage" ) == false then
call ShowDamageForUnit( u, true, admg, method, ConvertHandle(source) )
endif
endif
set source = 0
set pname = null
set uname = null
set u = null
endfunction
function ShowDamageForPlayerUnitGroupActions takes nothing returns nothing
// 检查单位受到攻击或者计时器到期时运行这个函数,以便于自动给单位添加伤害显示.
if GetStoredBoolean( CacheValue(), I2S(ConvertHandleInt(GetEnumUnit())), "HasShowedDamage" ) == false then
call ShowDamageForPlayerUnitActionsFunc( GetEnumUnit() )
endif
endfunction
function ShowDamageForPlayerUnitActions takes nothing returns nothing
// 检查单位受到攻击或者计时器到期时运行这个函数,以便于自动给单位添加伤害显示.
if GetStoredBoolean( CacheValue(), I2S(ConvertHandleInt(GetTriggerUnit())), "HasShowedDamage" ) == false then
call ShowDamageForPlayerUnitActionsFunc( GetTriggerUnit() )
endif
endfunction
function TimerCheckShowDamageForPlayerActions takes nothing returns nothing
local boolexpr b = null
local group g = CreateGroup() // 选取地图上的所有单位进行检查,一次最高可以选择255个单位.
call GroupEnumUnitsInRectCounted( g, GetWorldBounds(), b, 255 )
call DestroyBoolExpr( b )
call ForGroup( g, function ShowDamageForPlayerUnitGroupActions )
call DestroyGroup( g )
set g = null
set b = null
endfunction
function TimerCheckShowDamageForPlayer takes nothing returns nothing
local timer t = null // 运行计时器检查玩家伤害显示状态.
if GetStoredBoolean( CacheValue(), "Maps", "PlayerCheckDamage" ) == false then
set t = CreateTimer()
call TimerStart( t, 1.00, true, function TimerCheckShowDamageForPlayerActions )
call StoreBoolean( CacheValue(), "Maps", "PlayerCheckDamage", true )
endif
set t = null
endfunction
// ----> END <----
// ----> 为玩家的所有单位开启伤害显示 <----
function ShowDamageForPlayerUnit takes player p, boolean b, real admg, integer method, handle h returns nothing
// -> 开启/关闭玩家单位伤害显示.
local boolexpr f = null
local string name = I2S(ConvertHandleInt(p))
local trigger dmg_trig = null
local triggeraction dmg_ta = null
local boolean flag = GetStoredBoolean( CacheValue(), name, "HasShowedDamage" )
if b == true then
if flag == false and GetStoredInteger( CacheValue(), name, "PlayerDamageTrigger" ) == 0 then
set dmg_trig = CreateTrigger()
call TriggerRegisterPlayerUnitEvent( dmg_trig, p, EVENT_PLAYER_UNIT_ATTACKED, f )
set dmg_ta = TriggerAddAction( dmg_trig, function ShowDamageForPlayerUnitActions )
call StoreInteger( CacheValue(), name, "PlayerDamageTrigger", ConvertHandleInt(dmg_trig) )
call StoreInteger( CacheValue(), I2S(ConvertHandleInt(dmg_trig)), "TriggerAction", ConvertHandleInt(dmg_ta) )
else
set dmg_trig = ConvertTrigger( GetStoredInteger( CacheValue(), name, "PlayerDamageTrigger" ) )
if dmg_trig !=null and IsTriggerEnabled( dmg_trig) == false then
call EnableTrigger( dmg_trig )
endif
endif
// ---->> 开启:用计时器检查玩家单位伤害显示状态,建议使用.在一般情况下.当单位受到攻击时会自动添加伤害显示!
call ExecuteFunc( "TimerCheckShowDamageForPlayer" )
// ---->> 设置伤害加成数据, 伤害加成因素必须为句柄值.null为无因素.
call StoreInteger( CacheValue(), name, "AddMethod", method ) // 附加伤害的计算方法
call StoreInteger( CacheValue(), name, "AddSource", ConvertHandleInt(h) ) // 附加伤害的因素
call StoreReal( CacheValue(), name, "AddDamage", admg ) // 所附加的伤害
elseif flag == true then
set dmg_trig = ConvertTrigger( GetStoredInteger( CacheValue(), name, "PlayerDamageTrigger" ) )
call DisableTrigger( dmg_trig )
endif
call DestroyBoolExpr( f )
call StoreBoolean( CacheValue(), name, "HasShowedDamage", b )
set dmg_trig = null
set f = null
set dmg_ta = null
endfunction
// ----> ALL END <----
[/jass] |
|