I've used the net library before. Smart idea. However, I'm trying to use it in this code:
-- shared
local CATEGORY_NAME = "Utility"
util.AddNetworkString( "Stop Timer" )
function forceSpec( target_ply )
message = "You have been forced to AFK for not responding to the AFK check."
target_ply:ConCommand( "ttt_spectator_mode 1" )
ULib.tsayError( target_ply, message )
end
function ulx.cafk( calling_ply, target_ply )
ULib.clientRPC( target_ply, "ulx.cafkClientSide" )
ulx.fancyLogAdmin( calling_ply, "#A is checking if #T is AFK.", target_ply )
timer.Create( "AFK Timer", 10, 1, function() forceSpec( target_ply ) end )
end
local cafk = ulx.command( CATEGORY_NAME, "ulx cafk", ulx.cafk, "!cafk" )
cafk:addParam{ type=ULib.cmds.PlayerArg }
cafk:defaultAccess( ULib.ACCESS_OPERATOR )
cafk:help( "Used to check if a player is AFK." )
net.Receive( "Stop Timer", function()
timer.Remove( "AFK Timer" )
end )
---------------------------------------------------------------------------------------------------------------- client
-- cut out most derma code
afkButton.DoClick = function()
RunConsoleCommand( "say", "I'm not AFK." )
afkBox:Close()
net.Start( "Stop Timer" )
net.WriteString( "Stop the timer" )
net.SendToServer()
end
end
And it's throwing the error:
[ERROR] addons/customcommands/lua/ulx/modules/sh/sh_cc_cafk.lua:3: attempt to call field 'AddNetworkString' (a nil value)
1. unknown - addons/customcommands/lua/ulx/modules/sh/sh_cc_cafk.lua:3
and I don't know why, isn't util.AddNetworkString a thing that can be manually defined? (which I did with "Stop Timer")
AHA! I fixed it! Because I was making it in a shared file, I had to put in a
to define it, and now it's working perfectly!
shared.lua=
local CATEGORY_NAME = "Utility"
if SERVER then
util.AddNetworkString( "Stop Timer" )
end
function forceSpec( target_ply )
message = "You have been forced to AFK for not responding to the AFK check."
target_ply:ConCommand( "ttt_spectator_mode 1" )
ULib.tsayError( target_ply, message )
end
function ulx.cafk( calling_ply, target_ply )
ULib.clientRPC( target_ply, "ulx.cafkClientSide" )
ulx.fancyLogAdmin( calling_ply, "#A is checking if #T is AFK.", target_ply )
timer.Create( "AFK Timer", 10, 1, function() forceSpec( target_ply ) end )
end
local cafk = ulx.command( CATEGORY_NAME, "ulx cafk", ulx.cafk, "!cafk" )
cafk:addParam{ type=ULib.cmds.PlayerArg }
cafk:defaultAccess( ULib.ACCESS_OPERATOR )
cafk:help( "Used to check if a player is AFK." )
net.Receive( "Stop Timer", function()
timer.Remove( "AFK Timer" )
end )
client.lua =
surface.CreateFont( "AFKText", {
font = "DebugFixed", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 14,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
function ulx.cafkClientSide()
local afkBox = vgui.Create( "DFrame" )
afkBox:MakePopup()
afkBox:SetSize( 600,200 )
afkBox:Center()
afkBox:SetTitle( "Are you AFK?" )
afkBox:SetDraggable( false )
afkBox.Width = 600
afkBox.Height = 200
afkBox:ShowCloseButton( false )
local afkText = vgui.Create( "DLabel", afkBox )
afkText:SetText( "Are You AFK?" )
afkText:Center()
afkText:SetWidth( 600 )
afkText:SetFont( "AFKText" )
local afkButton = vgui.Create( "DButton", afkBox )
afkButton:SetPos( afkBox.Width/2-25, afkBox.Height/2+30 )
afkButton:SetText( "Not AFK" )
afkButton.DoClick = function()
RunConsoleCommand( "say", "I'm not AFK." )
afkBox:Close()
net.Start( "Stop Timer" )
net.WriteString( "Stop the timer" )
net.SendToServer()
end
end
No errors, and everything is working great! Thanks for all the help guys!