I just compiled my first binary for GMod in C++, I have followed several tutorials including out-dated ones and made it working pretty quickly.
I run GMod, go to LAN, submit “lua_run_cl require(‘test’); lua_run_cl MsgN(TestFunction()); lua_run_cl MsgN(TestFunction(100.24));” into console and it replies to me just fine.
Okay. Now, I have some question(s). I don’t get the most of this, but I understand C++ itself.
Here are my questions:
Please tell me what is this useful for?
Why C++ module and not pure glua script (benefits of C++ module versus pure glua script)?
How can I “convert” glua script into C++ module (see glua code below)?
For my last question from above, for example, I want to convert the following glua code into C++ gmod module representation, if this is even possible (please describe C++ code with comments):
[LUA]if not CLIENT or SERVER then
local function shTickHooked()
local ply = LocalPlayer():GetEyeTrace().Entity
if not ply:IsPlayer() then
hook.Remove(‘Tick’, ‘TestingTick’) – My tip: Remove previously loaded hook (if any exists, it wont throw error - it is good practise; I have spent some time debugging lots of glua codes).
hook.Add(‘Tick’, ‘TestingTick’, shTickHooked) – Now add a new hook (many devs forget to remove before add)[/LUA]
Above glua code was written out of my head (while I was writing this thread).
For the sake of sample, it will spam the “Nick”-name in developer console depending on player I aim at.
Thanks in advance.