Добавлен Стас Орлов
Решил сделать карту по механике напоминающую Mushroom Wars и столкнулся с проблемой. Я выбираю все здания на карте, в которые должны входить войска для их захвата и добавляю к каждому из зданий триггер с условием TriggerRegisterUnitInRange, но столкнулся с проблемой, что триггер срабатывает каждый раз, когда юнит входит в рейнж любого здания. Вопрос вот в чём: какую делать проверку на то, что юниты в рейнже именно нужного мне здания?
Код 1
function RandomBuilding takes nothing returns boolean
local unit BG = GetFilterUnit()
local integer uid = GetUnitTypeId(BG)
local integer r = GetRandomInt(0, arraycount)
local trigger Enter = CreateTrigger()
if uid == 'h000' then //Генератор зданий
call IssueImmediateOrderById(BG, BT[r])
set bj_lastCreatedTextTag = null
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "25/25", 15.00 * 0.023 / 10)
call SetTextTagColor(bj_lastCreatedTextTag, 150, 150, 150, 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(BG), GetUnitY(BG), 30.00)
call SaveTextTagHandle(H, GetHandleId(BG), StringHash("Unit Count Text"), bj_lastCreatedTextTag)
call SaveInteger(H, GetHandleId(BG), StringHash("Unit Count"), 25)
call SaveInteger(H, GetHandleId(BG), StringHash("Max Unit Count"), 25)
call TriggerRegisterUnitInRange(Enter, BG, 200, null)
call TriggerAddAction(Enter, function EnterRange)
elseif uid == 'h000' then //Замок
set bj_lastCreatedTextTag = null
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "50/50", 15.00 * 0.023 / 10)
call SetTextTagColor(bj_lastCreatedTextTag, 150, 150, 150, 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(BG), GetUnitY(BG), 30.00)
call SaveTextTagHandle(H, GetHandleId(BG), StringHash("Unit Count Text"), bj_lastCreatedTextTag)
call SaveInteger(H, GetHandleId(BG), StringHash("Unit Count"), 50)
call SaveInteger(H, GetHandleId(BG), StringHash("Max Unit Count"), 50)
call TriggerRegisterUnitInRange(Enter, BG, 200, null)
call TriggerAddAction(Enter, function EnterRange)
endif
return false
set BG = null
set Enter = null
endfunction
function Trig_GenerateBuildinds_Actions takes nothing returns nothing
local group g = CreateGroup()
local fogmodifier StartFog
local integer index = 0
local unit townhall
local trigger Enter
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, function RandomBuilding)
loop
set StartFog = CreateFogModifierRect(Player(index), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false)
call FogModifierStart(StartFog)
if (GetLocalPlayer() == Player(index)) then
call CameraSetupApplyForceDuration(gg_cam_Start, true, 0)
call PanCameraToTimed(GetStartLocationX(GetPlayerStartLocation(Player(index))), GetStartLocationY(GetPlayerStartLocation(Player(index))), 0)
set townhall = null
set townhall = CreateUnit(Player(index), 'htow', GetStartLocationX(GetPlayerStartLocation(Player(index))), GetStartLocationY(GetPlayerStartLocation(Player(index))), 270)
set Enter = null
set Enter = CreateTrigger()
call TriggerRegisterUnitInRange(Enter, townhall, 200, null)
call TriggerAddAction(Enter, function EnterRange)
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "1/50", 15.00 * 0.023 / 10)
call SetTextTagColor(bj_lastCreatedTextTag, 255, 255, 0, 0)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(townhall), GetUnitY(townhall), 30.00)
call SaveTextTagHandle(H, GetHandleId(townhall), StringHash("Unit Count Text"), bj_lastCreatedTextTag)
call SaveInteger(H, GetHandleId(townhall), StringHash("Unit Count"), 1)
call SaveInteger(H, GetHandleId(townhall), StringHash("Max Unit Count"), 50)
set AddUnitTime[index] = 1.0
set AddUnitTimer[index] = CreateTimer()
set BuildingsForPlayer[index] = CreateGroup()
set MaxUnitCount[index] = 0
set BonusDamage[index] = 0
call GroupAddUnit(BuildingsForPlayer[index], townhall)
call TimerStart(AddUnitTimer[index], AddUnitTime[index], false, function AddUnit)
call SavePlayerHandle(H, GetHandleId(AddUnitTimer[index]), StringHash("Owner"), Player(index))
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
set g = null
set StartFog = null
set townhall = null
set Enter = null
endfunction
//===========================================================================
function InitTrig_GenerateBuildinds takes nothing returns nothing
set gg_trg_GenerateBuildinds = CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_GenerateBuildinds, 0.01, false)
call TriggerAddAction( gg_trg_GenerateBuildinds, function Trig_GenerateBuildinds_Actions )
endfunction
Код 2
function EnterRange takes nothing returns nothing
local unit EnterUnit = GetTriggerUnit()
local player Owner = GetOwningPlayer(EnterUnit)
local integer id = GetHandleId(EnterUnit)
local unit Build = LoadUnitHandle(H, id, StringHash("Enter Building"))
local integer UnitCount = LoadInteger(H, GetHandleId(Build), StringHash("Unit Count"))
local integer CountInUnit = LoadInteger(H, id, StringHash("Count In Unit"))
local texttag Text = LoadTextTagHandle(H, GetHandleId(Build), StringHash("Unit Count Text"))
local integer MaxUC = LoadInteger(H, GetHandleId(Build), StringHash("Max Unit Count"))
local integer DamageNow = (CountInUnit * (100 + BonusDamage[GetPlayerIndex(Owner)]) / 100)
local unit SpawnBuilding = LoadUnitHandle(H, id, StringHash("Spawn Building"))
local player BuildingOwner = GetOwningPlayer(Build)
if Build != SpawnBuilding then
if Owner != BuildingOwner then
if UnitCount > DamageNow then
set UnitCount = UnitCount - DamageNow
call SaveInteger(H, GetHandleId(Build), StringHash("Unit Count"), UnitCount)
call SetTextTagText(Text, I2S(UnitCount) + "/" + I2S(MaxUC + MaxUnitCount[GetPlayerIndex(Owner)] * 2), 15.00 * 0.023 / 10)
call KillUnit(EnterUnit)
call RemoveUnit(EnterUnit)
elseif DamageNow > UnitCount then
set DamageNow = DamageNow - UnitCount
call SaveInteger(H, GetHandleId(Build), StringHash("Unit Count"), DamageNow)
call SetTextTagText(Text, I2S(DamageNow) + "/" + I2S(MaxUC + MaxUnitCount[GetPlayerIndex(Owner)] * 2), 15.00 * 0.023 / 10)
call SetTextTagColor(Text, 255, 255, 0, 0)
call KillUnit(EnterUnit)
call RemoveUnit(EnterUnit)
call SetUnitOwner(Build, Owner, true)
call GroupAddUnit(BuildingsForPlayer[GetPlayerIndex(Owner)], Build)
call CheckBuildingType(Build)
elseif DamageNow == UnitCount then
call SaveInteger(H, GetHandleId(Build), StringHash("Unit Count"), 0)
call SetTextTagText(Text, I2S(0) + "/" + I2S(MaxUC + MaxUnitCount[GetPlayerIndex(Owner)] * 2), 15.00 * 0.023 / 10)
call SetTextTagColor(Text, 255, 255, 0, 0)
call KillUnit(EnterUnit)
call RemoveUnit(EnterUnit)
call SetUnitOwner(Build, Owner, true)
call GroupAddUnit(BuildingsForPlayer[GetPlayerIndex(Owner)], Build)
call CheckBuildingType(Build)
endif
elseif Owner == BuildingOwner then
set UnitCount = UnitCount + CountInUnit
call SaveInteger(H, GetHandleId(Build), StringHash("Unit Count"), UnitCount)
call SetTextTagText(Text, I2S(UnitCount) + "/" + I2S(MaxUC + MaxUnitCount[GetPlayerIndex(Owner)] * 2), 15.00 * 0.023 / 10)
call KillUnit(EnterUnit)
call RemoveUnit(EnterUnit)
endif
endif
set EnterUnit = null
set Owner = null
set Build = null
set Text = null
set SpawnBuilding = null
endfunction
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Ред. goodlyhero
GetEventTargetUnit - юнит, который ивент вызвал, что-то такое.
никогда не пользовался этим и не понимаю как оно работает, прошу прощения, если не прав😀