• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to hide units

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
I want to display certain units for only certain players.

Since I think it is important for how it works, the units are essentially just dummies used for their models / animation. They have locust and are basically not interacted with in any way. All they do is appear and then die after their animation plays. I also plan to reuse these units, so they may need to be hidden and shown to different players. If that can't be done, I think I can work a solution out so each player has their own animation dummies.

I want to make it so these dummies do not appear for certain players. I know I can use GetLocalPlayer() to run specific code for only specific players, but how do I hide and show the unit?

I read somewhere that I can just set their transparency to 100%, but is that the best option? I thought there was a HideUnit() function to just hide them, but I can't seem to find it and I don't even know what it would do if it existed.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
JASS:
function UnitShow takes unit whichUnit, boolean show returns nothing
    if show then
        call SetUnitVertexColor(whichUnit, 255, 255, 255, 255)
    else
        call SetUnitVertexColor(whichUnit, 255, 255, 255, 0)
    endif
endfunction

public method show takes boolean show returns nothing
    if show then
        call SetUnitVertexColor(whichUnit, r, g, b, a)
    else
        call SetUnitVertexColor(whichUnit, r, g, b, 0)
    endif
    
    set isVisible = show
endmethod

The first function is basically what you want.
The second one is for more advanced programmers who make a library or struct for units so they can store more things and get more things than are basically possible.

This will hide the unit for a single player:
JASS:
function foo takes nothing returns nothing
    local player p = Player(0)
    local unit u = ...
    
    call UnitShow(u, false)
    if GetLocalPlayer() == p then
        call UnitShow(u, true)
    endif
    
    //  OR
    
    call UnitShow(u, GetLocalPlayer() == p)
    
endfunction


This is pretty much the most safe way to do it.
Hiding a unit locally using ShowUnit() is dangerous because if the non-hidden unit interacts with anything else, the game will bug because hidden units (for some players) cannot do anything.
So the players who have those units hidden will desync.

Setting the scale is another option... but you may understand that setting it to 0 might be dangerous because of divide by 0 calculations may occur.
I dont know how it works behind the screen so I am not sure but it may be in some cases.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Thanks.

EDIT:
Misread some of your code / post lol.

Anyway, I will go ahead with this. It is basically set transparency to 100%.
 
Status
Not open for further replies.
Top