From 0bb9c8d7d59d7ae358790c79cf24cdd5b93b9b27 Mon Sep 17 00:00:00 2001 From: Rubat <3299036+robotboy655@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:57:15 +0300 Subject: [PATCH] Do not use magic numbers for net.Read/WriteEntity --- garrysmod/lua/includes/extensions/net.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/garrysmod/lua/includes/extensions/net.lua b/garrysmod/lua/includes/extensions/net.lua index 416b298550..9c10603b03 100644 --- a/garrysmod/lua/includes/extensions/net.lua +++ b/garrysmod/lua/includes/extensions/net.lua @@ -1,4 +1,9 @@ +-- This is just enough for the entity index. This however is not perfect +-- as the entity at given index may have changed during transport. +-- If this becomes a problem, inclusion of entity's serial will also be necessary +local MAX_EDICT_BITS = 13 + TYPE_COLOR = 255 net.Receivers = {} @@ -51,16 +56,16 @@ end function net.WriteEntity( ent ) if ( !IsValid( ent ) ) then - net.WriteUInt( 0, 13 ) + net.WriteUInt( 0, MAX_EDICT_BITS ) else - net.WriteUInt( ent:EntIndex(), 13 ) + net.WriteUInt( ent:EntIndex(), MAX_EDICT_BITS ) end end function net.ReadEntity() - local i = net.ReadUInt( 13 ) + local i = net.ReadUInt( MAX_EDICT_BITS ) if ( !i ) then return end return Entity( i )