Skip to content
Permalink
Browse files

Fix issue with no knife on round start

I also added 3 new cvars, that allow to spawn with fists and no knives (configurable).

I copied this code from a private version where that issue was fixed. I can't guarantee that if it works with all ws/knives plugins.

Fix #349
  • Loading branch information...
Bara committed Mar 8, 2019
1 parent bdbe881 commit 11b4d8a1fe2bb16ce87cef3dca08166868ceb818
@@ -13,6 +13,7 @@
#define ROLE_LENGTH 16
#define MAX_ITEM_LENGTH 64
#define TTT_LOG_SIZE 512
#define CS_SLOT_MELEE CS_SLOT_KNIFE

#include <ttt_stock>
#include <sdktools>
@@ -728,6 +729,25 @@ stock bool TTT_RemoveWeaponByClassname(int client, const char[] classname, int s
return false;
}

stock void TTT_RemoveMeleeWeapons(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) || (StrContains(sClass, "taser", false) != -1) || (StrContains(sClass, "knife", false) != -1) || (StrContains(sClass, "bayonet", false) != -1))
{
TTT_SafeRemoveWeapon(client, weapon, CS_SLOT_MELEE);
}
}
}
}

stock bool TTT_SafeRemoveWeapon(int client, int weapon, int slot)
{
if (HasEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"))
@@ -112,7 +112,6 @@ void SetupConfig()
g_cPrimaryWeaponUpdate = AutoExecConfig_CreateConVar("ttt_primary_weapon_update", "0", "What should happen on round start with the primary weapon? 0 - nothing, 1 - drop old weapon, 2 - remove old weapon", _, true, 0.0, true, 2.0);
g_cSecondaryWeaponUpdate = AutoExecConfig_CreateConVar("ttt_secondary_weapon_update", "0", "What should happen on round start with the secondary weapon? 0 - nothing, 1 - drop old weapon, 2 - remove old weapon", _, true, 0.0, true, 2.0);
g_cAdvert = AutoExecConfig_CreateConVar("ttt_show_advert_message", "1", "Print a message on player spawn with some ttt details (like \"Trouble in Terrorist Town Version X.X.XXXX\")", _, true, 0.0, true, 1.0);
g_cInnocentKnife = AutoExecConfig_CreateConVar("ttt_give_innocent_knife", "1", "Give innocent a knife?", _, true, 0.0, true, 1.0);
g_cEnableDamageKarma = AutoExecConfig_CreateConVar("ttt_damage_karma_enable", "0", "Add/Del karma on damage?", _, true, 0.0, true, 1.0);
g_cDamageKarmaII = AutoExecConfig_CreateConVar("ttt_damage_karma_attacker_innocent_victim_innocent_subtract", "1", "The amount of karma an innocent will lose for damage an innocent.");
g_cDamageKarmaIT = AutoExecConfig_CreateConVar("ttt_damage_karma_attacker_innocent_victim_traitor_add", "1", "The amount of karma an innocent will recieve for damage a traitor.");
@@ -144,6 +143,9 @@ void SetupConfig()
g_cVersionMessage = AutoExecConfig_CreateConVar("ttt_version_message", "1", "This prints a version message to all players on every spawn", _, true, 0.0, true, 1.0);
g_cSendServerData = AutoExecConfig_CreateConVar("ttt_send_server_data", "1", "Send the Server Port to csgottt.com, server will be listed on csgottt.com", _, true, 0.0, true, 1.0);
g_cDisableRounds = AutoExecConfig_CreateConVar("ttt_disable_rounds", "0", "Disable TTT Rounds? This will require an map change, server restart or plugin that can execute TTT_TerminateRound.", _, true, 0.0, true, 1.0);
g_cStartMelee = AutoExecConfig_CreateConVar("ttt_start_melee_weapon", "fists", "Spawn with which melee weapon?");
g_cAdditionalMeleeRole = AutoExecConfig_CreateConVar("ttt_additional_melee_role", "14", "Who gets the additional melee weapon? (Useful: https://github.com/Bara/TroubleinTerroristTown/wiki/CVAR-Masks )", _, true, 0.0, true, 14.0);
g_cAdditionalMeleeWeapon = AutoExecConfig_CreateConVar("ttt_additional_melee_weapon", "knife", "Which additional weapon?");

g_cpluginTag.AddChangeHook(OnConVarChanged);
g_ckickImmunity.AddChangeHook(OnConVarChanged);
@@ -271,7 +271,6 @@ ConVar g_cCheckDuringWarmup = null;
ConVar g_cPrimaryWeaponUpdate = null;
ConVar g_cSecondaryWeaponUpdate = null;
ConVar g_cAdvert = null;
ConVar g_cInnocentKnife = null;
ConVar g_cEnableDamageKarma = null;
ConVar g_cDamageKarmaII = null;
ConVar g_cDamageKarmaIT = null;
@@ -303,6 +302,9 @@ ConVar g_cShowURL = null;
ConVar g_cVersionMessage = null;
ConVar g_cSendServerData = null;
ConVar g_cDisableRounds = null;
ConVar g_cStartMelee = null;
ConVar g_cAdditionalMeleeRole = null;
ConVar g_cAdditionalMeleeWeapon = null;

Handle g_hRules = null;
bool g_bRules[MAXPLAYERS + 1] = { false, ... };
@@ -1301,19 +1301,19 @@ void TeamInitialize(int client, bool skipWeapons = false)

if (iWeapon == -1)
{
GivePlayerItem(client, g_sDefaultPrimary);
RequestFrame(Frame_GivePrimary, GetClientUserId(client));
}
else
{
if (g_cPrimaryWeaponUpdate.IntValue == 1)
{
SDKHooks_DropWeapon(client, iWeapon);
GivePlayerItem(client, g_sDefaultPrimary);
RequestFrame(Frame_GivePrimary, GetClientUserId(client));
}
else if (g_cPrimaryWeaponUpdate.IntValue == 2)
{
TTT_SafeRemoveWeapon(client, iWeapon, CS_SLOT_PRIMARY);
GivePlayerItem(client, g_sDefaultPrimary);
RequestFrame(Frame_GivePrimary, GetClientUserId(client));
}
}
}
@@ -1327,30 +1327,27 @@ void TeamInitialize(int client, bool skipWeapons = false)
SetEntityHealth(client, g_cspawnHPD.IntValue);
}

