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

Only Allow AWP/Knife Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SnowHP
Senior Member
Join Date: Sep 2016
Location: Porto, Portugal
Old 08-20-2017 , 19:13   Only Allow AWP/Knife Plugin
Reply With Quote #1

Can someone made a code that only AWP/Knife is allow on the server?
SnowHP is offline
trzmielu
Member
Join Date: Aug 2016
Old 08-21-2017 , 07:16   Re: Only Allow AWP/Knife Plugin
Reply With Quote #2

Hello,

have you tried this: https://forums.alliedmods.net/showthread.php?p=950174

Regards
trzmielu is offline
SnowHP
Senior Member
Join Date: Sep 2016
Location: Porto, Portugal
Old 08-21-2017 , 09:53   Re: Only Allow AWP/Knife Plugin
Reply With Quote #3

Quote:
Originally Posted by trzmielu View Post
Hello,

have you tried this: https://forums.alliedmods.net/showthread.php?p=950174

Regards
I know! But that plugin prints mensages to chat Want something simpler
SnowHP is offline
zperkitny
Junior Member
Join Date: Aug 2017
Old 08-21-2017 , 22:33   Re: Only Allow AWP/Knife Plugin
Reply With Quote #4

Here's something:

The players are unable to purchase any weapons and whenever they spawn, their pistols are removed, and are given an AWP.

Source:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define PLUGIN_VERSION "0.0.2"

ConVar g_wrEnabled;

public 
Plugin myinfo =
{
    
name "Weapon Restriction",
    
author "Zach",
    
description "Restricts weapons to an AWP and Knife.",
    
version PLUGIN_VERSION
};

public 
void OnPluginStart()
{
  
g_wrEnabled CreateConVar("wr_enabled""1""Used to enable/disable AWP/Knife Weapon Restrictions.");
  
g_wrEnabled.AddChangeHook(EnabledChange);
  
HookEvent("player_spawn"Event_OnPlayerSpawn);
}

/* used to prevent users from buying items */
public Action CS_OnBuyCommand(int client, const char[] weapon)
{
  if(
g_wrEnabled.IntValue){ // if enabled
    
return Plugin_Handled;
  }
  return 
Plugin_Continue;
}

public 
void Event_OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
  if(!
g_wrEnabled.IntValue){ //if disabled, dont do anything
    
return;
  }
  
int client GetClientOfUserId(event.GetInt("userid"));
  if(
client//ensure valid user
    
removeWeaponsAndGiveAwp(client);
}

public 
void EnabledChange(ConVar convarchar[] oldValuechar[] newValue)
{
  
bool wasEnabled = !StrEqual(oldValue"0");
  
bool enabled = !StrEqual(newValue"0");
  if(!
wasEnabled && enabled)
  {
    
int i;
    for(
1<= MaxClientsi++){
      if(
IsClientConnected(i)){
        
removeWeaponsAndGiveAwp(i);
      }
    }
  }
}

