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?
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?
// =======================================
// 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
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
A quick re-writing of my function to work with local players. I have not tested it, but I think it works.
// =======================================
// 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:
// 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.
No, you must put the code inside the actions function.
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.
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!