Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Bara committed Oct 3, 2019
2 parents 5eac8a8 + 50a750d commit fc48283
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
56 changes: 42 additions & 14 deletions addons/sourcemod/scripting/ttt/ttt_taser.sp
Expand Up @@ -34,6 +34,7 @@ ConVar g_cBroadcastTaserResult = null;
ConVar g_cTDamage = null;
ConVar g_cInflictor = null;
ConVar g_cLongName = null;
ConVar g_cRoundKeep = null;
ConVar g_cTKDamage = null;
ConVar g_cTaserCooldown = null;
ConVar g_cGlowPlayer = null;
Expand All @@ -48,6 +49,7 @@ int g_iIPCount[MAXPLAYERS + 1] = { 0, ... };
int g_iDPCount[MAXPLAYERS + 1] = { 0, ... };
int g_iTPCount[MAXPLAYERS + 1] = { 0, ... };
bool g_bTaser[MAXPLAYERS + 1] = { false, ... };
bool g_bRoundTaser[MAXPLAYERS + 1] = { false, ... };

/* Block taser stuff or so... */
Handle g_hCooldown = null;
Expand All @@ -68,7 +70,7 @@ public Plugin myinfo =
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_hOnTased = CreateGlobalForward("TTT_OnTased", ET_Ignore, Param_Cell, Param_Cell);

RegPluginLibrary("ttt_taser");

return APLRes_Success;
Expand Down Expand Up @@ -97,6 +99,7 @@ public void OnPluginStart()
g_cBroadcastTaserResult = AutoExecConfig_CreateConVar("ta_broadcast_taser_result", "0", "When set to true the results of the taser message will be printed to everyone instead of the client that tased", _, true, 0.0, true, 1.0);
g_cInflictor = AutoExecConfig_CreateConVar("ta_barrel_fix", "1", "Prevent bug with taser and a explosive barrel", _, true, 0.0, true, 1.0);
g_cLongName = AutoExecConfig_CreateConVar("ta_name", "Taser", "The name of this in Shop");
g_cRoundKeep = AutoExecConfig_CreateConVar("ta_keep_to_next_round", "0", "Give the Innocents a tasers if they had one before round end?", _, true, 0.0, true, 1.0);
g_cTKDamage = AutoExecConfig_CreateConVar("ta_kill_traitor_credts", "2000", "The amount of credits an innocent or detective will recieve for discovering a traitor with their zues/taser.");
g_cTaserCooldown = AutoExecConfig_CreateConVar("ta_cooldown_after_round_start", "30.0", "Disable taser for X seconds after round starts (0.0 to disable it)");
g_cTaserCooldownMessage = AutoExecConfig_CreateConVar("ta_cooldown_after_round_start_message", "1", "Show message when tasers are enabled?", _, true, 0.0, true, 1.0);
Expand Down Expand Up @@ -137,7 +140,7 @@ public void TTT_OnShopReady()
void RegisterItem()
{
char sBuffer[MAX_ITEM_LENGTH];

g_cLongName.GetString(sBuffer, sizeof(sBuffer));
TTT_RegisterCustomItem(SHORT_NAME_D, sBuffer, g_cDPrice.IntValue, TTT_TEAM_DETECTIVE, g_cDPrio.IntValue);
TTT_RegisterCustomItem(SHORT_NAME, sBuffer, g_cIPrice.IntValue, TTT_TEAM_INNOCENT, g_cIPrio.IntValue);
Expand All @@ -154,7 +157,7 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n

public void OnClientDisconnect(int client)
{
ResetTaser(client);
ResetTaser(client, true);
}

public void OnClientPutInServer(int client)
Expand Down Expand Up @@ -201,12 +204,12 @@ public void TTT_OnRoundStart(int innocents, int traitors, int detective)
for(int offset = 0; offset < 128; offset += 4)
{
int weapon = GetEntDataEnt2(i, FindSendPropInfo("CBasePlayer", "m_hMyWeapons") + offset);

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

if (StrContains(sClass, "taser", false) != -1)
{
BlockTaser(weapon);
Expand All @@ -224,12 +227,12 @@ public Action Timer_ActivateTasers(Handle timer)
for(int offset = 0; offset < 128; offset += 4)
{
int weapon = GetEntDataEnt2(i, FindSendPropInfo("CBasePlayer", "m_hMyWeapons") + offset);

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

if (StrContains(sClass, "taser", false) != -1)
{
UnblockTaser(weapon);
Expand All @@ -254,6 +257,14 @@ public void TTT_OnRoundEnd(int winner, Handle array)
KillTimer(g_hCooldown);
}
g_hCooldown = null;

LoopValidClients(i)
{
if (IsPlayerAlive(i) && g_bTaser[i])
{
g_bRoundTaser[i] = true;
}
}
}

public void TTT_OnClientGetRole(int client, int role)
Expand All @@ -268,6 +279,18 @@ public void TTT_OnClientGetRole(int client, int role)
GivePlayerItem(client, "weapon_taser");
g_iDPCount[client]++;
}
else if (g_cRoundKeep.BoolValue)
{
if (!g_bRoundTaser[client])
{
return;
}

GivePlayerItem(client, "weapon_taser");
g_iDPCount[client]++;
}

g_bRoundTaser[client] = false;
}

public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
Expand All @@ -276,7 +299,7 @@ public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadca

if (TTT_IsClientValid(client))
{
ResetTaser(client);
ResetTaser(client, false);
}
}

