HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <sourcemod>
  2. #pragma semicolon 1
  3.  
  4. #define PLUGIN_VERSION "1.0"
  5.  
  6. public Plugin:myinfo =
  7. {
  8. name = "New Flash Color",
  9. author = "Regent",
  10. description = "szinet ad a vakto granatnak",
  11. version = PLUGIN_VERSION,
  12. url = ""
  13. };
  14.  
  15.  
  16. #define FFADE_IN 0x0001
  17. #define FFADE_OUT 0x0002
  18. #define FFADE_MODULATE 0x0004
  19. #define FFADE_STAYOUT 0x0008
  20. #define FFADE_PURGE 0x0010
  21.  
  22.  
  23.  
  24. new Handle: g_hConVar_sNewFlashColor = INVALID_HANDLE;
  25. new g_iNewFlashColor[3];
  26. new bool: g_bRandomColor;
  27. new Handle: g_hConVar_bPluginEnabled = INVALID_HANDLE;
  28. new bool: g_bPluginEnabled;
  29.  
  30.  
  31. new g_iOffset_flFlashMaxAlpha,
  32. g_iOffset_flFlashDuration;
  33.  
  34.  
  35. new Handle: g_hFlashTimer[MAXPLAYERS+1];
  36.  
  37. public OnPluginStart()
  38. {
  39. // find offsets
  40. g_iOffset_flFlashMaxAlpha = GetSendPropOffs("CCSPlayer", "m_flFlashMaxAlpha");
  41. g_iOffset_flFlashDuration = GetSendPropOffs("CCSPlayer", "m_flFlashDuration");
  42.  
  43. // create convars of plugin
  44. CreateConVar("sm_newflashcolor_version", PLUGIN_VERSION, "Pligin verzioja", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_SPONLY);
  45. g_hConVar_sNewFlashColor = CreateConVar("sm_newflashcolor_color", "255 0 0", "Flash szine", FCVAR_PLUGIN);
  46. HookConVarChange(g_hConVar_sNewFlashColor, OnConVarChange);
  47. g_hConVar_bPluginEnabled = CreateConVar("sm_newflashcolor_enabled", "1", "engedelyezes/tiltas", FCVAR_PLUGIN);
  48. HookConVarChange(g_hConVar_bPluginEnabled, OnConVarChange);
  49.  
  50. // hook events
  51. HookEvent("player_blind", Ev_PlayerBlind);
  52. HookEvent("player_spawn", Ev_PlayerSpawn);
  53. }
  54.  
  55. public OnClientPutInServer(iClient)
  56. {
  57. g_hFlashTimer[iClient] = INVALID_HANDLE;
  58. }
  59.  
  60. public OnClientDisconnect_Post(iClient)
  61. {
  62. CancelTimer(g_hFlashTimer[iClient]);
  63. g_hFlashTimer[iClient] = INVALID_HANDLE;
  64. }
  65.  
  66. CancelTimer(&Handle:hTimer)
  67. {
  68. if ( hTimer != INVALID_HANDLE )
  69. {
  70. KillTimer(hTimer);
  71. }
  72. }
  73.  
  74. public OnConfigsExecuted()
  75. {
  76. g_bPluginEnabled = GetConVarBool(g_hConVar_bPluginEnabled);
  77. GetNewFlashColor();
  78. }
  79.  
  80. public OnConVarChange(Handle:hConVar, const String:sOldValue[], const String:sNewValue[])
  81. {
  82. if ( hConVar == g_hConVar_sNewFlashColor )
  83. {
  84. GetNewFlashColor();
  85. }
  86. else if ( hConVar == g_hConVar_bPluginEnabled )
  87. {
  88. g_bPluginEnabled = GetConVarBool(g_hConVar_bPluginEnabled);
  89. }
  90. }
  91.  
  92. GetNewFlashColor()
  93. {
  94. // find first and last pos of space, then:
  95. // red part will be everything from start to first space pos
  96. // green part is everything between first and second space pos
  97. // blue part is everything else
  98. decl String:sBuffer[12], String:sPart[4];
  99. GetConVarString(g_hConVar_sNewFlashColor, sBuffer, sizeof(sBuffer));
  100. new iFirstSpace = FindCharInString(sBuffer, ' ', false) + 1;
  101. new iLastSpace = FindCharInString(sBuffer, ' ', true) + 1;
  102.  
  103. if ( iFirstSpace == -1 || iFirstSpace == iLastSpace )
  104. {
  105. g_bRandomColor = true;
  106. }
  107. else
  108. {
  109. strcopy(sPart, iFirstSpace, sBuffer);
  110. g_iNewFlashColor[0] = StringToInt(sPart);
  111. strcopy(sPart, iLastSpace - iFirstSpace, sBuffer[iFirstSpace]);
  112. g_iNewFlashColor[1] = StringToInt(sPart);
  113. strcopy(sPart, strlen(sBuffer) - iLastSpace + 1, sBuffer[iLastSpace]);
  114. g_iNewFlashColor[2] = StringToInt(sPart);
  115. g_bRandomColor = false;
  116. }
  117. }
  118.  
  119. GetSendPropOffs(const String:sClass[], const String:sProp[])
  120. {
  121. new iOffset = FindSendPropOffs(sClass, sProp);
  122. if ( iOffset == - 1 )
  123. {
  124. SetFailState("Offset %s::%s not found", sClass, sProp);
  125. return -1;
  126. }
  127. return iOffset;
  128. }
  129.  
  130. public Ev_PlayerBlind(Handle:hEvent, const String:sEvName[], bool:bSilent)
  131. {
  132. if ( g_bPluginEnabled )
  133. {
  134. new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid")),
  135. iAlpha = RoundToNearest(GetEntDataFloat(iClient, g_iOffset_flFlashMaxAlpha)),
  136. iDuration = RoundToNearest(GetEntDataFloat(iClient, g_iOffset_flFlashDuration)) * 1000;
  137.  
  138. // remove classic flash
  139. SetEntDataFloat(iClient, g_iOffset_flFlashMaxAlpha, 0.5);
  140.  
  141. // if random, get new color
  142. if ( g_bRandomColor )
  143. {
  144. g_iNewFlashColor[0] = GetRandomInt(1, 255);
  145. g_iNewFlashColor[1] = GetRandomInt(1, 255);
  146. g_iNewFlashColor[2] = GetRandomInt(1, 255);
  147. }
  148.  
  149. // fade client. hud will be hidden by game
  150. PerformFade(iClient, iDuration, g_iNewFlashColor, iAlpha);
  151. CancelTimer(g_hFlashTimer[iClient]);
  152. g_hFlashTimer[iClient] = CreateTimer(float(iDuration), Timer_FlashEnded, iClient);
  153. }
  154. }
  155.  
  156. // https://wiki.alliedmods.net/User_Messages
  157. PerformFade(iClient, iDuration, const iColor[3], iAlpha)
  158. {
  159. new iFullBlindDuration = iDuration / 4;
  160. new Handle:hFadeClient = StartMessageOne("Fade", iClient);
  161. BfWriteShort(hFadeClient, iDuration - iFullBlindDuration);
  162. BfWriteShort(hFadeClient, iFullBlindDuration);
  163. BfWriteShort(hFadeClient, (FFADE_PURGE|FFADE_IN));
  164. BfWriteByte(hFadeClient, iColor[0]);
  165. BfWriteByte(hFadeClient, iColor[1]);
  166. BfWriteByte(hFadeClient, iColor[2]);
  167. BfWriteByte(hFadeClient, iAlpha);
  168. EndMessage();
  169. }
  170. // end of https://wiki.alliedmods.net/User_Messages
  171.  
  172. public Action:Timer_FlashEnded(Handle:hTimer, any:iClient)
  173. {
  174. g_hFlashTimer[iClient] = INVALID_HANDLE;
  175. return Plugin_Stop;
  176. }
  177.  
  178. public Ev_PlayerSpawn(Handle:hEvent, const String:sEvName[], bool:bSilent)
  179. {
  180. if ( g_bPluginEnabled )
  181. {
  182.  
  183. new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
  184. if ( g_hFlashTimer[iClient] != INVALID_HANDLE )
  185. {
  186. PerformFade(iClient, 0, {0, 0, 0}, 0);
  187. CancelTimer(g_hFlashTimer[iClient]);
  188. g_hFlashTimer[iClient] = INVALID_HANDLE;
  189. }
  190. }
  191. }