Props/Player turn invisible after time


yesterday I updated my server and added (server-side) weapon skins. This is basically just a P250 (recompiled for gmod).
The problem is, after some time (NOT instantly) all players on the server turn invisible and the props, doors, etc. also turn invisible.

Here is some related Lua code:

-- fix invisible weapons
local plymeta = FindMetaTable( "Player" )

if PLY_SPECTATE_ENTITY == nil then PLY_SPECTATE_ENTITY = plymeta.SpectateEntity end
function plymeta:SpectateEntity(ent)
   PLY_SPECTATE_ENTITY (self, ent)

    if IsValid(ent) and ent:IsPlayer() then
		local hands = ents.Create( "gmod_hands" )
		if ( IsValid( hands ) ) then
			self:SetHands( hands )
			hands:SetOwner( self )

			local cl_playermodel = self:GetInfo( "cl_playermodel" )
			local info = player_manager.TranslatePlayerHands( cl_playermodel )
			if ( info ) then
				hands:SetModel( info.model )
				hands:SetSkin( )
				hands:SetBodyGroups( info.body )
			local vm = ent:GetViewModel( 0 )
			hands:AttachToViewmodel( vm )

			vm:DeleteOnRemove( hands )
			self:DeleteOnRemove( hands )



[blabla.. here is some checking and stuff, weapon = Entity]
    weapon:SetNetworkedString("WeaponSkinName", SELECTED_SKIN)

Take a look at these images:

Basically, what that is is a bug with the code. Its usually related to particles being spammed and not being released, etc. The doors, and everything remains solid, right, but they’re just invisible, or?

This is an example of a memory-leak. I don’t think its related to the hands code, but what game-mode are you running? What effects do you run? How frequently? Give us some more information please.

Thank you for your answer.

Yep, everything is still “there” - they remain solid.
I am running Murder, but I don’t create many particles/effects.

I looked through the code again, and the only thing I found so far is:

function SWEP:BulletCallback(att, tr, dmg)
	return {effects = true,damage = true}

function SWEP:PrimaryAttack()
	if !self.CanAttack then return false end
	local bullet = {}	-- Set up the shot
		bullet.Num = self.Primary.NumShots
		bullet.Src = self.Owner:GetShootPos()
		bullet.Dir = self.Owner:GetAimVector()
		bullet.Spread = Vector( self.Primary.Cone / 90, self.Primary.Cone / 90, 0 )
		bullet.Tracer = self.Primary.Tracer
		bullet.Force = self.Primary.Force
		bullet.Damage = self.Primary.Damage
		-- function bullet.Callback(att,tr,dmg)
		-- 	self:BulletCallback(att, tr, dmg)
		-- end
	self.Owner:FireBullets( bullet )

But this is just default Murder code, and I don’t think that can cause any problems.

By the way: Is it possible it’s because of the weapon model? It’s a recompiled P250 from CS:GO. I know that CS:GO is making a lot of trouble if it’s mounted, but in our case a friend of mine recompiled it and the server doesn’t mount CS:GO content. I also remember now, that we had a similar problem in CS:S where I created (server-side as well) weapon skins. Back then we recompiled the Knife to add skins. After some time on the server, things would turn invisible as well (just like here in GMod).
Either it’s the model’s fault, or I’m just too dumb to script in both cases. In CS:S I created a SourceMod addon…

That wouldn’t do it.

Is it a free game-mode? Does it happen on all maps? Does it happen after certain events or time?

Yes, Murder is a free game mode. The source code is on Github:

Before I added the weapon, this problem never occured, I’m certain it’s related to the new weapon. And I’m not sure when exactly it occurs, so far I was unable to reproduce the error locally, but I heard people having the problems on different maps - I only know for sure that it happens after time…

Can you post the full code you added?

Yea, here is the full shared.lua of the weapon. (commented some things with Default/Custom to show what I changed, because this modified version is not based on the latest github one)

I also added you on Steam.

[lua]SWEP.Primary.Sound = “csgo_recompiled/p250-1.wav”[/lua]

