HaodongMo / ArcCW

57 stars 36 forks source link

`SWEP.Animations["ready"]` SoundTable doesn't play for the client picking up a weapon on multiplayer servers #146

Open RalphORama opened 1 year ago

RalphORama commented 1 year ago

When writing a SWEP with a SoundTable field in the ["ready"] animation sequence, the sounds do not play for the client when in a multiplayer server. They will, however, play for other clients (i.e. you cannot hear yourself rack a slide when picking up a gun, but players around you can).

I believe this is an issue with how sound tables are played in sh_anim.lua.

Example Code

Taken from the Black Ops SWEP pack

SWEP.Animations = {
    ["ready"] = {
        Source = "first_draw",
        Time = 1.5,
        LHIK = false,
        LHIKIn = 1,
        LHIKOut = 1,
        SoundTable = {
            {s = "ArcCW_BO1.AK_Charge", t = 20 / 35}
        },
    },
-- ["reload"], etc.

Steps to reproduce

Sounds working in single player

  1. Subscribe to ArcCW Base and ArcCW Black Ops Weapons Pack
  2. Click "Start New Game" on the main menu in Garry's Mod
  3. In the top right, select "Single Player" from the drop-down
  4. Click "Start Game"
  5. Give yourself any ArcCW weapon from the spawn menu
  6. ready sounds will play when given a weapon in the single player game

Sounds not working in multiplayer

  1. Click "Start New Game" again
  2. In the top right, select "2 players" from the drop down
  3. Select "local server"
  4. Click "Start Game"
  5. Give yourself any ArcCW weapon from the spawn menu
  6. ready sounds will not play when given a weapon in the multiplayer server
TheOnly8Z commented 1 year ago

confirmed issue. around for a long time too

TheOnly8Z commented 1 year ago

there's a workaround in my fork here that mitigates the issue but it's fairly hacky: https://github.com/SpiffyJUNIOR/ArcCW/blob/master/lua/weapons/arccw_base/sh_anim.lua#L270

ArcCW already has a line that does the same thing - it doesn't fix this issue fully.

The problem appears to be that when the weapon is spawned directly into the player's hands, the deploy animation is never called with IsFirstTimePredicted() returning true, so the sound table never plays since this line only wants to play on first prediction. Can be verified by spawning a weapon on the ground, picking it up, then switching to it - ready animation sounds should work.

Probably symptom of a deeper issue, but we can workaround it.

TheOnly8Z commented 1 year ago

should probably close this because https://github.com/HaodongMo/ArcCW/pull/148 got merged

I just tested and #148 did not fix the ready sound issue in a dedicated server or as listen server host.

TheOnly8Z commented 1 year ago

Additionally, ready (and presumably draw) animations do not play sound in a dedicated server if swapping from another ArcCW weapon. The cause is likely the same - the PlayAnimation function is never called with a first predict so soundtable never plays.

TheOnly8Z commented 1 year ago

Does SWEP:Deploy being called on client change anything?

It's relevant because in singleplayer we don't ever worry about prediction, and SWEP:Deploy() is only ever called once.

I don't remember the bodygroup issue but if it's checking IsFirstTimePredicted() in SWEP:Deploy() it will likely encounter this exact issue.

TheOnly8Z commented 1 year ago

Pushed a hacky fix. If someone else can verify it works, I'll close this issue for the time being.

GermanPlasma commented 1 year ago

After testing it for some time, it seems to work...kind of. What I mean by that is that, yes, the ready sound does now play for me, but for some reason, it plays at a volume that is basically silent. It feels like the ready sound is at 1% volume for me, but still better than 0% of course lol!

And inspect animations did break for me too, but I don't know if that is because of this exact change or not.

TheOnly8Z commented 1 year ago

After testing it for some time, it seems to work...kind of. What I mean by that is that, yes, the ready sound does now play for me, but for some reason, it plays at a volume that is basically silent. It feels like the ready sound is at 1% volume for me, but still better than 0% of course lol!

If you enable arccw_dev_alwaysready, can you hear a difference between the volume of a bugged ready or a normal one?

Situations that trigger the ready bug including spawning a weapon directly into your hand, and swapping to a weapon from a different ArcCW gun (or potentially any gun with a holster mechanic). Swapping from an engine weapon (like physgun) to an already initialized weapon on your player should play the sounds normally.

Also, if you can provide the weapon pack you are testing this with, and/or video recording of the issue, it would help greatly.

GermanPlasma commented 1 year ago

arccw_dev_alwaysready did fix the problem! I was testing this within my TTT2 server and enabling that command does always play the sound with the correct value.

I've been testing this with the Urban Decay + Urban Renewal weapon packs. Here's a clip https://streamable.com/nk0a42 (if the clip's expired please let me know)

TheOnly8Z commented 1 year ago

Pushed another fix as I think I found the root cause.

Since the weapon is relying on SWEP.UnReady to check whether the deploy is the first time, and immediately unsets the flag, later predicted deploy calls will think this deploy is not the first time, and use draw animation instead. The flag is now only set for the client after deploy is over and disabled state changes to idle, or on holster.

@GermanPlasma Please pull latest and test again - I'm a lot more confident that this fix addresses the problem.

GermanPlasma commented 1 year ago

@TheOnly8Z I am sorry to say that after testing with the latest version, none of the sounds seem to appear anymore. arccw_dev_alwaysready doesn't change anything either :(

TheOnly8Z commented 1 year ago

@GermanPlasma I've made a few changes since - can you test again?

GermanPlasma commented 1 year ago

@TheOnly8Z So I've tested it and I think it's some good progress, but there is still an issue:

It seems that weapons do play their ready sounds now regardless of if arccw_dev_alwaysready is on or off. However, with arccw_dev_alwaysready set to off, they only do it once for each weapon. For example, if you play TTT2 and you pick up a weapon, it will play the ready sound, but if you throw that weapon away and pick it back up, it will not play the ready sound any more.

TheOnly8Z commented 1 year ago

It seems that weapons do play their ready sounds now regardless of if arccw_dev_alwaysready is on or off. However, with arccw_dev_alwaysready set to off, they only do it once for each weapon. For example, if you play TTT2 and you pick up a weapon, it will play the ready sound, but if you throw that weapon away and pick it back up, it will not play the ready sound any more.

The intended behavior (with alwaysready off) is that the gun should only play the ready animation and sound the first time it is deployed by anyone, and all subsequent deploys play the draw animation and sound even if the gun is dropped and picked up by someone else.

Are you saying that the animation is behaving as intended but the sounds are not?

GermanPlasma commented 1 year ago

The way it is right now, the ready animation plays every time the weapon is picked up, but the sound of the ready animation only plays the first time the weapon is picked up.

here's a video to demonstrate the issue (alwaysready is set to off)

TheOnly8Z commented 1 year ago

Seems like the client isn't setting the UnReady variable. I've pushed a fix - see if this one works.

GermanPlasma commented 1 year ago

It seems to still do it :/ However I'm pretty certain that it is unique to UC and UR weapons. Other weapons do not seem to have this issue, at least from what I could tell.

TheOnly8Z commented 1 year ago

Appears that there's code that resets UnReady on drop for TTT - but it was only serverside. It's disabled now, so it should really work this time, maybe. @GermanPlasma

GermanPlasma commented 1 year ago

Honestly I couldn't notice any apparent issue with the newest update! I only really did a small test, but yeah, the ready animation plays once per weapon now, sounds play fine as well. I'll do some more testing later on (and especially once I play with friends but that's gonna take some days) but I love it so far!

TheOnly8Z commented 1 year ago

Sounds good. I'll close the issue for now - feel free to reopen it if it's still happening.

GermanPlasma commented 1 year ago

The issue still exists. I was testing it with another user, animation and sound only plays one single time. Any further weapon after the first then on only plays the initial ready animation (as it should of course) but without any sound to it. However, this seems to only be the case for any user that isn't the host. I (as the host) don't seem to have the issue.

@TheOnly8Z And I don't think I have permission to reopen this issue

TheOnly8Z commented 1 year ago

However, this seems to only be the case for any user that isn't the host. I (as the host) don't seem to have the issue.

Presumably in a listen server?

GermanPlasma commented 1 year ago

Peer-to-peer, I believe that qualifies as listen server yeah.