Skip to content
Permalink
Browse files
Block out-of-range weapon shots
  • Loading branch information
RussellLVP committed Jul 9, 2020
1 parent bfe07d0 commit 383a10073064d3de0c9f884ba681dd33722aa587
Showing 5 changed files with 88 additions and 2 deletions.
@@ -6,8 +6,9 @@ import { Setting } from 'entities/setting.js';

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

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,72 @@
// Copyright 2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

// The default weapon range (from weapon.dat), imported from Oscar Broman's server-sided damage.
new const Float: kWeaponRange[] = {
0.0, // 0 - Fist
0.0, // 1 - Brass knuckles
0.0, // 2 - Golf club
0.0, // 3 - Nitestick
0.0, // 4 - Knife
0.0, // 5 - Bat
0.0, // 6 - Shovel
0.0, // 7 - Pool cue
0.0, // 8 - Katana
0.0, // 9 - Chainsaw
0.0, // 10 - Dildo
0.0, // 11 - Dildo 2
0.0, // 12 - Vibrator
0.0, // 13 - Vibrator 2
0.0, // 14 - Flowers
0.0, // 15 - Cane
0.0, // 16 - Grenade
0.0, // 17 - Teargas
0.0, // 18 - Molotov
90.0, // 19 - Vehicle M4 (custom)
75.0, // 20 - Vehicle minigun (custom)
0.0, // 21
35.0, // 22 - Colt 45
35.0, // 23 - Silenced
35.0, // 24 - Deagle
40.0, // 25 - Shotgun
35.0, // 26 - Sawed-off
40.0, // 27 - Spas
35.0, // 28 - UZI
45.0, // 29 - MP5
70.0, // 30 - AK47
90.0, // 31 - M4
35.0, // 32 - Tec9
100.0, // 33 - Cuntgun
320.0, // 34 - Sniper
0.0, // 35 - Rocket launcher
0.0, // 36 - Heatseeker
0.0, // 37 - Flamethrower
75.0 // 38 - Minigun
};

// Returns whether the given |weaponId| is a weapon that fires bullets.
bool: IsBulletWeapon(weaponId) {
return (WEAPON_COLT45 <= weaponId <= WEAPON_SNIPER) || weaponId == WEAPON_MINIGUN;
}

// Returns whether the last shot fired by the |playerId| was out of range. All this information is
// reported by the |playerId|, so there is no need to compensate for their ping here.
bool: IsLastShotOutOfRange(playerId, weaponId, hitType) {
if (hitType != BULLET_HIT_TYPE_PLAYER)
return false; // only process this for hits on players

if (!IsBulletWeapon(weaponId))
return false; // only process this for weapons which have bullets

new Float: origin[3];
new Float: target[3];

GetPlayerLastShotVectors(
playerId, origin[0], origin[1], origin[2], target[0], target[1], target[2]);

new const Float: distance = VectorSize(
origin[0] - target[0], origin[1] - target[1], origin[2] - target[2]);

return kWeaponRange[weaponId] < distance;
}
@@ -10,6 +10,7 @@ native ReportTrailerUpdate(vehicleid, trailerid);

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

// If out-of-range damage has been disabled, and the shot is out of range, block it.
if (g_abuseDisableOutOfRangeDamage && IsLastShotOutOfRange(playerid, weaponid, hittype)) {
printf("[%d] out of range shot (weapon: %d)", playerid, weaponid);
return 0;
}

// We might want to ignore damage done by players who are passengers as the sole occupant of a
// vehicle. They can only be damaged with a chainsaw, making this very unfair in fights.
if (g_abuseIgnoreSolePassengerDamage && hittype != BULLET_HIT_TYPE_NONE) {
@@ -6,6 +6,7 @@
// //features/settings/pawn_config.js. Each option will be stored as a global Pawn variable.

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

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

switch (property) {
case kAbuseDisableOutOfRangeDamage:
g_abuseDisableOutOfRangeDamage = !!intValue;

case kAbuseFakeCarEntryPreventionEnterMs:
g_abuseFakeCarEntryPreventionEnterMs = intValue;

0 comments on commit 383a100

Please sign in to comment.