Hey, I'm new to scripting in warcraft lll. I'm using newgen, and have tried to edit a script to suit my purposes.
Orignally the script checks number of items in region of certain type, if equal to or less than set number created a new of the same item checking for randomly inside of region.
Origanlly it worked for single set MIN_ITEM_COUNT (as a private constant), but I was not sure if it works as an array (as this way I could use the single script for the intire map with all items and regions and set item numbers in them.
MIN_ITEM_COUNT doesn't work, and in testing the map just constantly creates the item every second. Anyone able to shed some light on this for me? Thanks.
Orignally the script checks number of items in region of certain type, if equal to or less than set number created a new of the same item checking for randomly inside of region.
Origanlly it worked for single set MIN_ITEM_COUNT (as a private constant), but I was not sure if it works as an array (as this way I could use the single script for the intire map with all items and regions and set item numbers in them.
JASS:
scope Ritems initializer Init
globals
private constant real INTERVAL = 1.
private integer array MIN_ITEM_COUNT
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] <= 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
function Init takes nothing returns nothing
local trigger trig = CreateTrigger()
//Items to check for:
//<--- Shallow Shores --->
set ITEM_ID[0] = 039;I001039;
set ITEM_ID[1] = 039;I001039;
set ITEM_ID[2] = 039;I001039;
set ITEM_ID[3] = 039;I001039;
//<--- Shallow Shores --->
//Set Min_Item_Count:
//<--- Shallow Shores --->
set MIN_ITEM_COUNT[0] = 4
set MIN_ITEM_COUNT[1] = 1
set MIN_ITEM_COUNT[2] = 2
set MIN_ITEM_COUNT[3] = 3
//<--- Shallow Shores --->
//Define rects to check in:
//<--- Shallow Shores --->
set AREA[0] = (gg_rct_Shore_Shallows)
set AREA[1] = (gg_rct_Shore_Shallows_1)
set AREA[2] = (gg_rct_Shore_Shallows_2)
set AREA[3] = (gg_rct_Shore_Shallows_3)
//<--- Shallow Shores --->
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>
MIN_ITEM_COUNT doesn't work, and in testing the map just constantly creates the item every second. Anyone able to shed some light on this for me? Thanks.