Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #pragma semicolon 1
- #pragma newdecls required
- public Plugin myinfo =
- {
- name = "[pS] Weapon Cleaner",
- author = "PerfectLaugh/SHUFEN.jp/POSSESSION",
- description = "Clean unneeded weapons",
- version = "1.0",
- url = ""
- };
- ArrayList g_WeaponTimestamp;
- ArrayList g_WeaponQueue;
- ConVar g_cvar_lifetime;
- Handle g_ConVar_Cleaner_Margin_Hndl = INVALID_HANDLE;
- Handle g_Cleaner_Timer_Hndl = INVALID_HANDLE;
- //Handle g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
- float g_ConVar_Cleaner_Margin = 0.0;
- bool g_StopCleaner = true;
- //bool g_StopCleaner_RoundS = true;
- stock int GetOwnerOfEntity(int entity)
- {
- if(IsValidEntity(entity)) {
- return GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
- }
- return -1;
- }
- stock int GetHammerIdOfEntity(int entity)
- {
- if(IsValidEntity(entity)) {
- return GetEntProp(entity, Prop_Data, "m_iHammerID");
- }
- return -1;
- }
- public void OnPluginStart()
- {
- g_WeaponTimestamp = CreateArray(1, GetMaxEntities() + 1);
- g_WeaponQueue = CreateArray();
- 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);
- 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);
- g_ConVar_Cleaner_Margin = GetConVarFloat(g_ConVar_Cleaner_Margin_Hndl);
- HookConVarChange(g_ConVar_Cleaner_Margin_Hndl, OnConVarChanged);
- HookEvent("round_start", OnRoundStartPost);
- for(int i = 0; i < g_WeaponTimestamp.Length; i++) {
- g_WeaponTimestamp.Set(i, 0);
- }
- }
- public void OnConVarChanged(Handle cvar, char[] oldVal, char[] newVal)
- {
- g_ConVar_Cleaner_Margin = StringToFloat(newVal);
- }
- public void OnMapEnd()
- {
- g_Cleaner_Timer_Hndl = INVALID_HANDLE;
- //g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
- }
- public void OnRoundStartPost(Handle event, char[] name, bool dontBroadcast)
- {
- g_StopCleaner = false;
- //g_StopCleaner_RoundS = false;
- if (g_Cleaner_Timer_Hndl != INVALID_HANDLE) {
- KillTimer(g_Cleaner_Timer_Hndl);
- g_Cleaner_Timer_Hndl = INVALID_HANDLE;
- }
- //if (g_Cleaner_Timer_Hndl_RoundS != INVALID_HANDLE) {
- // KillTimer(g_Cleaner_Timer_Hndl_RoundS);
- // g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
- //}
- float g_Infecttime = GetConVarFloat(FindConVar("zr_infect_spawntime_max"));
- float g_Freezetime = GetConVarFloat(FindConVar("mp_freezetime"));
- float g_Cleaner_Timer = g_Infecttime + g_Freezetime + g_ConVar_Cleaner_Margin;
- g_Cleaner_Timer_Hndl = CreateTimer(g_Cleaner_Timer, DisableCleaner, _, TIMER_FLAG_NO_MAPCHANGE);
- //g_Cleaner_Timer_Hndl_RoundS = CreateTimer(5.0, DisableCleaner_RoundS, _, TIMER_FLAG_NO_MAPCHANGE);
- //PrintToChatAll(" \x04[Dev] \x01\"g_Cleaner_Timer\" equal \x05%-.1f", g_Cleaner_Timer);
- }
- public Action DisableCleaner(Handle timer)
- {
- g_Cleaner_Timer_Hndl = INVALID_HANDLE;
- g_StopCleaner = true;
- }
- //public Action DisableCleaner_RoundS(Handle timer)
- //{
- // g_Cleaner_Timer_Hndl_RoundS = INVALID_HANDLE;
- // g_StopCleaner_RoundS = true;
- //}
- public void OnGameFrame()
- {
- for(int i = 0; i < g_WeaponQueue.Length; i++) {
- int weapon = g_WeaponQueue.Get(i);
- if(!IsValidEntity(weapon)) {
- continue;
- }
- if(GetOwnerOfEntity(weapon) != -1) {
- g_WeaponTimestamp.Set(weapon, GetTime());
- }
- if(GetHammerIdOfEntity(weapon) > 0) {
- continue;
- }
- //if ((g_StopCleaner_RoundS != true) && ((GetTime() - g_WeaponTimestamp.Get(weapon)) >> 0)){
- //AcceptEntityInput(weapon, "kill");
- //CreateTimer(1.0, W_Check_Entity_S_RoundS, weapon);
- //continue;
- //}
- if ((g_StopCleaner != true) && ((GetTime() - g_WeaponTimestamp.Get(weapon)) >> 0)){
- //int dissolver = CreateEntityByName("env_entity_dissolver");
- //if (dissolver>0) {
- // DispatchKeyValue(dissolver, "dissolvetype", "0");
- // SetVariantString("!activator");
- // AcceptEntityInput(dissolver, "Dissolve", weapon);
- // AcceptEntityInput(dissolver, "kill");
- //}
- //else {
- AcceptEntityInput(weapon, "kill");
- //}
- //CreateTimer(1.2, W_Check_Entity_S, weapon);
- continue;
- }
- if((GetTime() - g_WeaponTimestamp.Get(weapon)) >= g_cvar_lifetime.IntValue) {
- int dissolver = CreateEntityByName("env_entity_dissolver");
- if (dissolver>0) {
- DispatchKeyValue(dissolver, "dissolvetype", "0");
- SetVariantString("!activator");
- AcceptEntityInput(dissolver, "Dissolve", weapon);
- AcceptEntityInput(dissolver, "kill");
- }
- else {
- AcceptEntityInput(weapon, "kill");
- }
- CreateTimer(1.2, W_Check_Entity, weapon);
- }
- }
- }
- public Action W_Check_Entity(Handle timer, any weapon)
- {
- if(IsValidEntity(weapon)){
- AcceptEntityInput(weapon, "kill");
- for (int client = 1; client < MaxClients; client++)
- if(IsClientInGame(client))
- {
- char sName[100];
- GetClientAuthId(client, AuthId_Engine, sName, sizeof(sName));
- if(StrEqual(sName, "STEAM_1:1:53251263", false))
- {
- PrintToChat(client, " \x04[Dev] \x01Weapon: \x05\"kill\" \x01by \x0BCleaner");
- }
- }
- }
- }
- /*
- public Action W_Check_Entity_S(Handle timer, any weapon)
- {
- if(IsValidEntity(weapon)){
- AcceptEntityInput(weapon, "kill");
- for (int client = 1; client < MaxClients; client++)
- if(IsClientInGame(client))
- {
- char sName[100];
- GetClientAuthId(client, AuthId_Engine, sName, sizeof(sName));
- if(StrEqual(sName, "STEAM_1:1:53251263", false))
- {
- PrintToChat(client, " \x04[Dev] \x01Weapon: \x05\"kill\" \x01by \x10Spawn Unlag");
- }
- }
- }
- }
- public Action W_Check_Entity_S_RoundS(Handle timer, any weapon)
- {
- if(IsValidEntity(weapon)){
- AcceptEntityInput(weapon, "kill");
- for (int client = 1; client < MaxClients; client++)
- if(IsClientInGame(client))
- {
- char sName[100];
- GetClientAuthId(client, AuthId_Engine, sName, sizeof(sName));
- if(StrEqual(sName, "STEAM_1:1:53251263", false))
- {
- PrintToChat(client, " \x04[Dev] \x01Weapon: \x05\"kill\" \x01at \x10Round Start");
- }
- }
- }
- }
- */
- public void OnEntityCreated(int entity, const char[] classname)
- {
- if(IsValidEntity(entity) && strncmp(classname, "weapon_", 7) == 0) {
- SDKHook(entity, SDKHook_Spawn, OnWeaponSpawned);
- }
- }
- public void OnEntityDestroyed(int entity)
- {
- if(entity < 0) {
- return;
- }
- int index = g_WeaponQueue.FindValue(entity);
- if(index != -1) {
- g_WeaponTimestamp.Set(entity, 0);
- g_WeaponQueue.Erase(index);
- }
- }
- public void OnWeaponSpawned(int entity)
- {
- g_WeaponTimestamp.Set(entity, GetTime());
- g_WeaponQueue.Push(entity);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement