• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Random Rect...XY...

Status
Not open for further replies.
SOLVED!

Why the unit is not created in RANDOM locations in this setup?...
JASS:
    local integer lev = GetRandomInt(1, 10)
    local rect r = bj_mapInitialPlayableArea   
    local location l = Location(GetRandomReal(GetRectMinX(r), GetRectMaxX(r)), GetRandomReal(GetRectMinY(r), GetRectMaxY(r)))
    local unit u = CreateUnitAtLoc(Player(14), ChooseRandomCreep(lev), l, bj_UNIT_FACING)
    call RemoveRect(r)
    call RemoveLocation(l)
    set u = null
    set l = null
    set r = null

While this is OK...
JASS:
    local integer lev = GetRandomInt(1, 10)   
    local location l = Location(GetRandomReal(GetRectMinX(bj_mapInitialPlayableArea), GetRectMaxX(bj_mapInitialPlayableArea)), GetRandomReal(GetRectMinY(bj_mapInitialPlayableArea), GetRectMaxY(bj_mapInitialPlayableArea))) 
    local unit u = CreateUnitAtLoc(Player(14), ChooseRandomCreep(lev), l, bj_UNIT_FACING)
    call RemoveLocation(l)
    set u = null
    set l = null
 
Last edited:
call RemoveRect(r)

- You don't want to remove bj_mapInitialPlayableArea. Delete this line and it will work.

JASS:
local rect r = bj_mapInitialPlayableArea   
local unit u = CreateUnit(Player(14), ChooseRandomCreep(GetRandomInt(1, 10)), GetRandomReal(GetRectMinX(r), GetRectMaxX(r)), GetRandomReal(GetRectMinY(r), GetRectMaxY(r)), 0)
set u = null
set r = null
 
A simple solution but it worked!...thanks Bribe!...

JASS:
function AttackAction takes nothing returns nothing
    local rect r = bj_mapInitialPlayableArea   
    local real x = GetRandomReal(GetRectMinX(r), GetRectMaxX(r)) 
    local real y = GetRandomReal(GetRectMinY(r), GetRectMaxY(r))
    call CreateUnit(Player(14), ChooseRandomCreep(GetRandomInt(1, 10)), x, y, bj_UNIT_FACING)
    set r = null
endfunction
 
Status
Not open for further replies.
Top