I tried this code and it works. But I need to spawn entity having only the coordinates of the Vector3
Code:[ChatCommand("boxhere")] private void cmdBoxHere(BasePlayer player, string command, string[] args) { var box = GameManager.server.CreateEntity("assets/prefabs/deployable/large wood storage/box.wooden.large.prefab", player.transform.position, new Quaternion(), true); box.OwnerID = player.userID; box.Spawn(); }
Using CreateEntity having only Vector3 coordinates?
Discussion in 'Rust Development' started by Fasta, Feb 6, 2017.
-
what? you had spawned only coordinates of the Vector3
-
Ok. I got to understand and write the solution.
At one point I was stuck for a long time:
Code://pos.y = TerrainMeta.HeightMap.GetHeight(pos.x, pos.z); pos.y = TerrainMeta.HeightMap.GetHeight(pos)
Code:[ChatCommand("spawn")] private void cmdBoxHere(BasePlayer player, string command, string[] args) { if (args.Length != 2) { SendReply(player, "Need two parameters: X Z\nExample: /spawn 15 15"); return; } Vector3 pos = Vector3.zero; float.TryParse(args[0], out pos.x); float.TryParse(args[1], out pos.z); if (pos.x == 0 || pos.z == 0) { SendReply(player, $"Syntax error: {args[0]}, {args[1]} "); return; } pos.y = TerrainMeta.HeightMap.GetHeight(pos); //var entity = GameManager.server.CreateEntity("assets/prefabs/deployable/large wood storage/box.wooden.large.prefab", pos, new Quaternion(), true); var entity = GameManager.server.CreateEntity("assets/bundled/prefabs/autospawn/resource/loot/loot-barrel-1.prefab", pos, new Quaternion(), true); entity.Spawn();
-