Create a sound name to use like WeaponSMG1.Single; otherwise sound may not play properly, or it may try to create the sound each time which could also be the culprit.

These too:
[lua]SWEP.ReloadFinishedSound = Sound(“csgo_recompiled/p250_clipin.wav”)
SWEP.ReloadSound = Sound(“csgo_recompiled/p250_clipout.wav”)
SWEP.DrawSound = Sound(“csgo_recompiled/p250_draw.wav”)[/lua]

May as well add this to the top just to reduce the number of if SERVER thens:
[lua]if SERVER then

There is a different way to use networked variables; DTVars or the newer version of it where you’re allowed up to 4 variables of the same type for each type:

[lua] self:SetNetworkedString(“WeaponSkinName”, “skin_p250_normal”)
self:SetNetworkedEntity(“WeaponSkinOriginalOwner”, Entity(0))[/lua]

I don’t see you calling [lua]IsFirstTimePredicted( )[/lua] inside of [lua]function SWEP:PrimaryAttack()[/lua] - this may cause issues because of the way SWEP works; this shouldn’t cause the issue with disappearing props though.

Why are you sending net-messages for determining when the next attack can occur? Use [lua]SetNextPrimaryAttack( )[/lua] in conjunction with [lua]IsFirstTimePredicted( )[/lua] to let SWEPs work how they’re designed.

Look at how weapon_fists, etc are coded. Most of these shouldn’t cause any issue; the biggest culprit may be the sound but I wouldn’t see how that’d cause an issue aside from not playing sounds properly…

The sound is playing fine. And how would I create a “sound name” ??

Changed that, although it’s pretty pointless - that’s not gonna change much :stuck_out_tongue:

Okay, changed that and the rest of my code. Although I remember reading somewhere that they are not correctly predicted and may get out-of-sync when a client experiences big lag…

This is the creator’s fault, I really have no idea why…

Again, the creator coded it like this. It worked/works, so I didn’t change it :smiley:

The sound plays perfectly :slight_smile:
I really start to believe that something is wrong with the model…

[lua]sound.Add( {
name = “MyWeapon.Single”;
channel = CHAN_WEAPON;
volume = 1.0;
soundlevel = 90;
sound = “csgo_recompiled/p250-1.wav”;
} );

sound.Add( {
name = “MyWeapon.MagInsert”;
channel = CHAN_WEAPON;
volume = 1.0;
soundlevel = 90;
sound = “csgo_recompiled/p250_clipin.wav”;
} );

sound.Add( {
name = “MyWeapon.MagDrop”;
channel = CHAN_WEAPON;
volume = 1.0;
soundlevel = 90;
sound = “csgo_recompiled/p250_clipout.wav”;
} );

sound.Add( {
name = “MyWeapon.Draw”;
channel = CHAN_WEAPON;
volume = 1.0;
soundlevel = 90;
sound = “csgo_recompiled/p250_draw.wav”;
} );[/lua]

True, it is still O( 1 ) regardless of where it is, but it looks cleaner.

Excellent. Run some benchmarks:

You’d want to use it around segments where the client-side code should only run once. The way SWEPs are, is when you left-click, the function gets SPAMMED until it syncs with the server. For code that should only be run once, use it.

The constant net messages may be an issue; they shouldn’t cause a memory leak ( I’ve done stress tests by sending 600 messages per second to 20 player on my dev, no lag; memory was managed though ), but there’s an easy way to test it.

I’d really recommend looking into fixing it to remove the net messages to tell when its ready to fire again.

Change the model to something else, see if the issue still occurs. It may be related to sound; it may not be, who knows. This issue of disappearing things is typically caused by an OVERLOAD of particles, or other errors or memory leaks.

Additionally, ViewPunch: self.Owner:ViewPunch(Angle( -self.Primary.Recoil, 0, 0 )) – isn’t good for recoil. It moves the view, but the aim stays directly on target. So if you empty out the mag with just viewpunch without moving your mouse, and there is no code to change the area it hits, they’ll all ( bullet holes ) be on top of each other. I recommend using SetEyeAngles, call it only ONCE ( on SERVER or CLIENT ; can’t recall off hand the realm )