Snow Script Glitchy?

Hey, I was testing a really old script yesterday and got some really weird results:



local REPLACING_TEXTURES = {
	// Grass, Fields, etc.. 
	//"ajacks/ajacks_grass01", "nature/forest_grass_01", "nature/forest_dirt_01", // "nature/grassfloor001a", //"nature/dirtfloor006a",
	//"nature/dirt02", "nature/dirtfloor002a", "nature/dirtfloor004a", "nature/dirtfloor012a", "nature/forest_dirt_02", "nature/forest_dirt_04",
	//"nature/grasslawn_dry01", "nature/milground005", "de_aztec/ground01grass", "de_cbble/grassfloor01", //"de_cbble/grassfloor001a",
	//"de_cbble/grassfloor002a", "de_cbble/grassfloor003a", "de_cbble/grassfloor004a", "de_cbble/grounddirt", "de_tides/tides_grass_a",
	//"de_train/train_grass_floor_01", "nature/blendgrassgravel001b", "nature/blenddirtgrass00", "nature/blendcliffgrass001a",
	//"nature/blendgrassgravel001a", "NATURE/BLENDDIRTGRASS008A",  "DE_TIDES/TIDES_DIRT", "nature/blendgraveldirt01", "nature/blendgrassdirt01",
	//"nature/blendgrassdirt02_noprop", "nature/blendgrassdirt01_noprop", "nature/blenddirtlawn01", "nature/blendpavedirt01", //"nature/blendrassdirt001a", 
	//"nature/blendgrassgravel01", "nature/forest_grass_01", //"nature/blendgrassgrass001a",
	
	// Road Textures
	"sgtsicktextures/gunroad_01", "sgtsicktextures/gunroad_02", "sgtsicktextures/gunroad_03", "sgtsicktextures/gunroad_04", "sgtsicktextures/sicknessroad_01",
	"sgtsicktextures/sicknessroad_02", "de_cbble/cobbleroad01", "ajacks/ajacks_road2", "ajacks/ajacks_road4", "ajacks/ajacks_road5", "ajacks/ajacks_road7",
	"ajacks/ajacks_road8", "ajacks/ajacks_10", "ajacks/ajacks_road6", "ajacks/ajacks_road7", "ajacks/ajacks_road1", "ajacks/ajacks_road3",
	
	// Parking lots, sidewalks
	"de_train/train_cementwear_01", "concrete/concretefloor_bunker01a", "de_nuke/nukfloorc", "cs_assault/pavement001a", "concrete/concretefloor011a", 
	"HIGHRISE/SE1_CEMENT_OFFICE_FLOOR_01", "CONCRETE/CONCRETEFLOOR038A", "CONCRETE/CONCRETEFLOOR037A", "de_train/train_cement_floor_02", "CONCRETE/CONCRETEFLOOR024A",
	"de_train/train_cement_floor_01", "STONE/INFFLRC", "CONCRETE/CURBREDA", "concrete/concretefloor027a", "concrete/concretefloor027b",
	"concrete/concretefloor031a", "stone/stonefloor_inn01", "concrete/concretefloor001a", "stone/stonefloor011a", "concrete/concretefloor006a",
	"nature/gravelfloor003a", "maps/rp_evocity_v3x/bridge/se1_concrete_flat_01_3088_-7809_218", "maps/rp_evocity_v3x/bridge/se1_concrete_flat_01_10142_14229_123", "maps/rp_evocity_v3x/bridge/se1_concrete_flat_01_3498_4227_126", 
	 
	// Misc 
	"PROPS/RUBBERROOF002A", "nature/cliffface001a", "models/props_wasteland/rockcliff02a", "models/props_wasteland/rockcliff0", "DE_PRODIGY/METAL01",
	"BUILDING_TEMPLATE/ROOF_TEMPLATE001A", "WOOD/MILROOF001", "WAREHOUSE/SE1_METAL_ROOF_CORRUG_04", "DE_NUKE/NUKROOF01", "DE_TIDES/TIDES_ROOF_1",
	"WOOD/WOODSHINGLES002A", "de_nuke/nukroofa", "metal/metalgrate004a", "concrete/concretefloor009a", "concrete/curba",
	"concrete/prodflra", "de_cbble/covvleroad01", "tile/grey01", "tile/grey04", "toronto/pavement/concrete_tile/pavement_tile_01", 
	"toronto/pavement/concrete_tile/pavement_tile_02", "de_ties/tides_floosr_cobble_1", "perps/tarpaperroof002a",
	"maps/rp_evocity_v8x/nature/blendgrassdirt02_noprop_wvt_patch", "nature/blendgrassdirt02_noprop_wvt_patch", "de_tides/tides_floor_stone_1", "stone/infflrd_blend_dirt",
	"concrete/concretefloor023a", "srp/metal/roof_metal_medium01", "wood/milroof005", "buildings/asph_shingles01", "maps/rp_evocity_v3x/tile/tileroof004b_-2877_-5493_262", 
	"maps/rp_evocity_v3x/tile/tileroof004b_-2770_-7024_262", "metal/milwall002", "maps/rp_evocity_v3x/tile/tileroof004b_-2893_-6215_262", "maps/rp_evocity_v3x/tile/tileroof004b_3088_-7809_218", "metal/milroof002",
	"maps/rp_evocity_v3x/nature/blendgrassgravel001a_wvt_patch", "maps/rp_evocity_v3x/metal/metalroof005a_-3404_11999_241", "concrete/prodroofa", "labs/se1_cement_lab_floor_02", "metal/metalwall026a",
	"maps/rp_evocity_v3x/cs_assault/pavement001a_-7835_-10036_144", "maps/rp_evocity_v3x/cs_assault/pavement001a_-8124_-10028_144", "maps/rp_evocity_v3x/cs_assault/pavement001a_-9310_-9239_200", "maps/rp_evocity_v3x/cs_assault/pavement001a_3498_4227_126", "maps/rp_evocity_v3x/cs_assault/pavement001a_-6806_-7527_137",
	"maps/rp_evocity_v3x/cs_assault/pavement001a_-6702_-7698_137", "maps/rp_evocity_v3x/cs_assault/pavement001a_-9368_-8601_200", "customtext/gc textures/blends/grass_dirt_blend04", "nature/blendgrassdirt001a", "ajacks/ajacks_grass01",
	"maps/rp_evocity_v2pdless/DE_TRAIN/TRAIN_CEMENTWEAR_01", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_-8124_-10028_144", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_-7835_-10036_144", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_-6806_-7527_137", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_-9368_-8601_200",
	"maps/rp_evocity_v2pdless/cs_assault/pavement001a_-6925_-4674_133", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_3250_4088_126", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_3498_4227_126", "maps/rp_evocity_v2pdless/metal/metalroof005a_3637_3853_126", "maps/rp_evocity_v2pdless/cs_assault/pavement001a_-6702_-7698_137",
	"maps/rp_evocity_v2pdless/cs_assault/pavement001a_-9310_-9239_200", "cs_havana/swampground01a", "hall_concrete/hall_concrete11_wet", "buildings/roof07", "buildings/roof08",
	"metal/metalwall017a", 	"metal/metalwall026a", "warehouse/se1_metal_corrugated_04b", "props/tarpaperroof002a", "warehouse/se1_concrete_sidewalk_02",
	"cs_italy/cobble03","cs_italy/cobble04","models/cs_havana/gazebo", "de_tides/tides_floor_cobble_1", "wood/shingles004",
	"wood/shingles006", "sgtsicktextures/bk_shingles01"
};
							
							

