Best way to network serverside mesh for to client on entity creation? Alternative solutions welcome.

Hey there. I’m trying to make a brush-based forcefield entity to make stuff easy for mappers. It needs to be able to take damage and “break”.

To goal is to simply lay a brush out in Hammer and then use the information about the brush to create the forcefield. I’m not fond of the idea of forcing mappers to set up millions of overlapping brushes to achieve the same effect, when I can do the hard work to simplify the process.

The problem is that brush entities in Garry’s Mod seem to be reserved within the context of triggering events, and are only available server-side. The only way to grab the necessary information about the brush is to ensure that it is a brush entity. Suggestions that I change it to “anim” makes grabbing any information useless as it will default to the world origin with collisions that matches the error model.


ENT.Base  = "base_entity";
ENT.Type  = "brush";

function ENT:Initialize()
  self:PhysicsInit(SOLID_BSP);
  self:SetMoveType(MOVETYPE_NONE);
  self:SetSolid(SOLID_BSP);
  self:GetPhysicsObject():EnableMotion(false);

  local vertices = self:GetPhysicsObject():GetMeshConvexes();
  
  for k, v in pairs(vertices[1]) do
    local point = ents.Create("info_point");
    if (!IsValid(point)) then return end
    point:SetPos(v.pos);
    point:Spawn();
  end

  self:Remove();
end

function ENT:Think()
end

(info_point is a debugging entity I’ve chosen)

I have the mesh information from GetMeshConvexes(), and I can create an entity that has the mesh information upon initialization on the server only, but I have no idea how to ensure the client gets all the information the server does for rendering. I’m aware of the net library and how to use it, but I just need a logical run down of how it can be applied here.

Any ideas? I’ll post the finished product so people who want to work with brush entities can do so with a reference.

https://dl.dropboxusercontent.com/u/965202/ShareX/2016/08/2016-08-20_09-15-03.png[/t]
[t]https://dl.dropboxusercontent.com/u/965202/ShareX/2016/08/2016-08-20_09-15-33.png

All Hammer models are compiled into the map, and as such, are available under both, client and server.

GMod’s “brush” type entities are not brush at all, don’t even bother trying to use them, they are only meant to be used as trigger entities. ( Blame Garry )

What you need is “anim” type entity as a workaround. Here’s an example, my several years old GMod implementation of func_respawnroomvisualizer from TF2.

http://hastebin.com/ujasibudiq.lua

I have questions:

Why is it that every time I’ve tried using anim, it’s defaulted to an error.mdl at the world origin, if at all?

What are you using as a model?

As it stands, I’m not even getting it to spawn with any solidity. In console:


[SERVER]: CurTime:  235 
[SERVER]: GetPos:  0.000000 0.000000 0.000000 
[SERVER]: OBBMins + OBBMaxs:  -7.545272 -37.840000 0.000000 9.642241 44.751400 67.782997

That doesn’t resemble the size of my brush.

https://dl.dropboxusercontent.com/u/965202/ShareX/2016/08/2016-08-21_21-53-24.png


AddCSLuaFile();

ENT.Base  = "base_anim";
ENT.Type  = "anim";

ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;

function ENT:Initialize()
  if (SERVER) then
    self:SetMoveType(MOVETYPE_VPHYSICS);
    self:SetSolid(SOLID_VPHYSICS);
    self:SetCustomCollisionCheck(true);
  else
    self:SetRenderBounds(self:OBBMins(), self:OBBMaxs());
  end
end

function ENT:Draw()
end

function ENT:Think()
  DebugMsg("server",{"%V","CurTime: ",math.floor(CurTime())});
  DebugMsg("server",{"%V","GetPos: ",tostring(self:GetPos())});
  DebugMsg("server",{"%V","OBBMins + OBBMaxs: ",tostring(self:OBBMins()),tostring(self:OBBMaxs())});
  if (SERVER) then self:NextThink( CurTime() + 5 ); end
  if (CLIENT) then self:SetNextClientThink( CurTime() + 5 ); end
  return true;
end

hook.Add( "ShouldCollide", "breakable_barrier_col_check", function( ent1, ent2 )
  return true;
end )


Please read my post above? The model is set manually.

[editline]22nd August 2016[/editline]

(Because anim type ents are not really meant for this)

I misunderstood. So you’re saying I’m better off using actual models since I can position them in Hammer and get the right positioning in Garry’s Mod, right?

[editline]21st August 2016[/editline]

Oh whoops, I’m dumb. I didn’t realize you meant the brush itself is treated as a model. Sorry about that, thanks!

https://dl.dropboxusercontent.com/u/965202/ShareX/2016/08/2016-08-21_22-06-36.png