Help with script (EnumItemsInRect)

Morbid

New Member
Reaction score
0
Hey,

I am currently working on a warcraft 3 FT map. I don't know really know JASS, I've had a look and its quite similar to coding I've done before (Morrowind scripting and Dungeon Keeper).

But, I am having trouble with a script and can't find much about it (of what I can doesn't make sence to the way the GUI editor writes it out.

Basicly, the script does:

Action:
Every set number of seconds

Condition:
Does a check on a region/rect (whats the diff?) for all items of a certain type (so I am guessing a ItemsInRect script with an item check).

Actions:
Then if there is 3 or less of this item... ->
Creates 1 more of the same item randomly inside the region.



So if someone can help me with a template script that I can modify to my likeing? Or if not, explain how to do so.

Thanks,
Morbid.
 

Tom Jones

N/A
Reaction score
437
I trust you have NewGen, if not get it here.

JASS:
scope Whatever initializer Init
globals
    private constant integer MIN_ITEM_COUNT = 3
    private constant real    INTERVAL       = 1.

    private integer array ITEM_ID
    private integer array ITEM_COUNT
    private rect array AREA
    
    private boolexpr FILTER
endglobals

private function CountItems takes nothing returns boolean
    local integer id = GetItemTypeId(GetFilterItem())
    local integer i = 0
    
    loop
        exitwhen ITEM_ID<i> == null
        if ITEM_ID<i> == id then
            set ITEM_COUNT<i> = ITEM_COUNT<i>+1
            return false
        endif
        set i = i+1
    endloop
    return false
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    local integer a
    
    loop
        //Looping through all of the assigned rects searching for and counting
        //the assigned item ids:
        exitwhen AREA<i> == null
        call EnumItemsInRect(AREA<i>,FILTER,function DoNothing)
        set a = 0
        loop
            //Looping through the number of assigned item ids in the rect,
            //creating an item of the type if the number is less than MIN_ITEM_COUNT.
            exitwhen ITEM_ID[a] == null
            if ITEM_COUNT[a] &lt;= MIN_ITEM_COUNT then
                call CreateItem(ITEM_ID[a],GetRandomReal(GetRectMinX(AREA<i>),GetRectMaxX(AREA<i>)),GetRandomReal(GetRectMinY(AREA<i>),GetRectMaxY(AREA<i>)))
            endif
            set ITEM_COUNT[a] = 0 //Reset the array index for next execution.
            set a = a+1
        endloop
        set i = i+1
    endloop
endfunction

private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    
    //Define items to check for:
    set ITEM_ID[0] = ...
    set ITEM_ID[1] = ...
    set ITEM_ID[2] = ...
    set ITEM_ID[3] = ...
    //Etc.
    
    //Define rects to check in:
    set AREA[0] = Rect(...)
    set AREA[1] = Rect(...)    
    set AREA[2] = Rect(...)
    set AREA[3] = Rect(...)
    set AREA[4] = Rect(...)
    //Etc.
    
    call TriggerRegisterTimerEvent(trig,INTERVAL,true)
    call TriggerAddAction(trig,function Actions)
    set FILTER = Condition(function CountItems)
endfunction
endscope

</i></i></i></i></i></i></i></i></i></i>
 
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