Where do I use resource.AddFile()?

I know how to use it, but what file do I put it in?
Is it possible to make another Lua file and put all of the resource.AddFile() instances in that file? If it is possible, then how do I do this?

this is the Garrysmod LUA documentation page on the subject:
**[Resource.AddFile

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Resource.AddFile)**

Create a lua file named “resources.lua” and put it in autorun/server and you can put all of your resource.AddFiles() in it.

you do not add the function to init.lua?

If you are making a gamemode, you can make a seperate file in your gamemode folder for the resource.AddFiles and **[G.include

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.include)** it in your init.lua.

What if it is a simple Addon?
I’m kind of new to Lua, so I do not know how to create an addon, I have usually just made files in the garrysmod/lua folder.

Then you put it in “garrysmod/addons/youraddonname/lua/autorun/server/” and you don’t have to include it anywhere.

If you do that, then don’t forget to make an info.txt at “garrysmod/addons/youraddonname/”

one more simple question relating to most lua code:
what does


for k, v in pairs () do
--code
end

do?

Loops through the table passed to pairs assigning each key to k and each value to v. For example:-

[lua]local table = {
a = 1,
b = 2,
c = 3
}

for k, v in pairs(table) do
print(k, v)
end[/lua]

output:


a    1
b    2
c    3

[lua]local mytable = {}

mytable[“Key”] = “Value”
mytable[“Hax”] = 0

for key , value in pairs(mytable) do – This instanciates key to the table key you are looking at, and value to the value of that table key.
print(key , value)
end
[/lua]

:ninja:'d

would this script work, or does it need anyhting else?


if (SERVER) then
	AddCSLuaFile("autorun/autorun,lua")
	for k, v in pairs(file.Find("../models/example/*")) do
		resource.AddFile("models/example/" .. v)
	end
	for k, v in pairs(file.Find("../materials/models/example/*")) do
		resource.AddFile("materials/models/example/" .. v)
	end
end

can this be shortened so that the for function loops for the set of directories?

Apart from the , instead of a . on the second line, it all looks fine. Unless I have missed something.