From 00beb4946685892a900ad5667fcb0e0289002f07 Mon Sep 17 00:00:00 2001 From: Damen Date: Fri, 25 Jan 2019 00:18:07 -0500 Subject: [PATCH] removes the ability for LEOs to purchase a chainsaw, while also reworking certain functions to make them more accessible for global use --- gamemodes/irresistible/anticheat/weapon.pwn | 30 ++++++++ gamemodes/irresistible/cnr/classes.pwn | 8 ++ .../irresistible/cnr/features/weapon_drop.pwn | 77 +++++++++++-------- gamemodes/sf-cnr.pwn | 3 + 4 files changed, 86 insertions(+), 32 deletions(-) diff --git a/gamemodes/irresistible/anticheat/weapon.pwn b/gamemodes/irresistible/anticheat/weapon.pwn index 503cfad..d1d8a48 100644 --- a/gamemodes/irresistible/anticheat/weapon.pwn +++ b/gamemodes/irresistible/anticheat/weapon.pwn @@ -49,6 +49,13 @@ hook OnPlayerDeath( playerid, killerid, reason ) return 1; } +hook OnPlayerUpdate( playerid ) +{ + if ( IsPlayerAnyLEO( playerid ) && CheckIfPlayerHasWeapon( playerid, 9 ) ) + RemoveSpecificPlayerWeapon( playerid, 9, false ); + return 1; +} + hook OnPlayerSpawn( playerid ) { if ( 0 <= playerid < MAX_PLAYERS ) @@ -300,3 +307,26 @@ stock AC_CreateDynamicPickup( modelid, type, Float: x, Float: y, Float: z, world #define _ALS_CreateDynamicPickup #endif #define CreateDynamicPickup AC_CreateDynamicPickup + +stock CheckIfPlayerHasWeapon( playerid, weaponid ) +{ + new + iCurrentWeapon = GetPlayerWeapon( playerid ), + iWeapon, + iAmmo + ; + + if ( iCurrentWeapon == weaponid ) + return true; + else + { + for ( new iSlot = 0; iSlot < 13; iSlot++ ) + { + GetPlayerWeaponData( playerid, iSlot, iWeapon, iAmmo ); + + if ( iWeapon == weaponid ) + return true; + } + return false; + } +} \ No newline at end of file diff --git a/gamemodes/irresistible/cnr/classes.pwn b/gamemodes/irresistible/cnr/classes.pwn index e073361..9fc145d 100644 --- a/gamemodes/irresistible/cnr/classes.pwn +++ b/gamemodes/irresistible/cnr/classes.pwn @@ -489,3 +489,11 @@ stock IsPlayerPolice( playerid ) } return false; } + +stock IsPlayerAnyLEO( playerid ) +{ + if ( IsPlayerPolice( playerid ) || IsPlayerArmy( playerid ) || IsPlayerCIA( playerid ) || IsPlayerFBI( playerid ) ) + return true; + else + return false; +} \ No newline at end of file diff --git a/gamemodes/irresistible/cnr/features/weapon_drop.pwn b/gamemodes/irresistible/cnr/features/weapon_drop.pwn index 25ab57b..10f8cf5 100644 --- a/gamemodes/irresistible/cnr/features/weapon_drop.pwn +++ b/gamemodes/irresistible/cnr/features/weapon_drop.pwn @@ -317,42 +317,12 @@ CMD:dropweapon( playerid, params[ ] ) { if ( p_Spectating{ playerid } ) return SendError( playerid, "You cannot use such commands while you're spectating." ); new - iCurrentWeapon = GetPlayerWeapon( playerid ), - iWeaponID[ 13 ], - iWeaponAmmo[ 13 ] + iCurrentWeapon = GetPlayerWeapon( playerid ) ; if ( iCurrentWeapon != 0 ) { - for( new iSlot = 0; iSlot < sizeof( iWeaponAmmo ); iSlot++ ) - { - new - iWeapon, - iAmmo; - - GetPlayerWeaponData( playerid, iSlot, iWeapon, iAmmo ); - - if ( iWeapon != iCurrentWeapon ) { - GetPlayerWeaponData( playerid, iSlot, iWeaponID[ iSlot ], iWeaponAmmo[ iSlot ] ); - } - else - { - new - Float: X, Float: Y, Float: Z; - - if ( GetPlayerPos( playerid, X, Y, Z ) && CreateWeaponPickup( iWeapon, iAmmo, iSlot, X + fRandomEx( 0.5, 3.0 ), Y + fRandomEx( 0.5, 3.0 ), Z, GetServerTime( ) + 120, .nonpassive_only = false ) != ITER_NONE ) { - p_PlayerPickupDelay[ playerid ] = GetServerTime( ) + 3; - } - } - } - - ResetPlayerWeapons( playerid ); - - for( new iSlot = 0; iSlot < sizeof( iWeaponAmmo ); iSlot++ ) { - GivePlayerWeapon( playerid, iWeaponID[ iSlot ], 0 <= iWeaponAmmo[ iSlot ] < 16384 ? iWeaponAmmo[ iSlot ] : 16384 ); - } - - SetPlayerArmedWeapon( playerid, 0 ); // prevent driveby + RemoveSpecificPlayerWeapon( playerid, iCurrentWeapon, true ); return SendServerMessage( playerid, "You have dropped your weapon." ); } else { return SendError( playerid, "You are not holding any weapon." ); @@ -439,3 +409,46 @@ stock ClearInactiveWeaponDrops( ) } return 1; } + +stock RemoveSpecificPlayerWeapon( playerid, weaponid, bool:createpickup ) +{ + new + iCurrentWeapon = GetPlayerWeapon( playerid ), + iWeaponID[ 13 ], + iWeaponAmmo[ 13 ] + ; + + if ( iCurrentWeapon != 0 ) + { + for( new iSlot = 0; iSlot < sizeof( iWeaponAmmo ); iSlot++ ) + { + new + iWeapon, + iAmmo; + + GetPlayerWeaponData( playerid, iSlot, iWeapon, iAmmo ); + + if ( iWeapon != iCurrentWeapon || iWeapon != weaponid ) { + GetPlayerWeaponData( playerid, iSlot, iWeaponID[ iSlot ], iWeaponAmmo[ iSlot ] ); + } + else if ( createpickup ) + { + new + Float: X, Float: Y, Float: Z; + + if ( GetPlayerPos( playerid, X, Y, Z ) && CreateWeaponPickup( iWeapon, iAmmo, iSlot, X + fRandomEx( 0.5, 3.0 ), Y + fRandomEx( 0.5, 3.0 ), Z, GetServerTime( ) + 120, .nonpassive_only = false ) != ITER_NONE ) { + p_PlayerPickupDelay[ playerid ] = GetServerTime( ) + 3; + } + } + } + + ResetPlayerWeapons( playerid ); + + for( new iSlot = 0; iSlot < sizeof( iWeaponAmmo ); iSlot++ ) { + GivePlayerWeapon( playerid, iWeaponID[ iSlot ], 0 <= iWeaponAmmo[ iSlot ] < 16384 ? iWeaponAmmo[ iSlot ] : 16384 ); + } + + SetPlayerArmedWeapon( playerid, 0 ); // prevent driveby + } + return 1; +} \ No newline at end of file diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index a831457..b0e4335 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -5039,6 +5039,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) case 17 .. 22: weaponid = listitem - 12; case 23 .. 24: weaponid = listitem - 9; } + if ( IsPlayerAnyLEO( playerid ) && weaponid == 9 ) return SendError( playerid, "You cannot purchase a chainsaw as a Law Enforcement Officer." ); GivePlayerWeapon( playerid, weaponid, 0xFFFF ); SendServerMessage( playerid, "You have redeemed a %s.", ReturnWeaponName( weaponid ) ); p_VIPWeaponRedeem[ playerid ] = g_iTime + ( p_VIPLevel[ playerid ] == VIP_PLATINUM ? 60 : 300 ); @@ -5566,6 +5567,8 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) { if ( x == listitem ) { + // Chainsaw Removal for LEO through Ammunation + if ( IsPlayerAnyLEO( playerid ) && g_AmmunationWeapons[ i ] [ E_WEPID ] == 9 ) return SendError( playerid, "You cannot purchase a chainsaw as a Law Enforcement Officer." ); if ( g_AmmunationWeapons[ i ] [ E_PRICE ] > GetPlayerCash( playerid ) ) { SendError( playerid, "You don't have enough money for this." );