Controlling Entity Transmission

From Garry's Mod
Revision as of 23:30, 27 October 2017 by EstevanTH (Talk | contribs)
Jump to: navigation, search

By default entities are only transmitted to a player if it's in the same PVS. 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.


Always Transmit

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

function ENT:UpdateTransmitState()	

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.

If you need to do so on a non-scripted entity, then you need to call

entity:AddEFlags( EFL_IN_SKYBOX )

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()	

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()	

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).

Personal tools