|
发表于 2011-6-26 19:34:49
|
显示全部楼层
多谢希瓦大人,偶地图用了老狼的那个显示伤害系统,代码如下,把你的放在后边会有隐患的不
// === 公用函数,如果你的地图中已有该函数则可以删除
function h2i takes handle h returns integer
return h
return 0
endfunction
function i2tg takes integer i returns trigger
return i
return null
endfunction
function i2tc takes integer i returns triggercondition
return i
return null
endfunction
// === 伤害显示主函数
function ShowDamage_Func takes nothing returns boolean
local texttag tt
if IsUnitType(GetEventDamageSource(),UNIT_TYPE_HERO) and GetEventDamage() > 0 then
set tt = CreateTextTag()
if udg_DamShowOn[GetPlayerId(GetLocalPlayer())] then
call SetTextTagText(tt, I2S(R2I(GetEventDamage())), 0.03) //字体大小
call SetTextTagPos(tt, GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),50) //显示位置
call SetTextTagColor(tt, 255, 0, 0, 0) //字体颜色
call SetTextTagVelocity(tt, 0, TextTagSpeed2Velocity(200)) //移动速度(x,y)
call SetTextTagFadepoint(tt, 0.1) //消逝点(0.1秒开始消逝效果)
endif
call SetTextTagPermanent(tt, false)
call SetTextTagLifespan(tt, 3) //漂浮文字生命期
endif
set tt = null
return false
endfunction
function ShowDamage takes unit u, boolean showOn returns nothing
local trigger t
local triggercondition c
local integer i
if showOn then
if not HaveStoredInteger(udg_GC,I2S(h2i(u)),"DamShowTrigger") then
set t = CreateTrigger()
set c = TriggerAddCondition(t, Condition(function ShowDamage_Func))
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_DAMAGED)
call StoreInteger(udg_GC,I2S(h2i(u)),"DamShowTrigger",h2i(t))
call StoreInteger(udg_GC,I2S(h2i(t)),"TriggerCondition",h2i(c))
endif
if udg_DamShow_alwaysOn then
if HaveStoredInteger(udg_GC,I2S(h2i(u)),"DamShowNum") then
set i = GetStoredInteger(udg_GC,I2S(h2i(u)),"DamShowNum")
call FlushStoredInteger(udg_GC,I2S(h2i(u)),"DamShowNum")
set udg_DamShow_GroupCount = udg_DamShow_GroupCount-1
set udg_DamShow_GroupUnit = udg_DamShow_GroupUnit[udg_DamShow_GroupCount]
call StoreInteger(udg_GC,I2S(h2i(udg_DamShow_GroupUnit)),"DamShowNum",i)
endif
set udg_DamShow_alwaysOn = false
else
if not HaveStoredInteger(udg_GC,I2S(h2i(u)),"DamShowNum") then
set udg_DamShow_GroupUnit[udg_DamShow_GroupCount] = u
call StoreInteger(udg_GC,I2S(h2i(u)),"DamShowNum",udg_DamShow_GroupCount)
set udg_DamShow_GroupCount = udg_DamShow_GroupCount+1
endif
endif
else
set t = i2tg(GetStoredInteger(udg_GC,I2S(h2i(u)),"DamShowTrigger"))
set c = i2tc(GetStoredInteger(udg_GC,I2S(h2i(t)),"TriggerCondition"))
set i = GetStoredInteger(udg_GC,I2S(h2i(u)),"DamShowNum")
set udg_DamShow_GroupCount = udg_DamShow_GroupCount-1
set udg_DamShow_GroupUnit = udg_DamShow_GroupUnit[udg_DamShow_GroupCount]
call StoreInteger(udg_GC,I2S(h2i(udg_DamShow_GroupUnit)),"DamShowNum",i)
call FlushStoredInteger(udg_GC,I2S(h2i(u)),"DamShowNum")
call FlushStoredInteger(udg_GC,I2S(h2i(u)),"DamShowTrigger")
call FlushStoredMission(udg_GC,I2S(h2i(t)))
call TriggerRemoveCondition(t,c)
call DestroyTrigger(t)
endif
set t = null
set c = null
endfunction
function DamShow_TimerFunc takes nothing returns nothing
local integer i=0
loop
exitwhen i >= udg_DamShow_GroupCount
if GetUnitState(udg_DamShow_GroupUnit, UNIT_STATE_MAX_LIFE) <= 0 then
call ShowDamage(udg_DamShow_GroupUnit, false)
endif
set i=i+1
endloop
endfunction
function InitDamShow takes nothing returns nothing
call TimerStart(CreateTimer(),60.0,true,function DamShow_TimerFunc)
endfunction
// === 为方便触发环境下使用而添加的2个函数
function ShowDamageOn takes nothing returns nothing
call ShowDamage(udg_DamShow_Unit,true)
endfunction
function ShowDamageOff takes nothing returns nothing
call ShowDamage(udg_DamShow_Unit,false)
endfunction |
|