Permalink
Browse files

Add tactical shield for detectives

  • Loading branch information...
Bara committed Dec 3, 2017
1 parent f219931 commit 1136aab364e7ffec0f35d729b66c4f9d26a6b913
@@ -0,0 +1,53 @@
/*
* This file is part of Tactical Shield.
* Copyright (C) 2017 Keplyx
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined _tacticalshield_included
#endinput
#endif
#define _tacticalshield_included
/**
* Give the specified player a shield, if he can have one.
* It is the same as the command ts_buy but without using money.
*
* @param client Client index.
* @return
* @error Invalid client.
*/
native void GivePlayerShield(int client);
/**
* Override shield status for the specified player.
*
* @param client Client index.
* @param override Override parameter: 0= no override, 1= force no shields, 2= force shields.
* @return
* @error Invalid client.
*/
native void OverridePlayerShield(int client, int override);
/**
* Remove the shield for the specified player.
*
* @param client Client index.
* @return
* @error Invalid client.
*/
native void RemovePlayerShield(int client);
@@ -0,0 +1,114 @@
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <ttt>
#include <ttt_shop>
#include <tacticalshield>
#define PLUGIN_NAME TTT_PLUGIN_NAME ... " - Tactical Shield"
#define SHORT_NAME_D "tacticalShield_d"
ConVar g_cLongName = null;
ConVar g_cPrice = null;
ConVar g_cPrio = null;
ConVar g_cDiscount = null;
ConVar g_cForce = null;
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = TTT_PLUGIN_AUTHOR,
description = TTT_PLUGIN_DESCRIPTION,
version = TTT_PLUGIN_VERSION,
url = TTT_PLUGIN_URL
};
public void OnPluginStart()
{
TTT_IsGameCSGO();
LoadTranslations("ttt.phrases");
StartConfig("tactical_shield");
CreateConVar("ttt2_tactical_shield_version", TTT_PLUGIN_VERSION, TTT_PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_DONTRECORD | FCVAR_REPLICATED);
g_cLongName = AutoExecConfig_CreateConVar("tactical_shield_name", "Tactical Shield", "The name of this in Shop");
g_cPrice = AutoExecConfig_CreateConVar("tactical_shield_price", "9000", "The amount of credits a tactical shield costs as detective. 0 to disable.");
g_cPrio = AutoExecConfig_CreateConVar("tactical_shield_sort_prio", "0", "The sorting priority of the tactical shield in the shop menu.");
g_cDiscount = AutoExecConfig_CreateConVar("tactical_shield_discount_drone", "0", "Should tactical shield discountable?", _, true, 0.0, true, 1.0);
g_cForce = AutoExecConfig_CreateConVar("tactical_shield_force", "0", "Force shield?", _, true, 0.0, true, 1.0);
EndConfig();
HookEvent("player_spawn", Event_PlayerSpawn);
}
public void OnConfigsExecuted()
{
char sFile[] = "tacticalshield.smx";
Handle hPlugin = FindPluginByFile(sFile);
if (hPlugin == null || GetPluginStatus(hPlugin) != Plugin_Running)
{
SetFailState("You must have this plugin as base plugin for this items: https://forums.alliedmods.net/showthread.php?t=303333", sFile);
return;
}
char sBuffer[MAX_ITEM_LENGTH];
g_cLongName.GetString(sBuffer, sizeof(sBuffer));
TTT_RegisterCustomItem(SHORT_NAME_D, sBuffer, g_cPrice.IntValue, TTT_TEAM_DETECTIVE, g_cPrio.IntValue, g_cDiscount.BoolValue);
}
public void OnClientDisconnect(int client)
{
ResetTacticalShield(client);
}
public Action TTT_OnItemPurchased(int client, const char[] itemshort, bool count)
{
if (TTT_IsClientValid(client) && IsPlayerAlive(client))
{
if (StrEqual(itemshort, SHORT_NAME_D, false))
{
int role = TTT_GetClientRole(client);
if (role == TTT_TEAM_DETECTIVE)
{
GivePlayerShield(client);
if (g_cForce.BoolValue)
{
OverridePlayerShield(client, 2);
}
else
{
OverridePlayerShield(client, 1);
}
}
else
{
return Plugin_Stop;
}
}
}
return Plugin_Continue;
}
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (TTT_IsClientValid(client))
{
ResetTacticalShield(client);
}
}
void ResetTacticalShield(int client)
{
RemovePlayerShield(client);
}

0 comments on commit 1136aab

Please sign in to comment.