Author Topic: IF range checks being ignored?  (Read 505 times)

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
IF range checks being ignored?
« on: December 01, 2014, 09:19:55 am »


               

In my onspawn default9 I have a section that grabs the spawnee's level and gear in each slot, and depending on their level, applies magic effects to their items if the items are valid.


 


The functions for choosing which effects get added are essentially just case switches, nothing fancy. The functions work properly, but for some reason my ranges are getting completely ignored, and the item is getting put through all of the scripts.


 


Here's an example of what it does for weapons


 


http://justpaste.it/i8dx


 


I've tried else if variants of the above and the result is the same.


 


So for instance, if the spawnee is level 22, his items will run through RandomMagicLow, RandomMagic, and then RandomMagic2, so what comes out the other end is usually screwed up.


 


I know that its being run through all three because sometimes I see the stats unique to RandomMagic2, but other times I'll see stats unique to RandomMagic or RandomMagicLow on lvl 22+ monsters.


 


Are my if check simply too absurd or something? I can't wrap my head around this, as I've used ranges similar to this in other places with no adverse effects.



               
               

               
            

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
IF range checks being ignored?
« Reply #1 on: December 01, 2014, 08:28:42 pm »


               

Well, I gave my IF ranges a lower range to check for and it seems to be working properly so far, but I'm still very very perplexed....


 


For example, I want it to change the description of an item to let the player know what 'Tier' the item is in. This works perfectly fine for all of the gear EXCEPT helmets, armor, and weapons, even though they use the EXACT SAME function.


 


If I put a trigger on the ground to change the description of these, it works fine. In the default9, it doesn't work at all. I can change the name of the helmet / armor/ weapon or do anything else to it, but the description won't work......


 


Here's what it looks like for the clothing section of the script



    object oSpawn = OBJECT_SELF;
    int iSpawnLevel = GetHitDice(oSpawn);
    object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oSpawn);
    object oOffhander = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oSpawn);
    object oChest = GetItemInSlot(INVENTORY_SLOT_CHEST, oSpawn);
    object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oSpawn);
    object oBelt = GetItemInSlot(INVENTORY_SLOT_BELT, oSpawn);
    object oBoots = GetItemInSlot(INVENTORY_SLOT_BOOTS, oSpawn);
    object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oSpawn);
    object oGauntlet = GetItemInSlot(INVENTORY_SLOT_ARMS, oSpawn);
    string sDesc;


    // Chest
    if(iSpawnLevel >= 1 && iSpawnLevel <= 20){
        RandomMagicArmor(oChest);
        sDesc = GetDescription(oChest);
        SetDescription(oChest, sDesc+"\n"+"Tier 1");
        }
    if(iSpawnLevel >= 21 && iSpawnLevel <= 30){
        RandomMagicArmor2(oChest);
        sDesc = GetDescription(oChest);
        SetDescription(oChest, sDesc+"\n"+"Tier 2");
        }

    // Helmet
    if(iSpawnLevel >= 1 && iSpawnLevel <= 20){
        RandomMagicArmor(oHelm);
        sDesc = GetDescription(oHelm);
        SetDescription(oHelm, "TEST");
        }
    if(iSpawnLevel >= 21 && iSpawnLevel <= 30){
        RandomMagicArmor2(oHelm);
        sDesc = GetDescription(oHelm);
        SetDescription(oHelm, "TEST");
        }

    // Belt
    if(iSpawnLevel >= 1 && iSpawnLevel <= 20 && GetIsObjectValid(oBelt) == TRUE){
        RandomMagicArmor(oBelt);
        sDesc = GetDescription(oBelt);
        SetDescription(oBelt, sDesc+"\n"+"Tier 1");
        }
    if(iSpawnLevel >= 21 && iSpawnLevel <= 30 && GetIsObjectValid(oBelt) == TRUE){
        RandomMagicArmor2(oBelt);
        sDesc = GetDescription(oBelt);
        SetDescription(oBelt, sDesc+"\n"+"Tier 2");
        }

    // Boots
    if(iSpawnLevel >= 1 && iSpawnLevel <= 20 && GetIsObjectValid(oBoots) == TRUE){
        RandomMagicArmor(oBoots);
        sDesc = GetDescription(oBoots);
        SetDescription(oBoots, sDesc+"\n"+"Tier 1");
        }
    if(iSpawnLevel >= 21 && iSpawnLevel <= 30 && GetIsObjectValid(oBoots) == TRUE){
        RandomMagicArmor2(oBoots);
        sDesc = GetDescription(oBoots);
        SetDescription(oBoots, sDesc+"\n"+"Tier 2");
        }

    // Cloak
    if(iSpawnLevel >= 1 && iSpawnLevel <= 20 && GetIsObjectValid(oCloak) == TRUE){
        RandomMagicArmor(oCloak);
        sDesc = GetDescription(oCloak);
        SetDescription(oCloak, sDesc+"\n"+"Tier 1");
        }
    if(iSpawnLevel >= 21 && iSpawnLevel <= 30 && GetIsObjectValid(oCloak) == TRUE){
        RandomMagicArmor2(oCloak);
        sDesc = GetDescription(oCloak);
        SetDescription(oCloak, sDesc+"\n"+"Tier 2");
        }

    // Gauntlet
    if(iSpawnLevel >= 1 && iSpawnLevel <= 20 && GetIsObjectValid(oGauntlet) == TRUE){
        RandomGauntMagic(oGauntlet);
        sDesc = GetDescription(oGauntlet);
        SetDescription(oGauntlet, sDesc+"\n"+"Tier 1");
        }
    if(iSpawnLevel >= 21 && iSpawnLevel <= 30 && GetIsObjectValid(oGauntlet) == TRUE){
        RandomGauntMagic2(oGauntlet);
        sDesc = GetDescription(oGauntlet);
        SetDescription(oGauntlet, sDesc+"\n"+"Tier 2");
        }

