Addon loads on local server but not dedicated server

I managed to get my local server to automatically call my init.lua and cl_init.lua files in a new small addon I made by placing it in:


garrysmod/addons/mymod/lua/autorun/init.lua
garrysmod/addons/mymod/lua/autorun/client/cl_init.lua

However when I move this to my dedicated server it doesn’t work :frowning: Any ideas?

First of all, name your files more unquely, so they don’t get overriden by other mods.

Second of all, post the files here. Make sure you have AddCSLuaFile’d both of them.

OK thanks for the advice. “mymod” is an example, it’s not the actual name.

Here’s the code:


myLightMod/lua/autorun/init.lua


local isNight = false

function GameInitialize()
	timer.Create("lightTimer", 10, 0, function() ToggleNight() end)
end

hook.Add("Initialize", "gameInit", GameInitialize)

function ToggleNight()
	if isNight == false then
		PrintMessage(HUD_PRINTTALK, "Night has descended..")
		engine.LightStyle(0, "a")
		isNight = true
	else
		PrintMessage(HUD_PRINTTALK, "Daylight has broken..")
		engine.LightStyle(0, "z")
		isNight = false
	end
end


myLightMod/lua/autorun/client/cl_client.lua


function GameInitialize()
	timer.Create("lightTimer", 10, 0, function() Refresh() end)
end

hook.Add("Initialize", "gameInit", GameInitialize)

function Refresh()
	render.RedownloadAllLightmaps( ) 
end

(quite proud of this, doesn’t look like much but after reading all over the net that it’s “impossible” to change map lighting I managed it on my local pc)

I meant the init.lua and cl_client.lua You should rename them. Files in addons are not sandboxed and can be overridden by addons that have files with same names in them.

What you should do, is move init.lua to server/init.lua and add
AddCSLusFile(“autorun/client/cl_client.lua”)

to it.

RENAME YOUR FILES THOUGH.

( It was made possible just a year ago with GMod 13, it was impossible to do on ALL maps before )

Thanks so much for your help. It works like a charm! Addon almost complete too :slight_smile:

OK, so I’m back. I simply CANNOT get this to work on my dedi server yet it works fine locally. I’ve made a simple zombie mod with day/night cycles. There are two files like this:

addons/myLightMod/lua/autorun/sv_mylightmod.lua
addons/myLightMod/lua/autorun/cl_mylightmod.lua

sv_mylightmod.lua


AddCSLuaFile("cl_mylightmod.lua")

local isNight = false
local nightMins = 0.3
local dayMins = 0.3

local npcSpawns = {
	Vector(-719.68, 892, 70),
	Vector(-1968, 922, 70),
	Vector(-2112, -1242, 70),
	Vector(190, -1490, 75),
	Vector(879, -1138, 75),
	Vector(285, -1652, 270),
	Vector(-268, 330, 75),
	Vector(389, 920, -50),
	Vector(1422, 1005, 75),
	Vector(1360, 2305, 75),
	Vector(1383, 3871, 75),
	Vector(-1316, 3556, 75),
	Vector(985, 4212, 75),
	Vector(1540, 3533, 75)
}

local liveNpcs = {}

function GameInitialize()
	timer.Create("nightTimer", nightMins*60, 1, function() ToggleNight() end)
end

hook.Add("Initialize", "gameInitServer", GameInitialize)

function SpawnZombies()
	for key,value in pairs(npcSpawns) do
		npc = ents.Create("npc_fastzombie")
		npc:SetPos(value)
		npc:Spawn()
		npc.LoseTargetDist = 2000
		npc.SearchRadius = 2000
	
		table.insert(liveNpcs, npc)
	end
end

function RemoveZombies()
	for key,value in pairs(liveNpcs) do
		if value:IsValid() then
			value:Remove()
		end
	end
end

function ToggleNight()
	if isNight == false then
		PrintMessage(HUD_PRINTTALK, "Night has descended.. beware of the streets!")
		engine.LightStyle(0, "a")
		isNight = true
		SpawnZombies()
		timer.Create("dayTimer", dayMins*60, 1, function() ToggleDay() end)
	end
end

function ToggleDay()
	if isNight == true then
		PrintMessage(HUD_PRINTTALK, "Daylight has broken..")
		engine.LightStyle(0, "v")
		isNight = false
		RemoveZombies()
		timer.Create("nightTimer", nightMins*60, 1, function() ToggleNight() end)
	end
end

cl_mylightmod.lua


function GameInitialize()
	timer.Create("lightTimer", 3, 0, function() Refresh() end)
end

hook.Add("Initialize", "gameInitClient", GameInitialize)

function Refresh()
	render.RedownloadAllLightmaps() 
end

There are no errors in the console, nothing. It just doesn’t execute. Any help would be massively appreciated!