AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Restrict weapons for players and allow for admins (https://forums.alliedmods.net/showthread.php?t=260738)

darkboy245 03-30-2015 17:01

Restrict weapons for players and allow for admins
 
I would like to restrict a certain weapon and only allow admins to wear it, is there any plugin that can do this?

TnTSCS 03-30-2015 17:42

Re: Restrict weapons for players and allow for admins
 
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;



darkboy245 03-31-2015 13:09

Re: Restrict weapons for players and allow for admins
 
Quote:

Originally Posted by TnTSCS (Post 2280027)
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.

TnTSCS 03-31-2015 14:25

Re: Restrict weapons for players and allow for admins
 
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.


All times are GMT -4. The time now is 12:35.

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