Raised This Month: $32 Target: $400
 8% 

[CSGO] Give fists when dropping the knife


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Deivid90
Junior Member
Join Date: Apr 2019
Old 04-14-2019 , 07:53   [CSGO] Give fists when dropping the knife
Reply With Quote #1

I'm using the Franc1sco plugin with the command "mp_drop_knife_enable", but I can not make it work only when you release the knife, then it will no longer allow you to pick it up.

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define DATA "2.2"

public Plugin myinfo =
{
    
name "SM CS:GO Spawn With Melee Weapons",
    
author "Franc1sco franug",
    
description "Force players to spawn different melee weapons",
    
version DATA,
    
url "http://steamcommunity.com/id/franug"
};

ConVar cv_team;
ConVar cv_fists;
ConVar cv_knife;
ConVar cv_axe;
ConVar cv_hammer;
ConVar cv_spanner;
ConVar cv_blockattack2;
ConVar cv_wtimer;

int g_iTeam;
int g_bFists;
int g_bKnife;
int g_bAxe;
int g_bHammer;
int g_bSpanner;
int g_bBlockAttack2;
float g_fTimer;

public 
void OnPluginStart()
{
    
CreateConVar("sm_csgomeleeweapons_version"DATA"Plugin Version"FCVAR_NONE|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
    
cv_team CreateConVar("sm_csgomeleeweapons_team""4""Apply only to a team. 2 = terrorist, 3 = counter-terrorist, 4 = both."0true0.0true4.0);
    
cv_fists CreateConVar("sm_csgomeleeweapons_fists""1""Give fists? 1 = yes, 0 = no."0true0.0true1.0);
    
cv_knife CreateConVar("sm_csgomeleeweapons_knife""1""Give knife? 1 = yes, 0 = no."0true0.0true1.0);
    
cv_axe CreateConVar("sm_csgomeleeweapons_axe""0""Give axe on spawn? 1 = yes, 0 = no."0true0.0true1.0);
    
cv_hammer CreateConVar("sm_csgomeleeweapons_hammer""0""Give hammer on spawn? 1 = yes, 0 = no."0true0.0true1.0);
    
cv_spanner CreateConVar("sm_csgomeleeweapons_spanner""0""Give spanner on spawn? 1 = yes, 0 = no."0true0.0true1.0);
    
cv_blockattack2 CreateConVar("sm_csgomeleeweapons_blockattack2""1""Block right click? 1 = yes, 0 = no."0true0.0true1.0);
    
cv_wtimer CreateConVar("sm_csgomeleeweapons_timer""1.6""Time in seconds after spawn to give melee weapons."0true0.0);
    
    
g_iTeam GetConVarInt(cv_team);
    
g_bFists GetConVarInt(cv_fists);
    
g_bKnife GetConVarInt(cv_knife);
    
g_bAxe GetConVarInt(cv_axe);
    
g_bHammer GetConVarInt(cv_hammer);
    
g_bSpanner GetConVarInt(cv_spanner);
    
g_bBlockAttack2 GetConVarInt(cv_blockattack2);
    
g_fTimer GetConVarFloat(cv_wtimer);
    
    
HookConVarChange(cv_teamOnConVarChanged);
    
HookConVarChange(cv_fistsOnConVarChanged);
    
HookConVarChange(cv_knifeOnConVarChanged);
    
HookConVarChange(cv_axeOnConVarChanged);
    
HookConVarChange(cv_hammerOnConVarChanged);
    
HookConVarChange(cv_spannerOnConVarChanged);
    
HookConVarChange(cv_blockattack2OnConVarChanged);
    
HookConVarChange(cv_wtimerOnConVarChanged);
    
    
// Plugin only for csgo
    
if(GetEngineVersion() != Engine_CSGO)
        
SetFailState("This plugin is for CSGO only.");
        
    
// hook spawn event
    
HookEvent("player_spawn"Event_PlayerSpawn);
    
    
AutoExecConfig(true"csgo_melee_weapons");
}

public 
void OnConVarChanged(ConVar convar, const char[] oldVal, const char[] newVal)
{
    if (
convar == cv_team) {
        
g_iTeam StringToInt(newVal);
    } else if (
convar == cv_fists) {
        
g_bFists StringToInt(newVal);
    } else if (
convar == cv_knife) {
        
g_bKnife StringToInt(newVal);
    } else if (
convar == cv_axe) {
        
g_bAxe StringToInt(newVal);
    } else if (
convar == cv_hammer) {
        
g_bHammer StringToInt(newVal);
    } else if (
convar == cv_spanner) {
        
g_bSpanner StringToInt(newVal);
    } else if (
convar == cv_blockattack2) {
        
g_bBlockAttack2 StringToInt(newVal);
    } else if (
convar == cv_wtimer) {
        
g_fTimer StringToFloat(newVal);
    }
}

public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
    
// delay for don't conflict with others plugins that give weapons on spawn (?)
    
CreateTimer(g_fTimerTimer_DelayGetClientUserId(client));
}  

