Get player position within game?Solved

Under the API / Player #Location section I found:

Position
Retrieve a player's in-game character position
GenericPosition position = player.Position();

I am working on a very simple "Where am I" plugin.

How do I find out what DLL I need to reference that contains the player.Position() function, and can I then take the variable
“position” and return it to the player with the “SendMessage” function?

Thanks!

When you install Oxide on a server, it adds various DLLs in the RustDedicated_Data/Managed directory. In my projects, I add references in my IDE to the following DLLs from that directory.

Assembly-CSharp.dll
Facepunch.Console.dll
Facepunch.GoogleSheets.dll
Facepunch.Input.dll
Facepunch.Network.dll
Facepunch.Raknet.dll
Facepunch.Rcon.dll
Facepunch.Skeleton.dll
Facepunch.Sqlite.dll
Facepunch.SteamNetworking.dll
Facepunch.Steamworks.Win64.dll
Facepunch.System.dll
Facepunch.Unity.dll
Facepunch.UnityEngine.dll
Oxide.Core.dll
Oxide.CSharp.dll
Oxide.MySql.dll
Oxide.References.dll
Oxide.Rust.dll
Oxide.SQLite.dll
Oxide.Unity.dll
Rust.Data.dll
Rust.Demo.dll
Rust.Global.dll
Rust.Harmony.dll
Rust.Localization.dll
Rust.UI.dll
Rust.Workshop.dll
Rust.World.dll
UnityEngine.dll
UnityEngine.CoreModule.dll
UnityEngine.PhysicsModule.dll
UnityEngine.TextRenderingModule.dll
UnityEngine.UI.dll​


There are several ways to send a message to a player. Given that you mentioned the Position() method, I'll assume you are using the IPlayer interface. That interface also has a Reply(string) method which prints the string to the player's chat or console (depending on where they initiated the command). You can read the coordinates of the position and build the string how you want.

WhiteThunder - Thank you for the quick reply!!

Merged post

I still having trouble finding the DLL that will let me access the player.Position() function.

I have verified that all of the suggested references are contained under Dependencies.
I trying to insert this into a verified plugin that can be activated using the chat command.

The only seems to be having an issue with the Position() part of the function but mentions the BasePlayer part of the HelloCommand.

I have included screen shots here:
a0AvPLi.png
sZDAxj5.png

I have tried this as both .NetStandard and .NetFramework.

Any help that you can give will be appreciated.

That's because you have a BasePlayer. You can get their position with basePlayer.transform.position.

The reason that method receives a BasePlayer is because you are using ChatCommand which works with RustPlugin. The alternative that some plugins do is to use CovalencePlugin (universal), which works with Command (generic for console and chat commands), and then you would change the method signature to use IPlayer.

internal class MyPlugin : RustPlugin
{
    [ChatCommand("hello")]
    private void HelloCommand(BasePlayer player, string command, string[] args)
}​

internal class MyPlugin : CovalencePlugin
{
    [Command("hello")]
    private void HelloCommand(IPlayer player, string command, string[] args)
}
Thank you again for your help.  It is much appreciated!!

Merged post

Can you please help me on how to convert “position” variable so that the “Puts”  function will display it and how I can get the same information to display in chat.

namespace Oxide.Plugins
{
    [Info("New Where","PEBKAC Error","1.0")]
    [Description("Same as whereami except that Covalence / IPlayer is used")]
    public class newwhere : CovalencePlugin
    {
        [Command("newwhere")]  
        private void Init()
        {
            Puts("NewWhere mod Initialized");
        }
  
        private void HelloCommand(IPlayer player, string command, string[] args)
        {           
            var position = player.Position();
            Puts(position);
        }
    }
}
namespace Oxide.Plugins
{
    [Info("New Where", "PEBKAC Error", "1.0")]
    [Description("Shows player their location")]
    public class newwhere : CovalencePlugin
    {
        [Command("newwhere")]
        private void WhereCommand(IPlayer player, string command, string[] args)
        {
            var position = player.Position();
            player.Reply(position.ToString());
        }
    }
}
Thank you sir!!

Merged post

@Wulf

This is what I currently have working:

private void WhereCommand(IPlayer player, string command, string[] args)
{
var position = player.Position();
string pos = position.ToString();
player.Reply("You are at " + pos);
//player.Reply(position.ToString());
}

Is there a way to condence the code in the block above into one line?
Meaning the two lines before the player.Reply statement.

Thanks again!
player.Reply($"You are at {player.Position()}");
Got it. So the $ does the string conversion. 

When working with variables does Oxide follow C# functions or is there grey area?

Thanks!
I'm not sure what you mean by "follow C# functions", plugins are just C# as is anything else written in C#.

The $ is for string interpolition; alternately you can write it this way:
player.Reply("You are at " + player.Position().ToString());​
Locked automatically