Author Topic: Get item level: The short formula  (Read 348 times)

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Get item level: The short formula
« on: October 22, 2011, 01:26:38 pm »


               Hi,

I remember to have seen a quick formula for retrieving the level of an item, instead of the long 'if' or switch checking all levels. However, IIRC it was on the old forums(I think it was posted by Axe), so I should have made a note of it...

Does anyone know the formula?

Thank you!

Kato
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get item level: The short formula
« Reply #1 on: October 22, 2011, 04:14:32 pm »


               Item level??

Are you asking for a Item Level Restriction fromula?

If you are, after looking at the progression, I do not know if there is a simple one.
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Get item level: The short formula
« Reply #2 on: October 22, 2011, 04:26:28 pm »


               Yes, I meant ILR, sorry. The formula I have seen needed the item gold value as a parameter and returned the item level after checking in the 2DA. 
               
               

               


                     Modifié par Kato_Yang, 22 octobre 2011 - 03:29 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Get item level: The short formula
« Reply #3 on: October 22, 2011, 06:08:28 pm »


               Taken from an ooooold post of mine:


if (iGPValue > 4000000) iItemLevel = 40; else if (iGPValue > 3800000) iItemLevel = 39; else if (iGPValue > 3600000) iItemLevel = 38; else if (iGPValue > 3400000) iItemLevel = 37; else if (iGPValue > 3200000) iItemLevel = 36; else if (iGPValue > 3000000) iItemLevel = 35; else if (iGPValue > 2800000) iItemLevel = 34; else if (iGPValue > 2600000) iItemLevel = 33; else if (iGPValue > 2400000) iItemLevel = 32; else if (iGPValue > 2200000) iItemLevel = 31; else if (iGPValue > 2000000) iItemLevel = 30; else if (iGPValue > 1800000) iItemLevel = 29; else if (iGPValue > 1600000) iItemLevel = 28; else if (iGPValue > 1400000) iItemLevel = 27; else if (iGPValue > 1200000) iItemLevel = 26; else if (iGPValue > 1000000) iItemLevel = 25; else if (iGPValue > 750000) iItemLevel = 24; else if (iGPValue > 500000) iItemLevel = 23; else if (iGPValue > 250000) iItemLevel = 22; else if (iGPValue > 130000) iItemLevel = 21; else if (iGPValue > 110000) iItemLevel = 20; else if (iGPValue > 90000) iItemLevel = 19; else if (iGPValue > 75000) iItemLevel = 18; else if (iGPValue > 65000) iItemLevel = 17; else if (iGPValue > 50000) iItemLevel = 16; else if (iGPValue > 40000) iItemLevel = 15; else if (iGPValue > 35000) iItemLevel = 14; else if (iGPValue > 30000) iItemLevel = 13; else if (iGPValue > 25000) iItemLevel = 12; else if (iGPValue > 19500) iItemLevel = 11; else if (iGPValue > 15000) iItemLevel = 10; else if (iGPValue > 12000) iItemLevel = 9; else if (iGPValue > 9000) iItemLevel = 8; else if (iGPValue > 6500) iItemLevel = 7; else if (iGPValue > 5000) iItemLevel = 6; else if (iGPValue > 3500) iItemLevel = 5; else if (iGPValue > 2500) iItemLevel = 4; else if (iGPValue > 1500) iItemLevel = 3; else if (iGPValue > 1000) iItemLevel = 2;

These days, it's probably smarter to loop checking the 2da (itemvalue.2da) - the caching is much improved, and it's good normalization to only store data in one place. That way, if you or someone else winds up modding the 2da, the function will still work.

Funky
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Get item level: The short formula
« Reply #4 on: October 22, 2011, 06:30:12 pm »


               Thanks Funky, I'll try to retrieve (or setup) the formula and I'll post it if I do. Otherwise, I'll use the one you posted.  '<img'>

Kato
               
               

               


                     Modifié par Kato_Yang, 22 octobre 2011 - 05:49 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Get item level: The short formula
« Reply #5 on: October 22, 2011, 09:27:41 pm »


               Eh...I'm not even sure that one uses bioware's values - my post took it from someplace I linked in it, which purported to use bioware values, but with the links no longer working, I have no way of checking, other than going to the 2da. And, if I'm going to do that...


