Lua Question - Overlays



  • So, I have gotten into Lua recently. Made some of my own neat little weapons for my TTT server. Started with some basic weapons simply using the SCK, then getting slightly more advanced with a special kind of grenade.

    Anyways, my next weapon is a zombie-creating gun, sort of like the Biohazard Ball. Infect someone, they become a zombie, etc. So far, its core mechanics work as intended (except for a small issue I will ask about at the end of this post), but there are details I still want to stick in that are making me scratch my head.

    As of now, I am unsure as to how to add an overlay to a single client with the specific weapon equipped. I know how to add the overlay that affects everybody on the server, but I do not want that. Simply so it affects the owner of the weapon while they have it out. Can anybody help me out here?



  • So, I have gotten into Lua recently. Made some of my own neat little weapons for my TTT server. Started with some basic weapons simply using the SCK, then getting slightly more advanced with a special kind of grenade.

    Anyways, my next weapon is a zombie-creating gun, sort of like the Biohazard Ball. Infect someone, they become a zombie, etc. So far, its core mechanics work as intended (except for a small issue I will ask about at the end of this post), but there are details I still want to stick in that are making me scratch my head.

    As of now, I am unsure as to how to add an overlay to a single client with the specific weapon equipped. I know how to add the overlay that affects everybody on the server, but I do not want that. Simply so it affects the owner of the weapon while they have it out. Can anybody help me out here?



  • Use WEAPON:DrawHUD() clientside.



  • @Benjy:

    Use WEAPON:DrawHUD() clientside.

    Okay, that solves that.

    What about resetting any of the changes made? I tried making a section function with all of the values around what looked like default, but the damned overlay never changed (on the weapon’s removal, by the way). The draw.Simple reset, the overlay did not.

    if CLIENT then
       function SWEP:DrawHUD()
       draw.SimpleText("You are a zombie! Traitors are immune to your infection!","CloseCaption_Normal",ScrW() * 0.5, ScrH() * 0.26,Color(255,30,30,255), 1, 1)
    		--hook.Add( "HUDPaint", "ZombieVision", PostProcess )
    **snip**
    end
    
    if CLIENT then
    	function SWEP:OnRemove()
    		hook.Add("HUDPaint","PostProcess",PostProcessReset)
    	end
    end
    
    function PostProcessReset()
    	local colr = {
    	["$pp_colour_addr"] = 0,
    	["$pp_colour_addb"] = 0,
    	["$pp_colour_addg"] = 0,
    	[ "$pp_colour_brightness" ] = 0,
    	[ "$pp_colour_contrast" ] = 1, 
    	[ "$pp_colour_colour" ] = 1,
    	}
    	DrawColorModify(colr)
    	DrawSharpen( 1,1 )
    	--DrawSobel ( 0 )
        DrawMaterialOverlay( "Models/effects/vol_light001", 0 )
    end
    
    function PostProcess()
    	local colr = {
    	["$pp_colour_addr"] = 1,
    	["$pp_colour_addb"] = 0,
    	["$pp_colour_addg"] = 0,
    	[ "$pp_colour_brightness" ] = 1,
    	[ "$pp_colour_contrast" ] = 1, 
    	[ "$pp_colour_colour" ] = 3.5,
    	}
    	DrawColorModify(colr)
        DrawMaterialOverlay( "models/props_combine/tprings_globe", 0 )
        DrawSharpen( 2, 5 )
    	DrawSobel( 0.8 )
    end
    

    I also eventually tried without the material overlay and just the Sharp, Sobel, and colors. Those never reset, either.



  • Things in draw and surface need to be called constantly otherwise they disappear. If you’re using HUDPaint, RenderScreenspaceEffects and overwriting postprocess methods with different hooks, you’ll want to remove the other hooks when you’re not wanting them.



  • So, would you simply add a hook.Remove line in the OnRemove() function? Trying that gave me no luck.

    My apologies if I am missing the easy solution here. I just recently started really getting into legitimate lua coding. It is exciting to see your creations enjoyed.


Log in to reply
 

6
Online

11064
Users

15297
Topics

297973
Posts

Looks like your connection to NoXiousNet was lost, please wait while we try to reconnect.