• 🏆 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] Transparent Roofs for 1 player

Status
Not open for further replies.
Level 2
Joined
Apr 10, 2004
Messages
10
I need it so that when a unit enters a region, the roof models become transparent (60%) for the owner of the unit only.
I can't JASS at all and i've read the guides and got the JASS editor

Set UnitVertexColor()
GetLocalPlayer()

I've tried, but its not preciest enouth to work. How do you correctly use these JASS functions to get it working? What is the presist way of doing this?
 
Level 1
Joined
Nov 16, 2005
Messages
3
if GetLocalPlayer()==Player(//player index//)then
call SetUnitVertexColor(//unit//,255,255,255,153)
endif

you can try this script but i've never tried it so i dont know whether it works
 
Level 2
Joined
Apr 10, 2004
Messages
10
This is KaTTaNa's FadeUnitVertexColor Jass snippet from this website http://www.wc3sear.ch/index.php?p=JASS&ID=271&sid=ac0c3aa12ec7cf615ccbf98625c538b4. How do you replace parts of it to refer to the units/players? How do I set up the even so that when the unit enters the region, this only applies to one player? is this even applicable?

JASS:
// =======================================
//    Fade unit vertex colors
 
function FadeUnitVertexColor_Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real r = GetHandleReal(t, "r") + GetHandleReal(t, "dr")
    local real g = GetHandleReal(t, "g") + GetHandleReal(t, "dg")
    local real b = GetHandleReal(t, "b") + GetHandleReal(t, "db")
    local real a = GetHandleReal(t, "a") + GetHandleReal(t, "da")
    local integer step = GetHandleInt(t, "step") - 1
    local unit u = GetHandleUnit(t, "u")
    call SetUnitVertexColor(u, R2I(r*255), R2I(g*255), R2I(b*255), R2I(a*255))
    if ( u == null or step <= 0 ) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        return
    endif
    call SetHandleReal(t, "r", r)
    call SetHandleReal(t, "g", g)
    call SetHandleReal(t, "b", b)
    call SetHandleReal(t, "a", a)
    call SetHandleInt(t, "step", step)
endfunction
function FadeUnitVertexColor takes unit u, real r1, real g1, real b1, real a1, real r2, real g2, real b2, real a2, real time returns nothing
    local timer t
    local real update = 0.05
    if ( time <= 0 ) then
        call SetUnitVertexColor(u, R2I(r2*255), R2I(g2*255), R2I(b2*255),  R2I(a2*255))
        return
    endif
    call SetUnitVertexColor(u, R2I(r1*255), R2I(g1*255), R2I(b1*255),  R2I(a1*255))
    set t = CreateTimer()
    call SetHandleReal(t, "r", r1)
    call SetHandleReal(t, "g", g1)
    call SetHandleReal(t, "b", b1)
    call SetHandleReal(t, "a", a1)
    call SetHandleReal(t, "dr", update*(r2-r1)/time)
    call SetHandleReal(t, "dg", update*(g2-g1)/time)
    call SetHandleReal(t, "db", update*(b2-b1)/time)
    call SetHandleReal(t, "da", update*(a2-a1)/time)
    call SetHandleHandle(t, "u", u)
    call SetHandleInt(t, "step", R2I(time/update + 0.99))
    call TimerStart(t, update, true, function FadeUnitVertexColor_Update)
endfunction
 
Level 1
Joined
Nov 16, 2005
Messages
3
you should post your trigger events and actions or i cant get the entering unit and its owning player ,which is the local player
 
Level 7
Joined
Jul 30, 2004
Messages
451
the code you posted is made to fade a unit from 1 rgba to another rgba over time in a consistant manner by calling the function FadeUnitVertexColor(u,r1,g1,b1,a1,r2,g2,b2,a2,time)

if u just want the thing to become transparent instantly for a player, the code snippet is of no use to you pretty much

do what cdp726 said, dunno if it'll desync or not

and learn a programming language, its useful :p
 
Level 3
Joined
Mar 27, 2004
Messages
70
A quick re-writing of my function to work with local players.
I have not tested it, but I think it works.
JASS:
// =======================================
//    Fade unit vertex colors

function FadeUnitVertexColorForPlayer_Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real r = GetHandleReal(t, "r") + GetHandleReal(t, "dr")
    local real g = GetHandleReal(t, "g") + GetHandleReal(t, "dg")
    local real b = GetHandleReal(t, "b") + GetHandleReal(t, "db")
    local real a = GetHandleReal(t, "a") + GetHandleReal(t, "da")
    local integer step = GetHandleInt(t, "step") - 1
    local unit u = GetHandleUnit(t, "u")
    local player who = Player( GetHandleInt(t, "player") )
    if ( who == GetLocalPlayer() ) then
        call SetUnitVertexColor(u, R2I(r*255), R2I(g*255), R2I(b*255), R2I(a*255))
    endif
    if ( u == null or step <= 0 ) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        return
    endif
    call SetHandleReal(t, "r", r)
    call SetHandleReal(t, "g", g)
    call SetHandleReal(t, "b", b)
    call SetHandleReal(t, "a", a)
    call SetHandleInt(t, "step", step)
endfunction
function FadeUnitVertexColorForPlayer takes unit u, real r1, real g1, real b1, real a1, real r2, real g2, real b2, real a2, real time, player who returns nothing
    local timer t
    local real update = 0.05
    if ( time <= 0 ) then
        if ( who == GetLocalPlayer() ) then
            call SetUnitVertexColor(u, R2I(r2*255), R2I(g2*255), R2I(b2*255),  R2I(a2*255))
        endif
        return
    endif
    call SetUnitVertexColor(u, R2I(r1*255), R2I(g1*255), R2I(b1*255),  R2I(a1*255))
    set t = CreateTimer()
    call SetHandleReal(t, "r", r1)
    call SetHandleReal(t, "g", g1)
    call SetHandleReal(t, "b", b1)
    call SetHandleReal(t, "a", a1)
    call SetHandleReal(t, "dr", update*(r2-r1)/time)
    call SetHandleReal(t, "dg", update*(g2-g1)/time)
    call SetHandleReal(t, "db", update*(b2-b1)/time)
    call SetHandleReal(t, "da", update*(a2-a1)/time)
    call SetHandleHandle(t, "u", u)
    call SetHandleInt(t, "step", R2I(time/update + 0.99))
    call SetHandleInt(t, "player", GetPlayerId(who))
    call TimerStart(t, update, true, function FadeUnitVertexColorForPlayer_Update)
endfunction

It is still up to you to detect when a player enters a house, and to find the unit that represents the roof which you want to become transparent.
To make the roof transparent, just do:
JASS:
// A unit enters the building
local unit roof = (.. get the roof somehow ..)
call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 1, 1, 1, 1, 0.40, 1.0, GetOwningPlayer( GetEnteringUnit() ) )

// A unit leaves the building
local unit roof = (.. get the roof somehow ..)
call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 0.40, 1, 1, 1, 1, 1.0, GetOwningPlayer( GetLeavingUnit() ) )
The 0.40 in the script represent 40% opacity = 60% transparency.
 
