Need some help with making a Material's tool

Hello guys.
I want to make a new tool. Nothing complicated. Just Materials Tool, separate from original Gmod’s Materials Tool.
I added some materials to the original tool so far by making folder “lua” and folder “autorun” inside along with materials folder.
Using these commands:


list.Add( "OverrideMaterials", "Textures/Water" )

                                                                           ^ Example

But now I want completely separate tool, name it My Materials (for example) and store everything there.
I need to know which folders need to be created and what .lua file should contain.
I would be very grateful for your help.
Good day!

Like this ?



TOOL.Category = "Render"
TOOL.Name = "#tool.mymaterials.name"

function TOOL:LeftClick()
-- Script
end


weapons/gmod_tool/stools/mymaterials.lua
create these in “addons” folder (garrysmod/addons/(mymaterials))

And what should be in that lua file?
The same lines which I posted in my example? (list.Add( “OverrideMaterials”, “Textures/Water” )

This.

No. You will need to do more than your example.
If you know how to add materials in the materials stools, you should be able to search yourself how to make it working.

Unfortunately no. Talking in English is hard, not to mention about finding anything as I do not know the whole terminology, so I asked you, on this phorum. If I could find anything myself I wouldn’t bother you guys.
So far I know I have to make the folders, I’ve got some lua code lines sent by you. Far simple for now.
But when I try to add materials path to that lua file it’s not working. I guess more folders are needed or even more lua files including other lines, right?

No.

Here a complete material tool (picked from original), You should now understand a bit how you can do it:


TOOL.Category = "Render"
TOOL.Name = "#tool.material.name"

TOOL.ClientConVar[ "override" ] = "debug/env_cubemap_model"

--
-- Duplicator function
--
local function SetMaterial( Player, Entity, Data )
	
	if ( SERVER ) then

		--
		-- Make sure this is in the 'allowed' list in multiplayer - to stop people using exploits
		--
		if ( !game.SinglePlayer() && !list.Contains( "OverrideMaterials", Data.MaterialOverride ) && Data.MaterialOverride != "" ) then return end

		Entity:SetMaterial( Data.MaterialOverride )
		duplicator.StoreEntityModifier( Entity, "material", Data )
	end

	return true

end
duplicator.RegisterEntityModifier( "material", SetMaterial )

--
-- Left click applies the current material
--
function TOOL:LeftClick( trace )

	if ( !IsValid( trace.Entity ) ) then return end

	if ( CLIENT ) then return true end
	
	local ent = trace.Entity
	if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end

	local mat = self:GetClientInfo( "override" )
	SetMaterial( self:GetOwner(), ent, { MaterialOverride = mat } )
	return true

end

--
-- Right click reverts the material
--
function TOOL:RightClick( trace )

	if ( !IsValid( trace.Entity ) ) then return end

	if ( CLIENT ) then return true end
	
	local ent = trace.Entity
	if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end

	SetMaterial( self:GetOwner(), ent, { MaterialOverride = "" } )
	return true

end

if ( IsMounted( "tf" ) ) then
	list.Add( "OverrideMaterials", "models/player/shared/gold_player" )
	list.Add( "OverrideMaterials", "models/player/shared/ice_player" )
end

list.Add( "OverrideMaterials", "models/wireframe" )
list.Add( "OverrideMaterials", "debug/env_cubemap_model" )
list.Add( "OverrideMaterials", "models/shadertest/shader3" )
list.Add( "OverrideMaterials", "models/shadertest/shader4" )
list.Add( "OverrideMaterials", "models/shadertest/shader5" )
list.Add( "OverrideMaterials", "models/shiny" )
list.Add( "OverrideMaterials", "models/debug/debugwhite" )
list.Add( "OverrideMaterials", "Models/effects/comball_sphere" )
list.Add( "OverrideMaterials", "Models/effects/comball_tape" )
list.Add( "OverrideMaterials", "Models/effects/splodearc_sheet" )
list.Add( "OverrideMaterials", "Models/effects/vol_light001" )
list.Add( "OverrideMaterials", "models/props_combine/stasisshield_sheet" )
list.Add( "OverrideMaterials", "models/props_combine/portalball001_sheet" )
list.Add( "OverrideMaterials", "models/props_combine/com_shield001a" )
list.Add( "OverrideMaterials", "models/props_c17/frostedglass_01a" )
list.Add( "OverrideMaterials", "models/props_lab/Tank_Glass001" )
list.Add( "OverrideMaterials", "models/props_combine/tprings_globe" )
list.Add( "OverrideMaterials", "models/rendertarget" )
list.Add( "OverrideMaterials", "models/screenspace" )
list.Add( "OverrideMaterials", "brick/brick_model" )
list.Add( "OverrideMaterials", "models/props_pipes/GutterMetal01a" )
list.Add( "OverrideMaterials", "models/props_pipes/Pipesystem01a_skin3" )
list.Add( "OverrideMaterials", "models/props_wasteland/wood_fence01a" )
list.Add( "OverrideMaterials", "models/props_foliage/tree_deciduous_01a_trunk" )
list.Add( "OverrideMaterials", "models/props_c17/FurnitureFabric003a" )
list.Add( "OverrideMaterials", "models/props_c17/FurnitureMetal001a" )
list.Add( "OverrideMaterials", "models/props_c17/paper01" )
list.Add( "OverrideMaterials", "models/flesh" )

-- phx
list.Add( "OverrideMaterials", "phoenix_storms/metalset_1-2" )
list.Add( "OverrideMaterials", "phoenix_storms/metalfloor_2-3" )
list.Add( "OverrideMaterials", "phoenix_storms/plastic" )
list.Add( "OverrideMaterials", "phoenix_storms/wood" )
list.Add( "OverrideMaterials", "phoenix_storms/bluemetal" )
list.Add( "OverrideMaterials", "phoenix_storms/cube" )
list.Add( "OverrideMaterials", "phoenix_storms/dome" )
list.Add( "OverrideMaterials", "phoenix_storms/gear" )
list.Add( "OverrideMaterials", "phoenix_storms/stripes" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_green" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_red" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_blue" )

list.Add( "OverrideMaterials", "hunter/myplastic" )
list.Add( "OverrideMaterials", "models/XQM/LightLinesRed_tool" )

function TOOL.BuildCPanel( CPanel )

	CPanel:AddControl( "Header", { Description = "#tool.material.help" } )

	CPanel:MatSelect( "material_override", list.Get( "OverrideMaterials" ), true, 64, 64 )

end



Nice. Thank You so much! Now I can try new things myself! :smiley:

You’re welcome.

Well, looks like I said that too fast. I can’t do nothing because I don’t even have that tool on my tools list. I tried everything. I made the folders just like you showed. I was trying to change the tool name and category several times. And there is no tool.

Did you put in the script this ?


TOOL.Category = "Render"
TOOL.Name = "#tool.material.name"

If this is the case, change this to:


TOOL.Category = "Render"
TOOL.Name = "#tool.mymaterials.name"

This is how it looks:


TOOL.Category = "Render"
TOOL.Name = "#tool.mymaterials.name"

function TOOL:LeftClick()
-- Script
end

I did it already and it’s not working. I can’t see the tool in the Render tab. Only Gmod’s Materials one. Other tabs still the same as they were.

I tried also copy all the lines from original Materials tool lua and change the tool’s name, but I can’t see the tool on the list either way.

And this ?


TOOL.Category = "Kaktus47"
TOOL.Name = "#tool.mymaterials.name"

if CLIENT then
language.Add("tool.mymaterials.name","My Materials")
language.Add("tool.mymaterials.name","My Materials")
language.Add("tool.mymaterials.desc","A replication of official materials tool!")
language.Add("tool.mymaterials.0","Same controls")
end

function TOOL:LeftClick()
end



I think I’m sure you didn’t put the lua file in the correct folder as I said.
Here a example, it should be like this:

(Steam)/garrysmod/addons/mymaterials/lua/weapons/gmod_tool/stools/
And in “stools” folder: mymaterials.lua (ONLY!)

It works man, it works. Finally. I started with “weapons” folder instead of “lua”. I’ve got the tool already working ingame. But that’s not all, unfortunately.
Still some problems, but I guess only some lines in the lua file should be changed. I hope you can help me with that one too.
First of all, no matter which material I will choose and apply it, the material will be changed to env_cubemap_model. Definitely it’s this line:


TOOL.ClientConVar[ "override" ] = "debug/env_cubemap_model"

But when I tried to get rid of that line, the tool stopped working, I couldn’t change material completely.
The second problem is that my tool contains materials from original Gmod’s tool, even when there are no responsible lines in my file, and vice versa, original tool has my materials. Do you know how to solve these 2 things? Man thanks in advance. You helped me a lot so far.

Someone? Help me please. Why my materials are changed to env_cubemap_model if I copied everything from original file except the materials. It should work then.

Be sure there no list.Add.


if ( IsMounted( "tf" ) ) then
	list.Add( "OverrideMaterials", "models/player/shared/gold_player" )
	list.Add( "OverrideMaterials", "models/player/shared/ice_player" )
end

list.Add( "OverrideMaterials", "models/wireframe" )
list.Add( "OverrideMaterials", "debug/env_cubemap_model" )
list.Add( "OverrideMaterials", "models/shadertest/shader3" )
list.Add( "OverrideMaterials", "models/shadertest/shader4" )
list.Add( "OverrideMaterials", "models/shadertest/shader5" )
list.Add( "OverrideMaterials", "models/shiny" )
list.Add( "OverrideMaterials", "models/debug/debugwhite" )
list.Add( "OverrideMaterials", "Models/effects/comball_sphere" )
list.Add( "OverrideMaterials", "Models/effects/comball_tape" )
list.Add( "OverrideMaterials", "Models/effects/splodearc_sheet" )
list.Add( "OverrideMaterials", "Models/effects/vol_light001" )
list.Add( "OverrideMaterials", "models/props_combine/stasisshield_sheet" )
list.Add( "OverrideMaterials", "models/props_combine/portalball001_sheet" )
list.Add( "OverrideMaterials", "models/props_combine/com_shield001a" )
list.Add( "OverrideMaterials", "models/props_c17/frostedglass_01a" )
list.Add( "OverrideMaterials", "models/props_lab/Tank_Glass001" )
list.Add( "OverrideMaterials", "models/props_combine/tprings_globe" )
list.Add( "OverrideMaterials", "models/rendertarget" )
list.Add( "OverrideMaterials", "models/screenspace" )
list.Add( "OverrideMaterials", "brick/brick_model" )
list.Add( "OverrideMaterials", "models/props_pipes/GutterMetal01a" )
list.Add( "OverrideMaterials", "models/props_pipes/Pipesystem01a_skin3" )
list.Add( "OverrideMaterials", "models/props_wasteland/wood_fence01a" )
list.Add( "OverrideMaterials", "models/props_foliage/tree_deciduous_01a_trunk" )
list.Add( "OverrideMaterials", "models/props_c17/FurnitureFabric003a" )
list.Add( "OverrideMaterials", "models/props_c17/FurnitureMetal001a" )
list.Add( "OverrideMaterials", "models/props_c17/paper01" )
list.Add( "OverrideMaterials", "models/flesh" )

-- phx
list.Add( "OverrideMaterials", "phoenix_storms/metalset_1-2" )
list.Add( "OverrideMaterials", "phoenix_storms/metalfloor_2-3" )
list.Add( "OverrideMaterials", "phoenix_storms/plastic" )
list.Add( "OverrideMaterials", "phoenix_storms/wood" )
list.Add( "OverrideMaterials", "phoenix_storms/bluemetal" )
list.Add( "OverrideMaterials", "phoenix_storms/cube" )
list.Add( "OverrideMaterials", "phoenix_storms/dome" )
list.Add( "OverrideMaterials", "phoenix_storms/gear" )
list.Add( "OverrideMaterials", "phoenix_storms/stripes" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_green" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_red" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_blue" )

list.Add( "OverrideMaterials", "hunter/myplastic" )
list.Add( "OverrideMaterials", "models/XQM/LightLinesRed_tool" )

If you want only the materials that are from you and not by default, use this instead:


TOOL.Category = "Kaktus47"
TOOL.Name = "#tool.mymaterials.name"

if CLIENT then
language.Add("tool.mymaterials.name","My Materials")
language.Add("tool.mymaterials.name","My Materials")
language.Add("tool.mymaterials.desc","A replication of official materials tool!")
language.Add("tool.mymaterials.0","Same controls")
end

--
-- Duplicator function
--
local function SetMaterial( Player, Entity, Data )
	
	if ( SERVER ) then

		--
		-- Make sure this is in the 'allowed' list in multiplayer - to stop people using exploits
		--
		if ( !game.SinglePlayer() && !list.Contains( "OverrideMaterialsMYMATERIALS", Data.MaterialOverride ) && Data.MaterialOverride != "" ) then return end

		Entity:SetMaterial( Data.MaterialOverride )
		duplicator.StoreEntityModifier( Entity, "material", Data )
	end

	return true

end
duplicator.RegisterEntityModifier( "material", SetMaterial )

--
-- Left click applies the current material
--
function TOOL:LeftClick( trace )

	if ( !IsValid( trace.Entity ) ) then return end

	if ( CLIENT ) then return true end
	
	local ent = trace.Entity
	if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end

	local mat = self:GetClientInfo( "override" )
	SetMaterial( self:GetOwner(), ent, { MaterialOverride = mat } )
	return true

end

--
-- Right click reverts the material
--
function TOOL:RightClick( trace )

	if ( !IsValid( trace.Entity ) ) then return end

	if ( CLIENT ) then return true end
	
	local ent = trace.Entity
	if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end

	SetMaterial( self:GetOwner(), ent, { MaterialOverride = "" } )
	return true

end

list.Add( "OverrideMaterialsMYMATERIALS", "models/props_c17/FurnitureMetal001a" )

function TOOL.BuildCPanel( CPanel )

	CPanel:AddControl( "Header", { Description = "#tool.mymaterials.help" } )

	CPanel:MatSelect( "material_override", list.Get( "OverrideMaterialsMYMATERIALS" ), true, 64, 64 )

end

Man, you’re Angel! You deserve a BIG BEER!
The list is working properly now! Only my, no combined materials.
But there is one last problem with overriding I told before. Changing materials is not working. :frowning:


TOOL.Category = "Kaktus47"
TOOL.Name = "#tool.mymaterials.name"



if CLIENT then
language.Add("tool.mymaterials.name","My Materials")
language.Add("tool.mymaterials.name","My Materials")
language.Add("tool.mymaterials.desc","A replication of official materials tool!")
language.Add("tool.mymaterials.0","Left click applies the current material, Right click reverts it")
end

Between these first two lines and “if CLIENT then” must be something. In original materials tool there is:


TOOL.ClientConVar[ "override" ] = "debug/env_cubemap_model"

And materials are changing whatever you want.
When I delete this line in my tool materials won’t change, but if I keep it, ale materials will be env_cubemap_model. I don’t understand this, completely. In original tool this is working, but not here. Any ideas for that one?

Man please, just this one more thing, everything is nearly done. Why the material don’t work without this line, and are changed to env_cubemap when the line is present?

The only solution, keep the TOOL.ClientConVar[“override”] = “debug/env_cubemap_model”.
(Don’t forget to change all things that is related to “override” and convert those to “overrideMYMATERIALS”, it could conflict with the official tool)
Be sure you have clicked on your materials you want in the stools.

Then, it should works, else, I think there no ways to do it (or yes but you will need to change everything to harder functions).

You forgot to change “material_override” to “mymaterial_override” in TOOL.BuildCPanel.

Great! Thank You both! The tool is working. Finally! I wouldn’t do that myself. I didn’t know that some of the lines can be changed, that they are no strict.
I’m gonna release my materials in a brand new tool on the Workshop :slight_smile: