QuestionGarry's Mod scripting - HUDPaint not called?

Posts 1–8 of 8 · Page 1 of 1
Garry's Mod scripting - HUDPaint not called?
Hello, I'm new to Garry's Mod (bought it couple of days ago)

Wrote up a simple script for testing;
Code:
local function Meatgrinder()
  print('hi');
  draw.SimpleTextOutlined("Hello World", "Default", 20, 20, Color(255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(0, 0, 0));
end

hook.Remove("HUDPaint", "Meatgrinder");
hook.Add("HUDPaint", "Meatgrinder", Meatgrinder);
I load it ingame in the console with lua_openscript however, after that nothing happens.

"hi" does not print to console, "Hello World" does not print on screen.

What am I doing wrong?


Thanks for help






If I hook "Think" it gets called, but LocalPlayer() gives me error "attempt to call global 'LocalPlayer' (a nil value)" is this because I'm playing on a local server?
Try typing:
sv_allowcslua 1
in console if it is your server.
Probably won't work though, I'm a noob at this stuff.
Try setting players to 2 before running the local server.
You should run lua_openscript_cl instead of lua_openscript if that doesnt work try running sv_allowcslua 1 and then lua_openscript_cl [filepathhere ] again.
I have no idea if the ";"s would cause problems but I dont think so.

BTW: Why are you running hook.Remove?
Quote Originally Posted by LennyPenny View Post
Try setting players to 2 before running the local server.
You should run lua_openscript_cl instead of lua_openscript if that doesnt work try running sv_allowcslua 1 and then lua_openscript_cl [filepathhere ] again.
I have no idea if the ";"s would cause problems but I dont think so.

BTW: Why are you running hook.Remove?
Thanks to both of you for your help.

Making a 2 player game and setting sv_allowcslua 1 helped!

The ";" does not cause a problem. It's optional in LUA, like in JavaScript. I'm just putting it because I'm used to it from C++ and PHP

To remove my old hook before adding new. Probably not necessary but made sense to me



Edit:

Everything WAS working fine, but now after playing around a bit, testing I've started getting this really weird(?) error, here's script now:
Code:
local function hThink()
  local Me;
  Me = LocalPlayer();
end

hook.Add("Think", "novThink", hThink);
Error
Code:
[ERROR] lua/novo.lua:3: attempt to call global 'LocalPlayer' (a nil value)
  1. v - lua/novo.lua:3
   2. unknown - lua/includes/modules/hook.lua:82
Are you sure you are running lua_openscript_cl?
Quote Originally Posted by MeepDarknessMeep View Post
Are you sure you are running lua_openscript_cl?
That was the problem! Thanks.
Don't know how I forgot that :'(
Code:
hook.Remove("HUDPaint", "Meatgrinder");
hook.Add("HUDPaint", "Meatgrinder", Meatgrinder);
Why are you removing a non existant hook then adding it?

Code:
  local Me;
  Me = LocalPlayer();
Why not just do
Code:
local Me = LocalPlayer();
I don't understand you.
Quote Originally Posted by wearing8 View Post
Code:
hook.Remove("HUDPaint", "Meatgrinder");
hook.Add("HUDPaint", "Meatgrinder", Meatgrinder);
Why are you removing a non existant hook then adding it?
To remove my old hook before adding new. Probably not necessary but made sense to me

Quote Originally Posted by wearing8 View Post
Code:
  local Me;
  Me = LocalPlayer();
Why not just do
Code:
local Me = LocalPlayer();
I don't understand you.
I cut it from a longer function before pasting, but yeah, that would've made more sense in the context :P
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us