Level 2
Joined
Apr 10, 2004
Messages
10
41 compile errors.


I added in the roof name etc: is this right?
JASS:
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Untitled_Trigger_001, gg_rct_Region_000 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
local unit roof = (gg_unit_hfoo_0000)
call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 1, 1, 1, 1, 0.40, 1.0, GetOwningPlayer( GetEnteringUnit() ) )
 
//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterLeaveRectSimple( gg_trg_Untitled_Trigger_002, gg_rct_Region_000 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction
local unit roof = (gg_unit_hfoo_0000)
call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 0.40, 1, 1, 1, 1, 1.0, GetOwningPlayer( GetLeavingUnit() ) )

50 complie errors :S does this have to separate or what?
 
Level 3
Joined
Mar 27, 2004
Messages
70
No, you must put the code inside the actions function.
JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    // A unit enters the building
    local unit roof = gg_unit_hfoo_0000
    call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 1, 1, 1, 1, 0.40, 1.0, GetOwningPlayer( GetEnteringUnit() ) ) 
endfunction

function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
    call TriggerRegisterEnterRectSimple( gg_trg_Untitled_Trigger_001, gg_rct_Region_000 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
Do the same for the other trigger.

Oh, and one last thing. For all this to work, go into the map header (the topmost item in the trigger editor with the icon of a map).
Copy and paste the Local Handle Variables in there.
Then, below all the code you just pasted, you paste the code I gave you in my previous post.
 
Level 2
Joined
Apr 10, 2004
Messages
10
Fustrating... 70 compile errors.

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    // A unit enters the building
    local unit roof = gg_unit_hfoo_0000
    call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 1, 1, 1, 1, 0.40, 1.0, GetOwningPlayer( GetEnteringUnit() ) )
