LUA Scripting?

i know how to code in lua, how to edit lua files, and every thing but the one thing i don’t understand is how do you know what to put to start a new thing and code something, because i dont know how you are supose to write something or do something to make it work. I dont know how to know what to write to make it work, like if you send me a lua file of something i can understand it but how do you know what to right to create something.


(User was banned for this post ("Undescriptive thread title" - Gran PC))

Are you talking about functions? I cant really understand what youre saying…

Uh… If you knew how to code Lua, then you’d know how to start writing a script.

I don’t really understand what is the problem but I will help you with what I understand.
If you have a file called <anything>.lua in your gamemode you will have to add in init.lua which is the server side “AddCSLuaFile(”<anything>.lua") if is a client side file if is serverside file you have to include("<anything>.lua") this is happening in init.lua
Then you will have to include the file in cl_init.lua to include("<anything>.lua")

If what I write above is not what you wanted then I’m sorry. But this is what I understand is your problem.

[editline]9th February 2013[/editline]

But if you are talking about functions you will have to write the function in your lua file hook it and call it in your serverside file, depend on what is doing your function. But if you are creating a hud for example you don’t have just to include the file and AddCSLuaFile.

ill just use this for a example like… say if i was going to make a headphone that made music how would i know how to start it and how would i now what hooks or stuff that im looking for.

Well, you could use a hook which will open that function via console (OpenMusic), or you could use a hook that open the function via chat like (/music)

He is asking about gmod’s structure, like how to set up an addon folder, entities, and where the documentation is.

Ok, but he said that how can he know what hooks he need, that’s why I said that.

yes exactly
he asked how to know what hooks he needs in projects
not which one in specific he needs now

If you just want to run a simple script, like a Hello World thing, put it in your garrysmod/garrysmod/lua/whateverfilename.lua . Then go in game in singleplayer and type in console:



lua_openscript whateverfilename.lua


Do you want an API? If so…

Look through the hooks and function and what not to find what you need.