function EnableSnow ( )
	if ( GAMEMODE.SnowOnGround ) then return; end
	GAMEMODE.SnowOnGround = true;
	LastSnowChange = CurTime()
	
	for k, v in pairs(REPLACING_TEXTURES) do
		if (v[1] && v[3]) then
			v[1]:SetTexture("$basetexture", v[3]);
			
			if (v[4]) then
				v[1]:SetTexture("$basetexture2", v[4]);
			end
		end
	end
end
concommand.Add("dev_snow_on", EnableSnow);

local function DisableSnow ( )
	GAMEMODE.SnowOnGround = false;
	
	for k, v in pairs(REPLACING_TEXTURES) do
		v[1]:SetTexture("$basetexture", v[2]);
		
		if (v[4]) then
			v[1]:SetTexture("$basetexture", v[4]);
		end
	end
end
concommand.Add("dev_snow_off", DisableSnow);

local function BuildSnowMaterials ( )
	for k, v in pairs(REPLACING_TEXTURES) do
		local useName = v
		local newTable = {};
		if (type(v) != "string") then
			useName = v[1]
			newTable[4] = Material("nature/snowfloor001a"):GetTexture("$basetexture2");
		end
		//   nature/snowfloor001a acrp/snow/acecools_snowb
		local defaultSnowMaterial = Material("nature/snowfloor001a"):GetTexture("$basetexture");
		
		newTable[1] = Material(useName);
		
		local snowName = "textures/snow/" .. string.GetFileFromFilename(useName);
		
		if file.Exists("materials/" .. snowName .. ".vmt", "GAME") then
			newTable[3] = Material(snowName):GetTexture("$basetexture");
		else
			newTable[3] = defaultSnowMaterial;
		end

		
		newTable[2] = newTable[1]:GetTexture("$basetexture");
		
		REPLACING_TEXTURES[k] = newTable;
	end
