1. Given a players Name, how do i get a GameObject for that player.

    For instance, If I want to give an item to another player and place it directly into their inventory how do I get the NetworkPlayer or PlayerIdentity or GameObject for that player?
     
  2. Wulf

    Wulf Community Admin

    Get all player identities (needed for the following snippets):
    Code:
    var identityMap = GameManager.Instance.GetIdentityMap();
    Get PlayerIdentity for "player name":
    Code:
    var identity = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Value);
    Get NetworkPlayer for "player name":
    Code:
    var targetMap = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Key);
    Get PlayerEntity (GameObject) for NetworkPlayer:
    Code:
    var entity = GameManager.GetPlayerEntity(player);
    You can also use other values instead of "Name" to get the identity and player, such as "SteamId" and more.
     
  3. Code:
    var targetMap = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Key);
    Says that i'm Missing an Assembly. Key is not Valid for bool.

    How can I fix this?
     
  4. Wulf

    Wulf Community Admin

    You'd need to import the correct references. I'd recommend using Visual Studio 2015, and it should prompt you for what to import. It should just be a matter of "using System.Linq;", but I'd still recommend VS.
     
  5. Hello,

    using System.Linq is inside. Im using Visual Studio 2015
     
  6. Wulf

    Wulf Community Admin

    It should prompt you for any missing references and using statements, which is the issue you are having.
     
  7. Well obviously i'm missing something. It just says THAT something is missing, but not the references i'm actually missing. There are my usings:
    using System.Collections.Generic;
    using System;
    using System.Linq;
    using uLink;
    using Steamworks;

    using Oxide.Core;
    using Oxide.Core.Libraries.Covalence;
    using Oxide.Game.Hurtworld;

    I pretty much imported all dlls

    Thanks for your help
     
  8. Wulf

    Wulf Community Admin

    Please provide your full plugin, and I'll take a look.
     
  9. Code:
    // Reference: UnityEngine.UIusing System.Collections.Generic;
    using System;
    using System.Linq;
    using uLink;
    using Steamworks;using Oxide.Core;
    using Oxide.Core.Libraries.Covalence;
    using Oxide.Game.Hurtworld;namespace Oxide.Plugins
    {
        [Info("Spawn", "Phate", "1.0.0")]
        class Spawn : HurtworldPlugin
        {        [ChatCommand("items")]
            void ItemsCommand(PlayerIdentity identity, NetworkMessageInfo info, string command, string[] args)
            {            var identityMap = GameManager.Instance.GetIdentityMap();
                var targetMap = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Key);
                var myPairs = ItemList.Where(pair => pair.Value.GetNameKey().StartsWith("Roach"));
                string Items = "";
                foreach (var Item in myPairs)
                {
                    Items += "" + Item.Value.GetNameKey() + " ";
                }
                ChatManager.Instance?.AppendChatboxServerSingle("Item Name: " + Items, info.sender);        }    }
    }
    
     
  10. Wulf

    Wulf Community Admin

    If you're trying to get the entity for the player using the command, you'd just need to use the last example I gave.
    Code:
    // Reference: UnityEngine.UIusing System.Linq;namespace Oxide.Plugins
    {
        [Info("Spawn", "Phate", "1.0.0")]    class Spawn : HurtworldPlugin
        {
            [ChatCommand("items")]
            void ItemsCommand(PlayerIdentity identity, uLink.NetworkMessageInfo info, string command, string[] args)
            {
                var entity = GameManager.GetPlayerEntity(info.sender);
                var items = GlobalItemManager.Instance.GetItems().Values.Where(i => i.GetNameKey().StartsWith("Roach")).ToList();
                hurt.SendChatMessage(info.sender, "Item Name: " + items);
            }
        }
    }