#include <sourcemod>
#pragma semicolon 1
#define PLUGIN_VERSION "1.0"
public Plugin:myinfo =
{
name = "New Flash Color",
author = "Regent",
description = "szinet ad a vakto granatnak",
version = PLUGIN_VERSION,
url = ""
};
#define FFADE_IN 0x0001
#define FFADE_OUT 0x0002
#define FFADE_MODULATE 0x0004
#define FFADE_STAYOUT 0x0008
#define FFADE_PURGE 0x0010
new Handle: g_hConVar_sNewFlashColor = INVALID_HANDLE;
new g_iNewFlashColor[3];
new bool: g_bRandomColor;
new Handle: g_hConVar_bPluginEnabled = INVALID_HANDLE;
new bool: g_bPluginEnabled;
new g_iOffset_flFlashMaxAlpha,
g_iOffset_flFlashDuration;
new Handle: g_hFlashTimer[MAXPLAYERS+1];
public OnPluginStart()
{
// find offsets
g_iOffset_flFlashMaxAlpha = GetSendPropOffs("CCSPlayer", "m_flFlashMaxAlpha");
g_iOffset_flFlashDuration = GetSendPropOffs("CCSPlayer", "m_flFlashDuration");
// create convars of plugin
CreateConVar("sm_newflashcolor_version", PLUGIN_VERSION, "Pligin verzioja", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_SPONLY);
g_hConVar_sNewFlashColor = CreateConVar("sm_newflashcolor_color", "255 0 0", "Flash szine", FCVAR_PLUGIN);
HookConVarChange(g_hConVar_sNewFlashColor, OnConVarChange);
g_hConVar_bPluginEnabled = CreateConVar("sm_newflashcolor_enabled", "1", "engedelyezes/tiltas", FCVAR_PLUGIN);
HookConVarChange(g_hConVar_bPluginEnabled, OnConVarChange);
// hook events
HookEvent("player_blind", Ev_PlayerBlind);
HookEvent("player_spawn", Ev_PlayerSpawn);
}
public OnClientPutInServer(iClient)
{
g_hFlashTimer[iClient] = INVALID_HANDLE;
}
public OnClientDisconnect_Post(iClient)
{
CancelTimer(g_hFlashTimer[iClient]);
g_hFlashTimer[iClient] = INVALID_HANDLE;
}
CancelTimer(&Handle:hTimer)
{
if ( hTimer != INVALID_HANDLE )
{
KillTimer(hTimer);
}
}
public OnConfigsExecuted()
{
g_bPluginEnabled = GetConVarBool(g_hConVar_bPluginEnabled);
GetNewFlashColor();
}
public OnConVarChange(Handle:hConVar, const String:sOldValue[], const String:sNewValue[])
{
if ( hConVar == g_hConVar_sNewFlashColor )
{
GetNewFlashColor();
}
else if ( hConVar == g_hConVar_bPluginEnabled )
{
g_bPluginEnabled = GetConVarBool(g_hConVar_bPluginEnabled);
}
}
GetNewFlashColor()
{
// find first and last pos of space, then:
// red part will be everything from start to first space pos
// green part is everything between first and second space pos
// blue part is everything else
decl String:sBuffer[12], String:sPart[4];
GetConVarString(g_hConVar_sNewFlashColor, sBuffer, sizeof(sBuffer));
new iFirstSpace = FindCharInString(sBuffer, ' ', false) + 1;
new iLastSpace = FindCharInString(sBuffer, ' ', true) + 1;
if ( iFirstSpace == -1 || iFirstSpace == iLastSpace )
{
g_bRandomColor = true;
}
else
{
strcopy(sPart, iFirstSpace, sBuffer);
g_iNewFlashColor[0] = StringToInt(sPart);
strcopy(sPart, iLastSpace - iFirstSpace, sBuffer[iFirstSpace]);
g_iNewFlashColor[1] = StringToInt(sPart);
strcopy(sPart, strlen(sBuffer) - iLastSpace + 1, sBuffer[iLastSpace]);
g_iNewFlashColor[2] = StringToInt(sPart);
g_bRandomColor = false;
}
}
GetSendPropOffs(const String:sClass[], const String:sProp[])
{
new iOffset = FindSendPropOffs(sClass, sProp);
if ( iOffset == - 1 )
{
SetFailState("Offset %s::%s not found", sClass, sProp);
return -1;
}
return iOffset;
}
public Ev_PlayerBlind(Handle:hEvent, const String:sEvName[], bool:bSilent)
{
if ( g_bPluginEnabled )
{
new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid")),
iAlpha = RoundToNearest(GetEntDataFloat(iClient, g_iOffset_flFlashMaxAlpha)),
iDuration = RoundToNearest(GetEntDataFloat(iClient, g_iOffset_flFlashDuration)) * 1000;
// remove classic flash
SetEntDataFloat(iClient, g_iOffset_flFlashMaxAlpha, 0.5);
// if random, get new color
if ( g_bRandomColor )
{
g_iNewFlashColor[0] = GetRandomInt(1, 255);
g_iNewFlashColor[1] = GetRandomInt(1, 255);
g_iNewFlashColor[2] = GetRandomInt(1, 255);
}
// fade client. hud will be hidden by game
PerformFade(iClient, iDuration, g_iNewFlashColor, iAlpha);
CancelTimer(g_hFlashTimer[iClient]);
g_hFlashTimer[iClient] = CreateTimer(float(iDuration), Timer_FlashEnded, iClient);
}
}
// https://wiki.alliedmods.net/User_Messages
PerformFade(iClient, iDuration, const iColor[3], iAlpha)
{
new iFullBlindDuration = iDuration / 4;
new Handle:hFadeClient = StartMessageOne("Fade", iClient);
BfWriteShort(hFadeClient, iDuration - iFullBlindDuration);
BfWriteShort(hFadeClient, iFullBlindDuration);
BfWriteShort(hFadeClient, (FFADE_PURGE|FFADE_IN));
BfWriteByte(hFadeClient, iColor[0]);
BfWriteByte(hFadeClient, iColor[1]);
BfWriteByte(hFadeClient, iColor[2]);
BfWriteByte(hFadeClient, iAlpha);
EndMessage();
}
// end of https://wiki.alliedmods.net/User_Messages
public Action:Timer_FlashEnded(Handle:hTimer, any:iClient)
{
g_hFlashTimer[iClient] = INVALID_HANDLE;
return Plugin_Stop;
}
public Ev_PlayerSpawn(Handle:hEvent, const String:sEvName[], bool:bSilent)
{
if ( g_bPluginEnabled )
{
new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
if ( g_hFlashTimer[iClient] != INVALID_HANDLE )
{
PerformFade(iClient, 0, {0, 0, 0}, 0);
CancelTimer(g_hFlashTimer[iClient]);
g_hFlashTimer[iClient] = INVALID_HANDLE;
}
}
}