#pragma semicolon 1
#include <sdkhooks>
#include <emitsoundany>
#include <sdktools>
/* Переменные */
#define BLEED_TIMER 2.5 // Отрезок времени через которое игроку будет снимать ХП.
#define MINUS_BLEED_HP 2 // Здоровье, отнимаемое у игрока в X секунд.
#define BLEED_BORDER 30 // Здоровье, ниже которого начинается кровотечение.
#define BLIND_TIMER 3.5 // Отрезок времени через которое игрока будет слепить.
#define SHAKE_TIMER 3.5 // Отрезок времени через которое у игрока будет трясти экран.
/* ========== */
new Handle:BleedChance;
new bool:Bleed[MAXPLAYERS+1];
new Handle:BleedTimerKill[MAXPLAYERS+1];
new Handle:BlindTimerKill[MAXPLAYERS + 1];
new Handle:ShakeTimerKill[MAXPLAYERS + 1];
new Float:g_fShakeAmp;
new Float:g_fShakeTime;
new String:g_szHeartbeatSound[256];
new Handle:g_hConVar_szHeartbeatSound = INVALID_HANDLE;
new Handle:g_hConVar_fShakeAmp = INVALID_HANDLE;
new Handle:g_hConVar_fShakeTime = INVALID_HANDLE;
public Plugin:myinfo = {
author = "Hejter",
name = "[CS:GO] Bleeding",
description = "Кровотечение с X шансом + сердцебиение.",
version = "0.5",
url = "hlmod.ru & excw.ru",
}
public OnPluginStart(){
BleedChance = CreateConVar("sm_bleeding_chance", "0.25", "Шанс кровотечения, 1.00 = 100%, 0.50 = 50%, и т.д", FCVAR_PLUGIN);
g_hConVar_szHeartbeatSound = CreateConVar("sm_heartbeat_sound", "excw/heart.mp3", "звук сердцебиения (относительно sound/)");
g_hConVar_fShakeAmp = CreateConVar("sm_heartbeat_shakeamp", "7.0", "Сила тряски экрана");
g_hConVar_fShakeTime = CreateConVar("sm_heartbeat_shaketime", "3.0", "промежуток тряски экрана");
HookConVarChange(g_hConVar_szHeartbeatSound, ConVar_Callback);
HookConVarChange(g_hConVar_fShakeAmp, ConVar_Callback);
HookConVarChange(g_hConVar_fShakeTime, ConVar_Callback);
GetConVarString(g_hConVar_szHeartbeatSound, g_szHeartbeatSound, sizeof(g_szHeartbeatSound));
g_fShakeAmp = GetConVarFloat(g_hConVar_fShakeAmp);
g_fShakeTime = GetConVarFloat(g_hConVar_fShakeTime);
HookEvent("player_death", PlayerDeath);
HookEvent("player_hurt", PlayerHurt);
HookEvent("player_spawn", PlayerSpawn);
AutoExecConfig(true, "sm_bleeding");
}
public OnMapStart()
{
decl String:szPath[256];
Format(szPath, sizeof(szPath), "sound/%s", g_szHeartbeatSound);
AddFileToDownloadsTable(szPath);
PrecacheSoundAny(g_szHeartbeatSound);
}
public ConVar_Callback(Handle:cvar, const String:oldVal[], const String:newVal[])
{
if ( cvar == g_hConVar_szHeartbeatSound )
{
GetConVarString(g_hConVar_szHeartbeatSound, g_szHeartbeatSound, sizeof(g_szHeartbeatSound));
}
else if ( cvar == g_hConVar_fShakeAmp )
{
g_fShakeAmp = GetConVarFloat(g_hConVar_fShakeAmp);
}
else if ( cvar == g_hConVar_fShakeTime )
{
g_fShakeTime = GetConVarFloat(g_hConVar_fShakeTime);
}
}
public PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast){
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsClientInGame(client) && IsPlayerAlive(client))
{
Bleed[client] = false;
ClientCommand(client,"r_screenoverlay 0");
}
}
public PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsClientInGame(client))
{
Bleed[client] = false;
ClientCommand(client,"r_screenoverlay 0");
}
func_shakekilltimer(client);
func_blindkilltimer(client);
func_killtimer(client);
}
public OnClientPutInServer(client)
{
InsertInfo(client);
func_killtimer(client);
func_blindkilltimer(client);
func_shakekilltimer(client);
}
public OnClientDisconnect(client){
InsertInfo(client);
func_killtimer(client);
func_blindkilltimer(client);
func_shakekilltimer(client);
}
public InsertInfo(client){
Bleed[client] = false;
}
public PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast){
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new Float:iBleedChance = GetConVarFloat(BleedChance);
new Float:iRoll = GetRandomFloat();
if(IsPlayerAlive(client) && Bleed[client] == false && client != GetClientOfUserId(GetEventInt(event, "attacker")))
{
if (iBleedChance >= iRoll)
{
if (GetEventInt(event, "health") <= BLEED_BORDER)
{
BleedTimerKill[client] = CreateTimer(BLEED_TIMER, Bleed_Timer, GetClientUserId(client), TIMER_REPEAT); // Кровотечение
BlindTimerKill[client] = CreateTimer(BLIND_TIMER, Blind_Timer, GetClientUserId(client), TIMER_REPEAT); // Эффект затемнения
ShakeTimerKill[client] = CreateTimer(SHAKE_TIMER, Shake_Timer, GetClientUserId(client), TIMER_REPEAT); // Тряска экрана
Bleed[client] = true;
}
}
}
}
public Action:Shake_Timer(Handle:timer, any:UserID){
new client = GetClientOfUserId(UserID);
if (client && IsPlayerAlive(client) && Bleed[client])
{
if (Bleed[client] == true)
{
SetShake(client);
}
}
}
public Action:Blind_Timer(Handle:timer, any:UserID){
new client = GetClientOfUserId(UserID);
if (client && IsPlayerAlive(client) && Bleed[client])
{
new cHealth = GetClientHealth(client);
if (Bleed[client] == true)
{
/* if (cHealth <= 150) SetBlind(client, 1536, 35, { 0, 0, 0, 30 } );
if (cHealth <= 100) SetBlind(client, 1536, 35, { 0, 0, 0, 50 } );
if (cHealth <= 90) SetBlind(client, 1536, 35, { 0, 0, 0, 70 } );
if (cHealth <= 80) SetBlind(client, 1536, 35, { 0, 0, 0, 90 } );
if (cHealth <= 70) SetBlind(client, 1536, 35, { 0, 0, 0, 110 } );
if (cHealth <= 60) SetBlind(client, 1536, 35, { 0, 0, 0, 130 } );
if (cHealth <= 50) SetBlind(client, 1536, 35, { 0, 0, 0, 150 } );
if (cHealth <= 40) SetBlind(client, 1536, 35, { 0, 0, 0, 170 } );
if (cHealth <= 30) SetBlind(client, 1536, 35, { 0, 0, 0, 190 } );
if (cHealth <= 20) SetBlind(client, 1536, 35, { 0, 0, 0, 210 } );
if (cHealth <= 10) SetBlind(client, 1536, 35, { 0, 0, 0, 230 } );
if (cHealth <= 5) SetBlind(client, 1536, 35, { 0, 0, 0, 250 } ); */
if (cHealth <= BLEED_BORDER) SetBlind(client, 300, 0, {255, 0, 0, 30});
}
}
}
public Action:Bleed_Timer(Handle:timer, any:UserID){
new client = GetClientOfUserId(UserID);
if (client && IsPlayerAlive(client) && Bleed[client])
{
new cHealth = GetClientHealth(client) - MINUS_BLEED_HP;
if (cHealth > 0){
SetEntityHealth(client, cHealth);
ClientCommand(client,"r_screenoverlay excw/bleed");
EmitSoundToClientAny(client, g_szHeartbeatSound);
return Plugin_Continue;
}
ForcePlayerSuicide(client);
Bleed[client] = false;
func_killtimer(client);
func_blindkilltimer(client);
func_shakekilltimer(client);
}
return Plugin_Stop;
}
/* Функция затемнение экрана */
public SetBlind(client, duration, hold_time, const color[4]) {
new flags = 0x0001;
new Handle:message = StartMessageOne("Fade", client);
if (message != INVALID_HANDLE)
{
PbSetInt(message, "duration", duration); // 1 * 300 = 300 - сколько duration поставишь, столько он времени будет светлеть
PbSetInt(message, "hold_time", hold_time); // Время задержки цвета
PbSetInt(message, "flags", flags);
PbSetColor(message, "clr", color);
EndMessage();
}
}
/* Функция тряски экрана */
public SetShake(client){
new Handle:hBf = StartMessageOne("Shake", client);
if( hBf != INVALID_HANDLE )
{
PbSetInt(hBf, "command", 0);
PbSetFloat(hBf, "local_amplitude", g_fShakeAmp);
PbSetFloat(hBf, "frequency", 1.0);
PbSetFloat(hBf, "duration", g_fShakeTime);
EndMessage();
}
}
/* Убиваем таймер - кровотечение */
public func_killtimer(client){
if(BleedTimerKill[client])
{
KillTimer(BleedTimerKill[client]);
BleedTimerKill[client] = INVALID_HANDLE;
}
}
/* Убиваем таймер - эффект затемнения */
public func_blindkilltimer(client){
if(BlindTimerKill[client])
{
KillTimer(BlindTimerKill[client]);
BlindTimerKill[client] = INVALID_HANDLE;
}
}
/* Убиваем таймер - тряска экрана */
public func_shakekilltimer(client){
if(ShakeTimerKill[client])
{
KillTimer(ShakeTimerKill[client]);
ShakeTimerKill[client] = INVALID_HANDLE;
}
}