if (TTT_HasClientKnife(client) == -1)
{
GivePlayerItem(client, "weapon_knife");
}
GiveMelee(client);

if (!skipWeapons)
{
int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);

if (iWeapon == -1)
{
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
else
{
if (g_cSecondaryWeaponUpdate.IntValue == 1)
{
SDKHooks_DropWeapon(client, iWeapon);
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
else if (g_cSecondaryWeaponUpdate.IntValue == 2)
{
TTT_SafeRemoveWeapon(client, iWeapon, CS_SLOT_SECONDARY);
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
}
}
@@ -1373,30 +1370,28 @@ void TeamInitialize(int client, bool skipWeapons = false)
CS_SwitchTeam(client, CS_TEAM_T);
}
}
if (TTT_HasClientKnife(client) == -1)
{
GivePlayerItem(client, "weapon_knife");
}

GiveMelee(client);

if (!skipWeapons)
{
int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);

if (iWeapon == -1)
{
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
else
{
if (g_cSecondaryWeaponUpdate.IntValue == 1)
{
SDKHooks_DropWeapon(client, iWeapon);
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
else if (g_cSecondaryWeaponUpdate.IntValue == 2)
{
TTT_SafeRemoveWeapon(client, iWeapon, CS_SLOT_SECONDARY);
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
}
}
@@ -1420,53 +1415,27 @@ void TeamInitialize(int client, bool skipWeapons = false)
}
}

if (g_cInnocentKnife.BoolValue && TTT_HasClientKnife(client) == -1)
{
GivePlayerItem(client, "weapon_knife");
}
else
{
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, "knife", false) != -1) || (StrContains(sClass, "bayonet", false) != -1))
{
if (!TTT_SafeRemoveWeapon(client, weapon, CS_SLOT_KNIFE))
{
LogError("Can't remove knife! Player: \"%L\"", client);
}

break;
}
}
}
}
GiveMelee(client);

if (!skipWeapons)
{
int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);

if (iWeapon == -1)
{
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
else
{
if (g_cSecondaryWeaponUpdate.IntValue == 1)
{
SDKHooks_DropWeapon(client, iWeapon);
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
else if (g_cSecondaryWeaponUpdate.IntValue == 2)
{
TTT_SafeRemoveWeapon(client, iWeapon, CS_SLOT_SECONDARY);
GivePlayerItem(client, g_sDefaultSecondary);
RequestFrame(Frame_GiveSecondary, GetClientUserId(client));
}
}
}
@@ -4625,3 +4594,43 @@ void SetClanTag(int client, int role)

CS_SetClientClanTag(client, sRole);
}

void GiveMelee(int client)
{
TTT_RemoveMeleeWeapons(client);

char sWeapon[32];
g_cStartMelee.GetString(sWeapon, sizeof(sWeapon));
Format(sWeapon, sizeof(sWeapon), "weapon_%s", sWeapon);

int iWeapon = GivePlayerItem(client, sWeapon);
EquipPlayerWeapon(client, iWeapon);

if (g_cAdditionalMeleeRole.IntValue & g_iRole[client])
{
g_cAdditionalMeleeWeapon.GetString(sWeapon, sizeof(sWeapon));
Format(sWeapon, sizeof(sWeapon), "weapon_%s", sWeapon);
iWeapon = GivePlayerItem(client, sWeapon);
EquipPlayerWeapon(client, iWeapon);
}
}

public void Frame_GivePrimary(int userid)
{
int client = GetClientOfUserId(userid);

if (TTT_IsClientValid(client) && TTT_IsPlayerAlive(client))
{
GivePlayerItem(client, g_sDefaultPrimary);
}
}

public void Frame_GiveSecondary(int userid)
{
int client = GetClientOfUserId(userid);

if (TTT_IsClientValid(client) && TTT_IsPlayerAlive(client))
{
GivePlayerItem(client, g_sDefaultSecondary);
}
}

0 comments on commit 11b4d8a

Please sign in to comment.
You can’t perform that action at this time.