Skip to content

Commit 3c787d5

Browse files
committed
Implement prevention for fake car entry
1 parent 68f0647 commit 3c787d5

5 files changed

Lines changed: 48 additions & 3 deletions

File tree

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: 11
9+
// Next ID: 12
1010
const kSynchronizedSettings = new Map([
11+
[ 'abuse/fake_car_entry_prevention_sec', { id: 11 } ],
1112
[ 'abuse/ignore_sole_passenger_damage', { id: 5 } ],
1213
[ 'abuse/kick_reason_public', { id: 6 } ],
1314
[ 'abuse/kill_attribution_time_sec', { id: 7 } ],

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.

pawn/Driver/Driver.pwn

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ new const kUnoccupiedSyncMarkTimeMs = 185000;
5151
// The area that describes the insides of Las Venturas. Made available and managed by the streamer.
5252
new STREAMER_TAG_AREA: g_areaLasVenturas;
5353

54+
// Time (in milliseconds) until when damage issued by a particular player should be disabled.
55+
new g_damageDisabledExpirationTime[MAX_PLAYERS] = { 0, ... };
56+
5457
// Boolean that indicates whether a particular player is currently in Las Venturas.
5558
new bool: g_inLasVenturas[MAX_PLAYERS] = { false, ... };
5659

@@ -148,6 +151,11 @@ public OnPlayerConnect(playerid) {
148151
return PlayerEvents(playerid)->onPlayerConnect();
149152
}
150153

154+
public OnPlayerSpawn(playerid) {
155+
g_damageDisabledExpirationTime[playerid] = 0;
156+
return LVPPlayerSpawn(playerid);
157+
}
158+
151159
public OnPlayerDisconnect(playerid, reason) {
152160
g_isDisconnecting[playerid] = true;
153161

@@ -453,6 +461,14 @@ public OnPlayerStateChange(playerid, newstate, oldstate) {
453461
if (oldstate == PLAYER_STATE_DRIVER)
454462
ProcessDriftLeaveVehicleForPlayer(playerid);
455463

464+
// When the player is leaving a vehicle, disable their damage for a predefined amount of time
465+
// to avoid players from abusing vehicle bugs to give them an advantage in a fight.
466+
if ((oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
467+
&& g_abuseFakeCarEntryPreventionSec > 0) {
468+
g_damageDisabledExpirationTime[playerid] =
469+
GetTickCount() + g_abuseFakeCarEntryPreventionSec * 1000;
470+
}
471+
456472
return LegacyPlayerStateChange(playerid, newstate, oldstate);
457473
}
458474

@@ -525,6 +541,15 @@ public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float: fX, Float:
525541
#if Feature::EnableServerSideWeaponConfig == 0
526542
DetectAbuseOnWeaponShot(playerid, hittype, hitid);
527543

544+
// If damage has been disabled for the |playerid|, discard the shots entirely. It will expire
545+
// automatically when the time has passed.
546+
if (g_damageDisabledExpirationTime[playerid] > 0) {
547+
if (g_damageDisabledExpirationTime[playerid] < GetTickCount())
548+
g_damageDisabledExpirationTime[playerid] = 0;
549+
else
550+
return 0;
551+
}
552+
528553
// We might want to ignore damage done by players who are passengers as the sole occupant of a
529554
// vehicle. They can only be damaged with a chainsaw, making this very unfair in fights.
530555
if (g_abuseIgnoreSolePassengerDamage && hittype != BULLET_HIT_TYPE_NONE) {
@@ -621,6 +646,19 @@ public OnPlayerUpdate(playerid) {
621646
if (g_driftingEnabled)
622647
ProcessDriftUpdateForPlayer(playerid);
623648

649+
// Determines if the player is entering a vehicle through animation, and if so, marks the time
650+
// until which their damage should be disabled based on the prevention setting.
651+
if (g_abuseFakeCarEntryPreventionSec > 0) {
652+
new const animationIndex = GetPlayerAnimationIndex(playerid);
653+
switch (animationIndex) {
654+
case 1043 /* CAR_OPEN_LHS */, 1044 /* CAR_OPEN_RHS */,
655+
1026 /* CAR_GETIN_LHS */, 1027 /* CAR_GETIN_RHS */: {
656+
g_damageDisabledExpirationTime[playerid] =
657+
GetTickCount() + g_abuseFakeCarEntryPreventionSec * 1000;
658+
}
659+
}
660+
}
661+
624662
return 1;
625663
}
626664
#endif

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 g_abuseFakeCarEntryPreventionSec = 3;
910
new bool: g_abuseIgnoreSolePassengerDamage = true;
1011
new bool: g_abuseKickReasonsPublic = true;
1112
new g_abuseKillAttributionTimeSec = 10;
@@ -23,8 +24,9 @@ new bool: g_vehicleKeysBlockedInLasVenturas = true;
2324

2425
// These are the unique Ids for each of the properties that can be updated. They must be identical
2526
// between the Pawn and the JavaScript code.
26-
// Next ID: 11
27+
// Next ID: 12
2728
enum PawnConfigProperty {
29+
kAbuseFakeCarEntryPrevention = 11,
2830
kAbuseIgnoreSolePassengerDamage = 5,
2931
kAbuseKickReasonPublic = 6,
3032
kAbuseKillAttributionTimeSec = 7,
@@ -44,6 +46,9 @@ public OnPawnConfigDataChange(PawnConfigProperty: property, Float: numberValue)
4446
new const intValue = floatround(numberValue, floatround_tozero);
4547

4648
switch (property) {
49+
case kAbuseFakeCarEntryPrevention:
50+
g_abuseFakeCarEntryPreventionSec = intValue;
51+
4752
case kAbuseIgnoreSolePassengerDamage:
4853
g_abuseIgnoreSolePassengerDamage = !!intValue;
4954

pawn/Features/Gameplay/SpawnManager.pwn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public OnPlayerRequestSpawn(playerid) {
458458
* @param playerid Id of the player who is spawning.
459459
* @return integer False if the player should be returned to class selection after the next spawn.
460460
*/
461-
public OnPlayerSpawn(playerid) {
461+
LVPPlayerSpawn(playerid) {
462462
if (Player(playerid)->isConnected() == false)
463463
return 0;
464464

0 commit comments

Comments
 (0)