View Single Post
root88
Senior Member
Join Date: May 2016
Old 12-11-2018 , 16:31   Re: [CSGO] Axe and hammer pick up
Reply With Quote #18

Quote:
Originally Posted by Bara View Post
https://github.com/Bara/TroubleinTer.../ttt.inc#L1030
Spanner, Axe and Hammer are known as "weapon_melee".

//Edit:
Code:
stock int TTT_HasClientMelee(int client)
{
    for(int offset = 0; offset < 128; offset += 4)
    {
        int weapon = GetEntDataEnt2(client, FindSendPropInfo("CBasePlayer", "m_hMyWeapons") + offset);

        if (IsValidEntity(weapon))
        {
            char sClass[32];
            GetEntityClassname(weapon, sClass, sizeof(sClass));

            if ((StrContains(sClass, "melee", false) != -1))
            {
                return weapon;
            }
        }
    }

    return -1;
}
It's working great, thank you!

In case someone need it, I've modified Papero plugin:
  • it will give random melee on player spawn
  • it will remove all meles on round end
  • it will allow knife pickup

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

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
    
HookEvent("round_end"Event_RoundEndEventHookMode_PostNoCopy);
    
//Lateload 
    
for (int i 1<= MaxClientsi++) if (IsClientInGame(i)) OnClientPutInServer(i);
}

public 
void OnMapStart()
{
    
ServerCommand("mp_drop_knife_enable 1");
}

public 
void OnClientPutInServer(int client

    
SDKHook(clientSDKHook_WeaponCanUseHook_WeaponCanUse); 


public 
Action Hook_WeaponCanUse(int clientint weapon

    
char classname[64]; 
    
GetEntityClassname(weaponclassnamesizeof classname); 
     
    if (
StrEqual(classname"weapon_melee") || StrEqual(classname"weapon_knife")) 
        
EquipPlayerWeapon(clientweapon); 


public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if(
IsPlayerAlive(client))
    {
        
int item GetRandomInt(13);
        if(
item == 1)
        {
            
GivePlayerItem(client"weapon_axe");
        }
        if(
item == 2)
        {
            
GivePlayerItem(client"weapon_hammer");
        }
        if(
item == 3)
        {
            
GivePlayerItem(client"weapon_spanner");
        }
    }
}

public 
Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    for(
int client 1client <= MaxClientsclient++)
    {
        if (
IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client))
        {
            for(
int offset 0offset 128offset += 4)
            {
                
int weapon GetEntDataEnt2(clientFindSendPropInfo("CBasePlayer""m_hMyWeapons") + offset);

                if (
IsValidEntity(weapon))
                {
                    
char sClass[32];
                    
GetEntityClassname(weaponsClasssizeof(sClass));

                    if ((
StrContains(sClass"melee"false) != -1))
                    {
                        
RemovePlayerItem(clientweapon);
                        
AcceptEntityInput(weapon"Kill");
                    }
                }
            }
        }
    }

__________________
root88 is offline