Hi,
Tried for long enough, but I dont know CS or anything and I just can't.
All I want is to make a command to spawn whatever entity wherever playing is standing/looking (either is fine!)
This is what I have so far. I've tried so many variations but, at best, the command does nothing.
Oddly, I can't even get it to broadcast chat message or console message as test, so I give up! Please help
Code:using System; using System.Collections.Generic; using Oxide.Core; using Oxide.Core.Plugins; using Oxide.Core.Configuration; using UnityEngine; using Oxide.Core.Libraries.Covalence;namespace Oxide.Plugins { [Info("Spawner", "Vox", "0.1.0", ResourceId = 18718777)] [Description("Spawn horse")] class Spawner : CovalencePlugin { public static string version = "0.1.0"; public Vector3 where; #region Hooks BaseEntity newHorse; BaseEntity horse; #endregion #region Chat Commands [Command("horse"), Permission("horse.use")] void HorseCommand(BasePlayer player, string command, string[] args) { string prefabstr = "assets/rust.ai/agents/horse/horse.prefab"; BaseEntity entity = GameManager.server.CreateEntity(prefabstr, new UnityEngine.Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z), new UnityEngine.Quaternion(), true); entity.Spawn(); server.Broadcast("used"); } #endregion } }
Spawning entity where player is looking
Discussion in 'Rust Development' started by Ichibu, Apr 20, 2018.
-
Look at the Unity forums, there's all kinds of threads. This isn't Oxide specific for the most part.
-
@Ichibu
To give you some base to fiddle together
based on the client console command "spawn", which spawns the choosen prefabname at the view point:
Code:// ConVar.Entity [ClientVar(Name = "spawn")] public static void clspawn(string name) { RaycastHit raycast = MainCamera.Raycast; if (raycast.collider != null) { ConsoleNetwork.ClientRunOnServer(string.Format("spawn \"{0}\" \"{1}\"", name, raycast.point.ToString())); } }
{1} will be taken from the MainCamera.Raycast raycast.point
Code:// MainCamera public static RaycastHit Raycast { get { RaycastHit result; Physics.Raycast(MainCamera.Ray, out result, 1024f, 95513345); return result; } }
Code:player.eyes.HeadRay()
Code:// ConVar.Entity [ServerVar(Name = "spawn")] public static string svspawn(string name, Vector3 pos) { if (string.IsNullOrEmpty(name)) { return "No entity name provided"; } string[] array = (from x in global::GameManifest.Current.entities where Path.GetFileNameWithoutExtension(x).Contains(name, CompareOptions.IgnoreCase) select x.ToLower()).ToArray<string>(); if (array.Length == 0) { return "Entity type not found"; } if (array.Length > 1) { string text = array.FirstOrDefault((string x) => string.Compare(Path.GetFileNameWithoutExtension(x), name, StringComparison.OrdinalIgnoreCase) == 0); if (text == null) { string arg_D6_0 = "Unknown entity - could be:\n\n"; string arg_D1_0 = "\n"; IEnumerable<string> arg_C7_0 = array; if (Entity.<>f__mg$cache0 == null) { Entity.<>f__mg$cache0 = new Func<string, string>(Path.GetFileNameWithoutExtension); } return arg_D6_0 + string.Join(arg_D1_0, arg_C7_0.Select(Entity.<>f__mg$cache0).ToArray<string>()); } array[0] = text; } global::BaseEntity baseEntity = global::GameManager.server.CreateEntity(array[0], pos, default(Quaternion), true); if (baseEntity == null) { return "Couldn't spawn " + name; } baseEntity.Spawn(); return string.Concat(new object[] { "spawned ", baseEntity, " at ", pos }); }
Btw: the used 95513345 is the ray is equal to these layers:
Code:Default | 0 Deployed | 8 Ragdoll | 9 AI | 11 Vehicle Movement | 13 Game Trace | 14 World | 16 Physics Prop | 20 Construction | 21 Terrain | 23 Transparent | 24 Debris | 26
Last edited by a moderator: Apr 25, 2018 -
Waw, thank you !
It's much more complex than I expected, but replicating client command "spawn" is exactly what I want to do with chat command, so this should be all I need as you say