Deriving from Sandbox - am I doing it wrong?


I’m working on a gamemode together with Vioxtar, which is based HEAVILY on sandbox. So, logically, we’re deriving from sandbox. This has served very useful (we make extensive use of the CanTool hook, for example), but has also posed several obstacles. For example, we want to remove all tabs except Spawnmenu from the spawn menu (i.e. Entities, Vehicles, Saves, Dupes). After a lot of tinkering, I finally managed to do it, and I even removed the NPCs menu at the top bar:

in cl_init.lua (or an included file therein):

local t = spawnmenu.GetCreationTabs()

for k in pairs(t) do
	if k != "#spawnmenu.content_tab" then t[k] = nil end	-- allow only the props tab

hook.Remove("PopulateMenuBar", "NPCOptions_MenuBar")	-- NPCs menu on the top of the screen holding C

This feels pretty bad though… I never prevent the tabs from being created, I just remove them before they get made use of for building the menu. Also, it’s sort of ‘abusing’ the fact that tables are pointers, this is clearly not the intended use of GetCreationTabs. I would prefer to have them not even be there in the first place, similar to how I prevent the NPCs menu. Is there a ‘correct’ way to do this?

The other problem I’m running into is disabling some of the default tools and removing them from the menu. I tried the same approach as I did with the creation tabs, but it doesn’t seem to be working quite the same way. No luck on this one yet.

This code is ugly and wrong. don’t look at it please.

local allowedtools = {
axis = true,
weld = true,
camera = true,

hook.Add("AddToolMenuCategories", "sgbhasbdkfsb", function() 
	local t = spawnmenu.GetTools()
	// PrintTable(t)
	for tab, tabdat in pairs(t) do
		if tabdat.Name != "AAAAAAA_Main" then print(tabdat.Name) else
			for category, catdat in pairs(tabdat.Items) do
				for tool, toolinfo in pairs(catdat) do
					if isnumber(tool) && !allowedtools[toolinfo.ItemName] then catdat[tool] = nil end
				if #catdat == 0 then tabdat[category] = nil end
end )

So this is really starting to make me feel like I SHOULDN’T be deriving from Sandbox. But what’s my other alternative? Derive from base and copy-paste all the stuff I want from sandbox? That sounds WAY worse. I want a TON of stuff from sandbox.

Am I doing something wrong?

I’ve been there. It is painful. I don’t have a quick answer for you.

Changing sandbox is override city. I’d be sorely tempted to make my own, but I’d do it by copying the entire sandbox gamemode folder as a new gamemode and massively editing it.

sigh… That’s what I thought. :suicide:

Thanks for the advice. Seeing as how I’ve already managed to override everything I need (that I can think of) except hiding tools, I’m going to dig deeper into that and see what I can come up with.

If you ask me, I think sandbox should be made far more derivable for other gamemodes, but needless to say that would take a LOT of work.

If I don’t manage to hide tools - screw it, I’ll leave them in. It beats completely rewriting half my code to work with a copy-pasted sandbox rather than a derived one, and it’s (hopefully) more future-proof because any update sandbox gets will automatically apply to my derived gamemode as well. Hopefully for the better and not for the worse…