• Overwriting files?
    9 replies, posted
What's the best way to overwrite a gamemode file without replacing it? Like for instance, if I wanted to make a custom TTT hud and wanted to replace a file called "cl_hud", how would I do so?
Correct me if I'm wrong but all you gotta do is overwrite these: GAMEMODE.HUDDrawTargetID GAMEMODE.HUDDrawPickupHistory GAMEMODE.HUDPaint
Just make a hook, it goes over gamemode functions
[QUOTE=Blinkenn;51172461]Just make a hook, it goes over gamemode functions[/QUOTE] This. However, it will draw WITH the gamemode functions. To remedy that, simply utilize the HUDShouldDraw hook, specifically the ones TTT setup for situations just like this. Use that to disable all parts of the HUD you want your custom hud to overwrite, so what ever ones down here: (Most likely the SpecHUD, and InfoPanel. Maybe some others too). Return false in one of these hooks to stop that specific element from drawing. (see [url]https://wiki.garrysmod.com/page/GM/HUDShouldDraw[/url]) [QUOTE] if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTTargetID" ) then hook.Call( "HUDDrawTargetID", GAMEMODE ) end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTMStack" ) then MSTACK:Draw(client) end if (not client:Alive()) or client:Team() == TEAM_SPEC then if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTSpecHUD" ) then SpecHUDPaint(client) end return end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTRadar" ) then RADAR:Draw(client) end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTTButton" ) then TBHUD:Draw(client) end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTWSwitch" ) then WSWITCH:Draw(client) end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTVoice" ) then VOICE.Draw(client) end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTDisguise" ) then DISGUISE.Draw(client) end if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTPickupHistory" ) then hook.Call( "HUDDrawPickupHistory", GAMEMODE ) end -- Draw bottom left info panel if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTInfoPanel" ) then InfoPaint(client) end [/QUOTE]
[QUOTE=Brassx;51172497]This. However, it will draw WITH the gamemode functions. To remedy that, simply utilize the HUDShouldDraw hook, specifically the ones TTT setup for situations just like this. Use that to disable all parts of the HUD you want your custom hud to overwrite, so what ever ones down here: (Most likely the SpecHUD, and InfoPanel. Maybe some others too). Return false in one of these hooks to stop that specific element from drawing. (see [url]https://wiki.garrysmod.com/page/GM/HUDShouldDraw[/url])[/QUOTE] But.... why. You can just overwrite the actual gamemode function
GM and GAMEMODE aren't a thing when addons are loading so you need a timer.Simple to make it work.
[QUOTE=Klaes4Zaugen;51172809]GM and GAMEMODE aren't a thing when addons are loading so you need a timer.Simple to make it work.[/QUOTE] [CODE]GAMEMODE.HUDPaint = function()[/CODE]Inside a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PostGamemodeLoaded]GM:PostGamemodeLoaded[/url] hook
[QUOTE=JasonMan34;51172782]But.... why. You can just overwrite the actual gamemode function[/QUOTE] Well, if you're making a HUD specifically: If you override the gamemode function you override all other aspects of the TTT HUD that are drawn inside that function(voice, radar, weapon switch, message stacks, etc).. Unless you specifically re-add them to yours (thus duplicating it). They set up TTT to have custom ShouldDraw hooks for their hud elements, specifically for custom huds. For his HUD, he might want to only draw certain things, and not overwrite everything like Radar drawing, Weapon switch, pickups, Player voices, etc. Override the HUDPaint gamemode function, and those will no longer be rendered. Now obviously you could(and should if this is your approach) just Copy&Paste those elements in your overwritten function, but Copy&pasting those elements into your HUD addon starts to become a pain to upkeep if TTT updates and changes something related to that.. You'd have to copy and paste the new changes into your script(obviously not for the global stuff, just for what ever they change inside that function). The method I listed you will not have to do anything like that, thus making future updates as pain-free as possible.. Obviously the chances of them updating something related to it is somewhat slim, but I see no reason NOT to do it this way and avoid having to update your script at all just in case. BUT To speak more-so on his question. If you want to overwrite a file specifically(lets say not HUD related stuff, or even Gamemode hook related stuff), you can copy it, paste it in your own script and wrap it in a PostGamemodeLoaded hook(or a timer.Simple) so it runs after the gamemode has loaded. I do not advise doing things like this unless there's no way around it, as like I've said earlier, it becomes a pain to manage when they start updating the file you copied/modified.
[QUOTE]If you override the gamemode function you override all other aspects of the TTT HUD that are drawn inside that function(voice, radar, weapon switch, message stacks, etc).. Unless you specifically re-add them to yours (thus duplicating it).[/QUOTE] Many HUDs have their own functions (HUDDrawTargetID, MSTACK:Draw, RADAR:Draw, TBHUD:Draw, ...). HUDShouldDraw has to be used if you want a new Health Bar HUD. Otherwise you can just override the gamemode functions.
[QUOTE=markusmarkusz;51175743]Many HUDs have their own functions (HUDDrawTargetID, MSTACK:Draw, RADAR:Draw, TBHUD:Draw, ...). HUDShouldDraw has to be used if you want a new Health Bar HUD. Otherwise you can just override the gamemode functions.[/QUOTE] Firstly, you missed my next statement: [QUOTE]For his HUD, he might want to only draw certain things, and not overwrite everything like Radar drawing, Weapon switch, pickups, Player voices, etc. Override the HUDPaint gamemode function, and those will no longer be rendered.[/QUOTE] Yes many HUDs have their own functions, and that's fine. You used to have to overwrite the gamemode function. But I don't think you understand, they can easily have those without replacing the gamemode functions, there's literally no reason to replace the gamemode functions now that there are ways to stop the TTT stuff from rendering at all.. Say they decide to add a new HUD element to TTT(I know it wont happen) and place it in their HUDPaint gamemode function.. You'll need to update your addon if you wish to allow the new element, easy to do yes, but especially if your HUD is a public addon, it's easily avoided.. Just a possible situation that can be avoided by designing your HUD around something that's just as easy to setup, and has no noticeable performance impact... HUDShouldDraw can literally be used to disable very specific parts, or even all of the TTT HUD elements now, and should be used. It's much more 'graceful' than overwriting cl_hud.lua directly. [CODE] local dis = {"TTTInfoPanel", "TTTSpecHUD", "TTTWSwitch"}; hook.Add("HUDShouldDraw", "disable_ttt_huds", function(name) for k, v in pairs(dis) do if (v == name) then return false; end end end) [/CODE] That's all you need to do to disable what most HUDs use the most. While keeping the old radar, weapon pickups, target ID's, etc. You can still EASILY disable those too, and make your very own through the same method.. See: [url]https://github.com/garrynewman/garrysmod/pull/868[/url]
Sorry, you need to Log In to post a reply to this thread.