Skip to content

Commit 383a100

Browse files
committed
Block out-of-range weapon shots
1 parent bfe07d0 commit 383a100

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

javascript/features/settings/pawn_config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { Setting } from 'entities/setting.js';
66

77
// List of PawnConfig settings with their unique values and settings. Must be synced with Pawn. The
88
// settings can be in any category, of any type, as long as the identifier is a valid one.
9-
// Next ID: 14
9+
// Next ID: 15
1010
const kSynchronizedSettings = new Map([
11+
[ 'abuse/disable_out_of_range_damage', { id: 14 } ],
1112
[ 'abuse/fake_car_entry_prevention_enter_ms', { id: 11 } ],
1213
[ 'abuse/fake_car_entry_prevention_exit_ms', { id: 12 } ],
1314
[ 'abuse/ignore_sole_passenger_damage', { id: 5 } ],

javascript/features/settings/setting_list.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2020 Las Venturas Playground. All rights reserved.
2+
// Use of this source code is governed by the MIT license, a copy of which can
3+
// be found in the LICENSE file.
4+
5+
// The default weapon range (from weapon.dat), imported from Oscar Broman's server-sided damage.
6+
new const Float: kWeaponRange[] = {
7+
0.0, // 0 - Fist
8+
0.0, // 1 - Brass knuckles
9+
0.0, // 2 - Golf club
10+
0.0, // 3 - Nitestick
11+
0.0, // 4 - Knife
12+
0.0, // 5 - Bat
13+
0.0, // 6 - Shovel
14+
0.0, // 7 - Pool cue
15+
0.0, // 8 - Katana
16+
0.0, // 9 - Chainsaw
17+
0.0, // 10 - Dildo
18+
0.0, // 11 - Dildo 2
19+
0.0, // 12 - Vibrator
20+
0.0, // 13 - Vibrator 2
21+
0.0, // 14 - Flowers
22+
0.0, // 15 - Cane
23+
0.0, // 16 - Grenade
24+
0.0, // 17 - Teargas
25+
0.0, // 18 - Molotov
26+
90.0, // 19 - Vehicle M4 (custom)
27+
75.0, // 20 - Vehicle minigun (custom)
28+
0.0, // 21
29+
35.0, // 22 - Colt 45
30+
35.0, // 23 - Silenced
31+
35.0, // 24 - Deagle
32+
40.0, // 25 - Shotgun
33+
35.0, // 26 - Sawed-off
34+
40.0, // 27 - Spas
35+
35.0, // 28 - UZI
36+
45.0, // 29 - MP5
37+
70.0, // 30 - AK47
38+
90.0, // 31 - M4
39+
35.0, // 32 - Tec9
40+
100.0, // 33 - Cuntgun
41+
320.0, // 34 - Sniper
42+
0.0, // 35 - Rocket launcher
43+
0.0, // 36 - Heatseeker
44+
0.0, // 37 - Flamethrower
45+
75.0 // 38 - Minigun
46+
};
47+
48+
// Returns whether the given |weaponId| is a weapon that fires bullets.
49+
bool: IsBulletWeapon(weaponId) {
50+
return (WEAPON_COLT45 <= weaponId <= WEAPON_SNIPER) || weaponId == WEAPON_MINIGUN;
51+
}
52+
53+
// Returns whether the last shot fired by the |playerId| was out of range. All this information is
54+
// reported by the |playerId|, so there is no need to compensate for their ping here.
55+
bool: IsLastShotOutOfRange(playerId, weaponId, hitType) {
56+
if (hitType != BULLET_HIT_TYPE_PLAYER)
57+
return false; // only process this for hits on players
58+
59+
if (!IsBulletWeapon(weaponId))
60+
return false; // only process this for weapons which have bullets
61+
62+
new Float: origin[3];
63+
new Float: target[3];
64+
65+
GetPlayerLastShotVectors(
66+
playerId, origin[0], origin[1], origin[2], target[0], target[1], target[2]);
67+
68+
new const Float: distance = VectorSize(
69+
origin[0] - target[0], origin[1] - target[1], origin[2] - target[2]);
70+
71+
return kWeaponRange[weaponId] < distance;
72+
}

pawn/Driver/Driver.pwn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ native ReportTrailerUpdate(vehicleid, trailerid);
1010

1111
#include "Driver/PawnConfig.pwn"
1212
#include "Driver/Abuse/WeaponDamageDecider.pwn"
13+
#include "Driver/Abuse/WeaponDistanceBlocker.pwn"
1314
#include "Driver/Abuse/WeaponShotDetection.pwn"
1415
#include "Driver/Drift/DriftHelpers.pwn"
1516
#include "Driver/Drift/DriftUi.pwn"
@@ -551,6 +552,12 @@ public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float: fX, Float:
551552
return 0;
552553
}
553554

555+
// If out-of-range damage has been disabled, and the shot is out of range, block it.
556+
if (g_abuseDisableOutOfRangeDamage && IsLastShotOutOfRange(playerid, weaponid, hittype)) {
557+
printf("[%d] out of range shot (weapon: %d)", playerid, weaponid);
558+
return 0;
559+
}
560+
554561
// We might want to ignore damage done by players who are passengers as the sole occupant of a
555562
// vehicle. They can only be damaged with a chainsaw, making this very unfair in fights.
556563
if (g_abuseIgnoreSolePassengerDamage && hittype != BULLET_HIT_TYPE_NONE) {

pawn/Driver/PawnConfig.pwn

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// //features/settings/pawn_config.js. Each option will be stored as a global Pawn variable.
77

88
// Section: abuse
9+
new bool: g_abuseDisableOutOfRangeDamage = true;
910
new g_abuseFakeCarEntryPreventionEnterMs = 3000;
1011
new g_abuseFakeCarEntryPreventionExitMs = 1750;
1112
new bool: g_abuseIgnoreSolePassengerDamage = true;
@@ -26,8 +27,9 @@ new bool: g_vehicleKeysBlockedInLasVenturas = true;
2627

2728
// These are the unique Ids for each of the properties that can be updated. They must be identical
2829
// between the Pawn and the JavaScript code.
29-
// Next ID: 14
30+
// Next ID: 15
3031
enum PawnConfigProperty {
32+
kAbuseDisableOutOfRangeDamage = 14,
3133
kAbuseFakeCarEntryPreventionEnterMs = 11,
3234
kAbuseFakeCarEntryPreventionExitMs = 12,
3335
kAbuseIgnoreSolePassengerDamage = 5,
@@ -50,6 +52,9 @@ public OnPawnConfigDataChange(PawnConfigProperty: property, Float: numberValue)
5052
new const intValue = floatround(numberValue, floatround_tozero);
5153

5254
switch (property) {
55+
case kAbuseDisableOutOfRangeDamage:
56+
g_abuseDisableOutOfRangeDamage = !!intValue;
57+
5358
case kAbuseFakeCarEntryPreventionEnterMs:
5459
g_abuseFakeCarEntryPreventionEnterMs = intValue;
5560

0 commit comments

Comments
 (0)