this is what i have so far
Its returning like ( x, y, z)Code:void OnUseNPC(BasePlayer npc, BasePlayer player, Vector3 destination) { ulong playerID = player.userID; string lowername = npc.displayName; string lowernpc = NpcID; object newpos = null; string spawn = SpawnsFile; var count = Spawns.Call("GetSpawnsCount", spawn); if (lowername.Contains(lowernpc)) newpos = Spawns.Call("GetRandomSpawn", spawn); else if (lowername.Contains(lowernpc)) newpos = Spawns.Call("GetRandomSpawn", spawn); SendReply(player, $"test {newpos} " ); }} }
how can i have it return x y z
Solved Formatting Vector3 without braces?
Discussion in 'Rust Development' started by Ts3hosting, Dec 16, 2016.
-
Wulf Community Admin
Get the individual values and format them how you'd like. Example:
Code:SendReply(player, $"test {newpos.x} {newpos.y} {newpos.z}");
-
(15:24:15) | [Oxide] 15:24 [Error] Error while compiling Npctp.cs(145,78): error CS1061: Type `object' does not contain a definition for `z' and no extension method `z' of type `object' could be found. Are you missing an assembly reference?
[DOUBLEPOST=1481923577][/DOUBLEPOST]
im new to c and i must be missing something somewhere
Code:using System.Collections.Generic; using System; using Oxide.Core; using Oxide.Core.Plugins; using Oxide.Core.Configuration; using Oxide.Game.Rust.Cui; using Newtonsoft.Json; using UnityEngine; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using Oxide.Core.Libraries.Covalence;namespace Oxide.Plugins { [Info("Npctp", "Ts3hosting", "2.2.0", ResourceId = 2229)] [Description("Some NPC Controle")] class Npctp : RustPlugin { #region Initialization [PluginReference] Plugin Spawns; const string permUse = "Npctp.admin"; private bool backroundimage; private bool Changed; bool NPCUSE = false; private string text; private bool displayoneveryconnect; private string NpcID; private string SpawnsFile; private bool Enabled; void Loaded() { permission.RegisterPermission("npctp.usecmd", this); data = Interface.GetMod().DataFileSystem.ReadObject<Data>("RulesGUIdata"); LoadVariables(); } object GetConfig(string menu, string datavalue, object defaultValue) { var data = Config[menu] as Dictionary<string, object>; if (data == null) { data = new Dictionary<string, object>(); Config[menu] = data; Changed = true; } object value; if (!data.TryGetValue(datavalue, out value)) { value = defaultValue; data[datavalue] = value; Changed = true; } return value; } void LoadVariables() { NpcID = Convert.ToString(GetConfig("NpcOne", "NpcID", "land_tp")); Enabled = Convert.ToBoolean(GetConfig("NpcOne", "Enabled", false)); SpawnsFile = Convert.ToString(GetConfig("NpcOne", "SpawnsFile", "arena")); if (Changed) { SaveConfig(); Changed = false; } } protected override void LoadDefaultConfig() { Puts("Creating a new configuration file!"); Config.Clear(); LoadVariables(); } class Data { public List<string> Players = new List<string>{}; } Data data; #endregion #region Localization void LoadDefaultMessages() { // English lang.RegisterMessages(new Dictionary<string, string> { ["CommandUsage"] = "Usage: {0} <name or id> <amount> (amount is optional)", }, this); } #endregion #region USENPC void OnUseNPC(BasePlayer npc, BasePlayer player, Vector3 destination) { ulong playerID = player.userID; string lowername = npc.displayName; string lowernpc = NpcID; object newpos = null; string spawn = SpawnsFile; var count = Spawns.Call("GetSpawnsCount", spawn); if (lowername.Contains(lowernpc)) newpos = Spawns.Call("GetRandomSpawn", spawn); else if (lowername.Contains(lowernpc)) newpos = Spawns.Call("GetRandomSpawn", spawn); SendReply(player, $"test {newpos.x} {newpos.y} {newpos.z}"); }} } #endregion
-
Wulf Community Admin
-
you have an example how to do that i have tried and tried been working on this for 8 hours seem stuck.
-
Wulf Community Admin
Code:(Vector3)Spawns.Call("GetRandomSpawn", spawn)
-
what would be the call after that to split it into x y z?
[DOUBLEPOST=1481925643][/DOUBLEPOST]i appreciate all the help i can get atm this is the only point i cant get past. i just got to get from format (100, 30.2, 100) to 100 30.2 100Last edited by a moderator: Dec 16, 2016 -
i think i got it thanks.
-
Spawns can also return a string containing a error message if the spawn point or spawn file is invalid, so you may want to check if the type is Vector3 before directly casting it
Code:if (newpos is Vector3) { SendReply(player, $"test {(Vector3)newpos.x} {(Vector3)newpos.y} {(Vector3)newpos.z}"); }
-
Here is what i have and it is working but i was wondering if i wanted to have my config calls better how would i go about calling somthing from the config example my config looks like this.
Code:{ "NpcOne": { "Enabled": false, "NpcID": "803382740", "SpawnsFile": "tpbot1" }, "NpcTwo": { "Enabled1": "false", "NpcID1": "123456789", "SpawnsFile1": "setme" } }
and the calls now i have are
string spawn = SpawnsFile;
string spawn1 = SpawnsFile1;
is there s way where i can eliminate the SpawnFile1 and have it called SpawnFile and still get the correct call?
[DOUBLEPOST=1481938382][/DOUBLEPOST]
the way i did the call i do not know if i can add that?
Code:if (lowernpc == lowername) { newpos = Spawns.Call("GetRandomSpawn", spawn); var location = (Vector3)newpos; var locx = location.x; var locy = location.y; var locz = location.z; rust.RunServerCommand($"teleport.topos {player.userID} {locx} {locy} {locz}"); }
-
Example:
Code:if (lowernpc == lowername) { object success = Spawns.Call("GetRandomSpawn", spawn); if (success is Vector3) // Check if the returned type is Vector3 { Vector3 location = (Vector3) success; rust.RunServerCommand($"teleport.topos {player.userID} {location.x} {location.y} {location.z}"); } else PrintError((string)newpos); // Otherwise print the error message to console so server owners know there is a problem }
-
is there a way to convert a x y z back into a vecotr3? example object test = x y z witch will become a vector3 format?
-
Wulf Community Admin
-
Code:
object success = new Vector3(x, y, z); TeleportPlayerPosition1(player, (Vector3)success)
-
Wulf Community Admin
-
[DOUBLEPOST=1485403235][/DOUBLEPOST]g
Code:float newX = float.Parse(x); float newY = float.Parse(y); float newZ = float.Parse(z); object success = new Vector3(newX, newY, newZ);
-
Wulf Community Admin
Also works. -
-
Wulf Community Admin