Raised This Month: $114 Target: $400
 28% 

Individual Weapon Restrictions


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Admin Commands        Approver:   Exolent[jNr] (178)
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-27-2008 , 18:16   Individual Weapon Restrictions
Reply With Quote #1

Individual Weapon Restrictions v0.5

- Description -
This plugin restricts weapons on a per-player basis. All primary and secondary weapons are supported including all grenades; no shield support at this time. It saves all restrictions to the vault using the players SteamID as the key; if the player disconnects and rejoins, the restrictions will get re-applied. If a player purchases a weapon that is restricted, the players money spent on the restricted weapon will be reimbursed and the weapon gets deleted from game.

- Console Commands -
  • amx_restrictadd <partial name> <partial weapon> - Add a weapon restriction. Example: amx_restrictadd bugs gloc
  • amx_restrictremove <partial name> <partial weapon> - Remove a weapon restriction. Example: amx_restrictremove bugs gloc
  • amx_restrictclear <partial name> - Clears all weapon restrictions
- Chat Commands -
  • /restrict - Displays list of players restricted weapons
- Changelog -
  • v0.5
    - Changed the way restrictions are stored. Instead of storing individual weapon restrictions with an array of integers for each player, they are now stored in a single integer using bit-flags to represent each weapon index.
    - Added Ham_AddPlayerItem forward to detect when a player purchases a weapon. Adding this removed the need to monitor money transactions and the SetModel forward. When a restricted weapon is purchased we can block the player from ever receiving the weapon; the weapon will then be deleted and the players money is reimbursed.
    - Forwards are now enabled\disabled so are only active when needed.
    - Added weapon priority switching so if a player is carrying a weapon when a restriction is for it is added, the most powerful weapon will be set as current weapon. (from VENs real nade drop)
    - This release is nearly a complete re-write
  • v0.4
    - Added notification of weapon restriction when purchased. Now displays name of weapon.
    - Fixed bug where the removal of a restriction was not getting saved to vault
  • v0.3
    - Removed cstrike module and replaced with all fakemeta functions. Also removed WeapPickup, this is now handled in FM_Touch forward. Thanks to Exolent for tips on cleaning up the code.
    Revision - Re-added WeapPickup because weapon was not getting dropped when purchased via buyscript in FM_Touch
  • v0.2
    - Cleaned up the code
  • v0.1
    - Fixed an error index out of bounds in fw_Touch.

328
Attached Files
File Type: sma Get Plugin or Get Source (weaponrestrict.sma - 4478 views - 18.2 KB)
__________________

Last edited by Bugsy; 06-09-2009 at 01:09. Reason: New release
Bugsy is offline
FuZ!on
Senior Member
Join Date: Aug 2007
Old 09-27-2008 , 18:35   Re: Individual Weapon Restrictions
Reply With Quote #2

Very interesting! I must try this!
FuZ!on is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 09-29-2008 , 00:28   Re: Individual Weapon Restrictions
Reply With Quote #3

I think this could be done more elegantly with Hamsandwich. Maybe something like this? I haven't tried it, it's just an idea.
Code:
    /**      * Description:  Deploys the entity (usually a weapon).      * Forward params:  function(this);      * Return type:  Integer (boolean).      * Execute params:  ExecuteHam(Ham_Item_Deploy, this);      */     Ham_Item_Deploy, new g_weapons[][] = {        "weapon_p228",     "weapon_scout",     "weapon_hegrenade",     "weapon_xm1014",     "weapon_c4",     "weapon_mac10",     "weapon_aug",     "weapon_smokegrenade",     "weapon_elite",     "weapon_fiveseven",     "weapon_ump45",     "weapon_sg550",     "weapon_galil",     "weapon_famas",     "weapon_usp",     "weapon_glock18",     "weapon_awp",     "weapon_mp5navy",     "weapon_m249",     "weapon_m3",     "weapon_m4a1",     "weapon_tmp",     "weapon_g3sg1",     "weapon_flashbang",     "weapon_deagle",     "weapon_sg552",     "weapon_ak47",     "weapon_knife",     "weapon_p90" } for(new i = 0; i < sizeof g_weapons; i++) {     RegisterHam(Ham_Item_Deploy, g_weapons[i], "bacon_item_deploy", 0) }
stupok is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-29-2008 , 01:10   Re: Individual Weapon Restrictions
Reply With Quote #4

What does 'deploy' do?
__________________
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-29-2008 , 16:58   Re: Individual Weapon Restrictions
Reply With Quote #5

No need to set them to 0. They are set to 0 when initialized.
Also, that won't set the whole array to 0.
You should've done: new variable[33] = {1, ...}; // sets all "variable" slots to 1
Code:
new g_NumWeapons[33] = {0};                 //Number of weapon restrictions for each player. new g_JoinedBeforeAuth[33] = {0};          //Set to 1 if player joins a team before authorizing with steam. new g_Authorized[33] = {0};                 //Set to 1 when authorizes.

