• 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.

SetUnitX/Y to inside a building - unit snaps to nearest spot

Status
Not open for further replies.
Level 25
Joined
Jul 10, 2006
Messages
3,315
[SOLVED] SetUnitX/Y to inside a building - unit snaps to nearest spot

Hi

I'm making a custom bunker system (thanks to http://www.hiveworkshop.com/forums/requests-341/bunker-221214/ for the idea)

Going very well so far, encountered my first problem.

My system works by instead hiding the units with Animation - Set unit vertex colouring, reducing speed to 0, and using SetUnitX/Y to move it to the center of the building, from where it can still attack.

The problem: for anything smaller than a lumber mill (10x10 pathing cells), the units are automatically moved to as close as possible right next to the building.

Is there any way I can ignore this automatic function?

I'd preferably not use a loop to constantly move the unit, and using Unit - Hide unit would completely defeat the purpose (the unit has to be able to attack).

Thanks
 

Attachments

  • BunkerSystem001.w3x
    21.9 KB · Views: 60
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
Can't you just use the ability from the orc burrow?

Burrow only allows one unit type, and uses the building's attack. The system I'm making is meant to be like in Starcraft.

Otherwise, I think turning unit's collision off while within the bunker should work.

Wow I'm stupid, never considered that.

+rep and my undying love. No homo.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I'd recommend changing the unit's size to 0.00%, what do you think ?
This will truly "hide" the unit from plain sight.

Because if you set to 100% transparency, it will make the unit's potrait turns dark.

Also, this might collide with another trigger that uses "Pick every unit..." to damage Picked unit, you have to somehow filter them, put in Unit Group / Save a Boolean / etc, to make sure that the unit inside the "Bunker" is not picked.

More testing will be done~

EDIT:
I got it, you have to use Unit - Hide Unit function, why ?
Because, if you truly want to imitate the behaviour of a "Bunker", the unit won't show up in the map when it enters the bunker, right ?
Therefore it should be hidden.

Your current method would fail, if someone presses "ALT" button, because the HP Bar would show up.

Also, Hidden Units does not get picked via Unit Group Pick, so your units in the Bunker is safe from Picking via Unit Group.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
They do, try it :)

They don't :(

Not automatically, at least.

I was also thinking it would be best to allow the player to micro the bunker occupants to each attack whatever they may please.

EDIT: New problem - if an autoattacked unit runs out of range, the bunker occupant still tries to attack it, since it thinks it can run up to it. If there a better way to disable movement than Set Unit Movement speed, or is there a better way to refresh attack targets than looping a stop command?

EDIT EDIT: Solved the new problem by using
  • Custom script: call SetUnitPropWindow(udg_tempUnit, 0)
First time the forum search function has actually been useful to me.

EDIT3: Found a nice read on removing health bars - workarounds using locust and chaos. http://www.wc3c.net/showthread.php?t=81742

EDIT4: Everything is shaping up nicely.
Attached is the updated version.
- Units autoattack from inside the bunker
- Loaded units aren't selectable, visible, and don't have healthbars
- Each bunker type can be assigned a capacity, and two capacity styles are available: count per unit, or count by units' supply
- Units now properly enter the bunker if ordered while adjacent
- Units are ejected if the bunker dies
Adding:
- Option for bonus regeneration
- Option for max attackers per bunker
Still need to experiment with heroes, and see if that option is plausible.
 

Attachments

  • CustomBunkerSystem003.w3x
    26.3 KB · Views: 45
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
I found a workaround for it (courtesy of PitzerMike)

JASS:
function UnitRemoveLocust takes unit u returns nothing
    local boolean backup = not IsUnitHidden(u)
    call ShowUnit(u, false)
    call UnitRemoveAbility(u, 'Aloc')
    call ShowUnit(u, backup)
endfunction

So the units that leave the bunker act as normal - I can select them, target them, and they have health bars!

I'll post this to the Spells section as soon as I'm happy with it, which should be tonight still :)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I found a workaround for it (courtesy of PitzerMike)

JASS:
function UnitRemoveLocust takes unit u returns nothing
    local boolean backup = not IsUnitHidden(u)
    call ShowUnit(u, false)
    call UnitRemoveAbility(u, 'Aloc')
    call ShowUnit(u, backup)
endfunction

So the units that leave the bunker act as normal - I can select them, target them, and they have health bars!

I'll post this to the Spells section as soon as I'm happy with it, which should be tonight still :)

Did you try what I wrote ?
Try it first, then write it here what is the result.

