Добавлен ArhiMEN,
опубликован
Алгоритмы, Наработки и Способности
Способ реализации:
vJass
Тип:
Наработка
Версия Warcraft:
1.26 (default)
Описание
Наработка позволяет создать плавающий текст, прикреплённый к юниту, который будет отображать время действия способности, каста и чего придёт в голову. Плавающий текст меняется в зависимости от оставшегося времени и меняет цвет от зелённого до красного.
Вызов
Временной
call CastingTime(unit, time)
Вызов функции создания плавающего текста, где unit - юнит, на которого крепится плавающий текст, time - время существования плавающего текста.
call CastingTimeRemove(unit)
Вызов функции уничтожения плавающего текста, где unit - юнит с которого снимается плавающий текст.
Числовой
Так же можно создать числовой показатель, который будет изменяться не от времени, а от самостоятельного изменения числа.
call Count(unit, count)
Вызов функции создания плавающего текста, где unit - юнит, на которого крепится плавающий текст, count - изначальное количество, хранимое в плавающем тексте.
Для изменения числа, используются две функции:
call AddCount(unit, count, "sign")
Функция для изменения числа, где unit - юнит, на котором закреплён нужный плавающий текст, count - число, на которое изменяем, sign - знак - или + (в зависимости от того, отнимаете вы или прибавляете).
call SetCount(unit, count)
Функция для установления числа, где unit - юнит, на котором закреплён нужный плавающий текст, count - число, на которое устанавливаем.
Кроме этого можно узнать максимальное и нынешнее количество
call GetCount(unit, "countstring")
Где unit - юнит, на котором закреплён нужный плавающий текст, countstring - одно из двух значений: max, now.
call CountRemove(unit)
Вызов функции уничтожения плавающего текста, где unit - юнит с которого снимается плавающий текст.
Код
library Duration
//Функции для отображения временного показателя
function CastingTimeRemove takes unit u returns nothing
local integer id = GetHandleId(u)
local timer Timer = LoadTimerHandle(udg_hash, id, StringHash("Timer"))
local texttag Texttag = LoadTextTagHandle(udg_hash, id, StringHash("CastingTimeTexxtag"))
local texttag Texttag2 = LoadTextTagHandle(udg_hash, id, StringHash("CastingTimeTexxtagBlack"))
call DestroyTimer(Timer)
call DestroyTextTag(Texttag)
call DestroyTextTag(Texttag2)
set Timer = null
set Texttag = null
set Texttag2 = null
endfunction
function RemoveTexttagTriggerCasting takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer id = GetHandleId(u)
local trigger t = LoadTriggerHandle(udg_hash, id, StringHash("Remove Texttag Casting"))
call DestroyTrigger(t)
call CastingTimeRemove(u)
set u = null
set t = null
endfunction
function CastingTimeString takes unit u, real ctn returns string
local integer id = GetHandleId(u)
local real CastingTimeStartCD = LoadReal(udg_hash, id, StringHash("CastingTimeStartCD"))
local integer StringLoop = 0
local string CastingTimeCDString = ""
local real CastingTimeStartCDNow
local real LoopCountR
local integer LoopCountI
set CastingTimeStartCDNow = CastingTimeStartCD - ctn
set LoopCountR = 100.0 * CastingTimeStartCDNow / CastingTimeStartCD
set LoopCountI = R2I(LoopCountR) / 10
loop
exitwhen StringLoop > LoopCountI
set CastingTimeCDString = CastingTimeCDString + "I"
set StringLoop = StringLoop + 1
endloop
return CastingTimeCDString
endfunction
function MoveAndSetTexttagCasting takes nothing returns nothing
local timer Timer = GetExpiredTimer()
local integer tid = GetHandleId(Timer)
local unit CastingTimeUnit = LoadUnitHandle(udg_hash, tid, StringHash("CastingTimeUnit"))
local integer id = GetHandleId(CastingTimeUnit)
local texttag CastingTimeTexxtag = LoadTextTagHandle(udg_hash, id, StringHash("CastingTimeTexxtag"))
local texttag CastingTimeTexxtagBlack = LoadTextTagHandle(udg_hash, id, StringHash("CastingTimeTexxtagBlack"))
local real CastingTimeStartCD = LoadReal(udg_hash, id, StringHash("CastingTimeStartCD"))
local real CastingTimeNowCD = LoadReal(udg_hash, id, StringHash("CastingTimeNowCD"))
local real ColorRed
local real ColorGreen
local real LoopCountR
local integer LoopCountI
set CastingTimeNowCD = CastingTimeNowCD - 0.01
if CastingTimeNowCD <= 0.00 then
call DestroyTimer(Timer)
call DestroyTextTag(CastingTimeTexxtag)
call DestroyTextTag(CastingTimeTexxtagBlack)
else
endif
call SaveReal(udg_hash, id, StringHash("CastingTimeNowCD"), CastingTimeNowCD)
set CastingTimeNowCD = CastingTimeStartCD - CastingTimeNowCD
call SetTextTagText(CastingTimeTexxtag, CastingTimeString(CastingTimeUnit, CastingTimeNowCD), 5 * 0.023 / 10)
set LoopCountR = 100.0 * (CastingTimeNowCD - 0.01) / CastingTimeStartCD
set LoopCountI = 10 - R2I(LoopCountR) / 10
if LoopCountI > 5 then
set ColorRed = 20 * (LoopCountI - 6)
set ColorRed = 100 - ColorRed
call SetTextTagColor(CastingTimeTexxtag, R2I(ColorRed * I2R(255) * 0.01), 255, 0, 0)
elseif LoopCountI == 5 then
call SetTextTagColor( CastingTimeTexxtag, 255, 255, 0, 0 )
elseif LoopCountI < 5 then
set ColorGreen = 20 * (LoopCountI - 1)
call SetTextTagColor( CastingTimeTexxtag, 255, R2I(ColorGreen * I2R(255) * 0.01), 0, 0 )
endif
call SetTextTagPos(CastingTimeTexxtag, GetUnitX(CastingTimeUnit) - 50, GetUnitY(CastingTimeUnit), 50)
call SetTextTagPos(CastingTimeTexxtagBlack, GetUnitX(CastingTimeUnit) - 50, GetUnitY(CastingTimeUnit), 50)
set Timer = null
set CastingTimeUnit = null
set CastingTimeTexxtag = null
set CastingTimeTexxtagBlack = null
endfunction
function CastingTime takes unit u, real ct returns nothing
local integer id = GetHandleId(u)
local texttag Tekst
local texttag Tekst2
local real CastingTimeStartCD = ct
local timer Timer = CreateTimer()
local integer tid = GetHandleId(Timer)
local trigger RemoveTexttag = LoadTriggerHandle(udg_hash, id, StringHash("Remove Texttag Casting"))
call SaveReal(udg_hash, id, StringHash("CastingTimeStartCD"), CastingTimeStartCD)
call SaveReal(udg_hash, id, StringHash("CastingTimeNowCD"), ct)
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "IIIIIIIIII!", 5.00)
call SetTextTagColor(bj_lastCreatedTextTag, 0, 255, 0, 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(u), GetUnitY(u), 10.00)
call SaveTextTagHandle(udg_hash, id, StringHash("CastingTimeTexxtag"), bj_lastCreatedTextTag)
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "IIIIIIIIII!", 5.00)
call SetTextTagColor(bj_lastCreatedTextTag, R2I(15 * I2R(255) * 0.01), R2I(15 * I2R(255) * 0.01), R2I(15 * I2R(255) * 0.01), 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(u), GetUnitY(u), 10.00)
call SaveTextTagHandle(udg_hash, id, StringHash("CastingTimeTexxtagBlack"), bj_lastCreatedTextTag)
call TimerStart( Timer, 0.01, true, function MoveAndSetTexttagCasting)
call SaveUnitHandle(udg_hash, tid, StringHash("CastingTimeUnit"), u)
call SaveTimerHandle(udg_hash, id, StringHash("Timer"), Timer)
call DestroyTrigger(RemoveTexttag)
set RemoveTexttag = CreateTrigger()
call TriggerRegisterUnitEvent(RemoveTexttag, u, EVENT_UNIT_DEATH)
call TriggerAddAction(RemoveTexttag, function RemoveTexttagTriggerCasting)
call SaveTriggerHandle(udg_hash, id, StringHash("Remove Texttag Casting"), RemoveTexttag)
set Tekst = null
set Tekst2 = null
set Timer = null
set RemoveTexttag = null
endfunction
//Функции для отображения числового показателя
function CountRemove takes unit u returns nothing
local integer id = GetHandleId(u)
local timer Timer = LoadTimerHandle(udg_hash, id, StringHash("Timer Count"))
local texttag Texttag = LoadTextTagHandle(udg_hash, id, StringHash("CountTexxtag"))
local texttag Texttag2 = LoadTextTagHandle(udg_hash, id, StringHash("CountTexxtagBlack"))
call DestroyTimer(Timer)
call DestroyTextTag(Texttag)
call DestroyTextTag(Texttag2)
set id = 0
set Timer = null
set Texttag = null
set Texttag2 = null
endfunction
function RemoveTexttagTriggerCount takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer id = GetHandleId(u)
local trigger t = LoadTriggerHandle(udg_hash, id, StringHash("Remove Texttag Count"))
call DestroyTrigger(t)
call CountRemove(u)
set u = null
set id = 0
set t = null
endfunction
function GetCount takes unit u, string countstring returns real
local real count
local integer id = GetHandleId(u)
if countstring == "max" then
set count = LoadReal(udg_hash, id, StringHash("PrimCount"))
elseif countstring == "now" then
set count = LoadReal(udg_hash, id, StringHash("NowCount"))
endif
return count
endfunction
function OverwriteCount takes unit u returns nothing
local integer id = GetHandleId(u)
local real MaxCount = GetCount(u, "max")
local real NowCount = GetCount(u, "now")
if NowCount > MaxCount then
call SaveReal(udg_hash, id, StringHash("PrimCount"), NowCount)
endif
endfunction
function AddCount takes unit u, real count, string sign returns nothing
local integer id = GetHandleId(u)
if sign == "+" then
call SaveReal(udg_hash, id, StringHash("NowCount"), GetCount(u, "now") + count)
elseif sign == "-" then
call SaveReal(udg_hash, id, StringHash("NowCount"), GetCount(u, "now") + count)
endif
endfunction
function SetCount takes unit u, real count returns nothing
local integer id = GetHandleId(u)
call SaveReal(udg_hash, id, StringHash("NowCount"), count)
endfunction
function CountTexttagSettings takes unit u returns string
local integer id = GetHandleId(u)
local real PrimCount = GetCount(u, "max")
local real NowCount = GetCount(u, "now")
local integer StringLoop = 1
local string CountString = ""
local real LoopCountR
local integer LoopCountI
local texttag CountTexxtag = LoadTextTagHandle(udg_hash, id, StringHash("CountTexxtag"))
local real ColorRed
local real ColorGreen
call OverwriteCount(u)
set LoopCountR = 100.0 * NowCount / PrimCount
set LoopCountI = R2I(LoopCountR) / 10
loop
exitwhen StringLoop > LoopCountI
set CountString = CountString + "I"
set StringLoop = StringLoop + 1
endloop
if StringLoop > 5 then
set ColorRed = 20 * (StringLoop - 6)
set ColorRed = 100 - ColorRed
call SetTextTagColor(CountTexxtag, R2I(ColorRed * I2R(255) * 0.01), 255, 0, 0)
elseif StringLoop == 5 then
call SetTextTagColor(CountTexxtag, 255, 255, 0, 0)
elseif StringLoop < 5 then
set ColorGreen = 20 * (StringLoop - 1)
call SetTextTagColor(CountTexxtag, 255, R2I(ColorGreen * I2R(255) * 0.01), 0, 0)
endif
if NowCount <= 0.0 then
call CountRemove(u)
endif
return CountString
set CountString = null
set CountTexxtag = null
endfunction
function MoveTexttagCount takes nothing returns nothing
local timer Timer = GetExpiredTimer()
local integer tid = GetHandleId(Timer)
local unit CountUnit = LoadUnitHandle(udg_hash, tid, StringHash("CountUnit"))
local integer id = GetHandleId(CountUnit)
local texttag CountTexxtag = LoadTextTagHandle(udg_hash, id, StringHash("CountTexxtag"))
local texttag CountTexxtagBlack = LoadTextTagHandle(udg_hash, id, StringHash("CountTexxtagBlack"))
call SetTextTagPos(CountTexxtag, GetUnitX(CountUnit) - 50, GetUnitY(CountUnit), 10.00)
call SetTextTagPos(CountTexxtagBlack, GetUnitX(CountUnit) - 50, GetUnitY(CountUnit), 10.00)
call SetTextTagText(CountTexxtag, CountTexttagSettings(CountUnit), 5 * 0.023 / 10)
set Timer = null
set CountUnit = null
set CountTexxtag = null
set CountTexxtagBlack = null
endfunction
function Count takes unit u, real ct returns nothing
local integer id = GetHandleId(u)
local texttag Tekst
local texttag Tekst2
local timer Timer = CreateTimer()
local integer tid = GetHandleId(Timer)
local trigger RemoveTexttag = LoadTriggerHandle(udg_hash, id, StringHash("Remove Texttag Count"))
call SaveReal(udg_hash, id, StringHash("PrimCount"), ct)
call SaveReal(udg_hash, id, StringHash("NowCount"), ct)
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "IIIIIIIIII!", 5.00)
call SetTextTagColor(bj_lastCreatedTextTag, 0, 255, 0, 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(u), GetUnitY(u), 10.00)
call SaveTextTagHandle(udg_hash, id, StringHash("CountTexxtag"), bj_lastCreatedTextTag)
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "IIIIIIIIII!", 5.00)
call SetTextTagColor(bj_lastCreatedTextTag, R2I(15 * I2R(255) * 0.01), R2I(15 * I2R(255) * 0.01), R2I(15 * I2R(255) * 0.01), 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(u), GetUnitY(u), 10.00)
call SaveTextTagHandle(udg_hash, id, StringHash("CountTexxtagBlack"), bj_lastCreatedTextTag)
call TimerStart( Timer, 0.01, true, function MoveTexttagCount)
call SaveUnitHandle(udg_hash, tid, StringHash("CountUnit"), u)
call SaveTimerHandle(udg_hash, id, StringHash("Timer Count"), Timer)
call DestroyTrigger(RemoveTexttag)
set RemoveTexttag = CreateTrigger()
call TriggerRegisterUnitEvent(RemoveTexttag, u, EVENT_UNIT_DEATH)
call TriggerAddAction(RemoveTexttag, function RemoveTexttagTriggerCount)
call SaveTriggerHandle(udg_hash, id, StringHash("Remove Texttag Count"), RemoveTexttag)
set Tekst = null
set Tekst2 = null
set Timer = null
set RemoveTexttag = null
endfunction
endlibrary
Для работы необходимо добавить библиотеку в код карты и всё.
Примечания
При смерти юнита, текст будет удаляться, однако, если юнит будет удалён из игры текст останется, поэтому во избежание проблем рекомендую убивать юнита перед его удалением.
Видео
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Отредактирован ArhiMEN
Обновление
Обновление
Обновление
ничего не сломалось бы