Should be:
Code:
new g_NumWeapons[33];                 //Number of weapon restrictions for each player. new g_JoinedBeforeAuth[33];          //Set to 1 if player joins a team before authorizing with steam. new g_Authorized[33];                 //Set to 1 when authorizes.
---------------------------------------------
Redundant code:
Code:
            iGrenade = 0;             switch (iIndex)             {                 case 1:                 {                     if( CheckWeapon(id,CSW_HEGRENADE) )                         iGrenade = CSW_HEGRENADE;                                             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )                     {                         get_weaponname( iGrenade, szWeapon , 19 );                         PayInfo[0] = id;                         PayInfo[1] = iGrenade;                         cs_set_user_bpammo(id,iGrenade ,0);                         RepayPlayer( PayInfo );                         return PLUGIN_HANDLED;                     }                 }                 case 2:                 {                     if( CheckWeapon(id,CSW_FLASHBANG) )                         iGrenade = CSW_FLASHBANG;                                             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )                     {                         get_weaponname( iGrenade, szWeapon , 19 );                         PayInfo[0] = id;                         PayInfo[1] = iGrenade;                         cs_set_user_bpammo(id,iGrenade ,0);                         RepayPlayer( PayInfo );                         return PLUGIN_HANDLED;                     }                 }                 case 3:                 {                     if( CheckWeapon(id,CSW_SMOKEGRENADE) )                         iGrenade = CSW_SMOKEGRENADE;                                             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )                     {                         get_weaponname( iGrenade, szWeapon , 19 );                         PayInfo[0] = id;                         PayInfo[1] = iGrenade;                         cs_set_user_bpammo(id,iGrenade ,0);                         RepayPlayer( PayInfo );                         return PLUGIN_HANDLED;                     }                 }             }

Should be:
Code:
            iGrenade = 0;             switch (iIndex)             {                 case 1:                 {                     if( CheckWeapon(id,CSW_HEGRENADE) )                         iGrenade = CSW_HEGRENADE;                 }                 case 2:                 {                     if( CheckWeapon(id,CSW_FLASHBANG) )                         iGrenade = CSW_FLASHBANG;                 }                 case 3:                 {                     if( CheckWeapon(id,CSW_SMOKEGRENADE) )                         iGrenade = CSW_SMOKEGRENADE;                 }             }             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )             {                 get_weaponname( iGrenade, szWeapon , 19 );                 PayInfo[0] = id;                 PayInfo[1] = iGrenade;                 cs_set_user_bpammo(id,iGrenade ,0);                 RepayPlayer( PayInfo );                 return PLUGIN_HANDLED;             }
