- Joined
- Jan 9, 2005
- Messages
- 2,126
So I'm making a small code that creates a unit every X distance covered and ends once the maximum distance has been reached or passed. The problem I'm having is that the relevant variables are indexed to a unit, and if that unit dies while the system is at work, the system breaks entirely and cannot occur again. I've tried checking if the unit is still inside the unit group used for that system, tried preventing the trigger from disabling, etc. Nothing I can think of is working.
The system works fine normally, and is used during a building's construction. If I cancel construction or kill the building while the units are being created, the system dies.
The system works fine normally, and is used during a building's construction. If I cancel construction or kill the building while the units are being created, the system dies.
JASS:
function CustomBuild_OnBuildStart takes nothing returns boolean
local unit Source = null
local unit dummy = null
local unit Building = GetTriggerUnit()
local integer dummy_id = 0
local integer building_id = 0
local integer source_id = 0
local real SOURCE_X = 0.00
local real SOURCE_Y = 0.00
local real TARGET_X = 0.00
local real TARGET_Y = 0.00
local real dx = 0.00
local real dy = 0.00
local real Angle = 0.00
local real Distance = 0.00
if /* ---- List of Buildings that will trigger this function ----
[Moon Well] */GetUnitTypeId(Building) == 'ffmw' or /*
[Barracks] */GetUnitTypeId(Building) == 'ffba' or /*
[Altar] */GetUnitTypeId(Building) == 'ffal' /*
*/then
set building_id = GetUnitUserData(Building)
set dummy = GetStructureBuilder(Building) //This uses Banar's ConstructEvent library
set dummy_id = GetUnitUserData(dummy)
set Source = FF_BuildingSource[dummy_id]
set source_id = GetUnitUserData(Source)
set SOURCE_X = GetUnitX(Source)
set SOURCE_Y = GetUnitY(Source)
set TARGET_X = GetUnitX(Building)
set TARGET_Y = GetUnitY(Building)
set Angle = Atan2(TARGET_Y - SOURCE_Y, TARGET_X - SOURCE_X)
set SOURCE_X = SOURCE_X + Cos(Angle) * (FF_MushroomRadius[source_id] + FF_MUSH_SEGMENT) //This is the radius of the mushroom ring off the Fairy Ring
set SOURCE_Y = SOURCE_Y + Sin(Angle) * (FF_MushroomRadius[source_id] + FF_MUSH_SEGMENT)
set dx = TARGET_X - SOURCE_X
set dy = TARGET_Y - SOURCE_Y
set Distance = SquareRoot(dy*dy + dx*dx)
set FF_IsAFairyBuilding[building_id] = true
set FF_BuildingSource[building_id] = Source
if FF_AttachmentGroup[building_id] == null then
set FF_AttachmentGroup[building_id] = CreateGroup()
endif
set FF_MushTrail_Time[building_id] = FF_BuildTime[building_id]
set FF_MushTrail_Distance[building_id] = Distance
set FF_MushTrail_Speed[building_id] = Distance / FF_BuildTime[building_id]
set FF_MushTrail_Angle[building_id] = Angle
set FF_MushTrail_X[building_id] = SOURCE_X
set FF_MushTrail_Y[building_id] = SOURCE_Y
set FF_MushTrail_Progress[building_id] = 0.0
set FF_MushTrail_NextSegment[building_id] = FF_MUSH_SEGMENT
call GroupAddUnit(FF_MushTrail_Group, Building)
if not IsTriggerEnabled(gg_trg_MushroomTrail) then
call EnableTrigger(gg_trg_MushroomTrail)
endif
endif
return false
endfunction
//===========================================================================
function InitTrig_CustomBuild_OnBuildStart takes nothing returns nothing
set gg_trg_CustomBuild_OnBuildStart = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_CustomBuild_OnBuildStart, EVENT_PLAYER_UNIT_CONSTRUCT_START )
call TriggerAddCondition( gg_trg_CustomBuild_OnBuildStart, function CustomBuild_OnBuildStart )
endfunction
JASS:
function Trig_CustomBuild_OnDeathOrCancel takes nothing returns boolean
local unit Building = GetTriggerUnit()
local unit u = null
local integer building_id = GetUnitUserData(Building)
local integer dummy_id = 0
local integer PlayerNumber = GetPlayerId(GetOwningPlayer(Building)) + 1
//Problem was occuring without this.
if IsUnitInGroup(Building, FF_MushTrail_Group) then
set FF_MushTrail_Distance[building_id] = FF_MushTrail_Progress[building_id]
call BJDebugMsg("In Mush Trail")
//call GroupAddUnit(FF_MushTrail_Group, u)
endif
/*set FF_MushTrail_Time[building_id] = 0.00
set FF_MushTrail_Distance[building_id] = 0.00
set FF_MushTrail_Speed[building_id] = 0.00
set FF_MushTrail_Angle[building_id] = 0.00
set FF_MushTrail_X[building_id] = 0.00
set FF_MushTrail_Y[building_id] = 0.00
set FF_MushTrail_Progress[building_id] = 0.0
set FF_MushTrail_NextSegment[building_id] = 0.00*/
if FF_IsAFairyBuilding[building_id] then
loop
set u = FirstOfGroup(FF_AttachmentGroup[building_id])
exitwhen u == null
call GroupRemoveUnit(FF_AttachmentGroup[building_id], u)
if GetUnitTypeId(u) == 'ffm1' or /*
*/ GetUnitTypeId(u) == 'ffm2' or /*
*/ GetUnitTypeId(u) == 'ffm3' or /*
*/ GetUnitTypeId(u) == 'ffm4' or /*
*/ GetUnitTypeId(u) == 'ffm5' or /*
*/ GetUnitTypeId(u) == 'ffm6' /*
*/ then
set dummy_id = GetUnitUserData(u)
//set udg_SizeChange_Size[id] = 0.00
set udg_SizeChange_EndSize[dummy_id] = 0.00
set udg_SizeChange_SizeRate[dummy_id] = 0.015625//udg_SizeChange_Size[dummy_id] / 64
set udg_SizeChange_Shrink[dummy_id] = true
set udg_SizeChange_DeathOnEnd[dummy_id] = true
if not IsUnitInGroup(u, udg_SizeChange_Group) then
call GroupAddUnit(udg_SizeChange_Group, u)
endif
if not IsTriggerEnabled(gg_trg_SizeChange) then
call EnableTrigger(gg_trg_SizeChange)
endif
endif
endloop
//call DestroyGroup(FF_AttachmentGroup[building_id])
if IsUnitInGroup(Building, udg_CustomBuildField_Group[PlayerNumber]) then
call GroupRemoveUnit( udg_CustomBuildField_Group[PlayerNumber], Building )
endif
set FF_BuildingSource[building_id] = null
set FF_BuildTime[building_id] = 0.00
set FF_IsAFairyBuilding[building_id] = false
endif
return false
endfunction
//===========================================================================
function InitTrig_CustomBuild_OnDeathOrCancel takes nothing returns nothing
set gg_trg_CustomBuild_OnDeathOrCancel = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_CustomBuild_OnDeathOrCancel, EVENT_PLAYER_UNIT_DEATH )
//call TriggerRegisterAnyUnitEventBJ( gg_trg_CustomBuild_OnDeathOrCancel, EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL )
call TriggerAddCondition( gg_trg_CustomBuild_OnDeathOrCancel, function Trig_CustomBuild_OnDeathOrCancel )
endfunction
JASS:
function Trig_MushroomTrail takes nothing returns boolean
local unit u = null
local unit dummy = null
local integer id = 0
local integer dummy_id = 0
local integer RandomInt = 0
local real x = 0.00
local real y = 0.00
local real RandomReal = 0.00
if FF_MushTrail_Group == null then
set FF_MushTrail_Group = CreateGroup()
endif
if FF_MushTrail_GroupTemp == null then
set FF_MushTrail_GroupTemp = CreateGroup()
endif
if FirstOfGroup(FF_MushTrail_Group) != null then
loop
set u = FirstOfGroup(FF_MushTrail_Group)
exitwhen u == null
set id = GetUnitUserData(u)
call GroupRemoveUnit(FF_MushTrail_Group, u)
if not UnitAlive(FF_BuildingSource[id]) then
call UnitApplyTimedLife(u, 'BTLF', 0.01)
endif
//if _Progress[id] is less than _Distance[id] and u is alive, continue increasing _Progress[id]
//else reset all relevant variables to 0.00 and remove u from FF_MushTrail_Group
if FF_MushTrail_Progress[id] < FF_MushTrail_Distance[id] and UnitAlive(u) then
call GroupAddUnit(FF_MushTrail_GroupTemp, u)
set FF_MushTrail_Progress[id] = FF_MushTrail_Progress[id] + FF_MushTrail_Speed[id] / 32 //since the periodic timer runs ever .03125 seconds, 32 represents 1 second.
if FF_MushTrail_Progress[id] >= FF_MushTrail_NextSegment[id] then
set RandomInt = GetRandomInt(1,6)
set dummy = CreateUnit(GetOwningPlayer(u), FF_Mush[RandomInt], FF_MushTrail_X[id], FF_MushTrail_Y[id], GetRandomReal(0.00, 360.00))
call GroupAddUnit(FF_AttachmentGroup[id], dummy)
if RandomInt == 6 then
set RandomReal = GetRandomReal(0.4, .55)
elseif RandomInt == 5 then
set RandomReal = GetRandomReal(.9, 1.15)
else
set RandomReal = GetRandomReal(.45, .8)
endif
// run SizeChange system. This doesn't conflict with this system, I've tried disabling it, but the problem persists.
set dummy_id = GetUnitUserData(dummy)
set udg_SizeChange_Size[dummy_id] = 0.00
set udg_SizeChange_EndSize[dummy_id] = RandomReal
set udg_SizeChange_SizeRate[dummy_id] = RandomReal / ((FF_MushTrail_Time[id] * .2) * 32)
call GroupAddUnit(udg_SizeChange_Group, dummy)
if not IsTriggerEnabled(gg_trg_SizeChange) then
call EnableTrigger(gg_trg_SizeChange)
endif
call PauseUnit(dummy, true)
// END Size Change system
set FF_MushTrail_NextSegment[id] = FF_MushTrail_NextSegment[id] + FF_MUSH_SEGMENT
set FF_MushTrail_X[id] = FF_MushTrail_X[id] + Cos(FF_MushTrail_Angle[id]) * FF_MUSH_SEGMENT
set FF_MushTrail_Y[id] = FF_MushTrail_Y[id] + Sin(FF_MushTrail_Angle[id]) * FF_MUSH_SEGMENT
set dummy = null
endif
else
call BJDebugMsg("Trail End")
set FF_MushTrail_Time[id] = 0.00
set FF_MushTrail_Distance[id] = 0.00
set FF_MushTrail_Speed[id] = 0.00
set FF_MushTrail_Angle[id] = 0.00
set FF_MushTrail_X[id] = 0.00
set FF_MushTrail_Y[id] = 0.00
set FF_MushTrail_Progress[id] = 0.0
set FF_MushTrail_NextSegment[id] = 0.00
endif
endloop
loop
set u = FirstOfGroup(FF_MushTrail_GroupTemp)
exitwhen u == null
call GroupRemoveUnit(FF_MushTrail_GroupTemp, u)
call GroupAddUnit(FF_MushTrail_Group, u)
endloop
else
call DisableTrigger(gg_trg_MushroomTrail)
endif
return false
endfunction
//===========================================================================
function InitTrig_MushroomTrail takes nothing returns nothing
set gg_trg_MushroomTrail = CreateTrigger()
call DisableTrigger(gg_trg_MushroomTrail)
call TriggerRegisterTimerEvent( gg_trg_MushroomTrail, 0.03125, true )
call TriggerAddCondition( gg_trg_MushroomTrail, function Trig_MushroomTrail )
endfunction
Last edited: