waaaks!
Zinctified
- Reaction score
- 256
hey guys, please take a look, a system that removes units that are affected with the town portal, wierd?
JASS:
//--------------------------------------------------------------------
// Function: PickPortalUnit - Picks all of the portal units on the map
// owned by the portal owner so they can be removed.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function PickPortalUnit takes nothing returns boolean
if (GetUnitTypeId(GetFilterUnit()) == udg_portalUnit) then
return true
endif
return false
endfunction
//--------------------------------------------------------------------
// Function: RemovePortalUnit - Removes the portal unit.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function RemovePortalUnit takes nothing returns nothing
call RemoveUnit(GetEnumUnit())
endfunction
//--------------------------------------------------------------------
// Function: DestroyPortals - Destroys a portal owned by a player.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function DestroyPortals takes integer i returns nothing
local group g1 = GetUnitsInRectMatching(udg_playerTownRegions[i-1], Condition(function PickPortalUnit))
local group g2 = GetUnitsInRectMatching(udg_playerSourceRegions[i-1], Condition(function PickPortalUnit))
call DestroyTrigger(udg_portalTriggers[i*2-2])
call DestroyTrigger(udg_portalTriggers[i*2-1])
call DestroyEffectBJ(udg_specialEffects[i*2-2])
call DestroyEffectBJ(udg_specialEffects[i*2-1])
if (udg_portalCloseSound != null) then
call SetSoundPositionLocBJ(udg_portalCloseSound, GetRectCenter(udg_playerTownRegions[i-1]), 0 )
call PlaySoundBJ(udg_portalCloseSound)
endif
call ForGroup(g1, function RemovePortalUnit)
call ForGroup(g2, function RemovePortalUnit)
endfunction
//--------------------------------------------------------------------
// Function: PortalSource - Handling for source portal (created at hero)
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function PortalSource takes nothing returns nothing
local integer i = GetPlayerId(GetOwningPlayer(GetEnteringUnit()))
call SetUnitPositionLoc(GetEnteringUnit(), OffsetLocation(GetRectCenter(udg_playerTownRegions<i>), 0, -200.00))
call TriggerSleepAction(0.01)
call IssueImmediateOrderBJ(GetTriggerUnit(), "stop")
call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetEnteringUnit()), GetUnitLoc(GetEnteringUnit()), 0)
endfunction
//--------------------------------------------------------------------
// Function: PortalSourceConditions - Makes sure the unit entering a
// portal is a hero and is an ally of the creating player.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function PortalSourceConditions takes nothing returns boolean
local integer i = 1
loop
exitwhen i > 12
if (GetTriggeringTrigger() == udg_portalTriggers[i*2-2]) then
exitwhen true
endif
set i = i + 1
endloop
if (IsUnitType(GetEnteringUnit(), UNIT_TYPE_HERO)) then
if (IsPlayerAlly(GetOwningPlayer(GetEnteringUnit()), Player(i-1))) then
return true
endif
endif
return false
endfunction
//--------------------------------------------------------------------
// Function: PortalTown - Handling for portal in town.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function PortalTown takes nothing returns nothing
local integer i = 1
loop
exitwhen i > 12
if (GetTriggeringTrigger() == udg_portalTriggers[i*2-1]) then
exitwhen true
endif
set i = i + 1
endloop
call SetUnitPositionLoc(GetEnteringUnit(), OffsetLocation(GetRectCenter(udg_playerSourceRegions[i-1]), 0, -200.00) )
call TriggerSleepAction(0.01)
call IssueImmediateOrderBJ(GetTriggerUnit(), "stop")
call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetEnteringUnit()), GetUnitLoc(GetEnteringUnit()), 0)
if (GetOwningPlayer(GetEnteringUnit()) == Player(i-1)) then
call DestroyPortals(i)
endif
endfunction
//--------------------------------------------------------------------
// Function: PortalTownConditions - Makes sure the unit entering a
// portal is a hero and is an ally of the creating player.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function PortalTownConditions takes nothing returns boolean
local integer i = 1
loop
exitwhen i > 12
if (GetTriggeringTrigger() == udg_portalTriggers[i*2-1]) then
exitwhen true
endif
set i = i + 1
endloop
if (IsUnitType(GetEnteringUnit(), UNIT_TYPE_HERO)) then
if (IsPlayerAlly(GetOwningPlayer(GetEnteringUnit()), Player(i-1))) then
return true
endif
endif
return true
endfunction
//--------------------------------------------------------------------
// Function: GetTeleportOk - Returns false if hero is in a "no TP" region.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function GetTeleportOk takes unit u, integer i returns boolean
local integer index = 0
local boolean result = true
loop
exitwhen index > i - 1
if (RectContainsUnit(udg_invalidTPRegions[index], u)) then
set result = false
exitwhen true
endif
set index = index + 1
endloop
return result
endfunction
//--------------------------------------------------------------------
// Function: TPConditions - Verifies the used item is a scroll of town
// portal.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function TPConditions takes nothing returns boolean
if (GetItemTypeId(GetManipulatedItem()) == udg_tpItem) then
return true
endif
return false
endfunction
//--------------------------------------------------------------------
// Function: TPActions - Portal Handling code.
// Author: rwxr-xr-x
//--------------------------------------------------------------------
function TPActions takes nothing returns nothing
local integer numRI = 0
local unit u = GetManipulatingUnit()
local integer x = GetConvertedPlayerId(GetTriggerPlayer())
local integer y = x * 2 - 2
local real posX = 0.0
local real posY = 0.0
set x = x - 1
// Before continuing, check to see if player has left
if (GetPlayerSlotState(Player(x)) == PLAYER_SLOT_STATE_LEFT) then
if (IsTriggerEnabled(udg_portalTriggers[y])) then
call DestroyPortals(x+1)
return
endif
return
endif
set posX = GetUnitX(GetManipulatingUnit())
set posY = GetUnitY(GetManipulatingUnit())
// Check for number of invalid regions
loop
if (udg_invalidTPRegions[numRI] == null) then
exitwhen true
endif
set numRI = numRI + 1
endloop
// Verify a town portal is placeable
if (GetTeleportOk(u,numRI) != true) then
call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 3.00, "|cFFFF0000Unable to use Town Portal from here.|r")
call TriggerSleepAction(0.01)
call UnitAddItemByIdSwapped(udg_tpItem, u)
return // Hero not able to TP, so exit early
endif
// If player has a town portal open already, close it
if (IsTriggerEnabled(udg_portalTriggers[y])) then
call DestroyPortals(x+1)
endif
// Effects
set udg_playerSourceRegions[x] = RectFromLoc(Location(posX-100,posY+25), Location(posX+100,posY+225))
set u = CreateUnitAtLoc(Player(x), udg_portalUnit, GetRectCenter(udg_playerSourceRegions[x]), bj_UNIT_FACING)
call PauseUnitBJ(true,u)
set u = CreateUnitAtLoc(Player(x), udg_portalUnit, GetRectCenter(udg_playerTownRegions[x]), bj_UNIT_FACING)
call PauseUnitBJ(true,u)
call AddSpecialEffectLocBJ(GetRectCenter(udg_playerTownRegions[x]), udg_portalSpecialEffectString)
set udg_specialEffects[y] = GetLastCreatedEffectBJ()
call AddSpecialEffectLocBJ(GetRectCenter(udg_playerSourceRegions[x]), udg_portalSpecialEffectString)
set udg_specialEffects[(y+1)] = GetLastCreatedEffectBJ()
// If udg_portalOpenSound is set, attatch and play the sound
if (udg_portalOpenSound != null) then
call SetSoundPositionLocBJ(udg_portalOpenSound, GetRectCenter(udg_playerSourceRegions[x]), 0)
call PlaySoundBJ(udg_portalOpenSound)
endif
set udg_portalTriggers[y] = CreateTrigger()
set udg_portalTriggers[y+1] = CreateTrigger()
// Activate the players portal triggers
call TriggerRegisterEnterRectSimple(udg_portalTriggers[y], udg_playerSourceRegions[x])
call TriggerAddAction(udg_portalTriggers[y], function PortalSource)
call TriggerAddCondition(udg_portalTriggers[y], Condition(function PortalSourceConditions))
call TriggerRegisterEnterRectSimple(udg_portalTriggers[y+1], udg_playerTownRegions[x])
call TriggerAddAction(udg_portalTriggers[y+1], function PortalTown)
call TriggerAddCondition(udg_portalTriggers[y+1], Condition(function PortalTownConditions))
endfunction
//===========================================================================
function InitTrig_Town_Portal takes nothing returns nothing
local integer i = 0
set gg_trg_Town_Portal = CreateTrigger()
loop
exitwhen i > 11
call TriggerRegisterPlayerUnitEventSimple(gg_trg_Town_Portal, Player(i), EVENT_PLAYER_UNIT_USE_ITEM)
call TriggerRegisterPlayerEvent(gg_trg_Town_Portal, Player(i), EVENT_PLAYER_LEAVE)
set i = i + 1
endloop
call TriggerAddAction(gg_trg_Town_Portal, function TPActions)
call TriggerAddCondition(gg_trg_Town_Portal, Condition(function TPConditions))
endfunction</i>