• 🏆 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!

[JASS] Local Tree Fade

Status
Not open for further replies.
Level 22
Joined
Jun 24, 2008
Messages
3,050
Will anybody be able to create a Tree Fade system, that changes the Opacity of 'Trees' in

900 range, to 90.
800 range, to 80.
700 range, to 70.
600 range, to 60.
500 range, to 50.
400 range, to 40.
300 range, to 30.
200 range, to 20.
100 range, to 10.

Use a custom model (Not trees!, but Units with the models!).

This would be really neat, and surely usefull for more than me.

(Must be Local, so that it only changes to the owner of the unit in range.)

Ps. Mustn't leak.
 
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
You're trying to do this for every unit in the map or only an array of heroes or something? It will lag like hell for all the units.
There are certain natives to avoid that.

Anyways, here is the code.
JASS:
library FDT

globals
    private constant integer treeId = 101 //Use your dummy unittree point value id.
    private constant real fadeRange = 1000. //The fade range.
    //---
    private group tempEnum = CreateGroup()
endglobals

private function IsDummyTree takes nothing returns boolean
    return GetUnitPointValue(GetFilterUnit()) == treeId
endfunction

function SetTreeTransparency takes unit fromWho returns nothing
    local unit u
    local real x0 = GetUnitX(fromWho)
    local real y0 = GetUnitY(fromWho)
    local real dx
    local real dy
    call GroupEnumUnitsInRange(tempEnum, x0, y0, fadeRange+100, Filter(function IsDummyTree))
    loop
        set u = FirstOfGroup(tempEnum)
        exitwhen u == null
        call GroupRemoveUnit(tempEnum, u)
        set dx = GetUnitX(u)-x0
        set dx = dx*dx
        set dy = GetUnitY(u)-y0
        set dy = dy*dy
        if GetLocalPlayer() == GetOwningPlayer(fromWho) then
            call SetUnitVertexColor(u, 255, 255, 255, R2I(SquareRoot(dx+dy)/1000*255))
        endif
    endloop
endfunction

endlibrary

And here is a testmap...

~Eccho~
 

Attachments

  • DummyTreeFading.w3x
    15.3 KB · Views: 54
Status
Not open for further replies.
Top