Author Topic: Getting Base AC value  (Read 681 times)

Legacy_Vincent07

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Getting Base AC value
« on: December 21, 2013, 03:06:05 am »


               So, I've been trying to come up with a good method to get the Base AC value of an equipped piece of armor.  I found a bit of sample script, but can not use it in this instance, because our Cost Table values are all set to 0.

So what is another good way to do this? 
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Getting Base AC value
« Reply #1 on: December 21, 2013, 03:39:06 am »


               Edit: this doesn't actually work, evidently, was told it did.  Sorry.

Set it to unidentified, get its AC, set it back to identified.
               
               

               


                     Modifié par MagicalMaster, 21 décembre 2013 - 05:49 .
                     
                  


            

Legacy_Vincent07

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Getting Base AC value
« Reply #2 on: December 21, 2013, 04:51:28 am »


               Still including the item enhancement when using GetItemACValue()
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting Base AC value
« Reply #3 on: December 21, 2013, 05:22:07 am »


               I believe I posted this recently for Lazarus.  Here is a function for getting the base AC of armor.

int GetArmorBaseAC(object oArmor)
{
int nAppear = GetItemAppearance(oArmor, ITEM_APPR_TYPE_ARMOR_MODEL, ITEM_APPR_ARMOR_MODEL_TORSO);
return StringToInt(Get2DAString("des_crft_appear", "BaseAC", nAppear));
}
               
               

               


                     Modifié par WhiZard, 21 décembre 2013 - 05:24 .
                     
                  


            

Legacy_Vincent07

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Getting Base AC value
« Reply #4 on: December 21, 2013, 05:24:24 am »


               Really hoping to avoid 2da string lookups, as that is a lag spike every time the function is called.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting Base AC value
« Reply #5 on: December 21, 2013, 05:26:11 am »


               Well 2da is faster than doing an item property search and comparison.  Unless you are using many 2das at once, the 2da caching should not leave a lag spike
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Getting Base AC value
« Reply #6 on: December 21, 2013, 05:44:38 am »


               Edit: nevermind, tested it, would have sworn it worked before.
               
               

               


                     Modifié par MagicalMaster, 21 décembre 2013 - 05:49 .
                     
                  


            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Getting Base AC value
« Reply #7 on: December 21, 2013, 05:53:04 am »


               Ah-ha!  I was half right.  NWNLexicon had this code:



// Returns the base armor type as a number, of oItem
// -1 if invalid, or not armor, or just plain not found.
// 0 to 8 as the value of AC got from the armor - 0 for none, 8 for Full plate.
[url=http://www.nwnlexicon.com/index.php/int]int[/url] GetArmorType([url=http://www.nwnlexicon.com/index.php/object]object[/url] oItem)
{
    // Make sure the item is valid and is an armor.
    if (![url=http://www.nwnlexicon.com/index.php/GetIsObjectValid]GetIsObjectValid[/url](oItem))
        return -1;
    if ([url=http://www.nwnlexicon.com/index.php/GetBaseItemType]GetBaseItemType[/url](oItem) != BASE_ITEM_ARMOR)
        return -1;
 
    // Get the identified flag for safe keeping.
    [url=http://www.nwnlexicon.com/index.php/int]int[/url] bIdentified = [url=http://www.nwnlexicon.com/index.php/GetIdentified]GetIdentified[/url](oItem);
    [url=http://www.nwnlexicon.com/index.php/SetIdentified]SetIdentified[/url](oItem,FALSE);
 
    [url=http://www.nwnlexicon.com/index.php/int]int[/url] nType = -1;
    switch ([url=http://www.nwnlexicon.com/index.php/GetGoldPieceValue]GetGoldPieceValue[/url](oItem))
    {
        case    1: nType = 0; break; // None
        case    5: nType = 1; break; // Padded
        case   10: nType = 2; break; // Leather
        case   15: nType = 3; break; // Studded Leather / Hide
        case  100: nType = 4; break; // Chain Shirt / Scale Mail
        case  150: nType = 5; break; // Chainmail / Breastplate
        case  200: nType = 6; break; // Splint Mail / Banded Mail
        case  600: nType = 7; break; // Half-Plate
        case 1500: nType = 8; break; // Full Plate
    }
    // Restore the identified flag, and return armor type.
    [url=http://www.nwnlexicon.com/index.php/SetIdentified]SetIdentified[/url](oItem,bIdentified);
    return nType;
}

               
               

               


                     Modifié par MagicalMaster, 21 décembre 2013 - 05:54 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Getting Base AC value
« Reply #8 on: December 21, 2013, 06:03:08 am »


               Eh. Setting to unidentified does work, and 2das don't generate lag spikes with the new caching, so long as you set your cache count to a reasonable number - the default number should be fine. So either way is good. I'd post sample code, but it does involve a check of cost, so just do the 2da lookup. The table is small enough that, when cached, it should be about as fast as a local read, if not faster.

Funky
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Getting Base AC value
« Reply #9 on: December 21, 2013, 06:03:55 am »


               

MagicalMaster wrote...

Ah-ha!  I was half right.  NWNLexicon had this code:

I'm assuming that's the sample code he was talking about. It uses as cost check.

Funky
               
               

               
            

Legacy_Vincent07

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Getting Base AC value
« Reply #10 on: December 21, 2013, 06:55:37 am »


               Yep, if we hadn't zeroed out the cost table, I'd have used that.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Getting Base AC value
« Reply #11 on: December 21, 2013, 05:34:30 pm »


               Ah, right.  I should post less while exhausted.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting Base AC value
« Reply #12 on: December 21, 2013, 07:01:38 pm »


               const int iType = ITEM_APPR_TYPE_ARMOR_MODEL;
const int iIndex=ITEM_APPR_ARMOR_MODEL_TORSO;
const int CATAGORY_ARMOR = 4;
const int CATAGORY_SHIELD = 3;

int GetBaseAC( object oItem)
{
  int nBaseType=GetBaseItemType(oItem);
  int nBaseCatagory= StringToInt(Get2DAString("baseitems", "Category",nBaseType));
  int BaseAC;

    switch( nBaseCatagory)
    {
      case  CATAGORY_SHIELD:
        BaseAC=  StringToInt(Get2DAString("baseitems", "BaseAC",nBaseType));
        break;
      case CATAGORY_ARMOR:
      {
        int nChest = GetItemAppearance(oItem, iType, iIndex );
        BaseAC= StringToInt( Get2DAString( "parts_chest","ACBONUS", nChest));
      }
    }
    return BaseAC;
}
               
               

               


                     Modifié par Lightfoot8, 21 décembre 2013 - 07:03 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting Base AC value
« Reply #13 on: December 21, 2013, 07:17:24 pm »


               

WhiZard wrote...

I believe I posted this recently for Lazarus.  Here is a function for getting the base AC of armor.

int GetArmorBaseAC(object oArmor)
{
int nAppear = GetItemAppearance(oArmor, ITEM_APPR_TYPE_ARMOR_MODEL, ITEM_APPR_ARMOR_MODEL_TORSO);
return StringToInt(Get2DAString("des_crft_appear", "BaseAC", nAppear));
}


Why "des_crft_appear" ?     The Item format  lists  "parts_chest"  as being the place to look.  

P.S.  Really wish I would have seen your code before figuring it all out myself again.  
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting Base AC value
« Reply #14 on: December 21, 2013, 08:41:38 pm »


               I think lightfoot's approach is best. The chest part determines base AC.