Aller au contenu

Photo

Getting Base AC value


  • Veuillez vous connecter pour répondre
19 réponses à ce sujet

#1
Vincent07

Vincent07
  • Members
  • 47 messages
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? 

#2
MagicalMaster

MagicalMaster
  • Members
  • 2 002 messages
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 .


#3
Vincent07

Vincent07
  • Members
  • 47 messages
Still including the item enhancement when using GetItemACValue()

#4
WhiZard

WhiZard
  • Members
  • 1 204 messages
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 .


#5
Vincent07

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

#6
WhiZard

WhiZard
  • Members
  • 1 204 messages
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

#7
MagicalMaster

MagicalMaster
  • Members
  • 2 002 messages
Edit: nevermind, tested it, would have sworn it worked before.

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


#8
MagicalMaster

MagicalMaster
  • Members
  • 2 002 messages
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 .


#9
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
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

#10
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages

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

#11
Vincent07

Vincent07
  • Members
  • 47 messages
Yep, if we hadn't zeroed out the cost table, I'd have used that.

#12
MagicalMaster

MagicalMaster
  • Members
  • 2 002 messages
Ah, right. I should post less while exhausted.

#13
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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 .


#14
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.  

#15
henesua

henesua
  • Members
  • 3 867 messages
I think lightfoot's approach is best. The chest part determines base AC.

#16
WhiZard

WhiZard
  • Members
  • 1 204 messages

Lightfoot8 wrote...

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


Both work.  des_crft_appear is used in looping through the armor torsos when modifying armor (so as not to change the Base AC).

@henesua  I did go via the torso, in fact Lightfoot's method is almost identical to my own.

Modifié par WhiZard, 22 décembre 2013 - 03:25 .


#17
henesua

henesua
  • Members
  • 3 867 messages
The methods are not identical because des_craft_appear is not used by the engine to determine the base ac of a torso.

#18
WhiZard

WhiZard
  • Members
  • 1 204 messages
True, but I have yet to see new custom armor appearances that are not incorporated with both 2das.

#19
Khuzadrepa

Khuzadrepa
  • Members
  • 188 messages
Not sure if this is similar to what MagicalMaster posted earlier since he removed it, but this is an OLD trick that I am quite certain works:

object oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC); //Or however you are getting the armor item
int baseAC = GetItemACValue(oArmor) - IPGetWeaponEnhancementBonus(oArmor, ITEM_PROPERTY_AC_BONUS);

Hope that helps!
Cheers,
Khuzadrepa

Modifié par Khuzadrepa, 31 décembre 2013 - 08:01 .


#20
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Khuzadrepa wrote...

Not sure if this is similar to what MagicalMaster posted earlier since he removed it, but this is an OLD trick that I am quite certain works:

object oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC); //Or however you are getting the armor item
int baseAC = GetItemACValue(oArmor) - IPGetWeaponEnhancementBonus(oArmor, ITEM_PROPERTY_AC_BONUS);

Hope that helps!
Cheers,
Khuzadrepa


 For anyone wanting to use this:  IPGetWeaponEnhancementBonus  is located in  x2_inc_itemprop

Modifié par Lightfoot8, 31 décembre 2013 - 09:00 .