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?
Solved Getting GameObject from player name?
Discussion in 'Hurtworld Development' started by sesmith2k, Dec 10, 2015.
-
Wulf Community Admin
Get all player identities (needed for the following snippets):
Code:var identityMap = GameManager.Instance.GetIdentityMap();
Code:var identity = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Value);
Code:var targetMap = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Key);
Code:var entity = GameManager.GetPlayerEntity(player);
-
Code:
var targetMap = identityMap.FirstOrDefault(x => string.Equals(x.Value.Name, "player name").Key);
How can I fix this? -
Wulf Community Admin
-
Hello,
using System.Linq is inside. Im using Visual Studio 2015 -
Wulf Community Admin
-
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 -
Wulf Community Admin
Please provide your full plugin, and I'll take a look.
-
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); } } }
-
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); } } }