Examples - c01dc0ffee/gm_sourcenet GitHub Wiki
Client FPS
Fetches and print information about a client's FPS.
require("sourcenet")
local netchan = CNetChan(1) -- Fetches net channel for player one
--print( netchan:DumpNetMessages() )
--[[
1. net_Tick (3)
2. net_StringCmd (4)
3. net_SetConVar (5)
4. net_SignonState (6)
5. clc_ClientInfo (8)
6. clc_Move (9)
7. clc_VoiceData (10)
8. clc_BaselineAck (11)
9. clc_ListenEvents (12)
10. clc_RespondCvarValue (13)
11. clc_FileCRCCheck (14)
12. clc_FileMD5Check (17)
13. clc_CmdKeyValues (16)
14. clc_GMod_ClientToServer (18)
]]--
-- Fetch most recent incoming net_Tick message
local recentTick = netchan:GetNetMessage( 1 )
-- Print the available methods for this message
--PrintTable( recentTick:GetTable() )
--[[
GetHostFrameTime = function: 0x378109b0
GetHostFrameTimeStdDeviation = function: 0x37810a58
GetTick = function: 0x37810938
SetHostFrameTime = function: 0x37810a38
SetHostFrameTimeStdDeviation = function: 0x37810b40
SetTick = function: 0x37810990
]]--
-- Print info about client's FPS
local fps = 1 / recentTick:GetHostFrameTime()
local fpsStDev = recentTick:GetHostFrameTimeStdDeviation()
print( "FPS: " .. fps, "St Dev: " .. fpsStDev )
Print message functions
Prints mutator functions available on incoming messages
require("sourcenet")
local netchan = CNetChan(1) -- Fetches net channel for player one
for i = 1, netchan:GetNetMessageNum() do
local msg = netchan:GetNetMessage( i )
local name = msg:GetName()
print(name)
for k, v in pairs( msg:GetTable() ) do
print(string.format("\tName: %-28s Type: %s", k, v))
end
print()
end
Output:
net_Tick
Name: GetTick Type: function: 0x3a0fcfa0
Name: GetHostFrameTimeStdDeviation Type: function: 0x3a0fd0c0
Name: GetHostFrameTime Type: function: 0x3a0fd018
Name: SetTick Type: function: 0x3a0fcff8
Name: SetHostFrameTimeStdDeviation Type: function: 0x3a0fd0e0
Name: SetHostFrameTime Type: function: 0x3a0fd0a0
net_StringCmd
Name: SetCommand Type: function: 0x3a0f4d98
Name: GetCommand Type: function: 0x3a0f4d20
...
Setting view angle
require("sourcenet")
local netchan = CNetChan( 1 )
local buffer = netchan:GetReliableBuffer()
-- Set player view angle to Angle( 0, 0, 0 )
-- ( buffer:WriteAngle doesn't seem to work properly here, bit sizes maybe wrong )
buffer:WriteUInt( svc_FixAngle, NET_MESSAGE_BITS )
buffer:WriteBit( 0 ) -- bool relative: false
buffer:WriteBitAngle( 0, 16 ) -- pitch in degrees
buffer:WriteBitAngle( 0, 16 ) -- yaw in degrees
buffer:WriteBitAngle( 0, 16 ) -- roll in degrees