Warcraft III resources & community, 2003–2006 · archived

RespawnItemAfterPickupInRect

not rated
Submitted by KaTTaNaFunctions0 downloads
Respawns the given item whenever it's picked up or destroyed. The item gets respawned at a random point inside the rect where. If where is null, it will always get spawned at it's current position.

Parameters
whichItem: The item to be respawned
delay: Time before item is respawned
where: Rect in which to respawn the item. (Pass null to keep current position)
count: How many times the item can max. get respawned. 0 or less = infinite.

Source

function RespawnItemAfterPickup_Child takes nothing returns nothing
    local item whichItem = bj_itemRandomCurrentPick
    local real delay     = bj_meleeNearestMineDist
    local real sleep = 1
    local real x = GetItemX(whichItem)
    local real y = GetItemY(whichItem)
    local integer id = GetItemTypeId(whichItem)
    local trigger trg
    local rect where = bj_isUnitGroupInRectRect
    local integer count = bj_destRandomConsidered
    if ( where != null ) then
        set x = GetRandomReal(GetRectMinX(where), GetRectMaxX(where))
        set y = GetRandomReal(GetRectMinY(where), GetRectMaxY(where))
    endif
    if ( delay <= 3.0 ) then 
        set sleep = 0.5 // If delay is small, increase the accuracy
    elseif ( delay >= 60.0 ) then
        set sleep = 2.0 // If delay is big, decrease accuracy to save performance
    endif
    loop // Loop until item is destroyed or picked up
        exitwhen (whichItem == null) or CheckItemStatus(whichItem, bj_ITEM_STATUS_OWNED)
        call TriggerSleepAction(sleep)
    endloop
    if ( delay > 0 ) then
        call PolledWait(delay) // Wait respawn time    
    endif
    set whichItem = CreateItem(id, x, y) // Respawn the item
    // If respawn is continual, repeat this trigger for the newly spawned item
    if ( count != 1 ) then
        set trg = CreateTrigger()
        call TriggerAddAction(trg, function RespawnItemAfterPickup_Child)
        set bj_itemRandomCurrentPick = whichItem
        set bj_meleeNearestMineDist  = delay
        set bj_isUnitGroupInRectRect = where
        set bj_destRandomConsidered  = count - 1
        call TriggerExecute(trg)
        call DestroyTrigger(trg)
        set trg = null
    endif
    set whichItem = null
endfunction

// Pass null in 'where' to make the item respawn at its current position
function RespawnItemAfterPickupInRect takes item whichItem, real delay, rect where, integer count returns nothing
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, function RespawnItemAfterPickup_Child)
    set bj_itemRandomCurrentPick = whichItem
    set bj_meleeNearestMineDist  = delay
    set bj_isUnitGroupInRectRect = where
    set bj_destRandomConsidered  = count
    call TriggerExecute(trg)
    call DestroyTrigger(trg)
    set trg = null
endfunction

Comments

0

No comments.