int GetItemLevel(object oItem) {
    int i, nMax, nValue = GetGoldPieceValue(oItem);
    for (i = 0; i < 39; i++) {
        nMax = StringToInt(Get2DAString("ITEMVALUE", "MAXSINGLEITEMVALUE", i));
        if (nMax >= nValue)
            break;
    }
    return i + 1;
}

EDIT: Lest you be confused, the i is row value - 0 is level one. This function will never return a 40 - 39 is considered the highest in our setup - everything else is handled by variable. If you want it to go up to 40, just add an = in the for loop, like so:
for (i = 0; i <= 39; i++) {

That's the code I yanked from our !itemlevel SIMTools command.  I'm not totally sure about that, because we don't use it that often, as our ILR is mostly handled by variables, but it's likely to be correct. The only reason for my uncertainty is the existance of the TOTAL VALUEFILTER column in that 2da. If you're curious, here's our full !itemlevel code:


            if (sCText == "itemlevel") {
                DeleteLocalString(oCPC, "FKY_CHAT_LOCAL_CTEXT");
                oCTarget = GetLocalObject(oCPC, "FKY_CHAT_TARGET");

                if (!GetIsObjectValid(oCTarget)) {
                    FloatingTextStringOnCreature(COLOR_GOLD + REQUIRES_TARGET + COLOR_END, oCPC, FALSE);
                    SetLocalString(oCPC, "FKY_CHAT_COMMAND", OBJECT_TARGET + "!" + sCText);

                    if (!GetIsObjectValid(GetItemPossessedBy(oCPC, "fky_chat_target")))
                        CreateItemOnObject("fky_chat_target", oCPC);
                    return;
                } else
                    DeleteLocalObject(oCPC, "FKY_CHAT_TARGET");

                if (GetObjectType(oCTarget) != OBJECT_TYPE_ITEM) {
                    FloatingTextStringOnCreature(COLOR_RED + "You can only check requirements on items!" + COLOR_END, oCPC, FALSE);
                    return;
                }


                string sMessage = "Requirements for " + GetName(oCTarget) + ":\\n";

                int i, nMax, nValue = GetGoldPieceValue(oCTarget);
                int nLevel = GetLocalInt(oCTarget, "HCLevel");

                if (nLevel)
                    sMessage += COLOR_ORANGE + "    Requires level " + IntToString((nLevel > 46 ? 41 : nLevel - 6)) +
                        " for a hardcore character to use.\\n";

                nLevel = GetLocalInt(oCTarget, "ILR");
                if (nLevel <= 0) {
                    for (i = 0; i < 39; i++) {
                        nMax = StringToInt(Get2DAString("ITEMVALUE", "MAXSINGLEITEMVALUE", i));
                        if (nMax >= nValue)
                            break;
                    }

                    nLevel = i + 1;
                }
                sMessage += COLOR_LT_YELLOW + "    Requires level " + IntToString(nLevel) + " to use.\\n";

                if (GetBaseItemType(oCTarget) != BASE_ITEM_SCROLL && GetBaseItemType(oCTarget) != BASE_ITEM_SPELLSCROLL) {
                    nLevel = -1;
                    for (i = 0; i < 64; i++) {
                        nMax = StringToInt(Get2DAString("SKILLVSITEMCOST", "DeviceCostMax", i));
                        if (nMax >= nValue) {
                            nLevel = StringToInt(Get2DAString("SKILLVSITEMCOST", "SkillReq_class", i));
                            break;
                        }
                    }

                    if (nLevel > 0)
                        sMessage += COLOR_LT_YELLOW + "    Requires UMD " + IntToString(nLevel) + "/" +
                            IntToString(nLevel + 5) + "/" + IntToString(nLevel + 10) + " to use.\\n";
                    else
                        sMessage += COLOR_LT_YELLOW + "    Cannot be used with UMD.\\n";
                }

                SendSystemMessage(oCPC, sMessage);

            }


Funky
               
               

               


                     Modifié par FunkySwerve, 22 octobre 2011 - 08:38 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Get item level: The short formula
« Reply #6 on: October 22, 2011, 09:39:42 pm »


               Many thanks once more, Funky!