initial commit
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
local ____exports = {}
|
||||
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
|
||||
local registerEntityFunction = ____dota_ts_adapter.registerEntityFunction
|
||||
local LOG = "[trigger_button]"
|
||||
--- Основной targetname пропа (prop_dynamic).
|
||||
local BUTTON_PROP_TARGETNAME = "trigger_button"
|
||||
--- Запасной targetname, если триггер тоже назван `trigger_button`.
|
||||
local BUTTON_PROP_TARGETNAME_FALLBACK = "trigger_button_prop"
|
||||
local function getThisTriggerIndex(self)
|
||||
do
|
||||
local ____try, ____hasReturned, ____returnValue = pcall(function()
|
||||
if thisEntity ~= nil and thisEntity ~= nil and not thisEntity:IsNull() then
|
||||
return true, thisEntity:entindex()
|
||||
end
|
||||
end)
|
||||
if ____try and ____hasReturned then
|
||||
return ____returnValue
|
||||
end
|
||||
end
|
||||
return -1
|
||||
end
|
||||
local function isVolumeTriggerEntity(self, ent)
|
||||
local cn = ""
|
||||
do
|
||||
local function ____catch(_)
|
||||
return true, false
|
||||
end
|
||||
local ____try, ____hasReturned, ____returnValue = pcall(function()
|
||||
cn = ent:GetClassname()
|
||||
end)
|
||||
if not ____try then
|
||||
____hasReturned, ____returnValue = ____catch(____hasReturned)
|
||||
end
|
||||
if ____hasReturned then
|
||||
return ____returnValue
|
||||
end
|
||||
end
|
||||
return cn == "trigger_multiple" or cn == "trigger_once" or cn == "trigger_look" or cn == "trigger_push" or cn == "trigger_teleport" or cn == "trigger_hurt"
|
||||
end
|
||||
--- Все сущности с targetname; пропускаем сам триггер и объёмные триггеры.
|
||||
local function findButtonPropDynamic(self)
|
||||
local myIdx = getThisTriggerIndex(nil)
|
||||
local list = Entities:FindAllByName(BUTTON_PROP_TARGETNAME)
|
||||
if list ~= nil then
|
||||
do
|
||||
local i = 0
|
||||
while i < #list do
|
||||
do
|
||||
local e = list[i + 1]
|
||||
if e == nil or not IsValidEntity(e) then
|
||||
goto __continue10
|
||||
end
|
||||
if myIdx >= 0 and e:entindex() == myIdx then
|
||||
goto __continue10
|
||||
end
|
||||
if isVolumeTriggerEntity(nil, e) then
|
||||
goto __continue10
|
||||
end
|
||||
print((((((LOG .. " findProp: \"") .. BUTTON_PROP_TARGETNAME) .. "\" → ent=") .. tostring(e:entindex())) .. " class=") .. e:GetClassname())
|
||||
return e
|
||||
end
|
||||
::__continue10::
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
local fb = Entities:FindByName(nil, BUTTON_PROP_TARGETNAME_FALLBACK)
|
||||
if fb ~= nil and fb ~= nil and IsValidEntity(fb) and not isVolumeTriggerEntity(nil, fb) then
|
||||
print((((LOG .. " findProp: fallback \"") .. BUTTON_PROP_TARGETNAME_FALLBACK) .. "\" ent=") .. tostring(fb:entindex()))
|
||||
return fb
|
||||
end
|
||||
print(((((((LOG .. " findProp: не найден подходящий prop (имена \"") .. BUTTON_PROP_TARGETNAME) .. "\" / \"") .. BUTTON_PROP_TARGETNAME_FALLBACK) .. "\", исключены trigger_* и thisEntity=") .. tostring(myIdx)) .. ")")
|
||||
return nil
|
||||
end
|
||||
--- Жесты — у CDOTA_BaseNPC / некоторых пропов; иначе SetSequence по имени секвенции.
|
||||
local function playButtonPropDotAttack(self)
|
||||
local ent = findButtonPropDynamic(nil)
|
||||
if ent == nil then
|
||||
return
|
||||
end
|
||||
local asNpc = ent
|
||||
local anyEnt = ent
|
||||
if type(anyEnt.StartGesture) == "function" then
|
||||
local startG = anyEnt.StartGesture
|
||||
local fadeG = anyEnt.FadeGesture
|
||||
do
|
||||
local function ____catch(e)
|
||||
print((LOG .. " StartGesture ошибка: ") .. tostring(e))
|
||||
end
|
||||
local ____try, ____hasReturned = pcall(function()
|
||||
if type(fadeG) == "function" then
|
||||
fadeG(nil, ACT_DOTA_ATTACK)
|
||||
end
|
||||
startG(nil, ACT_DOTA_ATTACK)
|
||||
print(((LOG .. " prop ent=") .. tostring(ent:entindex())) .. " → StartGesture(DOTA_ATTACK)")
|
||||
end)
|
||||
if not ____try then
|
||||
____catch(____hasReturned)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
if type(anyEnt.SetSequence) == "function" then
|
||||
local setSeq = anyEnt.SetSequence
|
||||
local candidates = {
|
||||
"ACT_DOTA_ATTACK",
|
||||
"attack",
|
||||
"dota_attack",
|
||||
"press",
|
||||
"down"
|
||||
}
|
||||
for ____, seq in ipairs(candidates) do
|
||||
do
|
||||
local ____try, ____hasReturned, ____returnValue = pcall(function()
|
||||
setSeq(nil, seq)
|
||||
print(((((LOG .. " prop ent=") .. tostring(ent:entindex())) .. " → SetSequence(\"") .. seq) .. "\")")
|
||||
return true
|
||||
end)
|
||||
if ____try and ____hasReturned then
|
||||
return ____returnValue
|
||||
end
|
||||
end
|
||||
end
|
||||
print(((((LOG .. " prop ent=") .. tostring(ent:entindex())) .. ": SetSequence не принял кандидатов ") .. table.concat(candidates, ", ")) .. " — проверь имя секвенции в модели")
|
||||
return
|
||||
end
|
||||
print(((((LOG .. " prop ent=") .. tostring(ent:entindex())) .. " class=") .. ent:GetClassname()) .. ": нет StartGesture/SetSequence — тип сущности не поддерживает анимацию как у героя")
|
||||
end
|
||||
local function handleStartTouch(self, trigger)
|
||||
local act = trigger.activator
|
||||
if act ~= nil and IsValidEntity(act) then
|
||||
print((LOG .. " StartTouch / OnStartTouch: activator=") .. tostring(act:entindex()))
|
||||
else
|
||||
print(LOG .. " StartTouch / OnStartTouch: нет activator (I/O — только анимация пропа)")
|
||||
end
|
||||
playButtonPropDotAttack(nil)
|
||||
end
|
||||
local function handleEndTouch(self, trigger)
|
||||
local act = trigger.activator
|
||||
if act ~= nil and IsValidEntity(act) then
|
||||
print((LOG .. " EndTouch / OnEndTouch: activator=") .. tostring(act:entindex()))
|
||||
else
|
||||
print(LOG .. " EndTouch / OnEndTouch: нет activator")
|
||||
end
|
||||
end
|
||||
registerEntityFunction(
|
||||
nil,
|
||||
"StartTouch",
|
||||
function(____, trigger)
|
||||
handleStartTouch(nil, trigger)
|
||||
end
|
||||
)
|
||||
registerEntityFunction(
|
||||
nil,
|
||||
"EndTouch",
|
||||
function(____, trigger)
|
||||
handleEndTouch(nil, trigger)
|
||||
end
|
||||
)
|
||||
registerEntityFunction(
|
||||
nil,
|
||||
"OnStartTouch",
|
||||
function(____, trigger)
|
||||
handleStartTouch(nil, trigger)
|
||||
end
|
||||
)
|
||||
registerEntityFunction(
|
||||
nil,
|
||||
"OnEndTouch",
|
||||
function(____, trigger)
|
||||
handleEndTouch(nil, trigger)
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
Reference in New Issue
Block a user