Hello, I'm trying to create a plugin, which will give a random item from a list. Can you help me please, I already wrote this:
sorry if I speak in the wrong section, and my english is bad enoughCode:void OnEntityDeath (BaseCombatEntity victim, HitInfo info) { if (victim == null) return; if (info? .Initiator == null) return; if (info.Initiator is Scientist) return; var player = info.Initiator.ToPlayer (); if (player == null) return; { if (victim.name == "assets / prefabs / npc / murderer / murderer.prefab") {player.inventory.GiveItem (ItemManager.CreateByItemID (3655341, 100)); player.Command ("note.inv", 3655341, 100);player.inventory.GiveItem (ItemManager.CreateByItemID (-892070738, 100)); player.Command ("note.inv", -892070738, 100);player.inventory.GiveItem (ItemManager.CreateByItemID (-1059362949, 50)); player.Command ("note.inv", -1059362949, 50);player.inventory.GiveItem (ItemManager.CreateByItemID (889398893, 50)); player.Command ("note.inv", 889398893, 50);} } }
Spawning random item from list?
Discussion in 'Rust Discussion' started by Chbec, May 6, 2018.
-
And which help do u need exactly? All seems fine, I dont get it...
-
Among the item list, I would like only one to be given at a time and randomly.
-
-
How can I do that ? (I'm a beginner).
-
Also, for assigning u can use dictionary Dictionary(TKey, TValue) Class (System.Collections.Generic) or just assign items (itemid, count) as variables, if u not going to change them from config. -
I have not understood anything, how to put an item in the dictionary, I need an example to understand.
-
Code:System.Random random = new Random(); int itemChoose = random.Next(1,5); switch(itemChoose) { case 1: player.inventory.GiveItem (ItemManager.CreateByItemID (3655341, 100)); player.Command ("note.inv", 3655341, 100); break; case 2: player.inventory.GiveItem (ItemManager.CreateByItemID (-892070738, 100)); player.Command ("note.inv", -892070738, 100); break; case 3: player.inventory.GiveItem (ItemManager.CreateByItemID (-1059362949, 50)); player.Command ("note.inv", -1059362949, 50); break; case 4: player.inventory.GiveItem (ItemManager.CreateByItemID (889398893, 50)); player.Command ("note.inv", 889398893, 50); break;
-
Thanks for your help, i will try it
It Works ! thanksLast edited by a moderator: May 8, 2018