Garry's Mod Wiki

Controlling Entity Transmission

By default entities are only transmitted to a player if it's in the same PVS (Potential Visibility Set). What that means is that the player is only receiving information over the network about entities they can see.

You might not want this to happen.

First of all

This guide deals with both scripted and non-scripted entities.

On a scripted entity, you need to call Entity:AddEFlags( EFL_FORCE_CHECK_TRANSMIT ) every time ENTITY:UpdateTransmitState should be called. You can do it in ENTITY:Initialize:

function ENT:Initialize() -- ..... self:AddEFlags( EFL_FORCE_CHECK_TRANSMIT ) -- ..... end

Non-scripted entities will never have their ENTITY:UpdateTransmitState called so you should not use Entity:AddEFlags( EFL_FORCE_CHECK_TRANSMIT ).

Always Transmit

If you want your entity to always transmit to all players, add this to your entity server side.

function ENT:UpdateTransmitState() return TRANSMIT_ALWAYS end

This is useful if you have an entity that controls gamerules. For instance - imagine your gamemode has a round timer. You could have an entity to represent the round timer with accessors for whether the round is started and what time it ends. Clientside when the entity was created you'd store a global variable with its entity pointer (set the value in the entity's Initialize function) and could update the information on the HUD based on that entity.

On a non-scripted entity, you only can force it to always be in PVS (Potential Visibility Set):

entity:AddEFlags( EFL_IN_SKYBOX )

Unlike TRANSMIT_ALWAYS, this will not force a non-networked entity to be networked.

Never Transmit

Sometimes entities are for serverside usage only. To make them never get sent to the client you can add this to your entity.

function ENT:UpdateTransmitState() return TRANSMIT_NEVER end

The client will never even know the entity exists. This is useful for things like player spawn points - which the server uses but the client doesn't need to be aware of.

This is the default setting of point based entities.

PVS Transmit

The default setting is..

function ENT:UpdateTransmitState() return TRANSMIT_PVS end

If you make a base_point based entity and want it to transmit like a normal entity you'll need to add this.

Hiding from certain players

You can prevent certain entities from transmitting to certain players by calling

entity:SetPreventTransmit( ply, true )

If you want to allow it to transmit again you can call

entity:SetPreventTransmit( ply, false )

This only works to block the player from receiving - and not the other way around (you can't have the entity TRANSMIT_NEVER and use this function to only send to certain players).