Facepunch / garrysmod-issues

Garry's Mod issue tracker
141 stars 56 forks source link

weapon.SetNextPrimaryFire compensates for lost time #3786

Open VortixDev opened 5 years ago

VortixDev commented 5 years ago

Setting the next primary fire time from a future time to a past time causes automatic weapons to simulate a number of shots based on how far into the past you set the next fire time.

To clarify:

  1. Spawn a bot (bot_zombie 1 would be helpful, too)
  2. Equip an automatic weapon (I've tested with weapon_ar2 and weapon_smg1)
  3. Set the next primary fire time some time far in the future, and set a timer which, once ran, sets it moderately into the past, e.g. Player(userID):GetActiveWeapon():SetNextPrimaryFire(CurTime() + 20) timer.Simple(6, function() Player(userID):GetActiveWeapon():SetNextPrimaryFire(CurTime() - 15) end)
  4. Aim at the bot, hold down your attack key, and wait for the timer delay to elapse

Once the timer runs and sets the primary fire time into the past, the game seems to treat the situation as if I'd been firing for the 15 seconds I set it back for. The bot dies instantly, and my ammo is depleted. If I set the time to something smaller, like 1 second, I notice a sudden decrease in ammo and a large health loss from the bot once the timer elapses, but the bot survives and I am left with some ammo remaining.

robotboy655 commented 5 years ago

So don't do it?

VortixDev commented 5 years ago

A practical example of this bug is in Clockwork, where next primary fire is set into the future when a weapon is lowered and is set back to a previous value (which lies in the past by the time it is set back) when it is raised. I've patched this on Clockwork's end, but older versions will still be affected, and other scripts may be too.

TIMONz1535 commented 1 year ago

I consider this a potential issue, because such shooting causes the server to lag for a second or so. If your weapon has a large clip, for example, about 500, then your server will freeze

So I tried to profile in singleplayer and something similar happens there, but not so terrible. Lag occurs in GMOD, GLua, CBaseEntity::EmitSound, Unaccounted perhaps some badcode called on top of the FireBullets can worsen the situation, but I can't profile dedicated server