• Props/Player turn invisible after time
    9 replies, posted
Hey, yesterday I updated my server and added (server-side) weapon skins. This is basically just a P250 (recompiled for gmod). The problem is, [I]after some time[/I] (NOT instantly) all players on the server turn invisible and the props, doors, etc. also turn invisible. Here is some related Lua code: [B]Server[/B] [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( info.skin ) hands:SetBodyGroups( info.body ) end local vm = ent:GetViewModel( 0 ) hands:AttachToViewmodel( vm ) vm:DeleteOnRemove( hands ) self:DeleteOnRemove( hands ) hands:Spawn() end end end [/CODE] [B]Server[/B] [CODE] [blabla.. here is some checking and stuff, weapon = Entity] weapon:SetNetworkedString("WeaponSkinName", SELECTED_SKIN) weapon:SetSkin(INVENTORY_SKINS[SELECTED_SKIN].SkinIndex) ply:GetViewModel():SetSkin(INVENTORY_SKINS[SELECTED_SKIN].SkinIndex) --weapon:SetWeaponSkinData(SELECTED_SKIN, INVENTORY_SKINS[SELECTED_SKIN].SkinIndex) end [/CODE]
Take a look at these images: [url]https://dl.dropboxusercontent.com/u/26074909/bugged_gmod/bugged_gmod.rar[/url] [quote][IMG]https://dl.dropboxusercontent.com/u/26074909/bugged_gmod/2012-12-23_00004.jpg[/IMG][/quote] 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: [CODE] function SWEP:BulletCallback(att, tr, dmg) return {effects = true,damage = true} end 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 ) [..] [/CODE] 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: [url]https://github.com/mechanicalmind/murder[/url] 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. [url]http://pastebin.com/hBeQJUm3[/url] (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 util.AddNetworkString("pkshotguncanattack") end[/lua] 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...
[QUOTE=Acecool;44728072][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] [/QUOTE] The sound is playing fine. And how would I create a "sound name" ?? [QUOTE=Acecool;44728072] May as well add this to the top just to reduce the number of if SERVER thens: [lua]if SERVER then util.AddNetworkString("pkshotguncanattack") end[/lua] [/QUOTE] Changed that, although it's pretty pointless - that's not gonna change much :P [QUOTE=Acecool;44728072] 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] [/QUOTE] 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.. [QUOTE=Acecool;44728072] 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. [/QUOTE] This is the creator's fault, I really have no idea why.. [QUOTE=Acecool;44728072] 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. [/QUOTE] Again, the creator coded it like this. It worked/works, so I didn't change it :D [QUOTE=Acecool;44728072] 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...[/QUOTE] The sound plays perfectly :) I really start to believe that something is wrong with the model...
[QUOTE=freakyy;44728200]The sound is playing fine. And how would I create a "sound name" ??[/QUOTE] [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] [QUOTE=freakyy;44728200]Changed that, although it's pretty pointless - that's not gonna change much :P[/QUOTE] True, it is still O( 1 ) regardless of where it is, but it looks cleaner. [QUOTE=freakyy;44728200]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..[/QUOTE] Excellent. Run some benchmarks: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_nw_vars.lua.html[/url] [QUOTE=freakyy;44728200]This is the creator's fault, I really have no idea why..[/QUOTE] 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. [QUOTE=freakyy;44728200]Again, the creator coded it like this. It worked/works, so I didn't change it :D[/QUOTE] 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. [QUOTE=freakyy;44728200]The sound plays perfectly :) I really start to believe that something is wrong with the model...[/QUOTE] 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 )
Sorry, you need to Log In to post a reply to this thread.