end
hook.Add("Initialize", "BuildSnowMaterials", BuildSnowMaterials);
concommand.Add("enablesnow", BuildSnowMaterials)


When a user joins and types “enablesnow” they get this lua error:



gamemodes/perp/gamemode/cl_modules/weather.lua:88: bad argument #1 to 'Material' (string expected, got userdata)
  1. Material - [C]:-1
   2. unknown - gamemodes/perp/gamemode/cl_modules/weather.lua:88
    3. unknown - lua/includes/modules/concommand.lua:69


However, if I save the file, (while the user is connected.) and they type in the command again, it works fine, builds the textures and allows them to toggle the snow on/off.
If the user just types dev_snow_on without building the materials, it throws in completly random textures instead of snow.

That is an old version of an update to HZ Perp code I finished; same concommand names and everything else. Where’d you get it?

Hah, just realized there’s a comment left in it as well.
In the BuildSnowMaterials:


//   nature/snowfloor001a acrp/snow/acecools_snowb

I spoke to Video about it; he’s on my friends list… He says he’s using perp to learn, if I recall correctly… or is using it to learn mechanics.

Honestly, it isn’t a good idea… It is private code, so it is a leaked copy plus extracted cache. PERP isn’t something you’d want to learn on because the code is all over the place, the moral issues, etc…

If you want a blank dev game-mode to use / test things on, learn mechanics, etc… I can teach you, but drop perp please…

This will have a ton of new functions and other things VERY soon ( SQL Query builder is done, but I am looking into adding a few examples and database structures from simple to complex with examples of how to build queries for them. I’ll also be adding support for Pivot Table / Cross Tab which should convert row data into “columns” in a query so that a table can be simplified, with very minimal repeats… Essentially an accounts table can have the basic stuff, another table can have numbers / ids and a value for extended column data which is optional, and a 3rd can have the enumeration / the actual string key and with 1 query build it properly… Still testing this )…

So if you want to learn, I’ll teach, but you’d have to drop using any / all leaked code.

Here’s my skeletonized dev-base which makes things a lot easier to make a game-mode. A lot of new content is right around the corner.
If you want something to make development easier: Please look into AcecoolDev_Base, a skeletonized-developer-base game-mode which features an autoloader ( to ignore ever needing to use include or AddCSLuaFile ever again, plus a range of useful console commands to force the game-mode to refresh “loadgm”, and to easily changelevel “relevel/remap <Current Map OR optionally mapname> <Current GM OR optionally gamemode>” ), many new and useful hooks, many helper-functions, many metatable “classes”, and much more.

My networking system ( lightweight version ) will be included in the near future along with a few other nice surprises.

It is recommended that you use a form of GIT/SVN software to allow for easy updating.
Src: https://bitbucket.org/Acecool/acecooldev_base/src/
Issue-Tracker: https://bitbucket.org/Acecool/acecooldev_base/issues/
Pull-Requests: https://bitbucket.org/Acecool/acecooldev_base/pull-requests/
Wiki: https://bitbucket.org/Acecool/acecooldev_base/wiki/Home/

Thanks for understanding, and for this <3