(I meant halo.. but i accidentally typed in bunnyhop and cannot change it.) If a mod can please change it, thanks!
I looked for the "small problems" thread but i cannot find it so...
[lua] function GlowPlayer()
for _, plays in pairs( player.GetAll()) do
effects.halo.Add( {plays}, Color( 255, 0, 0 ), 5, 5, 2 )
end
end
hook.Add("PreDrawHalos", "GlowPlayerHook", GlowPlayer)[/lua]
Any idea why this does not work? I'm trying to make it so everyone glows and it just refuses to work.
you don't need the effects
[QUOTE=tyguy;40079854]you don't need the effects[/QUOTE]
???
for _, plays in pairs(player.GetAll()) do
halo.Add( {plays}, Color( 255, 0, 0 ), 5, 5, 2 )
end
change to
halo.Add(player.GetAll(),Color(255,0,0),5,5,2)
halos are faster when they operate in one sweep, instead of running separately per entity for an unfiltered list like [i]every[/i] player
if you wanted to do it only for admins, you still shouldn't call halo.Add multiple times, unless you want them to have different colors
local t = {}
for k, v in pairs(player.GetAll()) do
if v:IsAdmin() then
table.insert(t,v)
end
end
halo.Add(t,Color(255,0,0),5,5,2)
be warned that halos are really slow usage of stencils, and lag with several calls to halo.add in a short timeframe (such as for ten separate colors, or ten separate calls to halo.Add of one color)
this example script will accomplish a similar effect using manual stencils, but be warned that it relies on a shared function garry hasn't made work properly clientside when used on players, so the following example will only be useful on non-player entities
[QUOTE=Bletotum;39671972]
This code adds a slightly fuzzy white border around entities using stencils.
It does NOT work on players though, because ent:SetModelScale() is broken when used clientside on players.
This is much faster than the halos, but also slightly less visually interesting; every player could have a unique color without significant FPS loss, though.
[lua]
hook.Add("PostDrawOpaqueRenderables","PlayerBorders",function()
--stencil work is done in postdrawopaquerenderables, where surface doesn't work correctly
--workaround via 3D2D
local pos = LocalPlayer():EyePos()+LocalPlayer():EyeAngles():Forward()*10
local ang = LocalPlayer():EyeAngles()
ang = Angle(ang.p+90,ang.y,0)
for k, v in pairs(ents.FindByClass("prop_physics")) do
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilWriteMask(255)
render.SetStencilTestMask(255)
render.SetStencilReferenceValue(15)
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetBlend(0) --don't visually draw, just stencil
v:SetModelScale(1.0+math.Rand(0.01,0.013),0) --slightly fuzzy, looks better this way
v:DrawModel()
v:SetModelScale(1,0)
render.SetBlend(1)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL)
cam.Start3D2D(pos,ang,1)
surface.SetDrawColor(math.Rand(200,255),math.Rand(200,255),math.Rand(200,255),255)
surface.DrawRect(-ScrW(),-ScrH(),ScrW()*2,ScrH()*2)
cam.End3D2D()
v:DrawModel()
render.SetStencilEnable(false)
end
end)
[/lua]
Here's what it looks like, minus the fuzzy and white part in the above code, with anything other than players:
[thumb]http://i.imgur.com/kxPRS6M.jpg[/thumb]
[thumb]http://i.imgur.com/pGuwoKk.jpg[/thumb]
[thumb]http://i.imgur.com/GKMoEx3.jpg[/thumb]
[thumb]http://i.imgur.com/Ju3SzK0.jpg[/thumb]
Garry's halos use stencils too, but with a bunch of filtering stuff to smooth it out that makes them slow. This code keeps me rocking 110 FPS with more customizability.
[editline]21st February 2013[/editline]
a bit of randomization to the alpha color of these borders could look nice too
[editline]21st February 2013[/editline]
You could make my code sample a bit better by using stenciling to remove the entity's real size from the stencil selection, again using setblend(0), before drawing the 3D2D coloring to the screen, and then not draw the player after (the player is drawn again at the end in the sample to appear over the color, but i'm suggesting to make the color only exist around the edge in the first place). It would still look the same, though, and the FPS difference is too small to be seen.[/QUOTE]
[editline]29th March 2013[/editline]
and here's a tutorial on stencils
[img]http://i.imgur.com/s2ctqme.png[/img]
[editline]29th March 2013[/editline]
the tutorial example draws 3D2D text onto a 1x1 phoenix square plate, that uses stencils in order to make the text only show up on the surface of the sign entity, clipping off at the edge, despite however many characters are being drawn in 3D2D
Sorry, you need to Log In to post a reply to this thread.