Fixing few issues about ClientSide and ServerSide entities and vars

Hello, before rate me dumb or something, i had issues working on an entitie on both sides, i asked few times how fix it, and i wasn’t helped, what was my issue this time? Think is called on both sides, but few times it turns itchy and just decide work on one side, like client, or server…Anyway, i sincerily don’t know why it occurs, and when i asked it someone told me about:

“When you are on singleplayer, you’re the server”

Okay, but what happen when i’m on multi, i must trhown everything? No, look at this:


function ENT:Think()

for k,v in pairs(ents.FindInSphere(self:GetPos(),self:GetcapDistance())) do

	self.CombNum = 0
	for a,f in pairs(ents.FindInSphere(self:GetPos(),self:GetcapDistance())) do
		if(f:GetClass() == "npc_combine_s") then 
			self.CombNum = self.CombNum + 1
	local bb = v:IsPlayer()
	if(bb && self.CombNum == 0) then

             <<Complex code>>


As you can see, i was working on a cap point, simple, if you are near of x distance, you can cap it, it work really nice on SP, but on MP it doesn’t work
If i trace the var BB it run on both sides, but if i trace after the condition it only return SERVER, only if distance is less than x*y (Y can be any value, change by client and map)

Example, the default cap distance is 256 on my dev map, i can cap it on SP

But if you are on MP, you can’t cap it, until you change the cap dist (Using edit properties) to a really bigger value (x*y) where x is the capDistance and y the misterious value

As i said, i don’t know what is the problem, i traced everything but nothing had worked…

If you have an issue like this, don’t worry, try to use hooks and don’t use the Entity hook, and verify each entity for each player (Is too much heavy, but it can save your life)


if(game.SinglePlayer()) then return false end

for k,v in pairs(ents.FindByClass("bf_cappoint")) do

	for j,h in pairs(player.GetAll()) do

		if(h:GetPos():Distance(v:GetPos()) < v:GetcapDistance()) then

			v.CombNum = 0
			for a,f in pairs(ents.FindInSphere(v:GetPos(),v:GetcapDistance())) do
				if(f:GetClass() == "npc_combine_s") then 
					v.CombNum = v.CombNum + 1

		if(v.progress > 0 && v:GetcurTeam() == 1 && v.CombNum == 0) then

     <<more complex code>>


I inserted it on my entity code and now works quite right, so let’s resume all my words

**-Always test on MP if your code will be use for MP
-If you experiment issues with parsing data from client>server>client, TRACE IT
-Don’t overuse networkvars
-Always try to set variables on both sides
-Entity properties is a really good way to debug entities

Sorry for my bad languaje and post it here, but i think that it can help someone in the future, if you have any doubt please feel free to ask