------------------------------------------------
This is disgusting:
Code:
public GetWeaponIndex(szPartial[]) {     if( containi( "p228", szPartial ) > -1)         return CSW_P228;     else if( containi("scout", szPartial ) > -1 )             return CSW_SCOUT;     else if( containi("xm1014", szPartial ) > -1 )             return CSW_XM1014;     else if( containi("mac10", szPartial ) > -1 )             return CSW_MAC10;     else if( containi("aug", szPartial ) > -1 )             return CSW_AUG;     else if( containi("elite", szPartial ) > -1 )             return CSW_ELITE;     else if( containi("fiveseven", szPartial ) > -1 )             return CSW_FIVESEVEN;     else if( containi("ump45", szPartial ) > -1 )             return CSW_UMP45;     else if( containi("sg550", szPartial ) > -1 )             return CSW_SG550;     else if( containi("galil", szPartial ) > -1 )             return CSW_GALIL;     else if( containi("famas", szPartial ) > -1 )             return CSW_FAMAS;     else if( containi("usp", szPartial ) > -1 )             return CSW_USP;     else if( containi("glock18", szPartial ) > -1 )             return CSW_GLOCK18;     else if( containi("awp", szPartial ) > -1 )             return CSW_AWP;     else if( containi("mp5navy", szPartial ) > -1 )             return CSW_MP5NAVY;     else if( containi("m249", szPartial ) > -1 )             return CSW_M249;     else if( containi("m3", szPartial ) > -1 )             return CSW_M3;     else if( containi("m4a1", szPartial ) > -1 )             return CSW_M4A1;     else if( containi("tmp", szPartial ) > -1 )             return CSW_TMP;     else if( containi("g3sg1", szPartial ) > -1 )             return CSW_G3SG1;     else if( containi("deagle", szPartial ) > -1 )             return CSW_DEAGLE;     else if( containi("sg552", szPartial ) > -1 )             return CSW_SG552;     else if( containi("ak47", szPartial ) > -1 )             return CSW_AK47;     else if( containi("p90", szPartial ) > -1 )             return CSW_P90;     else if( containi("hegrenade", szPartial ) > -1 )             return CSW_HEGRENADE;     else if( containi("smokegrenade", szPartial ) > -1 )             return CSW_SMOKEGRENADE;     else if( containi("flashbang", szPartial ) > -1 )             return CSW_FLASHBANG;             return 0; }
Should be:
Code:
new const g_weapon_names[][] = {     "p228",     "scout",     "xm1014",     "mac10",     "aug",     "elite",     "fiveseven",     "ump45",     "sg550",     "galil",     "famas",     "usp",     "glock18",     "awp",     "mp5navy",     "m249",     "m3",     "m4a1",     "tmp",     "g3sg1",     "deagle",     "sg552",     "ak47",     "p90",     "hegrenade",     "smokegrenade",     "flashbang" }; new const g_weapon_ids[sizeof(g_weapon_names)] = {     CSW_P228,     CSW_SCOUT,     CSW_XM1014,     CSW_MAC10,     CSW_AUG,     CSW_ELITE,     CSW_FIVESEVEN,     CSW_UMP45,     CSW_SG550,     CSW_GALIL,     CSW_FAMAS,     CSW_USP,     CSW_GLOCK18,     CSW_AWP,     CSW_MP5NAVY,     CSW_M249,     CSW_M3,     CSW_M4A1,     CSW_TMP,     CSW_G3SG1,     CSW_DEAGLE,     CSW_SG552,     CSW_AK47,     CSW_P90,     CSW_HEGRENADE,     CSW_FLASHBANG,     CSW_SMOKEGRENADE }; public GetWeaponIndex(szPartial[]) {     for( new i = 0; i < sizeof(g_weapon_names); i++ )     {         if( containi(szPartial, g_weapon_names[i]) != -1 )         {             return g_weapon_ids[i];         }     }             return 0; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2008 , 02:16   Re: Individual Weapon Restrictions
Reply With Quote #6

Sorry about the sloppy code, I meant to clean it up before releasing. I cleaned it up based on your reply and I also got rid of the weapon models array and getweaponmodel function altogether.
__________________

Last edited by Bugsy; 09-30-2008 at 02:44.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-30-2008 , 12:32   Re: Individual Weapon Restrictions
Reply With Quote #7

1.
Code:
                    //This will force a player to drop a weapon if he is carrying a weapon when                     //a restriction is added for it.                     client_cmd( iPlayer, "drop %s", szWeapon );

Wrong. Here is the correct way:
Code:
engclient_cmd( iPlayer, "drop", szWeapon );
--------------------------------------------------------------
2. You can remove <cstrike> and replace it with fakemeta conversions.
It's not required, but it's always nice to have 1 less module being used, especially when it's replaced with fakemeta.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2008 , 12:44   Re: Individual Weapon Restrictions
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
1.
Code:
                    //This will force a player to drop a weapon if he is carrying a weapon when                     //a restriction is added for it.                     client_cmd( iPlayer, "drop %s", szWeapon );

Wrong. Here is the correct way:
Code:
engclient_cmd( iPlayer, "drop", szWeapon );
--------------------------------------------------------------
2. You can remove <cstrike> and replace it with fakemeta conversions.
It's not required, but it's always nice to have 1 less module being used, especially when it's replaced with fakemeta.
I'll do all of the conversions you want, make me a list. It does work properly as it is written now, though.

These are the functions needed to be converted to fakemeta:
cs_get_user_bpammo
cs_set_user_bpammo
cs_get_user_money (done)
cs_set_user_money (done)
cs_get_weapon_id (can be replaced with get_weaponid?)
__________________

Last edited by Bugsy; 09-30-2008 at 12:56.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-30-2008 , 16:39   Re: Individual Weapon Restrictions
Reply With Quote #9

This is a full (almost) list of cstrike -> fakemeta conversions.
For the cs_[s|g|res]et_user_model() functions, look at Mercylezz tutorial on lowering SVC_BAD.
Attached Files
File Type: inc cs_to_fm.inc (33.3 KB, 283 views)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-01-2008 , 02:04   Re: Individual Weapon Restrictions
Reply With Quote #10

cstrike module has been removed and all functions now handled via fakemeta. Let me know if you see anything else that needs fixing.

Do you think I need to implement the SVC_BAD fix for this plugin. I did get the reliable channel overflow error a few times at round start when I was pressing my buy key. I removed notification to the player if a purchased weapon is restricted thinking that was the cause of the overflow and it did stop (unless it was coincidental?)
__________________

Last edited by Bugsy; 10-01-2008 at 02:42.
Bugsy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:36.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode