Quote:
Originally Posted by Bara
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_RoundEnd, EventHookMode_PostNoCopy);
//Lateload
for (int i = 1; i <= MaxClients; i++) if (IsClientInGame(i)) OnClientPutInServer(i);
}
public void OnMapStart()
{
ServerCommand("mp_drop_knife_enable 1");
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_WeaponCanUse, Hook_WeaponCanUse);
}
public Action Hook_WeaponCanUse(int client, int weapon)
{
char classname[64];
GetEntityClassname(weapon, classname, sizeof classname);
if (StrEqual(classname, "weapon_melee") || StrEqual(classname, "weapon_knife"))
EquipPlayerWeapon(client, weapon);
}
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsPlayerAlive(client))
{
int item = GetRandomInt(1, 3);
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[] name, bool dontBroadcast)
{
for(int client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(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))
{
RemovePlayerItem(client, weapon);
AcceptEntityInput(weapon, "Kill");
}
}
}
}
}
}
__________________