Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace Oxide.Plugins
  6. {
  7. [Info("MinicopterSeating", "Bazz3l", "1.0.8")]
  8. [Description("Allows 2 extra seats on the mini copter")]
  9. class MinicopterSeating : RustPlugin
  10. {
  11. /* void OnEntitySpawned(MiniCopter mini)
  12. {
  13. if (mini == null || mini.ShortPrefabName != "minicopter.entity") return;
  14. if (mini.mountPoints.Length < 4)
  15. mini?.gameObject.AddComponent<CopterSeating>();
  16. }*/
  17. void OnServerInitialized()
  18. {
  19. permission.RegisterPermission("minicopterseating.vip", this);
  20. }
  21. string EvilPenguins = "<color=#5e1bb1>E</color><color=#5329ce>v</color><color=#4247ef>i</color><color=#3a56ff>l</color> <color=#3a56ff>P</color><color=#3959ff>e</color><color=#3567ff>n</color><color=#307aff>g</color><color=#2995ff>u</color><color=#25a6ff>i</color><color=#22b2ff>n</color><color=#21b8ff>s</color>";
  22. public string ChairPrefab = "assets/prefabs/vehicle/seats/passengerchair.prefab";
  23.  
  24. void OnEntityMounted(BaseMountable entity, BasePlayer player)
  25. {
  26. BaseEntity entityParent = entity.GetParentEntity();
  27. if (entityParent == null || entityParent.ShortPrefabName != "minicopter.entity") return;
  28. MiniCopter mini = (MiniCopter)entityParent;
  29. if (!permission.UserHasPermission(player.UserIDString, "minicopterseating.vip"))
  30. {
  31. if((mini.mountPoints.Length>2) && entity.ShortPrefabName=="miniheliseat")
  32. {
  33. RemoveSeats(mini, player);
  34. }
  35. return;
  36. }
  37.  
  38.  
  39. if (mini.mountPoints.Length < 4 && entity.ShortPrefabName== "miniheliseat")
  40. {
  41. player.ChatMessage(EvilPenguins+" - Created more seats on the minicopter because of VIP..");
  42. mini?.gameObject.AddComponent<CopterSeating>();
  43. }
  44. }
  45. public void RemoveSeats(BaseVehicle mini, BasePlayer player)
  46. {
  47. List<BaseEntity> foundSeats = new List<BaseEntity>();
  48. foreach (BaseEntity item in mini.children)
  49. {
  50. if (item.PrefabName == ChairPrefab)
  51. {
  52. foundSeats.Add(item);
  53. //item.Kill();
  54. }
  55. }
  56. foreach (BaseEntity seat in foundSeats)
  57. {
  58. seat.Kill();
  59. }
  60. Array.Resize(ref mini.mountPoints, 2);
  61. player.ChatMessage(EvilPenguins + " - Removed extra seats as you are not VIP. /vip to buy.");
  62. }
  63.  
  64.  
  65. class CopterSeating : MonoBehaviour
  66. {
  67. public string ChairPrefab = "assets/prefabs/vehicle/seats/passengerchair.prefab";
  68. public BaseVehicle mini;
  69.  
  70. void Awake()
  71. {
  72. mini = GetComponent<BaseVehicle>();
  73. if (mini == null)
  74. {
  75. Destroy(this);
  76. return;
  77. }
  78.  
  79. BaseVehicle.MountPointInfo pilot = mini.mountPoints[0];
  80. BaseVehicle.MountPointInfo passenger1 = mini.mountPoints[1];
  81.  
  82. Array.Resize(ref mini.mountPoints, 4);
  83.  
  84. BaseVehicle.MountPointInfo passenger2 = new BaseVehicle.MountPointInfo
  85. {
  86. pos = new Vector3(0.6f, 0.2f, -0.2f),
  87. rot = mini.mountPoints[1].rot,
  88. prefab = mini.mountPoints[1].prefab,
  89. mountable = mini.mountPoints[1].mountable,
  90. };
  91.  
  92. BaseVehicle.MountPointInfo passenger3 = new BaseVehicle.MountPointInfo
  93. {
  94. pos = new Vector3(-0.6f, 0.2f, -0.2f),
  95. rot = mini.mountPoints[1].rot,
  96. prefab = mini.mountPoints[1].prefab,
  97. mountable = mini.mountPoints[1].mountable,
  98. };
  99.  
  100. mini.mountPoints[0] = pilot;
  101. mini.mountPoints[1] = passenger1;
  102. mini.mountPoints[2] = passenger2;
  103. mini.mountPoints[3] = passenger3;
  104.  
  105. MakeSeat(mini, new Vector3(0.6f, 0.2f, -0.5f));
  106. MakeSeat(mini, new Vector3(-0.6f, 0.2f, -0.5f));
  107. }
  108.  
  109. void MakeSeat(BaseVehicle mini, Vector3 locPos)
  110. {
  111. BaseEntity seat = GameManager.server.CreateEntity(ChairPrefab, mini.transform.position) as BaseEntity;
  112. if (seat == null) return;
  113.  
  114. seat.SetParent(mini);
  115. seat.Spawn();
  116. seat.transform.localPosition = locPos;
  117. seat.SendNetworkUpdateImmediate(true);
  118. }
  119.  
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement