- Joined
- Jan 3, 2010
- Messages
- 359
hello, i've created a system that will change the camera when a hero come inside a house, and i wanted to ask is this efficient and leakless ?
Credits to Opposum for his Oppicam, and the almighty vexorian for his Table
Credits to Opposum for his Oppicam, and the almighty vexorian for his Table
JASS:
library HouseCam requires Table, ThirdPersonCam, FixedCam
globals
private Table HouseTable = 0
private integer Houses = 0
endglobals
private function Conditions takes nothing returns boolean
return GetTriggerUnit() == hero
endfunction
private function opendoor takes nothing returns nothing
if GetDestructableTypeId(GetEnumDestructable()) == 'B001' then
call SetDestructableAnimation(GetEnumDestructable(), "stand alternate")
endif
endfunction
private function closedoor takes nothing returns nothing
if GetDestructableTypeId(GetEnumDestructable()) == 'B001' then
call SetDestructableAnimation(GetEnumDestructable(), "stand")
endif
endfunction
function H2I takes handle h returns integer
return GetHandleId(h)
endfunction
struct Houses
region reg = CreateRegion()
real regX = 0
real regY = 0
trigger EnterHouse =CreateTrigger()
trigger OutHouse = CreateTrigger()
private static method create takes rect whichRect returns thistype
local thistype this = thistype.allocate()
call RegionAddRect(.reg, whichRect)
set .regX = GetRectCenterX(whichRect)
set .regY = GetRectCenterY(whichRect)
call TriggerRegisterEnterRegion(.EnterHouse, .reg, null)
call TriggerRegisterLeaveRegion(.OutHouse, .reg, null)
set HouseTable[H2I(.reg)] = this
call TriggerAddAction(.EnterHouse, function thistype.enter)
call TriggerAddCondition(.EnterHouse, Condition(function Conditions))
call TriggerAddAction(.OutHouse, function thistype.out)
call TriggerAddCondition(.OutHouse, Condition(function Conditions))
return thistype
endmethod
private static method enter takes nothing returns nothing
local player p = GetOwningPlayer(GetEnteringUnit())
local thistype this = HouseTable[H2I(GetTriggeringRegion())]
call EnableThirdPersonCam(p, null, 0)
call EnableFixedCam(p, GetEnteringUnit(), .regX, .regY, 200, 1)
call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function opendoor)
endmethod
private static method out takes nothing returns nothing
local player p = GetOwningPlayer(GetLeavingUnit())
local thistype this = HouseTable[H2I(GetTriggeringRegion())]
call EnableFixedCam(p, null, 0, 0, 0, 0)
call EnableThirdPersonCam(p, GetLeavingUnit(), 1)
call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function closedoor)
endmethod
private static method onInit takes nothing returns nothing
set HouseTable = Table.create()
call Houses.create(gg_rct_H1)
call Houses.create(gg_rct_H2)
endmethod
endstruct
endlibrary