The RandomMagicArmor works fine for the helmet and armor, but the description just gets completely ignored....



               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
IF range checks being ignored?
« Reply #2 on: December 01, 2014, 11:34:21 pm »


               

Hmm. To be honest, your code in the JustPasteIt link worked for me, or it seemed to. I swapped oWeapon out for oChest and plopped it into the OnSpawn event for a 22 HD elemental and gave him a tunic in the chest slot. My RandomMagic* functions were just PrintString statements, but only the correct one (RandomMagic2) fired when the elemental spawned.


 


One suggestion might be to structure the code so that else statements help filter out the chance of more than one possibility occurring. For example,



    // Weapon Enchants
    if (GetIsObjectValid(oWeapon))
        {
        if ( GetMeleeWeapon(oWeapon) )  // melee
            {
            if ( iSpawnLevel >= 1 && iSpawnLevel <= 9 )
                RandomMagicLow(oWeapon);
            else if ( iSpawnLevel >= 10 && iSpawnLevel <= 20 )
                RandomMagic(oWeapon);
            else if ( iSpawnLevel >= 21 && iSpawnLevel <= 30 )
                RandomMagic2(oWeapon);
            else // iSpawnLevel >= 31
                RandomMagic3(oWeapon);
            }
        else if ( GetWeaponRanged(oWeapon) )  // ranged
            {
            if ( iSpawnLevel >= 1 && iSpawnLevel <= 9 )
                RandomMagicLow(oWeapon);
            else if ( iSpawnLevel >= 10 && iSpawnLevel <= 20 )
                RandomMagic(oWeapon);
            else if ( iSpawnLevel >= 21 && iSpawnLevel <= 30 )
                RandomMagic2(oWeapon);
            else // iSpawnLevel >= 31
                RandomMagic3(oWeapon);
            }
        else if ( GetWeaponBlahBlah(oWeapon) )  // etc.
            {
            if ( iSpawnLevel >= 1 && iSpawnLevel <= 9 )
                RandomMagicLow(oWeapon);
            else if ( iSpawnLevel >= 10 && iSpawnLevel <= 20 )
                RandomMagic(oWeapon);
            else if ( iSpawnLevel >= 21 && iSpawnLevel <= 30 )
                RandomMagic2(oWeapon);
            else // iSpawnLevel >= 31
                RandomMagic3(oWeapon);
            }
        }

I also made use of GetMeleeWeapon() in the conditionals. I would suggest something similar, even if you make a different function, instead of having quite so many individual calls to GetBaseItemType() and long conditional blocks to check for possible errors.


               
               

               
            

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
IF range checks being ignored?
« Reply #3 on: December 01, 2014, 11:47:54 pm »


               

Thank you for taking the time to try it out. The pasteit code does work, it just seems to have odd outcomes if no lower level range is declared for some reason.


 


Using GetMelee will help clean some of that up, thank you for that suggestion. Now I just have to figure out why this description change is being ignore but the rest of the function running xD



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
IF range checks being ignored?
« Reply #4 on: December 02, 2014, 09:07:57 am »


               It's hard to comment without seeing the RandomMagicX functions.