1. Hi im sure its a simple mistake but I need your help to solve this. Im simply getting a list of items then if each item is in the blueprints data list, there's 30% chances to be dropped as a blueprint. Else just drop the item.
    This codes works but I noticed that once it got the 30% chances, it just get all items that are in the bp data to drop as bp (when I just want that single item to have 30% chance). So it looks like that the 30% happens to get ALL items found in databp instead of just ONE item at a time.

    Idea (what I want):
    item 1: not in bpdata => drop normal
    item2: in bpdata => 30% chances => fail, drop normal item
    item3: in bpdata => 30% chances => success, drop as blueprint item
    item4: not in bpdata => drop normal
    item5: in bpdata => 30% chances => fail, drop normal item
    etc.

    This code (I need fix):
    item 1: not in bpdata => drop normal
    item2: in bpdata => 30% chances => success, drop as blueprint item
    item3: not in bpdata => drop normal
    item4: in bpdata => Forcing blueprint because was previously found success
    item5: in bpdata => Forcing blueprint because was previously found success
    etc.

    Code:
    var items = new List<Item>();
                                  ......skipping codes....
                                    if (items != null)
                                    {
                                        foreach (var item in items)
                                        {
                                            //Blueprints add
                                            if (storedDrops.Blueprints.Contains(item.info.shortname))
                                            {
                                            var itemid = item.info.itemid;
                                            var rand = new Random();
                                            var number = rand.Next(100);
                                            if (number <= 30) // 30 = 30% chance
                                                {
                                                Item itembp = ItemManager.CreateByName("blueprintbase", 1);
                                                itembp.blueprintTarget = itemid;
                                                itembp.MoveToContainer(corpse.containers[0]);
                                                }
                                                else
                                                    item.MoveToContainer(corpse.containers[0]);
                                            }
                                            else
                                                item.MoveToContainer(corpse.containers[0]);
                                        }
                                    }
     
  2. Code:
    foreach (var item in items)
    {
        Item blueprint;
        if (storedDrops.Blueprints.Contains(item.info.shortname) && (UnityEngine.Random.Range(0, 1) <= 0.3f))
        {
             // I didn't check, but I believe by default the amount is 1.
            blueprint = ItemManager.CreateByName("blueprintbase");
            blueprint.blueprintTarget = item.info.itemid;
            blueprint.MoveToContainer(corpse.containers[0]);
            continue;
        }    item.MoveToContainer(corpse.containers[0]);
    }
    I'd write it like this based off what you've given me. A better way to do this would be by populating the list initially with 30% blueprints, that way the cost of creating new items isn't incurred. Then you can just do something like below.
    Code:
    items.ForEach(x => x.MoveToContainer(corpse.containers[0]));
     
    Last edited by a moderator: Jun 20, 2018
  3. Hi thanks for your reply. I tried both
    Code:
    foreach (var item in items)
                                        {
                                            Item blueprint;
                                            if (storedDrops.Blueprints.Contains(item.info.shortname) && (UnityEngine.Random.Range(0, 1) <= 0.3f))
                                            {
                                                 // I didn't check, but I believe by default the amount is 1.
                                                blueprint = ItemManager.CreateByName("blueprintbase");
                                                blueprint.blueprintTarget = item.info.itemid;
                                                blueprint.MoveToContainer(corpse.containers[0]);
                                                continue;
                                            }                                        item.MoveToContainer(corpse.containers[0]);
                                        }
    Code:
    items.ForEach(x => {
                                        if (storedDrops.Blueprints.Contains(x.info.shortname) && (UnityEngine.Random.Range(0, 1) <= 0.3f))
                                        {
                                            var itemid = x.info.itemid;
                                            Item itembp = ItemManager.CreateByName("blueprintbase", 1);
                                            itembp.blueprintTarget = itemid;
                                            itembp.MoveToContainer(corpse.containers[0]);
                                        }
                                        else
                                            x.MoveToContainer(corpse.containers[0]);
                                        });
    They seem to do the same thing as the other example I tried. As soon as one is a blueprint (30% chance success), all other items that are found in the data are also converted into blueprint. While it should check the 30% chance on each item instead. I don't know if it should work like that or maybe there is a code somewhere else that prevents that. I'll check it
     
  4. OK that is very strange and I don't know why this minor change affect my solution.... As soon as I add a Puts(""); in each case to log and see what happens, the blueprint applies perfectly to each item (30% success or not). But when I don't add a Puts, it just overwrite all items found in data to a blueprint (global 30% chance instead of individual item chance).

    Code:
    Item itembp;
                                        int count = items.Count;
                                        var maxRetry = 20;
                                        for (int i = 0; i < count; ++i)
                                        {
                                            if (maxRetry == 0) break;
                                            if (items[i] == null)
                                            {
                                                --maxRetry;
                                                --i;
                                                continue;
                                            }
                                            if (storedDrops.Blueprints.Contains(items[i].info.shortname))
                                            {
                                                var itemid = items[i].info.itemid;
                                                var rand = new Random();
                                                var number = rand.Next(100);
                                                if (number <= 30) // 30 = 50% chance
                                                {
                                                    Puts("success");
                                                    itembp = ItemManager.CreateByName("blueprintbase", 1);
                                                    itembp.blueprintTarget = itemid;
                                                    itembp.MoveToContainer(corpse.containers[0]);
                                                }
                                                else
                                                {
                                                    Puts("not success");
                                                    items[i].MoveToContainer(corpse.containers[0]);
                                                }
                                            }
                                            else
                                            {
                                                Puts("not in bp data");
                                                items[i].MoveToContainer(corpse.containers[0]);
                                            }
                                        }
    This formula works... as soon as I take out the Puts, its just forgetting to work the way I want. WTF? Anybody knows? what is some strange thing

    EDIT: I just tried to keep only 1 Puts (no need to keep the 3 ones), it still works. So when there's atleast one Puts, it works, if I take all away, it just screw things up

    Is there something I can do to replace the Puts without spamming my console? to have the same "benefic" effect that makes my plugin work the way I want? this is just too crazy for me to understand why this still affects my script logics.
     
    Last edited by a moderator: Jun 21, 2018
  5. If you post the full code I can help you.
     
  6. Solved... maybe someone can explain why this matters?

    BUGGED code:
    Code:
    var rand = new Random();
    var number = rand.Next(100);
    if (number <= 30) // 30 = 30% chance
    {
        Puts("success");} // converts ALL items on success (BAD logic)
        itembp = ItemManager.CreateByName("blueprintbase", 1);
        itembp.blueprintTarget = itemid;
        itembp.MoveToContainer(corpse.containers[0]);
    }
    
    The fix is:
    Code:
    var number = random.Next(100);
    if (number <= 30) // 30 = 30% chance
    {
       Puts("success");}// converts THIS item only on success (THE logic)
       itembp = ItemManager.CreateByName("blueprintbase", 1);
       itembp.blueprintTarget = itemid;
       itembp.MoveToContainer(corpse.containers[0]);
    }
    
    making a new Random screws things up. I don't know why... so I figured out just calling the old "random" worked just fine.
     
    Last edited by a moderator: Jun 25, 2018
  7. What's that stray } doing after your Puts();?

    If the code compiles as shown above, I think the Puts(); is conditional and the rest will happen always.
     
  8. are you talking about the old posts or the post right before your? because the last post "Puts" is not necessary. It was fixed without it.
     
  9. Idk, maybe it's just a type error in the post but I spotted you have Puts("success");} and thought I'd point it out. :)
     
  10. hehe yeah well it was just to show this worked out. xD sry it got confusing with the problem I had with a Puts lol. that was random's fault