void removeWeaponsAndGiveAwp(client){
  
int team GetClientTeam(client);
  if(
team != 1// if the player isn't a spectator
  
{
    
int i;
    for(
05i++) // remove all weapons
    
{
      
int weapon;
      while((
weapon GetPlayerWeaponSlot(clienti)) != -1)
      {
        
RemovePlayerItem(clientweapon);
      }
    }
    
GivePlayerItem(client"weapon_knife");
    
GivePlayerItem(client"weapon_awp");
  }


Last edited by zperkitny; 08-24-2017 at 15:05. Reason: Updated Source Code
zperkitny is offline
martvonk
Junior Member
Join Date: Jul 2012
Old 08-23-2017 , 14:59   Re: Only Allow AWP/Knife Plugin
Reply With Quote #5

Quote:
Originally Posted by zperkitny View Post
Here's something:

The players are unable to purchase any weapons and whenever they spawn, their pistols are removed, and are given an AWP.

Source:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define PLUGIN_VERSION "0.0.1"

public Plugin myinfo =
{
    
name "Weapon Restriction",
    
author "Zach",
    
description "Restricts weapons to an AWP and Knife.",
    
version PLUGIN_VERSION
};

public 
void OnPluginStart()
{
  
HookEvent("player_spawn"Event_OnPlayerSpawn);
}

/* used to prevent users from buying items */
public Action CS_OnBuyCommand(int client, const char[] weapon)
{
  return 
Plugin_Handled;
}

public 
void Event_OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
  
int client GetClientOfUserId(event.GetInt("userid"));
  if(
client// ensure valid userid
  
{
    
int team GetClientTeam(client);
    if(
team != 1// if the player isn't a spectator
    
{
      
/* remove pistol (slot id 1) */
      
int weapon GetPlayerWeaponSlot(client1);
      if(
weapon != -1// make sure weapon exists
        
RemovePlayerItem(clientweapon);
      
/* give user an awp */
      
GivePlayerItem(client"weapon_awp");
    }
  }

thx, can you add a cvar, soo we disable/enable it,
martvonk is offline
zperkitny
Junior Member
Join Date: Aug 2017
Old 08-23-2017 , 17:12   Re: Only Allow AWP/Knife Plugin
Reply With Quote #6

Quote:
Originally Posted by martvonk View Post
thx, can you add a cvar, soo we disable/enable it,
Yes I will, I have some work to do right now, but I'll update the code sometime this evening.
zperkitny is offline
SnowHP
Senior Member
Join Date: Sep 2016
Location: Porto, Portugal
Old 08-24-2017 , 07:00   Re: Only Allow AWP/Knife Plugin
Reply With Quote #7

Quote:
Originally Posted by zperkitny View Post
Here's something:

The players are unable to purchase any weapons and whenever they spawn, their pistols are removed, and are given an AWP.

Source:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define PLUGIN_VERSION "0.0.1"

public Plugin myinfo =
{
    
name "Weapon Restriction",
    
author "Zach",
    
description "Restricts weapons to an AWP and Knife.",
    
version PLUGIN_VERSION
};

public 
void OnPluginStart()
{
  
HookEvent("player_spawn"Event_OnPlayerSpawn);
}

/* used to prevent users from buying items */
public Action CS_OnBuyCommand(int client, const char[] weapon)
{
  return 
Plugin_Handled;
}

public 
void Event_OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
  
int client GetClientOfUserId(event.GetInt("userid"));
  if(
client// ensure valid userid
  
{
    
int team GetClientTeam(client);
    if(
team != 1// if the player isn't a spectator
    
{
      
/* remove pistol (slot id 1) */
      
int weapon GetPlayerWeaponSlot(client1);
      if(
weapon != -1// make sure weapon exists
        
RemovePlayerItem(clientweapon);
      
/* give user an awp */
      
GivePlayerItem(client"weapon_awp");
    }
  }

Thx For Help

Last edited by SnowHP; 08-24-2017 at 07:01. Reason: Compile done!
SnowHP is offline
zperkitny
Junior Member
Join Date: Aug 2017
Old 08-24-2017 , 14:58   Re: Only Allow AWP/Knife Plugin
Reply With Quote #8

Quote:
Originally Posted by SnowHP View Post
Thx For Help
I updated my original response with a convar for enabling/disabling the plugin. If, for example, you decide to enable the plugin in the middle of the round, it will remove every player's (including bots) weapons and give them an awp and a knife. I haven't tested it, so let me know if there's anything you want me change/fix.

Last edited by zperkitny; 08-24-2017 at 15:05.
zperkitny is offline
SnowHP
Senior Member
Join Date: Sep 2016
Location: Porto, Portugal
Old 08-25-2017 , 07:18   Re: Only Allow AWP/Knife Plugin
Reply With Quote #9

Quote:
Originally Posted by zperkitny View Post
I updated my original response with a convar for enabling/disabling the plugin. If, for example, you decide to enable the plugin in the middle of the round, it will remove every player's (including bots) weapons and give them an awp and a knife. I haven't tested it, so let me know if there's anything you want me change/fix.
For me this is perfect! 100% working thx
SnowHP is offline
Reply



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 07:59.


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