• 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] Get unit size?

Status
Not open for further replies.
Welcome back.

1. You mean its collision size, or its physical size?

2. Physical size cannot be measured outisde of Object Editor. If you do a change to a unit's size the only way to remember that change is to set some kind of variable manually stating what its modified size is.

3. So you want the line to be spaced proportionately with differentiating unit sizes?
 
Level 11
Joined
Mar 31, 2009
Messages
732
Hmm.

I just want to create a line of ten or so towers next to each other, without having to look up the unit size for each type when/if I change them.

If its not possible, then where is the value I should go look up in the object editor? Couldn't find anything called radius or width or...
 
I don't think you can. That is, if you are talking about Scale (x,y,z).

The method I would use is just a struct to contain the initial info. Basically, the initial XYZ. Then just use a custom-defined function for XYZ and set the struct members to those input values. This way, you can use get/set and keep it in order. To find out the initial X/Y/Z of a unit, you can simply place it and double-click it, if I remember correctly.
 
Usually you can base the width of the model on the units own collision size in Object Editor, as the model file is sometimes bigger or smaller due to there often being a disproportionately scaled unit using the model (ie. the forest trollers are pretty much the same model but with different scaling value).

Blizzard's own collision radius should be accurate enough. However, you may consider, if you don't want to dig up all of their collsion sizes, doing a group enum that starts at 2 radius and increases by 2 radius, then until it finally grabs the unit it logs the current radius and that will correspond with the unit's collision size (as Group Enumeration doesn't enumerate a unit until its entire collision size is within its radius).
 
Level 11
Joined
Mar 31, 2009
Messages
732
Well it says the collision size is 72.0 in the object editor, so this is what I came up with:

JASS:
library TowerSpawns initializer init
    globals
        integer TS_MAX = 10
        Tower_Spawn array TS_left
    endglobals
    
    struct Tower_Spawn
        unit tower = null
        real col
        real row
    endstruct
    
    private function init takes nothing returns nothing
        local integer i = 1
        
        call TS_left[0].create()
        
        set TS_left[0].tower = gg_unit_h000_0019
        set TS_left[0].col = GetUnitX(gg_unit_h000_0019)
        set TS_left[0].row = GetUnitY(gg_unit_h000_0019)
        
        loop
            exitwhen i == TS_MAX
            call TS_left[i].create()
            
            set TS_left[i].col = TS_left[i-1].col
            set TS_left[i].row = TS_left[i-1].row - 144.0
            
            set TS_left[i].tower = CreateUnit(Player(2), GetUnitTypeId(gg_unit_h000_0019), TS_left[i].col, TS_left[i].row, bj_UNIT_FACING)
            set i = i + 1
        endloop
    endfunction
endlibrary

It created ten towers as I wanted it to, but.. it left a gap between the first and second, and the ninth and tenth :|
 
Level 11
Joined
Mar 31, 2009
Messages
732
Ughh what is going on here.

JASS:
library TowerSpawns initializer init
    globals
        integer TS_MAX = 15
        Tower_Spawn array TS_left
        Tower_Spawn array TS_right
    endglobals
    
    struct Tower_Spawn
        unit tower = null
        real col
        real row
    endstruct
    
    private function init takes nothing returns nothing
        local integer i = 1
        
        call TS_left[0].create()
        call TS_right[0].create()
        
        set TS_left[0].tower = gg_unit_h000_0019
        set TS_left[0].col = GetUnitX(gg_unit_h000_0019)
        set TS_left[0].row = GetUnitY(gg_unit_h000_0019)
        
        set TS_right[0].tower = gg_unit_h000_0024 // <-- Problem line
        //set TS_right[0].col = GetUnitY(gg_unit_h000_0024)
        //set TS_right[0].row = GetUnitX(gg_unit_h000_0024)
        
        loop
            exitwhen i == TS_MAX
            call TS_left[i].create()
            //call TS_right[i].create()
            
            set TS_left[i].col = TS_left[i-1].col
            set TS_left[i].row = TS_left[i-1].row - 125.0
            
            //set TS_right[i].col = TS_right[i-1].col
            //set TS_right[i].row = TS_right[i-1].row - 125.0
            
            set i = i + 1
        endloop
    endfunction
    
    //public function Spawn_Tower takes integer row, integer typeid returns nothing
    //    set TS_left[row].tower = CreateUnit(Player(2), TT_TYPES[typeid], TS_left[row].col, TS_left[row].row, bj_UNIT_FACING)
    //    set TS_right[row].tower = CreateUnit(Player(2), TT_TYPES[typeid], TS_right[row].col, TS_right[row].row, bj_UNIT_FACING)
    //endfunction
    
    public function Upgrade_Tower takes integer row, integer typeid returns nothing
        call IssueImmediateOrderById(TS_left[row].tower, TT_TYPES[typeid])
        //call IssueImmediateOrderById(TS_right[row].tower, TT_TYPES[typeid])
    endfunction
endlibrary

When I call it with...

JASS:
call TowerSpawns_Upgrade_Tower(0, 1)
Its upgrading the wrong tower, unless I comment out the line I arrowed in the comments.
I don't understand why. Its a separate variable?
 
Status
Not open for further replies.
Top