These two have always been a mystery to me, but have popped up frequently in pretty much any code I use as a base for something new.
AddCSLuaFile is meant to 'send an lua file to a client', but does this mean the client downloads the file, or is it equivalent to client:SendLua(file path)? Is this needed for entities, and why would this be when most entities I make only use server side commands? Where should this actually be used? Why bother making the client download it when you could just send the lua to the client when it is needed, or is this just what this does? Why not just do 'if CLIENT then' instead of it?
include is often used for shared files, but why bother with that when you could just put the file in lua/autorun? Does it copy variables created by one file to another when it executes? It doesn't make much sense to me...
Sorry if this is an obvious bunch of questions, or if they've already been answered, but I'd really like to know what to do with these!
include does exactly what it says. It includes the code from one file to another. It is quite handy for gamemodes or anywhere where autorun-ned scripts are just not cutting it.
Plugin systems. Splitting a SWEP into multiple files. etc.
AddCSLuaFile marks a file to be downloaded by clients when they join. Player:SendLua has a limit of 255 bytes. You COULD write a system that sends clientside Lua to every client and use that instead, but that has its own downsides.
You want to AddCSLuaFile all shared and clientside .lua files. If you don't, the file is never loaded on client so your "if CLIENT then" checks will never run. ( Many default file locations are marked automatically, like autorun/*.lua and autorun/client/*.lua & more )
You'd need to AddCSLuaFile for anim type entities mostly ( for them to draw and run the clientside part ).
An addendum to Robotboy's post: don't any sensitive information in shared files. Everyone who connects to the server will be sent your shared files, and they can read them. They can read your clientside files as well, but I'm mentioning shared files specifically because they can be used for serverside code.
[QUOTE=man with hat;48093180]An addendum to Robotboy's post: don't any sensitive information in shared files. Everyone who connects to the server will be sent your shared files, and they can read them. They can read your clientside files as well, but I'm mentioning shared files specifically because they can be used for serverside code.[/QUOTE]
Expanding on this, there's been a recent trend of people being 1337 haxxors and taking people clienside files and posting them everywhere else, so if you're bothered about your code getting taken by people, only put the code you need on the client.
[QUOTE=man with hat;48093180]Everyone who connects to the server can read your clientside files and shared files.[/QUOTE]
They could just decompile the addon creating and using the scripts anyway?
Sorry, you need to Log In to post a reply to this thread.