1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problems giving item per race

Discussion in 'Script Support' started by cmileto, Dec 13, 2013.

  1. cmileto
    Offline

    cmileto Member

    Joined:
    Nov 18, 2013
    Messages:
    177
    Likes Received:
    9
    Im trying to drop a letter and a weapon into this bag depending on what race the character is. This is in charactercreation.cs
    When i make a new toon they get the bag with only skillball, gold, and map... no weapon or letter. What am i doing wrong? Prob noob mistake.

    Code (C#):
    1. Bag bag = new Bag();
    2. bag.Hue = Utility.RandomList(102, 2432, 2450);
    3. bag.Name = string.Format("{0}'s sack", m.Name);
    4. PlaceItemIn(bag, 16, 51, new SkillBall(50));
    5. PlaceItemIn(bag, 28, 51, new Gold(1000));
    6. PlaceItemIn(bag, 40, 51, new TreasureMap(1, Map.Trammel));
    7. {
    8. if ((m.Race == Race.Elf) && (m.Race == Race.Gargoyle)) // is human
    9. {
    10. PlaceItemIn(bag, 52, 51, new Dagger());
    11. PlaceItemIn(bag, 64, 51, new LetterofApprenticeship());
    12. }
    13. if ((m.Race == Race.Elf) && (m.Race == Race.Human)) // is gargoyle
    14. {
    15. PlaceItemIn(bag, 64, 51, new GargishDagger());
    16. PlaceItemIn(bag, 64, 51, new LetterofGargoyleApprenticeship());
    17. }
    18. if ((m.Race == Race.Gargoyle) && (m.Race == Race.Human)) // is elf
    19. {
    20. PlaceItemIn(bag, 64, 51, new Bow());
    21. PlaceItemIn(bag, 64, 51, new LetterofApprenticeship());
    22. }
    23. }
    24. PackItem(bag);
     
  2. Ravenwolfe
    Offline

    Moderator ServUO Developer

    Joined:
    Sep 7, 2013
    Messages:
    1,155
    Likes Received:
    125
    You are using a conditional AND (&&), meaning that both things must be met. You didn't use a NOT operation (!), so there is no possible way that your IF statement can be true.

    I think you meant to do this:
    Code (C#):
    1. if ((m.Race != Race.Elf) && (m.Race != Race.Gargoyle)) // is human
    2. {
    3. PlaceItemIn(bag, 52, 51, new Dagger());
    4. PlaceItemIn(bag, 64, 51, new LetterofApprenticeship());
    5. }
    However, even that is an odd way to do it. You should probably do this:

    Code (C#):
    1. If (m.Race == Race.Human) // is Human
    2. {
    3. Place....
    4. }
    5.  
    6. if (m.Race == Race.Gargoyle) // is Gargoyle
    7. {
    8. Place...
    9. }
     
    • Like Like x 1
  3. cmileto
    Offline

    cmileto Member

    Joined:
    Nov 18, 2013
    Messages:
    177
    Likes Received:
    9
    I had tried
    If (Race == Race.Human) before and it didnt work.
    No idea why I didnt try m.Race
    or maybe it was m.Race==Human i tried, either way it didnt work and yours does.
    ty!
     
    #3 cmileto, Dec 13, 2013
    Last edited: Dec 13, 2013
  4. Ravenwolfe
    Offline

    Moderator ServUO Developer

    Joined:
    Sep 7, 2013
    Messages:
    1,155
    Likes Received:
    125
    Race == Race.Human would not work, because it would be assuming you mean (this.Race == Race.Human)

    m.Race == Human would not work, because it would be assuming you mean (m.Race == this.Human)

    Unless you are referring to the direct class you are in, you must declare the object. In this case the object you are checking is the Mobile, known as "m".

    Thus m.Race is like saying "the Race of the Mobile". Just like you created a new object here:

    Code (C#):
    1. Bag bag = new Bag();
    You then did something to that object and had to declare it:

    Code (C#):
    1. bag.Hue = Utility.RandomList(102, 2432, 2450);
    Which is saying the new object "bag" should have a Hue of: and then pick a random from the list.

    If you don't declare the object, it assumes you mean "this" which always refers to the class itself.
     
  5. cmileto
    Offline

    cmileto Member

    Joined:
    Nov 18, 2013
    Messages:
    177
    Likes Received:
    9
    Oh cool, I learned something! thx man
     
  6. Ravenwolfe
    Offline

    Moderator ServUO Developer

    Joined:
    Sep 7, 2013
    Messages:
    1,155
    Likes Received:
    125
    No problem, that's why we are all here!
     
Similar Threads: Problems giving
Forum Title Date
Bug Reports Problems with Trophy Dec 4, 2017
Script Support Mount problems Nov 10, 2017
Script Support Two problems Nov 5, 2017
3rd Party Support UOFiddler problems Nov 5, 2017
Script Support Problems with Add-ons Jul 31, 2017
General Discussion CentrED+ problems Jul 26, 2017
Script Support CentrEd+ Problems with installation Jul 6, 2017