C#:
using Oxide.Core;
using UnityEngine;
using System.Linq;
namespace Oxide.Plugins
{
[Info("PatrolControl", "dfgg", "1.0.0")]
[Description("Activa o desactiva la IA del patrol helicopter para capturas")]
public class PatrolControl : RustPlugin
{
private BaseHelicopter heli;
[ChatCommand("heli.freeze")]
private void FreezeHeli(BasePlayer player, string command, string[] args)
{
foreach (var entity in BaseNetworkable.serverEntities)
{
if (entity is PatrolHelicopter heli)
player.ChatMessage("SE ENCONTRO HELI");
Freeze();
return;
}
player.ChatMessage("NO SE ENCONTRO HELI");
}
[ChatCommand("heli.unfreeze")]
private void UnfreezeHeli(BasePlayer player, string command, string[] args)
{
if (heli == null) heli = BaseNetworkable.serverEntities.OfType<BaseHelicopter>().FirstOrDefault();
if (heli == null)
{
player.ChatMessage("No hay helicóptero activo.");
return;
}
Unfreeze();
player.ChatMessage("IA del helicóptero reactivada.");
}
private void Freeze()
{
heli.CancelInvoke("Think");
heli.CancelInvoke("UpdateRotation");
heli.CancelInvoke("MoveToPathNode");
var rb = heli.GetComponent<Rigidbody>();
if (rb != null) rb.isKinematic = true;
heli.SetFlag(BaseEntity.Flags.Reserved5, false); // Simula motores apagados
}
private void Unfreeze()
{
var rb = heli.GetComponent<Rigidbody>();
if (rb != null) rb.isKinematic = false;
heli.InvokeRepeating("Think", 0f, 0.25f);
heli.InvokeRepeating("UpdateRotation", 0f, 0.015f);
heli.InvokeRepeating("MoveToPathNode", 0f, 0.25f);
heli.SetFlag(BaseEntity.Flags.Reserved5, true);
}
}
}