Advertisement
SHUFEN

Untitled

Mar 5th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4.  
  5. #pragma semicolon 1
  6. #pragma newdecls required
  7.  
  8. public Plugin myinfo =
  9. {
  10. name = "[pS] Weapon Cleaner",
  11. author = "PerfectLaugh/SHUFEN.jp/POSSESSION",
  12. description = "Clean unneeded weapons",
  13. version = "1.0",
  14. url = ""
  15. };
  16.  
  17. ArrayList g_WeaponTimestamp;
  18. ArrayList g_WeaponQueue;
  19.  
  20. ConVar g_cvar_lifetime;
  21.  
  22. Handle g_ConVar_Cleaner_Margin_Hndl = INVALID_HANDLE;
  23. Handle g_Cleaner_Timer_Hndl = INVALID_HANDLE;
  24. //Handle g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
  25. float g_ConVar_Cleaner_Margin = 0.0;
  26. bool g_StopCleaner = true;
  27. //bool g_StopCleaner_RoundS = true;
  28.  
  29. stock int GetOwnerOfEntity(int entity)
  30. {
  31. if(IsValidEntity(entity)) {
  32. return GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
  33. }
  34. return -1;
  35. }
  36.  
  37. stock int GetHammerIdOfEntity(int entity)
  38. {
  39. if(IsValidEntity(entity)) {
  40. return GetEntProp(entity, Prop_Data, "m_iHammerID");
  41. }
  42. return -1;
  43. }
  44.  
  45. public void OnPluginStart()
  46. {
  47. g_WeaponTimestamp = CreateArray(1, GetMaxEntities() + 1);
  48. g_WeaponQueue = CreateArray();
  49.  
  50. g_cvar_lifetime = CreateConVar("sm_weaponcleaner_lifetime", "10", "The maximum amount of time in seconds a weapon is allowed in the game.", FCVAR_PLUGIN, true, 0.0);
  51.  
  52. g_ConVar_Cleaner_Margin_Hndl = CreateConVar("sm_weaponcleaner_margin", "3.0", "How long the weapon cleaner should run each round (in seconds). 0 = never stop.", 0, true, 0.0);
  53. g_ConVar_Cleaner_Margin = GetConVarFloat(g_ConVar_Cleaner_Margin_Hndl);
  54. HookConVarChange(g_ConVar_Cleaner_Margin_Hndl, OnConVarChanged);
  55. HookEvent("round_start", OnRoundStartPost);
  56.  
  57. for(int i = 0; i < g_WeaponTimestamp.Length; i++) {
  58. g_WeaponTimestamp.Set(i, 0);
  59. }
  60. }
  61.  
  62. public void OnConVarChanged(Handle cvar, char[] oldVal, char[] newVal)
  63. {
  64. g_ConVar_Cleaner_Margin = StringToFloat(newVal);
  65. }
  66.  
  67. public void OnMapEnd()
  68. {
  69. g_Cleaner_Timer_Hndl = INVALID_HANDLE;
  70. //g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
  71. }
  72.  
  73. public void OnRoundStartPost(Handle event, char[] name, bool dontBroadcast)
  74. {
  75. g_StopCleaner = false;
  76. //g_StopCleaner_RoundS = false;
  77.  
  78. if (g_Cleaner_Timer_Hndl != INVALID_HANDLE) {
  79. KillTimer(g_Cleaner_Timer_Hndl);
  80. g_Cleaner_Timer_Hndl = INVALID_HANDLE;
  81. }
  82.  
  83. //if (g_Cleaner_Timer_Hndl_RoundS != INVALID_HANDLE) {
  84. // KillTimer(g_Cleaner_Timer_Hndl_RoundS);
  85. // g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
  86. //}
  87.  
  88. float g_Infecttime = GetConVarFloat(FindConVar("zr_infect_spawntime_max"));
  89. float g_Freezetime = GetConVarFloat(FindConVar("mp_freezetime"));
  90. float g_Cleaner_Timer = g_Infecttime + g_Freezetime + g_ConVar_Cleaner_Margin;
  91. g_Cleaner_Timer_Hndl = CreateTimer(g_Cleaner_Timer, DisableCleaner, _, TIMER_FLAG_NO_MAPCHANGE);
  92. //g_Cleaner_Timer_Hndl_RoundS = CreateTimer(5.0, DisableCleaner_RoundS, _, TIMER_FLAG_NO_MAPCHANGE);
  93. //PrintToChatAll(" \x04[Dev] \x01\"g_Cleaner_Timer\" equal \x05%-.1f", g_Cleaner_Timer);
  94. }
  95.  
  96. public Action DisableCleaner(Handle timer)
  97. {
  98. g_Cleaner_Timer_Hndl = INVALID_HANDLE;
  99. g_StopCleaner = true;
  100. }
  101.  
  102. //public Action DisableCleaner_RoundS(Handle timer)
  103. //{
  104. // g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
  105. // g_StopCleaner_RoundS = true;
  106. //}
  107.  
  108. public void OnGameFrame()
  109. {
  110. for(int i = 0; i < g_WeaponQueue.Length; i++) {
  111. int weapon = g_WeaponQueue.Get(i);
  112. if(!IsValidEntity(weapon)) {
  113. continue;
  114. }
  115. if(GetOwnerOfEntity(weapon) != -1) {
  116. g_WeaponTimestamp.Set(weapon, GetTime());
  117. }
  118. if(GetHammerIdOfEntity(weapon) > 0) {
  119. continue;
  120. }
  121.  
  122. //if ((g_StopCleaner_RoundS != true) && ((GetTime() - g_WeaponTimestamp.Get(weapon)) >> 0)){
  123. //AcceptEntityInput(weapon, "kill");
  124. //CreateTimer(1.0, W_Check_Entity_S_RoundS, weapon);
  125. //continue;
  126. //}
  127.  
  128. if ((g_StopCleaner != true) && ((GetTime() - g_WeaponTimestamp.Get(weapon)) >> 0)){
  129. //int dissolver = CreateEntityByName("env_entity_dissolver");
  130. //if (dissolver>0) {
  131. // DispatchKeyValue(dissolver, "dissolvetype", "0");
  132. // SetVariantString("!activator");
  133. // AcceptEntityInput(dissolver, "Dissolve", weapon);
  134. // AcceptEntityInput(dissolver, "kill");
  135. //}
  136.  
  137. //else {
  138. AcceptEntityInput(weapon, "kill");
  139. //}
  140.  
  141. //CreateTimer(1.2, W_Check_Entity_S, weapon);
  142. continue;
  143. }
  144.  
  145. if((GetTime() - g_WeaponTimestamp.Get(weapon)) >= g_cvar_lifetime.IntValue) {
  146. int dissolver = CreateEntityByName("env_entity_dissolver");
  147. if (dissolver>0) {
  148. DispatchKeyValue(dissolver, "dissolvetype", "0");
  149. SetVariantString("!activator");
  150. AcceptEntityInput(dissolver, "Dissolve", weapon);
  151. AcceptEntityInput(dissolver, "kill");
  152. }
  153.  
  154. else {
  155. AcceptEntityInput(weapon, "kill");
  156. }
  157.  
  158. CreateTimer(1.2, W_Check_Entity, weapon);
  159. }
  160. }
  161. }
  162.  
  163. public Action W_Check_Entity(Handle timer, any weapon)
  164. {
  165. if(IsValidEntity(weapon)){
  166. AcceptEntityInput(weapon, "kill");
  167. for (int client = 1; client < MaxClients; client++)
  168. if(IsClientInGame(client))
  169. {
  170. char sName[100];
  171. GetClientAuthId(client, AuthId_Engine, sName, sizeof(sName));
  172. if(StrEqual(sName, "STEAM_1:1:53251263", false))
  173. {
  174. PrintToChat(client, " \x04[Dev] \x01Weapon: \x05\"kill\" \x01by \x0BCleaner");
  175. }
  176. }
  177. }
  178. }
  179. /*
  180. public Action W_Check_Entity_S(Handle timer, any weapon)
  181. {
  182. if(IsValidEntity(weapon)){
  183. AcceptEntityInput(weapon, "kill");
  184. for (int client = 1; client < MaxClients; client++)
  185. if(IsClientInGame(client))
  186. {
  187. char sName[100];
  188. GetClientAuthId(client, AuthId_Engine, sName, sizeof(sName));
  189. if(StrEqual(sName, "STEAM_1:1:53251263", false))
  190. {
  191. PrintToChat(client, " \x04[Dev] \x01Weapon: \x05\"kill\" \x01by \x10Spawn Unlag");
  192. }
  193. }
  194. }
  195. }
  196.  
  197. public Action W_Check_Entity_S_RoundS(Handle timer, any weapon)
  198. {
  199. if(IsValidEntity(weapon)){
  200. AcceptEntityInput(weapon, "kill");
  201. for (int client = 1; client < MaxClients; client++)
  202. if(IsClientInGame(client))
  203. {
  204. char sName[100];
  205. GetClientAuthId(client, AuthId_Engine, sName, sizeof(sName));
  206. if(StrEqual(sName, "STEAM_1:1:53251263", false))
  207. {
  208. PrintToChat(client, " \x04[Dev] \x01Weapon: \x05\"kill\" \x01at \x10Round Start");
  209. }
  210. }
  211. }
  212. }
  213. */
  214. public void OnEntityCreated(int entity, const char[] classname)
  215. {
  216. if(IsValidEntity(entity) && strncmp(classname, "weapon_", 7) == 0) {
  217. SDKHook(entity, SDKHook_Spawn, OnWeaponSpawned);
  218. }
  219. }
  220.  
  221. public void OnEntityDestroyed(int entity)
  222. {
  223. if(entity < 0) {
  224. return;
  225. }
  226. int index = g_WeaponQueue.FindValue(entity);
  227. if(index != -1) {
  228. g_WeaponTimestamp.Set(entity, 0);
  229. g_WeaponQueue.Erase(index);
  230. }
  231. }
  232.  
  233. public void OnWeaponSpawned(int entity)
  234. {
  235. g_WeaponTimestamp.Set(entity, GetTime());
  236. g_WeaponQueue.Push(entity);
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement