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
[QUOTE]for _, ply in ipairs( player.GetAll() ) do[/QUOTE]
but it isn't doing it to everyone.
[QUOTE]
[CODE] concommand.Add( "testpaint", function()
for _, ply in ipairs( player.GetAll() ) do
hook.Add("HUDPaint", "Test", function()
DrawingInfo = true
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 )
end[/CODE]
[/QUOTE]
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 [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/SendLua]Player:SendLua[/url] will probably work, but it's very messy and [URL="https://wiki.garrysmod.com/page/Net_Library_Usage"]net messages[/URL] 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:
[CODE]
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 )
[/CODE]
Clientside:
[CODE]
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 )
[/CODE]
[editline]4th January 2017[/editline]
I don't know if there's a way to do it without the net library :(
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.
[QUOTE=RaKo;51621830]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.[/QUOTE]
Variables aren't networked. Globals are for constants.
Sorry, you need to Log In to post a reply to this thread.