public 
Action Timer_Delay(Handle timerint id)
{
    
// check if client valid
    
int client GetClientOfUserId(id);
    if(!
client || !IsClientInGame(client) || !IsPlayerAlive(client) || (g_iTeam && g_iTeam != GetClientTeam(client)))
        return;
            
    
// remove all the weapons on "melee slot" in order to prevent the bug of duplicated fists
    
int weapon;
    while((
weapon GetPlayerWeaponSlot(clientCS_SLOT_KNIFE)) != -1)
    {
        
RemovePlayerItem(clientweapon);
        
AcceptEntityInput(weapon"Kill");
    }
    
    
int iMelee;
    
    
//Fists
    
if (g_bFists)
    {
        
iMelee GivePlayerItem(client"weapon_fists");
        
EquipPlayerWeapon(clientiMelee);
    }
    
    if (
g_bAxe)
    {
        
iMelee GivePlayerItem(client"weapon_axe");
        
EquipPlayerWeapon(clientiMelee);
    }
    
    if (
g_bHammer)
    {
        
iMelee GivePlayerItem(client"weapon_hammer");
        
EquipPlayerWeapon(clientiMelee);
    }
    
    if (
g_bSpanner)
    {
        
iMelee GivePlayerItem(client"weapon_spanner");
        
EquipPlayerWeapon(clientiMelee);
    }
    
    if (
g_bKnife)
    {
        
iMelee GivePlayerItem(client"weapon_knife");
        
EquipPlayerWeapon(clientiMelee); // if not then knife dropped :s
    
}
}

public 
Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weapon)
{
    if (!
g_bBlockAttack2)
    {
        return 
Plugin_Continue;
    }
    
    
//Client is not valid
    
if (!IsValidClient(client) || !IsPlayerAlive(client))
    {
        return 
Plugin_Continue;
    }
    
    if (
g_iTeam && g_iTeam != GetClientTeam(client))
    {
        return 
Plugin_Continue;
    }
    
    
//Attempting to use right click
    
if (buttons IN_ATTACK2)
    {
        
char buffer[128];
        
        
int item GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        
        
// prevent log errors
        
if(item == -1)
            return 
Plugin_Continue;
        
        
GetEntityClassname(itembuffersizeof(buffer));
        
        if (
StrEqual(buffer"weapon_fists"false) || StrEqual(buffer"weapon_melee"false))
        {
            
buttons &= ~IN_ATTACK2//Don't press attack 2
            
return Plugin_Changed;
        }        
    }
    
    return 
Plugin_Continue;
}

stock bool IsValidClient(int client)
{
    if ((
client <= 0) || (client MaxClients)) {
        return 
false;
    }
    if (!
IsClientInGame(client)) {
        return 
false;
    }
    return 
true;

Deivid90 is offline
darkboss
Member
Join Date: Mar 2020
Location: Street (Homeless)
Old 11-30-2021 , 20:27   Re: [CSGO] Give fists when dropping the knife
Reply With Quote #2

u can add mp_items_prohibited 0 to see if its work pick up dropped knife

Last edited by darkboss; 11-30-2021 at 22:19.
darkboss 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 19:50.


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