//////////////////////////////////////////////////////////////////
// Grenade Smoke Color By HSFighter / www.hsfighter.net
//////////////////////////////////////////////////////////////////
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1
#define PLUGIN_VERSION "1.3.4"
#undef REQUIRE_PLUGIN
#include <updater>
/* Updater */
#define UPDATE_URL "http://update.hsfighter.net/sourcemod/grenadesmokecolor/grenadesmokecolor.txt"
//////////////////////////////////////////////////////////////////
// Declare variables and handles
//////////////////////////////////////////////////////////////////
new Handle:g_SmokecolorEnabled;
new Handle:g_SmokecolorMode;
new Handle:g_hCVColor;
new Handle:g_hCVTColor;
new Handle:g_hCVCTColor;
// new Handle:TimeHandle;
new Float:g_HSV_Temp = 0.0;
//////////////////////////////////////////////////////////////////
// Plugin info
//////////////////////////////////////////////////////////////////
public Plugin:myinfo =
{
name = "Grenade Smoke Color",
author = "HSFighter",
description = "Adds color to grenade smoke",
version = PLUGIN_VERSION,
url = "www.hsfighter.net"
}
//////////////////////////////////////////////////////////////////
// Start plugin
//////////////////////////////////////////////////////////////////
public OnPluginStart()
{
CreateConVar("sm_grenadesmokecolor_version", PLUGIN_VERSION, "Grenade Smoke Color Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_SmokecolorEnabled = CreateConVar("sm_grenadesmokecolor_enable", "1", "Engedelyezes/Kikapcsolas");
g_hCVTColor = CreateConVar("sm_grenadesmokecolor_t_color", "255 0 0", "Milyen szinu legyen a terrorista fust szine? \"Piros zold kek\" 0 - 255.", FCVAR_PLUGIN);
g_hCVCTColor = CreateConVar("sm_grenadesmokecolor_ct_color", "0 0 255", "Milyen szinu legyen a counter-terroristak fust szine ? \"Piros zold kek\" 0 - 255.", FCVAR_PLUGIN);
g_hCVColor = CreateConVar("sm_grenadesmokecolor_color", "225 255 0", "Itt tudod az egyedi szint beallitani \"Piros zold kek\" 0 - 255.", FCVAR_PLUGIN);
g_SmokecolorMode = CreateConVar("sm_grenadesmokecolor_mode", "0", "Milyen legyen a fust szin fajtaja (0 = Csapat szin, 1 = barmilyen szin, 2 = Valtozo szin, 3 = Megadot szin [sm_grenadesmokecolor_color])", FCVAR_PLUGIN, true, 0.0, true, 3.0);
// Hook events
HookEvent("smokegrenade_detonate", smokegrenade_detonate);
// Updater
if(LibraryExists("updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
// Create config
AutoExecConfig(true, "plugin.grenadesmokecolor");
}
public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
//////////////////////////////////////////////////////////////////
// Hook event grenade detonate and color the smoke
//////////////////////////////////////////////////////////////////
public smokegrenade_detonate(Handle:event, const String:name[], bool:dontBroadcast)
{
// Check if plugin is enabled
if(GetConVarInt(g_SmokecolorEnabled) != 1) return;
// Get client ID of this event
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (!IsValidClient(client)) return;
// Get coordinates of this event
new Float:a[3], Float:b[3];
a[0] = GetEventFloat(event, "x");
a[1] = GetEventFloat(event, "y");
a[2] = GetEventFloat(event, "z");
new checkok = 0;
new ent = -1;
// List all entitys by classname
while((ent = FindEntityByClassname(ent, "env_particlesmokegrenade")) != -1)
{
// Get entity coordinates
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", b);
// If entity same coordinates some event coordinates
if(a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
{
checkok = 1;
break;
}
}
if (checkok == 1)
{
// Create light
new iEntity = CreateEntityByName("light_dynamic");
if (iEntity != -1)
{
// Retrieve entity
new iRef = EntIndexToEntRef(iEntity);
decl String:sBuffer[64];
// Select Action Mode
switch (GetConVarInt(g_SmokecolorMode))
{
// Team Color
case 0:
{
// Get client team
new player_team_index = GetClientTeam(client);
new String: game_folder[64];
GetGameFolderName(game_folder, 64);
switch (player_team_index)
{
case 1:
{
GetConVarString(g_hCVColor, sBuffer, sizeof(sBuffer));
}
case 2:
{
GetConVarString(g_hCVTColor, sBuffer, sizeof(sBuffer));
}
case 3:
{
GetConVarString(g_hCVCTColor, sBuffer, sizeof(sBuffer));
}
}
DispatchKeyValue(iEntity, "_light", sBuffer);
}
// Random Color
case 1:
{
g_HSV_Temp = GetRandomFloat(1.0, 360.0);
new Float:flRed, Float:flGreen, Float:flBlue;
HSVtoRGB(g_HSV_Temp, 1.0, 1.0, flRed, flGreen, flBlue );
Format(sBuffer, sizeof(sBuffer), "%i %i %i", RoundFloat(flRed*255.0), RoundFloat(flGreen*255.0), RoundFloat(flBlue*255.0));
DispatchKeyValue(iEntity, "_light", sBuffer);
}
// Multi color change
case 2:
{
new Float:rand = GetRandomFloat(0.1, 0.2);
CreateTimer(rand, Checktime, iRef, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
// Definet color
case 3:
{
GetConVarString(g_hCVColor, sBuffer, sizeof(sBuffer));
DispatchKeyValue(iEntity, "_light", sBuffer);
}
}
Format(sBuffer, sizeof(sBuffer), "smokelight_%d", iEntity);
DispatchKeyValue(iEntity,"targetname", sBuffer);
Format(sBuffer, sizeof(sBuffer), "%f %f %f", a[0], a[1], a[2]);
DispatchKeyValue(iEntity, "origin", sBuffer);
DispatchKeyValue(iEntity, "iEntity", "-90 0 0");
DispatchKeyValue(iEntity, "pitch","-90");
DispatchKeyValue(iEntity, "distance","256");
DispatchKeyValue(iEntity, "spotlight_radius","96");
DispatchKeyValue(iEntity, "brightness","3");
DispatchKeyValue(iEntity, "style","6");
DispatchKeyValue(iEntity, "spawnflags","1");
DispatchSpawn(iEntity);
AcceptEntityInput(iEntity, "DisableShadow");
AcceptEntityInput(iEntity, "TurnOn");
CreateTimer(20.0, Delete, iRef, TIMER_FLAG_NO_MAPCHANGE);
}
}
}
//////////////////////////////////////////////////////////////////
// Multi color change timer
//////////////////////////////////////////////////////////////////
public Action:Checktime(Handle:colortimer, any:ref){
new entity= EntRefToEntIndex(ref);
if (!IsValidEntity(entity)) return Plugin_Stop;
if (entity != -1)
{
decl String:sBuffer[64];
g_HSV_Temp = g_HSV_Temp + 3.0;
new Float:flRed, Float:flGreen, Float:flBlue;
HSVtoRGB(g_HSV_Temp, 1.0, 1.0, flRed, flGreen, flBlue );
//PrintHintTextToAll ("Debug: %i -->> r=%i g=%i b=%i", RoundFloat(g_HSV_Temp), RoundFloat(flRed*255.0), RoundFloat(flGreen*255.0), RoundFloat(flBlue*255.0));
Format(sBuffer, sizeof(sBuffer), "%i %i %i", RoundFloat(flRed*255.0), RoundFloat(flGreen*255.0), RoundFloat(flBlue*255.0));
if (g_HSV_Temp >= 360.0) g_HSV_Temp = 0.0;
DispatchKeyValue(entity, "_light", sBuffer);
}
return Plugin_Continue;
}
//////////////////////////////////////////////////////////////////
// Check client
//////////////////////////////////////////////////////////////////
public bool:IsValidClient(client)
{
if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) || IsFakeClient(client) )
{
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////
// HSV to RGB color
//////////////////////////////////////////////////////////////////
HSVtoRGB(&Float:h, Float:s, Float:v, &Float:r, &Float:g, &Float:b){
if (s == 0)
{
r = v; g = v; b = v;
} else {
new Float:fHue, Float:fValue, Float:fSaturation;
new Float:f; new Float:p,Float:q,Float:t;
if (h == 360.0) h = 0.0;
fHue = h / 60.0;
new i = RoundToFloor(fHue);
f = fHue - i;
fValue = v;
fSaturation = s;
p = fValue * (1.0 - fSaturation);
q = fValue * (1.0 - (fSaturation * f));
t = fValue * (1.0 - (fSaturation * (1.0 - f)));
switch (i)
{
case 1:
{
r = q; g = fValue; b = p;
}
case 2:
{
r = p; g = fValue; b = t;
}
case 3:
{
r = p; g = q; b = fValue;
}
case 4:
{
r = t; g = p; b = fValue;
}
case 5:
{
r = fValue; g = p; b = q;
}
default:
{
r = fValue; g = t; b = p;
}
}
}
}
//////////////////////////////////////////////////////////////////
// Delete entitys
//////////////////////////////////////////////////////////////////
public Action:Delete(Handle:timer, any:iRef)
{
new entity= EntRefToEntIndex(iRef);
if (entity != INVALID_ENT_REFERENCE)
{
if (IsValidEdict(entity)) AcceptEntityInput(entity, "kill");
}
/*
if (GetConVarInt(g_SmokecolorMode) == 2)
{
if (TimeHandle[iRef] != INVALID_HANDLE)
{
CloseHandle(TimeHandle[iRef]);
TimeHandle[iRef] = INVALID_HANDLE;
}
}
*/
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
*/