private void OnWeaponFired(BaseProjectile projectile, BasePlayer player, ItemModProjectile mod, ProjectileShoot projectileShoot) { var item = player.GetActiveItem(); if (!(item.info.shortname == "rifle.ak" || item.info.shortname == "lmg.m249")) { return; } if (item.contents.itemList.Any(x => blacklistedAttachments.Contains(x.info.shortname))) { return; } NoRecoilData info; if (!data.TryGetValue(player.userID, out info)) { data.Add(player.userID, info = new NoRecoilData()); } UnityEngine.Vector3 eyesDirection = player.eyes.HeadForward(); if (eyesDirection.y < -0.80) { return; } info.Ticks++; int probModifier = 0; foreach (Item attachment in item.contents.itemList) { if (probabilityModifiers.ContainsKey(attachment.info.shortname)) { probModifier += probabilityModifiers[attachment.info.shortname]; } } if (player.modelState.aiming && probabilityModifiers.ContainsKey("aiming")) { probModifier += probabilityModifiers["aiming"]; } if (player.IsDucked() && probabilityModifiers.ContainsKey("crouching")) { probModifier += probabilityModifiers["crouching"]; } Timer detectionTimer; if (detections.TryGetValue(player.userID, out detectionTimer)) { detectionTimer.Reset(detectionDiscardSeconds); } else { detections.Add(player.userID, timer.Once(detectionDiscardSeconds, delegate() { if (info.Violations > 0) { info.Violations--; } })); } timer.Once(recoilTimer, () => { ProcessRecoil(projectile, player, mod, projectileShoot, info, probModifier, eyesDirection); }); }
private void ProcessRecoil(BaseProjectile projectile, BasePlayer player, ItemModProjectile mod, ProjectileShoot projectileShoot, NoRecoilData info, int probModifier, UnityEngine.Vector3 eyesDirection) { var nextEyesDirection = player.eyes.HeadForward(); if (Math.Abs(nextEyesDirection.y - eyesDirection.y) < .009 && nextEyesDirection.y < .8) { info.Count++; } if (info.Ticks <= 10) { return; } var prob = 100 * info.Count / info.Ticks; if (prob > ((100 - violationProbability) + probModifier)) { info.Violations++; PrintWarning($"{player.displayName} ({player.UserIDString}), {prob}% probability, {info.Violations.ToString()} violations."); LogToFile("violations", $"[{DateTime.Now.ToString()}] {player.displayName} ({player.UserIDString}), {prob}% probability, {info.Violations.ToString()} violations.", this, false); if (info.Violations > maximumViolations) { if (banEnabled) { Player.Ban(player, "Recoil Scripts"); } else if (kickEnabled) { Player.Kick(player, "Recoil Scripts"); } } } foreach (BasePlayer _player in BasePlayer.activePlayerList) { if (_player.IsAdmin && prob > ((100 - violationProbability) + probModifier)) { SendReply(_player, $"<size=12>NoRecoil: {player.displayName} ({player.UserIDString}), {prob}% probability, {info.Violations.ToString()} violations.</size>"); } } info.Ticks = 0; info.Count = 0; }