Raised This Month: $12 Target: $400
 3% 

Restrict weapons for players and allow for admins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
darkboy245
Senior Member
Join Date: Feb 2014
Old 03-30-2015 , 17:01   Restrict weapons for players and allow for admins
Reply With Quote #1

I would like to restrict a certain weapon and only allow admins to wear it, is there any plugin that can do this?
darkboy245 is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-30-2015 , 17:42   Re: Restrict weapons for players and allow for admins
Reply With Quote #2

Something like this might work - untested - it's SM1.7+ syntax - it's just for the weapon_m4a1 - edit that to what you want. And only admins who have the generic admin flag (or whatever you override the command "allow_admin_weapon" to)

PHP Code:
#include <sourcemod>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

bool PlayerIsAdmin[MAXPLAYERS+1];

public 
void OnClientPostAdminCheck(int client)
{
    
PlayerIsAdmin[client] = CheckCommandAccess(client"allow_admin_weapon"ADMFLAG_GENERIC);
    
SDKHook(clientSDKHook_WeaponCanUseOnWeaponCanUse);
}

public 
void OnClientDisconnect(int client)
{
    
SDKUnhook(clientSDKHook_WeaponCanUseOnWeaponCanUse);
}

public 
Action CS_OnBuyCommand(int client, const char[] weapon)
{
    if (!
IsClientInGame(client) || GetClientTeam(client) <= 1)
    {
        return 
Plugin_Continue;
    }

    if (!
PlayerCanUseWeapon(clientweapon))
    {
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;
}

bool PlayerCanUseWeapon(int client, const char[] weapon)
{
    if (
StrEqual("weapon_m4a1"weaponfalse) && !PlayerIsAdmin[client])
    {
        return 
false;
    }
    
    return 
true;
}

public 
Action OnWeaponCanUse(int clientint weapon)
{
    
char g_sWeapon[50];
    
GetEntityClassname(weapong_sWeaponsizeof(g_sWeapon));    
    
    if (!
PlayerCanUseWeapon(clientg_sWeapon))
    {
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;

__________________
View my Plugins | Donate

Last edited by TnTSCS; 03-30-2015 at 17:45.
TnTSCS is offline
darkboy245
Senior Member
Join Date: Feb 2014
Old 03-31-2015 , 13:09   Re: Restrict weapons for players and allow for admins
Reply With Quote #3

Quote:
Originally Posted by TnTSCS View Post
Something like this might work - untested - it's SM1.7+ syntax - it's just for the weapon_m4a1 - edit that to what you want. And only admins who have the generic admin flag (or whatever you override the command "allow_admin_weapon" to)

PHP Code:
#include <sourcemod>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

bool PlayerIsAdmin[MAXPLAYERS+1];

public 
void OnClientPostAdminCheck(int client)
{
    
PlayerIsAdmin[client] = CheckCommandAccess(client"allow_admin_weapon"ADMFLAG_GENERIC);
    
SDKHook(clientSDKHook_WeaponCanUseOnWeaponCanUse);
}

public 
void OnClientDisconnect(int client)
{
    
SDKUnhook(clientSDKHook_WeaponCanUseOnWeaponCanUse);
}

public 
Action CS_OnBuyCommand(int client, const char[] weapon)
{
    if (!
IsClientInGame(client) || GetClientTeam(client) <= 1)
    {
        return 
Plugin_Continue;
    }

    if (!
PlayerCanUseWeapon(clientweapon))
    {
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;
}

bool PlayerCanUseWeapon(int client, const char[] weapon)
{
    if (
StrEqual("weapon_m4a1"weaponfalse) && !PlayerIsAdmin[client])
    {
        return 
false;
    }
    
    return 
true;
}

public 
Action OnWeaponCanUse(int clientint weapon)
{
    
char g_sWeapon[50];
    
GetEntityClassname(weapong_sWeaponsizeof(g_sWeapon));    
    
    if (!
PlayerCanUseWeapon(clientg_sWeapon))
    {
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;

I want to restrict the sticky jumper so I used "tf_weapon_pipebomblauncher", but it doesn't do anything in-game, so I suppose this doesn't work.
darkboy245 is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-31-2015 , 14:25   Re: Restrict weapons for players and allow for admins
Reply With Quote #4

You never said it was for TF. I don't know if CS_OnBuyCommand works for TF and I don't know TF well enough.

The SDKHooks should still work for OnWeaponCanUse though.
__________________
View my Plugins | Donate
TnTSCS 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 04:45.


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