Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Oxide.Core;
- using Oxide.Core.Plugins;
- using Rust;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using UnityEngine;
- namespace Oxide.Plugins
- {
- [Info("HumanNPCChairRepair", "Toliman", "0.0.1")]
- [Description("RepairsMountables")]
- class HumanNPCChairRepair : RustPlugin
- {
- [PluginReference] private Plugin ZoneManager;
- void OnServerInitialized(bool initial)
- {
- timer.Repeat(7200, 0, () =>
- {
- restoreChairs();
- });
- }
- [ChatCommand("rc")]
- private void cmdOccupiedChairs(BasePlayer player, string command, string[] args)
- {
- if (!player.IsAdmin) return;
- restoreChairs();
- }
- void restoreChairs()
- {
- int i = 0;
- try
- {
- if (ZoneManager != null)
- {
- string zoneID = GetZoneIDByName("stadium");
- List<BaseEntity> listEntities = (List<BaseEntity>)ZoneManager.Call("GetEntitiesInZone", zoneID);
- foreach (var Chair in listEntities.OfType<BaseChair>())
- {
- if (Chair != null && Chair.GetMounted() == null && Chair.IsMounted())
- {
- Chair.SetFlag(BaseEntity.Flags.Busy, false, false);
- i++;
- }
- }
- }
- Puts("[Info]Restored: " + i.ToString() + " chairs.");
- }
- catch (Exception e)
- {
- Puts("[Exception]" + e.Message);
- }
- }
- string GetZoneIDByName(string zoneName)
- {
- string FoundZoneID = "";
- try
- {
- if (ZoneManager != null)
- {
- foreach (object zoneID in (string[])ZoneManager.Call("GetZoneIDs"))
- {
- if (zoneID != null)
- {
- string TempZoneName = (string)ZoneManager.Call("GetZoneName", zoneID);
- if (TempZoneName != null && TempZoneName.ToLower() == zoneName)
- {
- FoundZoneID = (string)zoneID;
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- Puts("[Exception]" + e.Message);
- }
- return FoundZoneID;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment