ILR Script Customization

I have a custom ILR script currently in place but I would like to expand the functionality to include all levels for the local Int check at the bottom of the script. So if I place the int “LEVEL_ONE” on an item with a value of 1 the item is flagged as being level 1 required regardless of value of the item.


 int GetRequiredLevel(object oItem);
 int StartingConditional(){return 0;}
// Define the ForceDrop function
void SHA_ActionForceUnequipItem(object oItem)
{
    FloatingTextStringOnCreature("You are too inexperienced to use " + GetName(oItem), OBJECT_SELF, FALSE);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectCutsceneImmobilize(), OBJECT_SELF, 0.1);
    ClearAllActions(TRUE);
    ActionUnequipItem(oItem);
    ActionDoCommand(SetCommandable(TRUE));
    SetCommandable(FALSE);
}

void CheckAndUnequip(object oItem, object oPlayer)
{
   int iLevPC = GetHitDice(oPlayer);
   int iLevItem = GetRequiredLevel(oItem);
   if (GetIsPC(oPlayer) && !GetIsDM(oPlayer) && GetIsObjectValid(oItem))
   {
      int iType = GetBaseItemType(oItem);
      if(iType == BASE_ITEM_CREATUREITEM)
      {
           return;
      }
      else if (iLevPC < iLevItem)
      {
         FloatingTextStringOnCreature("You are too inexperienced to use " + GetName(oItem), OBJECT_SELF, FALSE);
         DelayCommand(0.1, AssignCommand(oPlayer, ActionUnequipItem(oItem)));
      }
   }

}
void CheckItemLevelRestriction(object oPlayer)
{
   object oItem = GetItemInSlot(INVENTORY_SLOT_ARMS, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_ARROWS, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_BELT, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_BOLTS, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_BOOTS, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_BULLETS, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_CLOAK, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_HEAD, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_LEFTRING, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_NECK, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
   oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oPlayer);
   CheckAndUnequip(oItem, oPlayer);
}



int GetRequiredLevel(object oItem)
{
    // Initial flag
    int bIdent = GetIdentified(oItem);
    int bPlot =  GetPlotFlag(oItem);

    // If not already, set to identfied
    if (!bIdent) SetIdentified(oItem, TRUE);
    if (bPlot)   SetPlotFlag(oItem, FALSE);
    // Get the GP value
    int nGP = GetGoldPieceValue(oItem);
    string oName = GetStringLowerCase(GetName(oItem));
    // Re-set the identification and plot flag to its original
    SetIdentified(oItem, bIdent);
    SetPlotFlag(oItem, bPlot);
    int ReqLevel = 1;

    if(nGP<=400)    ReqLevel = 1;
    else if(nGP>400 && nGP<=800) ReqLevel = 2;
    else if(nGP>800 && nGP<=1200)  ReqLevel = 3;
    else if(nGP>1200 && nGP<=2000)  ReqLevel = 4;
    else if(nGP>2000 && nGP<=3500)  ReqLevel = 5;
    else if(nGP>3500 && nGP<=6500)    ReqLevel = 6;
    else if(nGP>6500 && nGP<=8500)   ReqLevel = 7;
    else if(nGP>8500 && nGP<=10000)   ReqLevel = 8;
    else if(nGP>10000 && nGP<=11000)   ReqLevel = 9;
    else if(nGP>11000 && nGP<=13000)    ReqLevel = 10;
    else if(nGP>13000 && nGP<=15000)   ReqLevel = 11;
    else if(nGP>15000 && nGP<=17000)   ReqLevel = 11;
    else if(nGP>17000 && nGP<=19500)   ReqLevel = 12;
    else if(nGP>19500 && nGP<=20000)   ReqLevel = 12;
    else if(nGP>20000 && nGP<=25000)   ReqLevel = 12;
    else if(nGP>25000 && nGP<=30000)   ReqLevel = 12;
    else if(nGP>30000 && nGP<=35000)   ReqLevel = 13;
    else if(nGP>35000 && nGP<=40000)   ReqLevel = 13;
    else if(nGP>40000 && nGP<=50000)   ReqLevel = 14;
    else if(nGP>50000 && nGP<=60000)    ReqLevel = 14;
    else if(nGP>60000 && nGP<=65000)    ReqLevel = 15;
    else if(nGP>65000 && nGP<=75000)    ReqLevel = 15;
    else if(nGP>75000 && nGP<=80000)    ReqLevel = 15;
    else if(nGP>80000 && nGP<=90000)    ReqLevel = 16;
    else if(nGP>90000 && nGP<=100000)    ReqLevel = 16;
    else if(nGP>100000 && nGP<=110000)    ReqLevel = 16;
    else if(nGP>110000 && nGP<=130000)    ReqLevel = 16;
    else if(nGP>130000 && nGP<=150000)    ReqLevel = 16;
    else if(nGP>150000 && nGP<=200000)    ReqLevel = 17;
    else if(nGP>200000 && nGP<=250000)    ReqLevel = 18;
    else if(nGP>250000 && nGP<=300000)    ReqLevel = 18;
    else if(nGP>300000 && nGP<=350000)    ReqLevel = 19;
    else if(nGP>350000 && nGP<=400000)    ReqLevel = 20;
    else if(nGP>400000 && nGP<=500000)    ReqLevel = 21;
    else if(nGP>500000 && nGP<=600000)    ReqLevel = 22;
    else if(nGP>600000 && nGP<=700000)    ReqLevel = 22;
    else if(nGP>700000 && nGP<=750000)    ReqLevel = 23;
    else if(nGP>750000 && nGP<=800000)    ReqLevel = 23;
    else if(nGP>800000 && nGP<=900000)    ReqLevel = 24;
    else if(nGP>900000 && nGP<=1000000)    ReqLevel = 25;
    else if(nGP>1000000 && nGP<=1100000)    ReqLevel = 25;
    else if(nGP>1100000 && nGP<=1200000)    ReqLevel = 26;
    else if(nGP>1200000 && nGP<=1300000)    ReqLevel = 27;
    else if(nGP>1300000 && nGP<=1400000)    ReqLevel = 29;
    else if(nGP>1400000 && nGP<=1500000)    ReqLevel = 30;
    else if(nGP>1500000 && nGP<=1600000)    ReqLevel = 30;
    else if(nGP>1600000 && nGP<=1700000)    ReqLevel = 31;
    else if(nGP>1700000 && nGP<=1800000)    ReqLevel = 32;
    else if(nGP>1800000 && nGP<=1900000)    ReqLevel = 32;
    else if(nGP>1900000 && nGP<=2000000)    ReqLevel = 33;
    else if(nGP>2000000 && nGP<=2100000)    ReqLevel = 33;
    else if(nGP>2100000 && nGP<=2200000)    ReqLevel = 34;
    else if(nGP>2200000 && nGP<=2300000)    ReqLevel = 34;
    else if(nGP>2300000 && nGP<=2400000)    ReqLevel = 35;
    else if(nGP>2400000 && nGP<=2600000)    ReqLevel = 35;
    else if(nGP>2600000 && nGP<=2800000)    ReqLevel = 36;
    else if(nGP>2800000 && nGP<=3000000)    ReqLevel = 36;
    else if(nGP>3000000 && nGP<=3200000)    ReqLevel = 37;
    else if(nGP>3200000 && nGP<=3400000)    ReqLevel = 37;
    else if(nGP>3400000 && nGP<=3600000)    ReqLevel = 38;
    else if(nGP>3600000 && nGP<=4200000)    ReqLevel = 38;
    else if(nGP>4200000 && nGP<=4300000)    ReqLevel = 39;
    else if(nGP>4300000 && nGP<=4500000)    ReqLevel = 39;
    else if(nGP > 4500000) ReqLevel = 40;

//    if(FindSubString(oName, "epic ") >= 0)
if (GetLocalInt(oItem, "LEVEL_THIRTYSIX")== 1)
{
if(ReqLevel < 36)
{
ReqLevel = 36;
}
}
return ReqLevel;
}

You could add a check for the integer into GetRequiredLevel, at the same point where the check for local integer LEVEL_THIRTYSIX is.

if (GetLocalInt(oItem, "LEVEL_ONE"))
    ReqLevel = 1;
else if (GetLocalInt(oItem, "LEVEL_THIRTYSIX"))
    {
    if (ReqLevel < 36)
        ReqLevel = 36;
    }

For better readability, you can place code into [code] insert text here [/code] tags.