endfunction
 
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
    call TriggerRegisterEnterRectSimple( gg_trg_Untitled_Trigger_001, gg_rct_Region_000 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    // A unit leaves the building
local unit roof = (.. get the roof somehow ..)
call FadeUnitVertexColorForPlayer( roof, 1, 1, 1, 0.40, 1, 1, 1, 1, 1.0, GetOwningPlayer( GetLeavingUnit() ) )
 
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
    call TriggerRegisterEnterRectSimple( gg_trg_Untitled_Trigger_001, gg_rct_Region_000 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

// =======================================
//    Fade unit vertex colors
 
function FadeUnitVertexColorForPlayer_Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real r = GetHandleReal(t, "r") + GetHandleReal(t, "dr")
    local real g = GetHandleReal(t, "g") + GetHandleReal(t, "dg")
    local real b = GetHandleReal(t, "b") + GetHandleReal(t, "db")
    local real a = GetHandleReal(t, "a") + GetHandleReal(t, "da")
    local integer step = GetHandleInt(t, "step") - 1
    local unit u = GetHandleUnit(t, "u")
    local player who = Player( GetHandleInt(t, "player") )
    if ( who == GetLocalPlayer() ) then
        call SetUnitVertexColor(u, R2I(r*255), R2I(g*255), R2I(b*255), R2I(a*255))
    endif
    if ( u == null or step <= 0 ) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        return
    endif
    call SetHandleReal(t, "r", r)
    call SetHandleReal(t, "g", g)
    call SetHandleReal(t, "b", b)
    call SetHandleReal(t, "a", a)
    call SetHandleInt(t, "step", step)
endfunction
function FadeUnitVertexColorForPlayer takes unit u, real r1, real g1, real b1, real a1, real r2, real g2, real b2, real a2, real time, player who returns nothing
    local timer t
    local real update = 0.05
    if ( time <= 0 ) then
        if ( who == GetLocalPlayer() ) then
            call SetUnitVertexColor(u, R2I(r2*255), R2I(g2*255), R2I(b2*255),  R2I(a2*255))
        endif
        return
    endif
    call SetUnitVertexColor(u, R2I(r1*255), R2I(g1*255), R2I(b1*255),  R2I(a1*255))
    set t = CreateTimer()
    call SetHandleReal(t, "r", r1)
    call SetHandleReal(t, "g", g1)
    call SetHandleReal(t, "b", b1)
    call SetHandleReal(t, "a", a1)
    call SetHandleReal(t, "dr", update*(r2-r1)/time)
    call SetHandleReal(t, "dg", update*(g2-g1)/time)
    call SetHandleReal(t, "db", update*(b2-b1)/time)
    call SetHandleReal(t, "da", update*(a2-a1)/time)
    call SetHandleHandle(t, "u", u)
    call SetHandleInt(t, "step", R2I(time/update + 0.99))
    call SetHandleInt(t, "player", GetPlayerId(who))
    call TimerStart(t, update, true, function FadeUnitVertexColorForPlayer_Update)
endfunction

Sorry if I'm being n00b-like cause i am Jass n00b!
 
Status
Not open for further replies.
Top