Dynamic Trigger Oddities

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I'm making a trigger that spawns items randomly about the map, then use "A unit comes withing range" event to automatically pickup the items. However, something odd happens: go in range of the first one and nothing happens. When the second item spawns, going to the first one gives you the second item. I used visible dummies for extra testing. The bj_lastCreatedUnit/Item is because this is for a GUI user. Test map attached. Also, for some reason the reals aren't random, they appear to have a set order. Map attached.

JASS:
scope ItemSpawn initializer init
globals
    private real RANGE = 400
    private boolexpr rangeFilter
    private rect worldBounds
    private integer array itemID[6]
    private constant integer dummyID = 'zZzZ'
    private hashtable ht = InitHashtable()
endglobals

private function RangeFilter takes nothing returns boolean
    return IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO) == true
endfunction

private function RangeActions takes nothing returns nothing
    local integer parentKey = GetHandleId(GetTriggeringTrigger())
    local integer i = 0
    local unit u = GetTriggerUnit()
    call BJDebugMsg(I2S(GetHandleId(GetTriggeringTrigger())))
    loop
        if UnitItemInSlot(u,i) == null then
            call UnitAddItem(u,LoadItemHandle(ht,parentKey,0))
            exitwhen true
        elseif i >= 5 then
            return
        endif
        set i = i+1
    endloop
    call RemoveUnit(LoadUnitHandle(ht,parentKey,1))
    call FlushChildHashtable(ht,parentKey)
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

private function Actions takes nothing returns nothing
    local real x = GetRandomReal(GetRectMinX(worldBounds),GetRectMaxX(worldBounds))
    local real y = GetRandomReal(GetRectMinY(worldBounds),GetRectMaxY(worldBounds))
    local trigger t = CreateTrigger()
    local integer randomInt = GetRandomInt(0, 5)
    if ( udg_Boolean_GameOn == true ) then
        call PingMinimap(x,y,8.00)
        //PingMinimapLocForForceEx
        call TriggerRegisterUnitInRange(t,bj_lastCreatedUnit,RANGE,rangeFilter)
        call TriggerAddAction(t,function RangeActions)
        set bj_lastCreatedUnit = CreateUnit(Player(15),dummyID,x,y,0)
        set bj_lastCreatedItem = CreateItem(itemID[randomInt],x,y)
        call SaveItemHandle(ht,GetHandleId(t),0,bj_lastCreatedItem)
        call SaveUnitHandle(ht,GetHandleId(t),1,bj_lastCreatedUnit)
        call BJDebugMsg(I2S(GetHandleId(t)))
    endif
    set t=null
   // call TriggerSleepAction( GetRandomReal(16.00, 20.00) )
    //call TriggerExecute( GetTriggeringTrigger() )
endfunction

//===========================================================================
private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    set rangeFilter = Condition(function RangeFilter)
    call TriggerRegisterTimerEvent(t,10.,true)
    call TriggerAddAction(t,function Actions)
   // call Actions()
    set worldBounds = GetWorldBounds()
    set itemID[0] = 'I002'
    set itemID[1] = 'I003'
    set itemID[2] = 'I001'
    set itemID[3] = 'I000'
    set itemID[4] = 'I004'
    set itemID[5] = 'I005'
endfunction
endscope
 

Attachments

  • itemrangetest.w3x
    17.6 KB · Views: 109
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top