I'm running a dedicated server. I'm no stranger to managing add-ons from a server, but I am still new with Lua, and I am having trouble with an add-on I am making to strip the HUD from a client. I figured an add-on format would make it easiest for me to simply add stuff to it and remove stuff, at a whim.
The hierarchy goes like this:
"C:\Source Dedicated Server\orangebox\garrysmod\addons\ServerScripts\lua\autorun"
**why does this have a space in the word lua? The text on here has it as one solid word.**
Here is my init.lua:
[lua]
AddCSLuaFile( "hudowner.lua" )
AddCSLuaFile( "cl_init.lua" )
[/lua]
Here is my cl_init.lua:
[lua]
include( "hudowner.lua" )
[/lua]
And my hudowner.lua:
[lua]
if CLIENT then
function hidehud(name) --For things that can be removed via this command.
for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", "CHudSquadStatus"} do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "hidehud", hidehud)
function StopDeathHUDForever() --For things that cannot be removed from script above. Since these can be changed by player, this will force what we want forever, until kills HUD is changed.
RunConsoleCommand( "hud_deathnotice_time", "0" )
end
timer.Create( "GoAwayKillHUD", 1, 0, StopDeathHUDForever)
end
[/lua]
I can put these files into the client's add-on folder and it works perfectly. I've rewritten this about 8 times over the last few hours, watching carefully what I am doing with init, cl_init, and hudowner, I can't seem to figure out why it won't load. And I can't even detect an error anywhere. I also close the server completely, dump the files in the cache folder, and open the server, since, if I remember right, that is a good thing to do when messing around with addons.
From here:
[b][url=http://wiki.garrysmod.com/?title=G.AddCSLuaFile]G.AddCSLuaFile [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
"The filename is relative to the [b]lua/[/b] directory."
I saw that to, and had it that way on the fifth rewrite. Does it have to look like this:
AddCSLuaFile( "autorun/hudowner.lua" ) ?
I had it that way and didn't work, do the slashes need to be switched with \, because that was not working either. Or, am I just being retarded and missing a folder along the way?
[QUOTE=q3k;26145083]From here:
[b][url=http://wiki.garrysmod.com/?title=G.AddCSLuaFile]G.AddCSLuaFile [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b]
"The filename is relative to the [b]lua/[/b] directory."[/QUOTE]
That wiki page isn't entirely accurate. AddCSLuaFile() uses the same path convention as include(). This is why when you make a SENT, you use AddCSLuaFile("cl_init.lua") and not AddCSLuaFile("entities/myent/cl_init.lua")
[QUOTE=Jcw87;26147063]That wiki page isn't entirely accurate. AddCSLuaFile() uses the same path convention as include(). This is why when you make a SENT, you use AddCSLuaFile("cl_init.lua") and not AddCSLuaFile("entities/myent/cl_init.lua")[/QUOTE]
I prefer to use IncludeClientFile("") on my scripts.
I appreciate the responses. I don't have the add-on working yet, but what I decided to do instead is add it to the gamemode I am making, since I know that is working right. It works correctly between the server and the client, so I know my script is at least capable of accomplishing this task. I will go over the scripts between init, cl_init, and whatever else in the gamemode, probably later tonight.
Which then leads me to another question: Will Garry's Mod allow me to write each type of module I want into individual files, or will they need to be together? Like, let's say I have init.lua and cl_init.lua told to load three files, weathercontrol.lua, hudowner.lua, and playerpermission.lua. Will all three of these need to be written into init.lua, cl_init.lua, and shared.lua? I am bad at trying to explain what I want, so please forgive me. I like the idea of being able to open the file that I want to change instead of looking through a single file that has all three in it. I don't mind doing so if I have to.
Sorry, you need to Log In to post a reply to this thread.