Expand Down Expand Up @@ -388,13 +411,18 @@ public Action TTT_OnItemPurchased(int client, const char[] itemshort, bool count
return Plugin_Continue;
}

void ResetTaser(int client)
void ResetTaser(int client, bool fullReset)
{
g_iDPCount[client] = 0;
g_iIPCount[client] = 0;
g_iTPCount[client] = 0;

g_bTaser[client] = false;

if (fullReset)
{
g_bRoundTaser[client] = false;
}
}

public Action OnTraceAttack(int iVictim, int &iAttacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
Expand Down Expand Up @@ -436,7 +464,7 @@ public Action OnTraceAttack(int iVictim, int &iAttacker, int &inflictor, float &
if (StrContains(sWeapon, "taser", false) != -1)
{
char sAttackerID[32], sVictimID[32];

ConVar hTag = FindConVar("ttt_steamid_add_to_logs");
if (hTag.BoolValue)
{
Expand All @@ -456,14 +484,14 @@ public Action OnTraceAttack(int iVictim, int &iAttacker, int &inflictor, float &
GetClientAuthId(iAttacker, AuthId_SteamID64, sAttackerID, sizeof(sAttackerID));
GetClientAuthId(iVictim, AuthId_SteamID64, sVictimID, sizeof(sVictimID));
}

if (strlen(sAttackerID) > 2 && strlen(sVictimID) > 2)
{
Format(sAttackerID, sizeof(sAttackerID), " (%s)", sAttackerID);
Format(sVictimID, sizeof(sVictimID), " (%s)", sVictimID);
}
}

// TODO: Make it shorter(?) with this natives - https://github.com/Bara/TroubleinTerroristTown/issues/309
if (iRole == TTT_TEAM_TRAITOR)
{
Expand All @@ -477,7 +505,7 @@ public Action OnTraceAttack(int iVictim, int &iAttacker, int &inflictor, float &
{
CPrintToChat(iAttacker, "%s %T", g_sPluginTag, "You hurt a Traitor", iVictim, iVictim);
}

TTT_SetClientCredits(iAttacker, TTT_GetClientCredits(iAttacker) + g_cTKDamage.IntValue);
}
else if (iRole == TTT_TEAM_DETECTIVE)
Expand Down Expand Up @@ -506,7 +534,7 @@ public Action OnTraceAttack(int iVictim, int &iAttacker, int &inflictor, float &
CPrintToChat(iAttacker, "%s %T", g_sPluginTag, "You hurt an Innocent", iVictim, iVictim);
}
}

Call_StartForward(g_hOnTased);
Call_PushCell(iAttacker);
Call_PushCell(iVictim);
Expand Down
7 changes: 6 additions & 1 deletion ci/build.sh
Expand Up @@ -25,7 +25,12 @@ echo -e "Compile ttt plugins"
for file in addons/sourcemod/scripting/ttt/*.sp
do
echo -e -e "\nCompiling $file..."
addons/sourcemod/scripting/spcomp -E -w234 -O2 -v2 $file

if [ $1 == "1.9" ]; then
addons/sourcemod/scripting/spcomp -E -w234 -O2 -v2 $file
else
addons/sourcemod/scripting/spcomp -w234 -O2 -v2 $file
fi
done

echo -e "\nCompile 3rd-party-plugins"
Expand Down
7 changes: 5 additions & 2 deletions ci/test.sh
Expand Up @@ -11,8 +11,11 @@ chmod +x addons/sourcemod/scripting/spcomp
echo -e "Compile ttt plugins"
for file in addons/sourcemod/scripting/ttt/*.sp
do
echo -e "\nCompiling $file..."
addons/sourcemod/scripting/spcomp -E -w234 -O2 -v2 $file
if [ $1 == "1.9" ]; then
addons/sourcemod/scripting/spcomp -E -w234 -O2 -v2 $file
else
addons/sourcemod/scripting/spcomp -w234 -O2 -v2 $file
fi
done

echo -e "\nCompile 3rd-party-plugins"
Expand Down

0 comments on commit fc48283

Please sign in to comment.