I am trying to find a item on the map based on his UID, I tried to use some tricks with GameEntity, but it failed. I just started with Oxide and I need a little of help as it is quite basic question.
Here is my code
So far so good, but later I can't find this wooden box with UID 22701Code:namespace Oxide.Plugins { [Info("EpicPlugin", "Unknown", 0.1)] [Description("Makes epic stuff happen")] class EpicPlugin : RustPlugin { // The rest of the code and magic void Init() { Puts("Hi hello!"); } void OnPlayerChat(ConsoleSystem.Arg arg) { Puts("ITS ME, SERVER!"); var player = BasePlayer.Find("Płomyk"); var item = ItemManager.CreateByItemID(-770311783); // a wooden box Puts(item.uid.ToString()); // 22701 player.GiveItem(item); } } }
I wish I could tell something more, but all my efforts were like blind bullets :s
Create item and find it later
Discussion in 'Rust Development' started by Płomyk, Feb 21, 2016.
-
What do you mean you can't find the box? You're creating the box and giving it to the player Piomyk - does this not work?
-
CreateItemByID(...)
GiveThisItemToPlayer()
<player puts it on the ground>
var item_on_the_ground = FindThisItemPlease(UID) // Can't achieve this
And if you want to ask why I want to assign it again - just in case of server restart or player logout, etc. -
Well if I remember correctly UIDs are unique per server session and so differ upon server restart.
Can you show the code where you're trying to find it again? You've only posted giving the box and displaying its UID. -
Ok I solved my problem, here is a little piece of code that can help somebody in future
Code:var items = WorldItem.Util.FindTargets("box", false); // *box* on the map for (int i = 0; i < items.Length; i++) { Puts("Item name: " + items[i].name); Puts("Item instance: " + items[i].gameObject.GetInstanceID()); Puts("Owner: " + items[i].OwnerID.ToString()); }
-
You could create the box like you did to start with and save the net.id to data, then you can find the box using it instead of looping through every 'box' on the server
-
Calytic Community Admin Community Mod
Code:StorageContainer box = (StorageContainer)BaseNetworkable.serverEntities.Find(net.ID); StorageContainer box1 = BaseNetworkable.serverEntities.Find(net.ID).GetComponent<StorageContainer>();
-
-
Calytic Community Admin Community Mod
Code:public static string GetEntityID(BaseEntity entity) { Vector3 position = entity.transform.position; return "x" + position.x + "y" + position.y + "z" + position.z; }
-
Please correct me if I am wrong -
Calytic Community Admin Community Mod
I wouldn't be surprised if they fixed this. Thanks for the info @k1lly0u