Sure, there's those two, but Skere_'s method also allows full græyscale
[URL]https://github.com/PatrickRatzow/EnhancedAvatarImage/blob/master/enhancedavatarimage.lua[/URL]
Enhanced version of AvatarImage supporting 5 different shapes:
1. Hexagon
2. Triangle
3. Circle
4. Square
5. Pentagon
Call [code]PANEL:SetType(type [int], direction [bool])[/code] on your EnhancedAvatarImage to change shape. Numbers are listed above and only hexagon (1) and triangle (2) supports a different direction.
Call [code]PANEL:ResetPanel()[/code] if you wish to recalculate the data, but this is automatically done when [code]PANEL:PerformLayout(w, h)[/code] is called or if the polygon data for your set panel is nil (haven't been calculated yet, or reset)
[QUOTE=Klaes4Zaugen;51296694]Enhanced version of AvatarImage supporting 5 different shapes:
1. Hexagon
2. Triangle
3. Circle
4. Square
5. Pentagon
[/QUOTE]
What? Why not just copy the DrawPoly example on the wiki and let the user set whatever they want as the number of vertices? Your circle code is literally just that... except there's no way to set the amount of verts
[editline]3rd November 2016[/editline]
[QUOTE=Moat;51300684]Here are some cool customizable text effects :D[/QUOTE]
The rainbow text doesn't actually go in a rainbow? Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/HSVToColor]HSVToColor[/url]
[QUOTE=MPan1;51300921]What? Why not just copy the DrawPoly example on the wiki and let the user set whatever they want as the number of vertices? Your circle code is literally just that... except there's no way to set the amount of verts[/QUOTE]
I could allow the second argument to be verts for circle, but hey circle was copy pasted from wiki.
[QUOTE=Klaes4Zaugen;51300931]I could allow the second argument to be verts for circle, but hey circle was copy pasted from wiki.[/QUOTE]
If you let the user change the amount of the vertices on the circle you let them make literally any polygon including squares, polygons, hexagons and whatever else they want without having to have tons of meaningless functions and code... just try running the circle function with a segment count of 4 to see what I mean (it should make a square)
[editline]3rd November 2016[/editline]
I think your entire code could be simplified a ton by doing this:
[CODE]
local PANEL = {}
function PANEL:Init()
self.segments = 4 -- default to square
self.avatar = vgui.Create( "AvatarImage", self )
self.avatar:SetPaintedManually( true )
end
function PANEL:CalculatePoly( w, h, seg )
local poly = {}
local x = w/2;
local y = h/2;
local radius = h/2;
table.insert( poly, { x = x, y = y } )
for i = 0, seg do
local a = math.rad( ( i / seg ) * -360 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
end
local a = math.rad( 0 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
return poly
end
function PANEL:PerformLayout()
self.avatar:SetSize( self:GetWide(), self:GetTall() )
end
function PANEL:SetPlayer( ply, size )
self.avatar:SetPlayer( ply, size )
end
function PANEL:SetSegments( seg )
self.segments = seg
end
function PANEL:Paint( w, h )
render.ClearStencil()
render.SetStencilEnable( true )
render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )
render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
render.SetStencilPassOperation( STENCILOPERATION_ZERO )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
render.SetStencilReferenceValue( 1 )
draw.NoTexture()
surface.SetDrawColor(color_white)
surface.DrawPoly( self:CalculatePoly( w, h, self.segments ) )
render.SetStencilFailOperation( STENCILOPERATION_ZERO )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilReferenceValue( 1 )
self.avatar:PaintManual()
render.SetStencilEnable( false )
render.ClearStencil()
end
vgui.Register( "EnhancedAvatarImage", PANEL )
[/CODE]
And that still lets you draw hexagons and all that if you just do panel:SetSegments(6)
That code is untested though
[editline]3rd November 2016[/editline]
I just did a quick test, and it turns out the above code works. Math can make things a whole lot simpler, you know. I pull-requested this code on your thing. Try it. It works.
[i]*cracks fingers*[/i]
I've probably posted these elsewhere but here they are.
[B]Scissor circle which works like render.SetScissorRect().[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/scissorCircle.lua[/url]
[B]Converts ACT_ enums to ACT_HL2MP_ enums.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/npc_to_hl2mp.lua[/url]
[B]Function-overriding library to reduce boilerplate code.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/hooks.lua[/url]
[B]Draws arcs.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/drawarc.lua[/url]
[B]Draws complex polygons.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/complexpoly.lua[/url]
[B]Draw a regular convex polygon.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/convexPolyDraw.lua[/url]
[B]SWEP that designates positions and angles and prints them as Lua to the console. Useful for map config.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/weapon_designator.lua[/url]
[B]Lua obfuscator which makes ugly-ass code. I didn't make this one.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/Obfuscator.lua[/url]
[B]Bullet drop for SWEPs.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/bulletdrop.lua[/url]
[B]Centered DTextEntry text. Thank you, Oubliette.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/centered_dtextentry.lua[/url]
[B]Download Materials from a URL and save them.[/B]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/cl_downloadpng.lua[/url]
[B]Stencil library.[/B]
[url]https://facepunch.com/showthread.php?t=1449800[/url]
[B]Old glon library for legacy addons.[/B]
[url]https://www.dropbox.com/s/khq18n3htrz92n4/glon.lua?dl=0[/url]
[editline]asdf[/editline]
These are standlone programs but they are SO useful:
[B]Workshop Publishing Tool. Credit to whoever made it :v:[/B]
[url]https://www.dropbox.com/sh/3rboppgbzbxqp4u/AACoHIxYsI30LsfZUcoUURU0a?dl=1[/url]
[B]Lightweight Garry's Mod SVN downloader. Also not made by me but I haven't a clue where I got it from.[/B]
[url]https://www.dropbox.com/sh/gono5huejtc3tmc/AABj08QuAnQfImbp9n4QW98Ga?dl=1[/url]
[B]Fox-Warrior's resouce.AddFile() generator. Makes a file full of resource.AddFile()'s for every file you have.[/B]
[url]https://www.dropbox.com/sh/ae6ek2nkja77dm6/AABHtyUKmNZ0M97x9Mha2cJza?dl=1[/url]
None of those links work :v:
[QUOTE=Robotboy655;51302626]None of those links work :v:[/QUOTE]
Fuck let me fix that.
EDIT
Fixed.
[QUOTE=Robotboy655;51302626]None of those links work :v:[/QUOTE]
Well, actually the last facepunch one does. :v:
[QUOTE=MPan1;51300946]If you let the user change the amount of the vertices on the circle you let them make literally any polygon including squares, polygons, hexagons and whatever else they want without having to have tons of meaningless functions and code... just try running the circle function with a segment count of 4 to see what I mean (it should make a square)
[editline]3rd November 2016[/editline]
I think your entire code could be simplified a ton by doing this:
[CODE]
local PANEL = {}
function PANEL:Init()
self.segments = 4 -- default to square
self.avatar = vgui.Create( "AvatarImage", self )
self.avatar:SetPaintedManually( true )
end
function PANEL:CalculatePoly( w, h, seg )
local poly = {}
local x = w/2;
local y = h/2;
local radius = h/2;
table.insert( poly, { x = x, y = y } )
for i = 0, seg do
local a = math.rad( ( i / seg ) * -360 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
end
local a = math.rad( 0 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
return poly
end
function PANEL:PerformLayout()
self.avatar:SetSize( self:GetWide(), self:GetTall() )
end
function PANEL:SetPlayer( ply, size )
self.avatar:SetPlayer( ply, size )
end
function PANEL:SetSegments( seg )
self.segments = seg
end
function PANEL:Paint( w, h )
render.ClearStencil()
render.SetStencilEnable( true )
render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )
render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
render.SetStencilPassOperation( STENCILOPERATION_ZERO )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
render.SetStencilReferenceValue( 1 )
draw.NoTexture()
surface.SetDrawColor(color_white)
surface.DrawPoly( self:CalculatePoly( w, h, self.segments ) )
render.SetStencilFailOperation( STENCILOPERATION_ZERO )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilReferenceValue( 1 )
self.avatar:PaintManual()
render.SetStencilEnable( false )
render.ClearStencil()
end
vgui.Register( "EnhancedAvatarImage", PANEL )
[/CODE]
And that still lets you draw hexagons and all that if you just do panel:SetSegments(6)
That code is untested though
[editline]3rd November 2016[/editline]
I just did a quick test, and it turns out the above code works. Math can make things a whole lot simpler, you know. I pull-requested this code on your thing. Try it. It works.[/QUOTE]
The squares angle is bad, also sure your version supports as many segments as you want (to a limit of around 4095 verts) but yours cant be rotated around either.
Anyway, when doing this kind of thing you should cache the poly instead of calculating every frame
Without caching:
[t]https://vgy.me/htoBR4.jpg[/t]
With caching:
[t]https://vgy.me/fSyMfF.jpg[/t]
Using 4080 segments here, which is kinda extreme but still A LOT better FPS.
[lua]
local PANEL = {}
PANEL.data = nil;
function PANEL:Init()
self.avatar = vgui.Create( "AvatarImage", self )
self.avatar:SetPaintedManually( true )
end
function PANEL:CalculatePoly( w, h, seg )
local poly = {}
local x = w/2;
local y = h/2;
local radius = h/2;
table.insert( poly, { x = x, y = y } )
for i = 0, seg do
local a = math.rad( ( i / seg ) * -360 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
end
local a = math.rad( 0 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
self.data = poly;
end
function PANEL:PerformLayout()
self.avatar:SetSize( self:GetWide(), self:GetTall() )
self:CalculatePoly(self:GetWide(), self:GetTall(), self.segments or 4)
end
function PANEL:SetPlayer( ply, size )
self.avatar:SetPlayer( ply, size )
end
function PANEL:SetSegments( seg )
self.segments = seg
self:CalculatePoly(self:GetWide(), self:GetTall(), seg)
end
function PANEL:DrawPoly(w, h)
if (self.data == nil) then
self:CalculatePoly(w, h, self.segments);
end
surface.DrawPoly(self.data);
end
function PANEL:Paint( w, h )
render.ClearStencil()
render.SetStencilEnable( true )
render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )
render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
render.SetStencilPassOperation( STENCILOPERATION_ZERO )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
render.SetStencilReferenceValue( 1 )
draw.NoTexture()
surface.SetDrawColor(color_white)
self:DrawPoly(w, h);
render.SetStencilFailOperation( STENCILOPERATION_ZERO )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilReferenceValue( 1 )
self.avatar:PaintManual()
render.SetStencilEnable( false )
render.ClearStencil()
end
vgui.Register( "EnhancedAvatarImage", PANEL )
if (IsValid(MyHUD_Avatar)) then
MyHUD_Avatar:Remove();
end
hook.Add("HUDPaint", "kektest", function()
if (!IsValid(MyHUD_Avatar)) then
MyHUD_Avatar = vgui.Create("EnhancedAvatarImage");
MyHUD_Avatar:SetSize(128, 128);
MyHUD_Avatar:SetPos(5, ScrH() / 2 - 128/2);
MyHUD_Avatar:SetPlayer(LocalPlayer(), 128);
MyHUD_Avatar:SetSegments(4080);
end
end)
[/lua]
[editline]3rd November 2016[/editline]
ugh, can't edit my post because of recaptcha for some reason..
this is a better picture of it (looking pretty much same spot)
[t]https://vgy.me/aLRn6i.jpg[/t]
If you're just using a polygon (or circle) for stenciling, you shouldn't need more than 90 points, or one per 4 degrees. It'll still look like a circle unless it's a huge one.
[QUOTE=bobbleheadbob;51302912]If you're just using a polygon (or circle) for stenciling, you shouldn't need more than 90 points, or one per 4 degrees. It'll still look like a circle unless it's a huge one.[/QUOTE]
No reasons to do bad practices, always cache data when you can. I know I was pushing it to the extreme but good practices are a very important thing in programming.
[QUOTE=Klaes4Zaugen;51304728]No reasons to do bad practices, always cache data when you can. I know I was pushing it to the extreme but good practices are a very important thing in programming.[/QUOTE]
You can't simply say "caching is always good practice" (even though in this case it is better to cache it). You may save CPU cycles, but you have the overhead now of storing things in memory that would otherwise be garbage collected. In many situations it's simply not worth it to maintain a cache.
That is true but things such as calculating lets say, 90 verts every frame with an algorithm like the circle one is probably worth those kilobytes of RAM, I just do it cuz I used to have a shittop and FPS was horrible so I learnt a lot of optimization tricks.
[QUOTE=Klaes4Zaugen;51302819]but yours cant be rotated around either.[/QUOTE]
NOW YOU'RE GETTING SERIOUS - full 360 degree rotation:
[CODE]
local PANEL = {}
AccessorFunc( PANEL, "vertices", "Vertices", FORCE_NUMBER ) // so you can call panel:SetVertices and panel:GetRotation
AccessorFunc( PANEL, "rotation", "Rotation", FORCE_NUMBER ) // so you can call panel:SetRotation and panel:GetRotation
function PANEL:Init()
self.rotation = 0
self.vertices = 4
self.avatar = vgui.Create( "AvatarImage", self )
self.avatar:SetPaintedManually( true )
end
function PANEL:CalculatePoly( w, h )
local poly = {}
local x = w/2
local y = h/2
local radius = h/2
table.insert( poly, { x = x, y = y } )
for i = 0, self.vertices do
local a = math.rad( ( i / self.vertices ) * -360 ) + self.rotation // MATHS FOR THE WIN
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
end
local a = math.rad( 0 )
table.insert( poly, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
self.data = poly
end
function PANEL:PerformLayout()
self.avatar:SetSize( self:GetWide(), self:GetTall() )
self:CalculatePoly( self:GetWide(), self:GetTall() )
end
function PANEL:SetPlayer( ply, size )
self.avatar:SetPlayer( ply, size )
end
function PANEL:DrawPoly( w, h )
if not self.data then
self:CalculatePoly( w, h );
end
surface.DrawPoly( self.data );
end
function PANEL:Paint( w, h )
render.ClearStencil()
render.SetStencilEnable( true )
render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )
render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
render.SetStencilPassOperation( STENCILOPERATION_ZERO )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
render.SetStencilReferenceValue( 1 )
draw.NoTexture()
surface.SetDrawColor(color_white)
self:DrawPoly( w, h )
render.SetStencilFailOperation( STENCILOPERATION_ZERO )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilReferenceValue( 1 )
self.avatar:PaintManual()
render.SetStencilEnable( false )
render.ClearStencil()
end
vgui.Register( "EnhancedAvatarImage", PANEL )
[/CODE]
Full 360 degree rotation just by calling PANEL:SetRotation. Yours only does it in two directions. I tried to optimize it as much as possible (such as by removing the part creating a nil variable, not actually needed)
[editline]4th November 2016[/editline]
I replaced the SetSegments thing with SetVertices so it's more understandable (by me, at least)
[editline]4th November 2016[/editline]
Pull-requested it again. Maybe you'll like this version
[editline]4th November 2016[/editline]
If you'd rather use 'or' statements to specify the value that gets used if one isn't supplied, then make sure to use the 'or' statement consistently in every part that needs it (you forgot to do it in your SetSegments and DrawPoly function in your last post)
Maybe someone will find this snippet useful, it's a third-person aim sort of thing when you right click.
[CODE]
local function OverShoulder( ply, pos, angles, fov )
if input.IsMouseDown( MOUSE_RIGHT ) then
local view = {}
view.origin = pos-( angles:Forward()*30+angles:Right()*-30 )
view.angles = angles
view.fov = fov
view.drawviewer = true
return view
end
end
hook.Add( "CalcView", "OverShoulder", OverShoulder )
[/CODE]
Made for [URL="https://facepunch.com/showthread.php?t=1542291"]this thread[/URL] which I probably misunderstood
[QUOTE=MPan1;51397753]Man, after all this time he's still stuck to his old code... what more do I have to do to convince you mate? Just test it one time and you'll find it does everything and more than your original code is able to.[/QUOTE]
Been lazy :\
simple library to draw images fetched from the web instead of hardmounted vtfs/pngs.
unlike most implementations i've seen, this one doesn't require any caching prerequisites within your code on your end.
functions: ( use in a paint hook/anywhere you could use the surface library )
[lua]draw.WebImage( url, x, y, width, height, color=Color(255,255,255) )[/lua]
steam avatars without bothering with creating a separate avatarimage panel.
[lua]draw.SteamAvatar( string steamID64, string size = "small", x, y, width, height, color=Color(255,255,255) )[/lua]
source: [url]https://github.com/bull29/b_draw-lib/blob/master/lua/autorun/client/b-draw_lib.lua[/url]
[QUOTE=Moat;51300684]Here are some cool customizable text effects :D
[/QUOTE]
Pretty late, but this is the first thing I thought of:
[vid]https://dl.dropboxusercontent.com/s/8j1eo4tldxna7p9/2016-12-10_12-00-00.mp4[/vid]
[QUOTE=VeXan;51508971]Pretty late, but this is the first thing I thought of:
:snip:[/QUOTE]
Website doesn't actually exist, I am disappointed. :(
Turn Eye Angle Degrees from 0.1 to 179.9 and -0.1 to -179.9 to just 360 degrees on the y axis.
[CODE]local angle = ply:EyeAngles().y
if angle < 0 then
angle = (180 - math.abs(angle)) + 180
end[/CODE]
[QUOTE=FlyPiggyBanks;51510214]Turn Eye Angle Degrees from 0.1 to 179.9 and -0.1 to -179.9 to just 360 degrees on the y axis.
[CODE]local angle = ply:EyeAngles().y
if angle < 0 then
angle = (180 - math.abs(angle)) + 180
end[/CODE][/QUOTE]
Why would you need to do this? [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/math/NormalizeAngle]math.NormalizeAngle[/url] and other functions in the math library return the -180 - 180 range (though none of them care what the input is), you're better off learning to work with that range.
[QUOTE=NeatNit;51511470]Why would you need to do this? [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/math/NormalizeAngle]math.NormalizeAngle[/url] and other functions in the math library return the -180 - 180 range (though none of them care what the input is), you're better off learning to work with that range.[/QUOTE]
Sometimes it's nice being able to test if one angle is greater than another or perform math without having to account for negative numbers.
[QUOTE=NeatNit;51511470]Why would you need to do this? [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/math/NormalizeAngle]math.NormalizeAngle[/url] and other functions in the math library return the -180 - 180 range (though none of them care what the input is), you're better off learning to work with that range.[/QUOTE]
If someone wants to make a visual degrees circle and they don't want -180 to 180 to show up but rather 360 degrees.
[lua]ang % 360[/lua]
I'm sorry :P
[QUOTE=NeatNit;51512345][lua]ang % 360[/lua]
I'm sorry :P[/QUOTE]
I hate you so much. Well at least the moudolo finally makes some sense for me. I never understood what use it stood.
[QUOTE=FlyPiggyBanks;51512361]I hate you so much. Well at least the moudolo finally makes some sense for me. I never understood what use it stood.[/QUOTE]
This is [b]exactly[/b] what modulo is good for - taking an arbitrary number x and saying "hey, x should always be in the range 0 <= x < 360, and if it's outside this range it should loop around" (where 360 is, of course, up to you).
Some programming languages infuriatingly define it such that negatives remain negative - so -500 % 360 = -140. This is never useful*. [url=https://www.lua.org/manual/5.1/manual.html#2.5.1]Lua's implementation[/url] is way better, it guarantees that the value will always [b]actually[/b] be in the range.
[quote]Modulo is defined as
[code]a % b == a - math.floor(a/b)*b[/code][/quote]
* it's probably useful sometimes but I haven't come across such a case
An incredibly basic aimbot (possibly the simplest):
[CODE]
hook.Add( "Think", "TrashAimbot", function()
local ply = LocalPlayer()
local trace = ply:GetEyeTrace()
if trace.HitNonWorld then
local target = trace.Entity
local eyes = target:GetAttachment(target:LookupAttachment("eyes"))
if eyes ~= nil then
ply:SetEyeAngles((eyes.Pos - ply:GetShootPos()):Angle())
end
end
end )
[/CODE]
[editline]21st December 2016[/editline]
[URL="https://facepunch.com/showthread.php?t=1546030"]Inspired by this thread[/URL]
[URL="https://facepunch.com/showthread.php?t=1547198&p=51616729&viewfull=1#post51616729"]I was asked[/URL] to post [URL="https://facepunch.com/showthread.php?t=1547198&p=51615538&viewfull=1#post51615538"]this[/URL] here.
This creates a ring that radiates from a given point, using depth and stencils.
[video]https://youtu.be/b0-kqiMuv5w[/video]
[LUA]
local echoes = echoes or {}
local echo_thickness = 75.0
local color_mask = Color(0,0,0,0)
local function drawStencilSphere( pos, ref, compare_func, radius, color, detail )
render.SetStencilReferenceValue( ref )
render.SetStencilCompareFunction( compare_func )
render.DrawSphere(pos, radius, detail, detail, color)
end
hook.Add( "PostDrawTranslucentRenderables", "PostDrawTranslucentRenderablesDrawEcho", function( )
local localplayer_pos = LocalPlayer():EyePos()
local detail = 25
local realtime = RealTime()
render.SetStencilEnable(true)
render.SetStencilPassOperation( STENCILOPERATION_KEEP )
render.SetStencilFailOperation( STENCILOPERATION_KEEP )
for i, echo in ipairs(echoes) do
local dist = echo.pos:Distance(localplayer_pos)
local opacity = ((echo.radius - (dist/2))/echo.radius) * 0.25
local p = (realtime - echo.start) / (echo.lifetime)
if p < 1.0 and opacity > 0 then
local outer_r = Lerp(p, 0, echo.radius)
local inner_r = math.max(outer_r-echo_thickness,0)
local color = echo.color
color.a = 255*opacity*math.pow(1-p, 2)
render.ClearStencil()
render.SetColorMaterial()
render.SetStencilZFailOperation( STENCILOPERATION_REPLACE )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, -outer_r, color_mask, detail ) -- big, inside-out
render.SetStencilZFailOperation( STENCILOPERATION_INCR )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, outer_r, color_mask, detail ) -- big
render.SetStencilZFailOperation( STENCILOPERATION_INCR )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, -inner_r, color_mask, detail ) -- small, inside-out
render.SetStencilZFailOperation( STENCILOPERATION_DECR )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, inner_r, color_mask, detail ) -- small
render.SetColorMaterialIgnoreZ()
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_EQUAL, -outer_r, color, detail ) -- big, inside-out
end
end
render.SetStencilEnable(false)
end)
[/LUA]
How to simulate serverside gameplay in singleplayer
[CODE]
local serverlag = 2 -- the higher, the more realistic
local pos, ang = Vector( 0, 0, 0 ), Angle( 0, 0, 0 )
hook.Add( 'CalcView', 'REALISTICGAMEPLAY', function( ply, origin, angles, fov )
if math.random( 1, serverlag ) == 1 then
pos = origin
ang = angles
end
return { origin = pos, angles = ang, fov = fov }
end )
[/CODE]
[editline]5th January 2017[/editline]
[QUOTE=MPan1;51397753]Man, after all this time he's still stuck to his old code... what more do I have to do to convince you mate?[/QUOTE]
Jesus christ i was a total cunt a few months ago, sorry everyone
Sorry, you need to Log In to post a reply to this thread.