| 01-05-2005, 03:39 AM | #1 |
This trigger is intended to make a destructable near each unit of the appropriate type ('Hapm') every 0.20 seconds, and since each player can only have one unit of that type, it stores the destructable created in a destructable array indexed by the owner's player number. Then it waits 2.00 seconds and destroys that destructable. It alternates what kind of destructable is made and which side of the unit it's made on, and it only places a destructable if the unit has moved since the last time the trigger fired. However, the provision in the code which is supposed to prevent it from firing never does, even when the unit stays motionless. Furthermore, now it seems to be stacking up the destructables constantly, much much faster than they're being deleted, if it is deleting them (I can't tell if it's getting that far). Something's seriously wrong, even though the code is pretty basic. I'm just not sure where the error is. Code:
//======================
// Functi0ns
//======================
function Trig_Equine_Training_footprints_Actions takes nothing returns nothing
//== Loc4ls ============
local location locKhan = null
local location locOffset = null
local group groupKhan = GetUnitsOfTypeIdAll('Hapm')
local unit unitPick = null
local player playerOwner = null
local integer intPlayer = 0
local integer intLoop = 0
local real realFacing = 0
local destructable array destArPrint
//== Ac7ions ===========
loop
set unitPick = FirstOfGroup(groupKhan)
exitwhen unitPick == null
set playerOwner = GetOwningPlayer(unitPick)
set intPlayer = GetPlayerId(playerOwner)
set locKhan = GetUnitLoc(unitPick)
set realFacing = GetUnitFacing(unitPick)
if ((GetUnitAbilityLevelSwapped('AUts', unitPick) >= 1) and (DistanceBetweenPoints(udg_locArHeroPosition[intPlayer], locKhan) > 25.00)) then
set udg_locArHeroPosition[intPlayer] = locKhan
if (udg_booArHeroAbility[intPlayer] == false) then
set udg_booArHeroAbility[intPlayer] = true
set locOffset = OffsetLocation(locKhan, (20.00 * -1.00 * SinBJ(realFacing)), (20.00 * CosBJ(realFacing)))
set destArPrint[intPlayer] = CreateDestructable('B001', GetLocationX(locOffset), GetLocationY(locOffset), realFacing, 1, 1)
call RemoveLocation(locOffset)
else
set udg_booArHeroAbility[intPlayer] = false
set locOffset = OffsetLocation(locKhan, (-20.00 * -1.00 * SinBJ(realFacing)), (-20.00 * CosBJ(realFacing)))
set destArPrint[intPlayer] = CreateDestructable('B001', GetLocationX(locOffset), GetLocationY(locOffset), realFacing, 1, 0)
call RemoveLocation(locOffset)
endif
endif
call RemoveLocation(locKhan)
call GroupRemoveUnit(groupKhan, unitPick)
endloop
call PolledWait(2.00)
//== Cl3anup ===========
set intLoop = 0
loop
exitwhen intLoop >= 12
call RemoveDestructable(destArPrint[intLoop])
set destArPrint[intLoop] = null
set intLoop = intLoop + 1
endloop
call DestroyGroup(groupKhan)
set groupKhan = null
call RemoveLocation(locKhan)
set locKhan = null
set unitPick = null
endfunction
//======================
// Event5
//======================
function InitTrig_Equine_Training_footprints takes nothing returns nothing
set gg_trg_Equine_Training_footprints = CreateTrigger()
call DisableTrigger(gg_trg_Equine_Training_footprints)
call TriggerRegisterTimerEventPeriodic(gg_trg_Equine_Training_footprints, 0.20)
call TriggerAddAction(gg_trg_Equine_Training_footprints, function Trig_Equine_Training_footprints_Actions)
endfunction |
| 01-05-2005, 11:55 PM | #2 |
Cubasis helped me to fix a couple misconceptions in the trigger, and now it works mostly perfectly, although the location comparison still seems to be working incorrectly. |
| 01-06-2005, 01:06 AM | #3 | |
Quote:
Change: set udg_locArHeroPosition[intPlayer] = locKhan to: set udg_locArHeroPosition[intPlayer] = Location( GetLocationX(locKhan), GetLocationY(locKhan)) Unless I'm mistaken, when you assign udg_locArHeroPosition[] as locKhan you are only changing which memory location to which udg_locArHeroPosition[] and when you assign locKhan as null, it causes the value for udg_locArHeroPosition[] to be null as well. I'm not sure why it's able to calculate the distance (perhaps it creates a point somewhere on the map if you try to compare a variable that is null), but apparently, however it does it, it is always greater than 25. By writing it this way, you will create another Location for udg_locArHeroPosition[], so you don't have to worry about it being set to null. |
