HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. //////////////////////////////////////////////////////////////////
  2. // Grenade Smoke Color By HSFighter / www.hsfighter.net
  3. //////////////////////////////////////////////////////////////////
  4.  
  5. #include <sourcemod>
  6. #include <sdktools>
  7. #pragma semicolon 1
  8. #define PLUGIN_VERSION "1.3.4"
  9.  
  10. #undef REQUIRE_PLUGIN
  11. #include <updater>
  12.  
  13.  
  14. /* Updater */
  15. #define UPDATE_URL "http://update.hsfighter.net/sourcemod/grenadesmokecolor/grenadesmokecolor.txt"
  16.  
  17.  
  18. //////////////////////////////////////////////////////////////////
  19. // Declare variables and handles
  20. //////////////////////////////////////////////////////////////////
  21.  
  22. new Handle:g_SmokecolorEnabled;
  23. new Handle:g_SmokecolorMode;
  24.  
  25. new Handle:g_hCVColor;
  26. new Handle:g_hCVTColor;
  27. new Handle:g_hCVCTColor;
  28.  
  29. // new Handle:TimeHandle;
  30.  
  31. new Float:g_HSV_Temp = 0.0;
  32.  
  33. //////////////////////////////////////////////////////////////////
  34. // Plugin info
  35. //////////////////////////////////////////////////////////////////
  36.  
  37. public Plugin:myinfo =
  38. {
  39. name = "Grenade Smoke Color",
  40. author = "HSFighter",
  41. description = "Adds color to grenade smoke",
  42. version = PLUGIN_VERSION,
  43. url = "www.hsfighter.net"
  44. }
  45.  
  46.  
  47. //////////////////////////////////////////////////////////////////
  48. // Start plugin
  49. //////////////////////////////////////////////////////////////////
  50.  
  51. public OnPluginStart()
  52. {
  53. CreateConVar("sm_grenadesmokecolor_version", PLUGIN_VERSION, "Grenade Smoke Color Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  54.  
  55. g_SmokecolorEnabled = CreateConVar("sm_grenadesmokecolor_enable", "1", "Engedelyezes/Kikapcsolas");
  56. g_hCVTColor = CreateConVar("sm_grenadesmokecolor_t_color", "255 0 0", "Milyen szinu legyen a terrorista fust szine? \"Piros zold kek\" 0 - 255.", FCVAR_PLUGIN);
  57. 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);
  58. g_hCVColor = CreateConVar("sm_grenadesmokecolor_color", "225 255 0", "Itt tudod az egyedi szint beallitani \"Piros zold kek\" 0 - 255.", FCVAR_PLUGIN);
  59. 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);
  60.  
  61.  
  62. // Hook events
  63. HookEvent("smokegrenade_detonate", smokegrenade_detonate);
  64.  
  65. // Updater
  66. if(LibraryExists("updater"))
  67. {
  68. Updater_AddPlugin(UPDATE_URL);
  69. }
  70.  
  71. // Create config
  72. AutoExecConfig(true, "plugin.grenadesmokecolor");
  73.  
  74. }
  75.  
  76.  
  77. public OnLibraryAdded(const String:name[])
  78. {
  79. if (StrEqual(name, "updater"))
  80. {
  81. Updater_AddPlugin(UPDATE_URL);
  82. }
  83. }
  84.  
  85.  
  86.  
  87. //////////////////////////////////////////////////////////////////
  88. // Hook event grenade detonate and color the smoke
  89. //////////////////////////////////////////////////////////////////
  90.  
  91. public smokegrenade_detonate(Handle:event, const String:name[], bool:dontBroadcast)
  92. {
  93. // Check if plugin is enabled
  94. if(GetConVarInt(g_SmokecolorEnabled) != 1) return;
  95.  
  96. // Get client ID of this event
  97. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  98.  
  99. if (!IsValidClient(client)) return;
  100.  
  101. // Get coordinates of this event
  102. new Float:a[3], Float:b[3];
  103. a[0] = GetEventFloat(event, "x");
  104. a[1] = GetEventFloat(event, "y");
  105. a[2] = GetEventFloat(event, "z");
  106.  
  107. new checkok = 0;
  108. new ent = -1;
  109.  
  110. // List all entitys by classname
  111. while((ent = FindEntityByClassname(ent, "env_particlesmokegrenade")) != -1)
  112. {
  113. // Get entity coordinates
  114. GetEntPropVector(ent, Prop_Send, "m_vecOrigin", b);
  115.  
  116. // If entity same coordinates some event coordinates
  117. if(a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
  118. {
  119. checkok = 1;
  120. break;
  121. }
  122. }
  123.  
  124. if (checkok == 1)
  125. {
  126. // Create light
  127. new iEntity = CreateEntityByName("light_dynamic");
  128.  
  129. if (iEntity != -1)
  130. {
  131. // Retrieve entity
  132. new iRef = EntIndexToEntRef(iEntity);
  133.  
  134.  
  135. decl String:sBuffer[64];
  136. // Select Action Mode
  137. switch (GetConVarInt(g_SmokecolorMode))
  138. {
  139. // Team Color
  140. case 0:
  141. {
  142. // Get client team
  143. new player_team_index = GetClientTeam(client);
  144.  
  145. new String: game_folder[64];
  146. GetGameFolderName(game_folder, 64);
  147.  
  148. switch (player_team_index)
  149. {
  150. case 1:
  151. {
  152. GetConVarString(g_hCVColor, sBuffer, sizeof(sBuffer));
  153. }
  154. case 2:
  155. {
  156. GetConVarString(g_hCVTColor, sBuffer, sizeof(sBuffer));
  157. }
  158. case 3:
  159. {
  160. GetConVarString(g_hCVCTColor, sBuffer, sizeof(sBuffer));
  161. }
  162. }
  163.  
  164. DispatchKeyValue(iEntity, "_light", sBuffer);
  165. }
  166. // Random Color
  167. case 1:
  168. {
  169. g_HSV_Temp = GetRandomFloat(1.0, 360.0);
  170.  
  171. new Float:flRed, Float:flGreen, Float:flBlue;
  172. HSVtoRGB(g_HSV_Temp, 1.0, 1.0, flRed, flGreen, flBlue );
  173. Format(sBuffer, sizeof(sBuffer), "%i %i %i", RoundFloat(flRed*255.0), RoundFloat(flGreen*255.0), RoundFloat(flBlue*255.0));
  174. DispatchKeyValue(iEntity, "_light", sBuffer);
  175. }
  176. // Multi color change
  177. case 2:
  178. {
  179. new Float:rand = GetRandomFloat(0.1, 0.2);
  180. CreateTimer(rand, Checktime, iRef, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  181. }
  182. // Definet color
  183. case 3:
  184. {
  185. GetConVarString(g_hCVColor, sBuffer, sizeof(sBuffer));
  186. DispatchKeyValue(iEntity, "_light", sBuffer);
  187. }
  188. }
  189.  
  190. Format(sBuffer, sizeof(sBuffer), "smokelight_%d", iEntity);
  191. DispatchKeyValue(iEntity,"targetname", sBuffer);
  192. Format(sBuffer, sizeof(sBuffer), "%f %f %f", a[0], a[1], a[2]);
  193. DispatchKeyValue(iEntity, "origin", sBuffer);
  194. DispatchKeyValue(iEntity, "iEntity", "-90 0 0");
  195. DispatchKeyValue(iEntity, "pitch","-90");
  196. DispatchKeyValue(iEntity, "distance","256");
  197. DispatchKeyValue(iEntity, "spotlight_radius","96");
  198. DispatchKeyValue(iEntity, "brightness","3");
  199. DispatchKeyValue(iEntity, "style","6");
  200. DispatchKeyValue(iEntity, "spawnflags","1");
  201. DispatchSpawn(iEntity);
  202. AcceptEntityInput(iEntity, "DisableShadow");
  203.  
  204. AcceptEntityInput(iEntity, "TurnOn");
  205.  
  206. CreateTimer(20.0, Delete, iRef, TIMER_FLAG_NO_MAPCHANGE);
  207. }
  208. }
  209. }
  210.  
  211. //////////////////////////////////////////////////////////////////
  212. // Multi color change timer
  213. //////////////////////////////////////////////////////////////////
  214.  
  215. public Action:Checktime(Handle:colortimer, any:ref){
  216.  
  217. new entity= EntRefToEntIndex(ref);
  218.  
  219. if (!IsValidEntity(entity)) return Plugin_Stop;
  220.  
  221. if (entity != -1)
  222. {
  223.  
  224. decl String:sBuffer[64];
  225. g_HSV_Temp = g_HSV_Temp + 3.0;
  226. new Float:flRed, Float:flGreen, Float:flBlue;
  227. HSVtoRGB(g_HSV_Temp, 1.0, 1.0, flRed, flGreen, flBlue );
  228. //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));
  229. Format(sBuffer, sizeof(sBuffer), "%i %i %i", RoundFloat(flRed*255.0), RoundFloat(flGreen*255.0), RoundFloat(flBlue*255.0));
  230. if (g_HSV_Temp >= 360.0) g_HSV_Temp = 0.0;
  231. DispatchKeyValue(entity, "_light", sBuffer);
  232. }
  233.  
  234. return Plugin_Continue;
  235. }
  236.  
  237. //////////////////////////////////////////////////////////////////
  238. // Check client
  239. //////////////////////////////////////////////////////////////////
  240.  
  241. public bool:IsValidClient(client)
  242. {
  243. if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) || IsFakeClient(client) )
  244. {
  245. return false;
  246. }
  247. return true;
  248. }
  249.  
  250.  
  251. //////////////////////////////////////////////////////////////////
  252. // HSV to RGB color
  253. //////////////////////////////////////////////////////////////////
  254.  
  255. HSVtoRGB(&Float:h, Float:s, Float:v, &Float:r, &Float:g, &Float:b){
  256.  
  257. if (s == 0)
  258. {
  259. r = v; g = v; b = v;
  260. } else {
  261.  
  262. new Float:fHue, Float:fValue, Float:fSaturation;
  263. new Float:f; new Float:p,Float:q,Float:t;
  264. if (h == 360.0) h = 0.0;
  265. fHue = h / 60.0;
  266. new i = RoundToFloor(fHue);
  267. f = fHue - i;
  268. fValue = v;
  269. fSaturation = s;
  270. p = fValue * (1.0 - fSaturation);
  271. q = fValue * (1.0 - (fSaturation * f));
  272. t = fValue * (1.0 - (fSaturation * (1.0 - f)));
  273. switch (i)
  274. {
  275. case 1:
  276. {
  277. r = q; g = fValue; b = p;
  278. }
  279. case 2:
  280. {
  281. r = p; g = fValue; b = t;
  282. }
  283. case 3:
  284. {
  285. r = p; g = q; b = fValue;
  286. }
  287. case 4:
  288. {
  289. r = t; g = p; b = fValue;
  290. }
  291. case 5:
  292. {
  293. r = fValue; g = p; b = q;
  294. }
  295. default:
  296. {
  297. r = fValue; g = t; b = p;
  298. }
  299. }
  300. }
  301. }
  302.  
  303.  
  304. //////////////////////////////////////////////////////////////////
  305. // Delete entitys
  306. //////////////////////////////////////////////////////////////////
  307.  
  308. public Action:Delete(Handle:timer, any:iRef)
  309. {
  310.  
  311. new entity= EntRefToEntIndex(iRef);
  312.  
  313. if (entity != INVALID_ENT_REFERENCE)
  314. {
  315. if (IsValidEdict(entity)) AcceptEntityInput(entity, "kill");
  316. }
  317.  
  318. /*
  319. if (GetConVarInt(g_SmokecolorMode) == 2)
  320. {
  321. if (TimeHandle[iRef] != INVALID_HANDLE)
  322. {
  323. CloseHandle(TimeHandle[iRef]);
  324. TimeHandle[iRef] = INVALID_HANDLE;
  325. }
  326. }
  327. */
  328. }
  329. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  330. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
  331. */
  332.