1. Order the unit to enter bunker
2. Unload the unit
3. Click-select the unit (you can't) (CLICK-SELECT, NOT DRAG-SELECT)
4. Choose any Hero that has Target-unit type spell (Blood Mage: Banish)
5. Order the Banish to the removed unit from the Bunker (you can't)

However, Mortar has the solution.

But, using chaos is limited to units only, right ?
Heroes will bug if they use it ?
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
3. Click-select the unit (you can't) (CLICK-SELECT, NOT DRAG-SELECT)
4. Choose any Hero that has Target-unit type spell (Blood Mage: Banish)
5. Order the Banish to the removed unit from the Bunker (you can't)

However, Mortar has the solution.

But, using chaos is limited to units only, right ?
Heroes will bug if they use it ?

Damn my haste!

I'll see if simply replacing the units will work.
EDIT: Works fine, but that leaves the problem of erasing variables.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I'll see if simply replacing the units will work.
You can't replace Heroes :/
It would be quite unefficient to replace Heroes because they are unique to one another compared to Units, they are just bunch of data that's not so important.
If you replace Heroes, I think there would be a Unit Leak, somehow.

Well maybe your system has a restriction to it ?
It supports Units only ?
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Well maybe your system has a restriction to it ?
It supports Units only ?

Yeah, I'll probably have to do that.

Maybe I'll make a special function that allows a single hero, but makes it selectable to cast spells and such.

EDIT: on the topic of variables, I'll at the very least save and set the unit's custom value to make it compatible with maps that use an indexing system.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You should solve first the Locust + Chaos issue.
Else, you can't target it~

EDIT: Works fine, but that leaves the problem of erasing variables.
I worked with Unit - Replace Unit function before (save data to it via Hashtable), after I replaced it, I loaded it using the (Last replaced unit)'s ID.

And it proves that (Last replaced unit) = Original Unit, meaning that the data saved to it will be carried by Replaced Unit.

So if you save any data to it, it will carry the data over to the new replaced unit, neat huh ?
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
I worked with Unit - Replace Unit function before (save data to it via Hashtable), after I replaced it, I loaded it using the (Last replaced unit)'s ID.

And it proves that (Last replaced unit) = Original Unit, meaning that the data saved to it will be carried by Replaced Unit.

So if you save any data to it, it will carry the data over to the new replaced unit, neat huh ?

So this is the day I break my hashtable virginity. Sounds so wrong.

EDIT: Ugh, I need to go look up a tutorial.
... maybe I'll just hide the actual unit, and create a locust copy of it to place in the bunker?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
and create a locust copy of it to place in the bunker?
Why do you still want the units to be shown, whereas the unit should be inside the bunker ?
Also, make a check condition whether the unit is Melee or Ranged, if it's Melee, kinda useless to be put in a Bunker if you ask me.

Because Bunker's cell size > attackRange of the Melee Unit (100), therefore it will never get to attack the unit (does not test this yet).
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Why do you still want the units to be shown, whereas the unit should be inside the bunker ?
I'll be hiding the locust copy, its only function would be to provide the unit's attack from within the bunker. Visually we just have an attacking bunker that doesn't show its attack in the info card.

Also, make a check condition whether the unit is Melee or Ranged, if it's Melee, kinda useless to be put in a Bunker if you ask me.

Because Bunker's cell size > attackRange of the Melee Unit (100), therefore it will never get to attack the unit (does not test this yet).

Well of course, but the allowed unit types are all configurable, so its up to the system's user(s) to allow/disallow units. Melee units can obviously still be included (to take refuge), but you're right, I should add the range check, no need to create a dummy that won't be used.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Okay it's working great!

- Real unit is hidden, paused, made invulnerable
- Dummy unit is created as copy of unit
- On unload, real unit unhidden, dummy unit destroyed

I'm using Bribe's unit indexer to reference the dummy unit, so I'll probably redo the indexing for my bunkers to also use it.

Thanks again for all your help defskull :)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
- Real unit is hidden, paused, made invulnerable
Pause can sometimes bug the unit.
To prevent him from further attacking nearby enemy units, simply add Cargo Hold to it ('Abun')
  • Custom script: call UnitAddAbility(whichUnit, 'Abun')
'Abun' will make your physical attack to be disabled.

- Dummy unit is created as copy of unit
Is this only to show the "attack animation" played ?
So you would have to create "each unit-type" dummy for each unit-type, is it ?
But if you're making it a different unit, bonuses from the original unit is not the same with the dummy such as Attack Speed/Passive Ability/etc.

- On unload, real unit unhidden, dummy unit destroyed
Make sure the "destroy dummy" part, first you hide the dummy and kill it, you don't wanna see a sudden death animation plays, right ?
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Pause can sometimes bug the unit.
To prevent him from further attacking nearby enemy units, simply add Cargo Hold to it ('Abun')
  • Custom script: call UnitAddAbility(whichUnit, 'Abun')
'Abun' will make your physical attack to be disabled.
Adding this now.

I take it this has no side effects when removed?

Is this only to show the "attack animation" played ?
So you would have to create "each unit-type" dummy for each unit-type, is it ?
But if you're making it a different unit, bonuses from the original unit is not the same with the dummy such as Attack Speed/Passive Ability/etc.

Make sure the "destroy dummy" part, first you hide the dummy and kill it, you don't wanna see a sudden death animation plays, right ?

I'm creating unit type of loaded unit.

To destroy the dummy, I remove it.
 
Status
Not open for further replies.
Top