Forcing a hook to activate to everyone

I am trying to make a hook.Add HUD PAINT to run to everyone on the server when a command is made.

I’ve tried doing

but it isn’t doing it to everyone.

The server just needs to have the clientside HUDPaint file AddCSLuaFile()'d in and it will work for all clients. Don’t use a concommand or a player loop, that won’t work.

[editline]4th January 2017[/editline]

If you really really need to then

Player:SendLua will probably work, but it’s very messy and net messages would be a much better alternative

Once I’ve done that what would I need to do to trigger it remotely from a command?

Perhaps like this:
Serverside:



util.AddNetworkString( 'change_this_name' )

concommand.Add( 'testpaint', function()
    net.Start( 'change_this_name' ) // this simply sends all clients a blank message which is used to set DrawingInfo to be true
    net.Broadcast()
end )


Clientside:



local DrawingInfo = false

net.Receive( 'change_this_name', function()
    DrawingInfo = true // set it to be true once we receive the serverside message
end )

hook.Add( "HUDPaint", "Test", function()
	if DrawingInfo then
		draw.DrawText( "Don't Worry! Riotline is Testing Stuff", "CloseCaption_Bold", ScrW() * 0.5, ScrH() * 0.25, Color( 0, 255, 255, 255 ), TEXT_ALIGN_CENTER )
	end
end )


[editline]4th January 2017[/editline]

I don’t know if there’s a way to do it without the net library :frowning:

Thanks. That was really helpful!

if you >really< don’t want to use net library, you can use a global variable and just include it on clientside, or shared var. But as we all know, global vars are ew unless for configs or gamemodes.

Variables aren’t networked. Globals are for constants.