0

YES this is a gmod and a lua question! I would like to know if its possible to run LUA commands though an addon when the user has just launched the game and if so how?

berrixsez
  • 1
  • 2

1 Answers1

0

It is not possible to run Lua commands in the menu state when the user has launched the game. This is unless you mean when they first spawn into a map, which is possible - and is what I'm about to describe.

You can use the hook system to hook onto events that happen in the game. One of these hooks is Initialize which is called when the game first loads and Lua is initialized. Another option is InitPostEntity which is called after all map entities have been spawned.

To use the hook system, call hook.Add("Hook name", "Custom identifier", function(...) end)

For example, to use the Initialize hook, use this code:

hook.Add("Initialize", "myidentifier", function()
    -- put your code here
end) 
MattJeanes
  • 268
  • 2
  • 10