Or use these: ```, they work too.

Thanks for the reply. I will try that. As for the [code] it didn’t seem to work for me. Maybe edit doesn’t work?

Tried that change and get “taip_r_header.nss(67): ERROR: NOT ALL CONTROL PATHS RETURN A VALUE”

Line 67 is: int GetRequiredLevel(object oItem)

That is super odd. :thinking: Wonder why the formatting’s not working. It should be doing this:

int GetRequiredLevel(object oItem)
{
    // Initial flag
    int bIdent = GetIdentified(oItem);
    int bPlot = GetPlotFlag(oItem);

    // If not already, set to identfied
    if (!bIdent)
        SetIdentified(oItem, TRUE);
    if (bPlot)
        SetPlotFlag(oItem, FALSE);

    // Get the GP value
    int nGP = GetGoldPieceValue(oItem);
    string oName = GetStringLowerCase(GetName(oItem));

    // Re-set the identification and plot flag to its original
    SetIdentified(oItem, bIdent);
    SetPlotFlag(oItem, bPlot);
    int ReqLevel = 1;

    if(nGP<=400)                            ReqLevel = 1;
    else if(nGP>400     && nGP<=800)        ReqLevel = 2;
    else if(nGP>800     && nGP<=1200)       ReqLevel = 3;
    else if(nGP>1200    && nGP<=2000)       ReqLevel = 4;
    else if(nGP>2000    && nGP<=3500)       ReqLevel = 5;
    else if(nGP>3500    && nGP<=6500)       ReqLevel = 6;
    else if(nGP>6500    && nGP<=8500)       ReqLevel = 7;
    else if(nGP>8500    && nGP<=10000)      ReqLevel = 8;
    else if(nGP>10000   && nGP<=11000)      ReqLevel = 9;
    else if(nGP>11000   && nGP<=13000)      ReqLevel = 10;
    else if(nGP>13000   && nGP<=15000)      ReqLevel = 11;
    else if(nGP>15000   && nGP<=17000)      ReqLevel = 11;
    else if(nGP>17000   && nGP<=19500)      ReqLevel = 12;
    else if(nGP>19500   && nGP<=20000)      ReqLevel = 12;
    else if(nGP>20000   && nGP<=25000)      ReqLevel = 12;
    else if(nGP>25000   && nGP<=30000)      ReqLevel = 12;
    else if(nGP>30000   && nGP<=35000)      ReqLevel = 13;
    else if(nGP>35000   && nGP<=40000)      ReqLevel = 13;
    else if(nGP>40000   && nGP<=50000)      ReqLevel = 14;
    else if(nGP>50000   && nGP<=60000)      ReqLevel = 14;
    else if(nGP>60000   && nGP<=65000)      ReqLevel = 15;
    else if(nGP>65000   && nGP<=75000)      ReqLevel = 15;
    else if(nGP>75000   && nGP<=80000)      ReqLevel = 15;
    else if(nGP>80000   && nGP<=90000)      ReqLevel = 16;
    else if(nGP>90000   && nGP<=100000)     ReqLevel = 16;
    else if(nGP>100000  && nGP<=110000)     ReqLevel = 16;
    else if(nGP>110000  && nGP<=130000)     ReqLevel = 16;
    else if(nGP>130000  && nGP<=150000)     ReqLevel = 16;
    else if(nGP>150000  && nGP<=200000)     ReqLevel = 17;
    else if(nGP>200000  && nGP<=250000)     ReqLevel = 18;
    else if(nGP>250000  && nGP<=300000)     ReqLevel = 18;
    else if(nGP>300000  && nGP<=350000)     ReqLevel = 19;
    else if(nGP>350000  && nGP<=400000)     ReqLevel = 20;
    else if(nGP>400000  && nGP<=500000)     ReqLevel = 21;
    else if(nGP>500000  && nGP<=600000)     ReqLevel = 22;
    else if(nGP>600000  && nGP<=700000)     ReqLevel = 22;
    else if(nGP>700000  && nGP<=750000)     ReqLevel = 23;
    else if(nGP>750000  && nGP<=800000)     ReqLevel = 23;
    else if(nGP>800000  && nGP<=900000)     ReqLevel = 24;
    else if(nGP>900000  && nGP<=1000000)    ReqLevel = 25;
    else if(nGP>1000000 && nGP<=1100000)    ReqLevel = 25;
    else if(nGP>1100000 && nGP<=1200000)    ReqLevel = 26;
    else if(nGP>1200000 && nGP<=1300000)    ReqLevel = 27;
    else if(nGP>1300000 && nGP<=1400000)    ReqLevel = 29;
    else if(nGP>1400000 && nGP<=1500000)    ReqLevel = 30;
    else if(nGP>1500000 && nGP<=1600000)    ReqLevel = 30;
    else if(nGP>1600000 && nGP<=1700000)    ReqLevel = 31;
    else if(nGP>1700000 && nGP<=1800000)    ReqLevel = 32;
    else if(nGP>1800000 && nGP<=1900000)    ReqLevel = 32;
    else if(nGP>1900000 && nGP<=2000000)    ReqLevel = 33;
    else if(nGP>2000000 && nGP<=2100000)    ReqLevel = 33;
    else if(nGP>2100000 && nGP<=2200000)    ReqLevel = 34;
    else if(nGP>2200000 && nGP<=2300000)    ReqLevel = 34;
    else if(nGP>2300000 && nGP<=2400000)    ReqLevel = 35;
    else if(nGP>2400000 && nGP<=2600000)    ReqLevel = 35;
    else if(nGP>2600000 && nGP<=2800000)    ReqLevel = 36;
    else if(nGP>2800000 && nGP<=3000000)    ReqLevel = 36;
    else if(nGP>3000000 && nGP<=3200000)    ReqLevel = 37;
    else if(nGP>3200000 && nGP<=3400000)    ReqLevel = 37;
    else if(nGP>3400000 && nGP<=3600000)    ReqLevel = 38;
    else if(nGP>3600000 && nGP<=4200000)    ReqLevel = 38;
    else if(nGP>4200000 && nGP<=4300000)    ReqLevel = 39;
    else if(nGP>4300000 && nGP<=4500000)    ReqLevel = 39;
    else if(nGP>4500000)                    ReqLevel = 40;

    if (GetLocalInt(oItem, "LEVEL_ONE"))
        ReqLevel = 1;
    else if (GetLocalInt(oItem, "LEVEL_THIRTYSIX"))
        {
        if (ReqLevel < 36)
            ReqLevel = 36;
        }

    return ReqLevel;
}

^- Inserted the check in the right spot, should (hopefully) work. Fingers crossed.

The “Not all control paths return a value” thing happens because an int function needs to be able to return an integer when it’s run its course - like designing a lego block that automatically determines the colour of the piece, but still needs to keep the overall shape of the piece so it’ll fit where it’s supposed to go.

In this one, the value of the integer ReqLevel gets changed according to various conditions, but whatever ReqLevel ends up being always gets returned at the very end, which is currently the only “exit”. Depending on where you inserted the code, there might have been a new potential “end point” where no int value was being returned.

Awesome! Ok that compiled. Now I would like an int for each level from 1-40 so I can assign any level to any item. Also when reporting the item level with the associated item level checker it returns the level 7 times and does not report the item flagged as level 1?

What does the code for the item level checker look like?

I think you can save yourself the hassle of using lots and lots of differently-named integers, and just use the same one, set to different values. As in, if local integer LEVEL_REQ is not zero, use that value instead of the GP-determined one.

int nReqFixed = GetLocalInt(oItem, "LEVEL_REQ");
// If the value of local integer LEVEL_REQ on the item is not zero, the level req is that value.
if (nReqFixed)
    nReqLevel = nReqFixed;

Or, if you want to cap the item requirement:

int nReqCap = GetLocalInt(oItem, "LEVEL_REQ_CAP");
// If there is a level requirement cap, and the determined req level is greater than the cap, the req level is the cap.
if (nReqCap &&
    nReqLevel > nReqCap)
    nReqLevel = nReqCap;
1 Like

Item level checker is nothing fancy, unique power item.


//:://////////////////////////////////////////////
/*
    Put into: OnItemActivate Event

*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-16
//:://////////////////////////////////////////////
#include "taip_r_header"
#include "x2_inc_switches"
void main()
{
     object oItem = GetItemActivated();

     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss
     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }

     }


      if (oItem == GetObjectByTag("stoneofappraisal"))
      {
           SendMessageToPC(GetItemActivator(),GetTag(oItem) + " requires level: " + IntToString(GetRequiredLevel(GetItemActivatedTarget())));
       }

}

hmm! And it’s sending the message seven times, and not recognizing the alterations?

First suspect for the latter: Try compiling all your scripts. Top row - Build -> Build Module. Tick everything except for Compile -> Scripts inactive, then hit the Build button.

When you make alterations to a library, you need to compile all scripts that make use of the library again. That might be it, for the changes we’ve made not having an effect.

That seems to have done it. ill test more tomorrow and let you know. thanks for all the help!!!

1 Like

Custom content advice, instead of “LEVEL_REQ” use “CILR”.

This variable name is used by at minimum one major custom ILR system on vault and is also used by nwncx_patch/nwnx_patch plugin (which makes the item unusable in engine so it will overwrite default vanilla IRL and you get the vanilla ILR “GUI”).

Thus if you use same variable name you will make your items compatible with these already existing systems. While this might not look like to you as anything you should bother, it might be useful to others working with your content…

1 Like

Thanks Shadooow, its great advice if I ever release the PW I host and work on or if I want to utilize other systems which can be and has been problematic in the past because of things like you stated.

TheBarbarian- The script works just fine in the original module I pulled it from. It still did the 7 times reporting in the “Test” module, not sure why and honestly not too worried about it as long as it works as needed in the original.

Much appreciated!!

1 Like