C#:
using System;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("MiniCopterSeating", "Ryamkk", "1.0.0")]
class MiniCopterSeating : RustPlugin
{
static MiniCopterSeating _instance;
int seats = 0;
void OnEntitySpawned(BaseNetworkable entity)
{
_instance = this;
if (entity == null || !(entity is MiniCopter)) return;
BaseVehicle vehicle = entity as BaseVehicle;
seats = vehicle.mountPoints.Length;
if (entity is MiniCopter && entity.ShortPrefabName.Equals("minicopter.entity"))
{
seats += 2;
if (vehicle.mountPoints.Length < seats)
vehicle?.gameObject.AddComponent<Seating>();
}
}
void AddSeat(BaseVehicle ent, Vector3 locPos, Quaternion q)
{
BaseEntity seat = GameManager.server.CreateEntity("assets/prefabs/vehicle/seats/passengerchair.prefab",
ent.transform.position, q) as BaseEntity;
if (seat == null) return;
seat.SetParent(ent);
seat.Spawn();
seat.transform.localPosition = locPos;
seat.SendNetworkUpdateImmediate(true);
}
BaseVehicle.MountPointInfo CreateMount(Vector3 vec, BaseVehicle.MountPointInfo exampleSeat, Vector3 rotation)
{
return new BaseVehicle.MountPointInfo
{
pos = vec,
rot = rotation != null ? rotation : new Vector3(0, 0, 0),
prefab = exampleSeat.prefab,
mountable = exampleSeat.mountable
};
}
class Seating : MonoBehaviour
{
public BaseVehicle entity;
void Awake()
{
entity = GetComponent<BaseVehicle>();
Vector3 emptyVector = new Vector3(0, 0, 0);
if (entity == null)
{
Destroy(this);
return;
}
Array.Resize(ref entity.mountPoints, _instance.seats);
if (entity is MiniCopter)
{
BaseVehicle.MountPointInfo pFront = entity.mountPoints[1];
Vector3 leftVector = new Vector3(0.6f, 0.2f, -0.2f);
Vector3 rightVector = new Vector3(-0.6f, 0.2f, -0.2f);
Vector3 playerOffsetVector = new Vector3(0f, 0f, -0.25f);
BaseVehicle.MountPointInfo pLeftSide = _instance.CreateMount(leftVector, pFront, emptyVector);
BaseVehicle.MountPointInfo pRightSide = _instance.CreateMount(rightVector, pFront, emptyVector);
entity.mountPoints[2] = pLeftSide;
entity.mountPoints[3] = pRightSide;
_instance.AddSeat(entity, leftVector + playerOffsetVector, new Quaternion());
_instance.AddSeat(entity, rightVector + playerOffsetVector, new Quaternion());
}
}
}
}
}