HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Changing a unnit's size?

08-30-2009, 05:31 PM#1
thehellman
I want to change a unit's scaling size.

I'm using SetUnitScale(u, 0.5, 0.5, 0.5)

Then using SetUnitScale(u, 1, 1, 1) to restore it back to it's original size.

The problem is that I have a unit with a base-scaled value of 0.75 (in the Object Editor his scaling value is 0.75).

When I SetUnitScale to 1, it is changing it's size so that it is bigger than it originally was. Any fix?
08-30-2009, 05:35 PM#2
Rikim4ru
SetUnitScale(u, 0.75, 0.75, 0.75)?
08-30-2009, 05:36 PM#3
thehellman
Yes I was hoping if there was an alternative to doing

if ( IsTheTargetUnit == TheUnitWith0.75Scale ) then
SetScale to 0.75
endif
08-30-2009, 05:40 PM#4
Rising_Dusk
No. Create a wrapper function like SetUnitScaleEx that does it for you if you need to.
08-30-2009, 06:11 PM#5
Vexorian
Something crazy using Table:

Collapse JASS:
globals
    Table UnitTypeScale 
endglobals

// during init:
 set UnitTypeScale = Table.create()
 set UnitTypeScale[ 'hfoo' ] = 2.0 //Let's say your footman starts with 2.0 scale in object editor


function SetUnitScaleEx takes unit u, real s returns nothing
 local integer t = GetUnitTypeId(u)
 local real o = 1.0
   if( UnitTypeScale.exists(t) ) then
       set o = UnitTypeScale[ t ]
   endif
   call SetUnitScale(u, s*o, s*o, s*o)
endfunction


This way you can easily add more units with special scales.

If you already have a lot of code from other sources that uses SetUnitScale:

Collapse JASS:
globals
    private boolean enabled = true
endglobals

    private function SetUnitScaleDetect takes unit u, real x, real y, real z returns nothing
      local integer t
      local real o
          if(enabled) then
               set enabled = false
               set t = GetUnitTypeId(u)
               set o = 1.0
               if( UnitTypeScale.exists(t) ) then
                       set o = UnitTypeScale[ t ]
               endif
               call SetUnitScale(u, x*o, y*o, z*o)

               set enabled = true
        endif
    endfunction

     hook SetUnitScale SetUnitScaleDetect

notice this makes all calls to SetUnitScale a little slower... but it will make all calls to SetUnitScale work correctly.
08-30-2009, 07:06 PM#6
thehellman
Thanks Vexorian for the in-depth.

I only have 4 units that need this, so I'll go ahead with the if statements to keep things simple. But I've learned 2 very interesting an unrelated things for your post.

#1 is Table. Never knew how it worked at all, now I can see how it is used in a real-application example.

#2 Something I notice is the word 'hook' What does this do exactly? I'm thinking that it makes calls to a native and directs it to the function that is user-defined?
08-30-2009, 09:25 PM#7
Themerion
Quote:
Something I notice is the word 'hook' What does this do exactly? I'm thinking that it makes calls to a native and directs it to the function that is user-defined?

I think you might have gotten it right, but you're somewhat vague... hook doesn't usually make calls to a native as you state (even if you can likely make so that it does).

Hook replaces any calls to a certain function, making them call another function. In this case: hook SetUnitScale SetUnitScaleDetect will cause all references to SetUnitScale to magically become SetUnitScaleDetect.

If your code looks like this:
Collapse JASS:
function A
    call SetUnitScale(u,a,b,c)
endfunction

     hook SetUnitScale SetUnitScaleDetect

It will (after compilation) become:

Collapse JASS:
function A
    call SetUnitScaleDetect(u,a,b,c)
endfunction
08-31-2009, 03:08 PM#8
0zyx0
It is also possible to use bloodlust to temporarily change the size of a unit.
08-31-2009, 03:58 PM#9
Anitarf
Wait, Table can store reals now?

Also, do hooked functions get executed before or after the native they are hooked to?
08-31-2009, 04:05 PM#10
Vexorian
Quote:
Originally Posted by Anitarf
Wait, Table can store reals now?

Also, do hooked functions get executed before or after the native they are hooked to?
Sure, something should be done before that, I suggest just using a 100 scale multiplier.

it does not really matter in this case what gets called before.
08-31-2009, 04:33 PM#11
Anitarf
Quote:
Originally Posted by Vexorian
it does not really matter in this case what gets called before.
Wouldn't the original SetUnitScale call override the one in the hooked function if it got called after the hooked function?
08-31-2009, 04:39 PM#12
Vexorian
I think so.

I think though that if hooks are getting called before I should change so.

Though this abuse of hooks is not really for what they were intended to do.

We might need something more powerful than hooks, specially for this, like a way to actually modify the parameter, that would actually work in change so multiple of these 'hooks' would work for the same native.
08-31-2009, 07:42 PM#13
Karawasa
I just want to say that if you're not using Point Value, it's great for storing the scale...Custom Value is used for indexing utilities (I prefer PUI), but Point Value is up for grabs.