1. 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:
    Code:
    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);}
    }
    }
    sorry if I speak in the wrong section, and my english is bad enough
     
    Last edited by a moderator: May 6, 2018
  2. pdr

    pdr

    And which help do u need exactly? All seems fine, I dont get it...
     
  3. Among the item list, I would like only one to be given at a time and randomly.
     
  4. pdr

    pdr

    U can store these items as key:value and access them using Math.Random function csharp provides
     
  5. How can I do that ? (I'm a beginner).
     
  6. pdr

    pdr

  7. I have not understood anything, how to put an item in the dictionary, I need an example to understand.
     
  8. pdr

    pdr

    Im kinda far away from IDE or any pc, so ill just give u the simpliest example. Code formating is terrible, i wrote this on my smartphone.
    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;
    As i remember - u need to specify System.Random, because Unity has own Random class which cannot be used for generating pseudorandom numbers.
     
  9. Thanks for your help, i will try it ;)

    It Works ! thanks ;)
     
    Last edited by a moderator: May 8, 2018