Guest User

Untitled

a guest
Jun 5th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using Oxide.Core;
  2. using Oxide.Core.Plugins;
  3. using Rust;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using UnityEngine;
  9.  
  10.  
  11. namespace Oxide.Plugins
  12. {
  13. [Info("HumanNPCChairRepair", "Toliman", "0.0.1")]
  14. [Description("RepairsMountables")]
  15. class HumanNPCChairRepair : RustPlugin
  16. {
  17.  
  18. [PluginReference] private Plugin ZoneManager;
  19. void OnServerInitialized(bool initial)
  20. {
  21.  
  22.  
  23. timer.Repeat(7200, 0, () =>
  24. {
  25. restoreChairs();
  26. });
  27. }
  28.  
  29.  
  30. [ChatCommand("rc")]
  31. private void cmdOccupiedChairs(BasePlayer player, string command, string[] args)
  32. {
  33. if (!player.IsAdmin) return;
  34. restoreChairs();
  35. }
  36.  
  37.  
  38. void restoreChairs()
  39. {
  40. int i = 0;
  41. try
  42. {
  43. if (ZoneManager != null)
  44. {
  45. string zoneID = GetZoneIDByName("stadium");
  46. List<BaseEntity> listEntities = (List<BaseEntity>)ZoneManager.Call("GetEntitiesInZone", zoneID);
  47. foreach (var Chair in listEntities.OfType<BaseChair>())
  48. {
  49. if (Chair != null && Chair.GetMounted() == null && Chair.IsMounted())
  50. {
  51. Chair.SetFlag(BaseEntity.Flags.Busy, false, false);
  52. i++;
  53. }
  54. }
  55. }
  56. Puts("[Info]Restored: " + i.ToString() + " chairs.");
  57. }
  58. catch (Exception e)
  59. {
  60. Puts("[Exception]" + e.Message);
  61. }
  62. }
  63.  
  64. string GetZoneIDByName(string zoneName)
  65. {
  66. string FoundZoneID = "";
  67. try
  68. {
  69. if (ZoneManager != null)
  70. {
  71. foreach (object zoneID in (string[])ZoneManager.Call("GetZoneIDs"))
  72. {
  73. if (zoneID != null)
  74. {
  75. string TempZoneName = (string)ZoneManager.Call("GetZoneName", zoneID);
  76. if (TempZoneName != null && TempZoneName.ToLower() == zoneName)
  77. {
  78. FoundZoneID = (string)zoneID;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. catch (Exception e)
  85. {
  86. Puts("[Exception]" + e.Message);
  87. }
  88. return FoundZoneID;
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment