Aller au contenu

Photo

Another scripting poser ... dealing with item(s) and properties...


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

#1
ghowriter

ghowriter
  • Members
  • 21 messages
Scenario: The PC has a sword with +1d6 fire damage and encounters an NPC who will raise the fire damage to 2d6...

I have the ability to get an items properties. So I know the item (weapon) already has a damage bonus and that that damage type is fire, but I cannot locate a function that will return the IP_CONST_DAMAGEBONUS_* so I can make sure the item being upgraded doesn't already have a more powerful fire bonus before applying the new bonus.

Have I successfully confused everyone?

#2
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
Here is some things that should get you on the right track, mostly this code was for showing string values to the owner of a weapon, but can be adapted. First two functions just get a string value from a constant, 3rd block of code is what is important, it goes thru an items properties and pulls out data on each one and then uses the first 2 functions to put data into a string ( which can be presented to the player )

Last function goes and takes a given damage bonus and returns one better, almost the same as the 1st function except it returns a constant instead of a string.

string CSLDamageBonusToString(int nDamageBonus)
{
	// Returns total damage done by property, this is actually values from some 2da for item props which can be adjusted so you have to be careful if it's changed
	// Fixed damage ones are doubled due to lack of randomness
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_1    ) return  "1";// 1
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_2    ) return  "2";//  2;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_3    ) return  "3";//  3;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_4    ) return  "4";//  4;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_5    ) return  "5";//  5;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d4  ) return  "1d4";//  6;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d6  ) return  "1d6";//  7;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d8  ) return  "1d8";//  8;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d10 ) return  "1d10";//  9;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d6  ) return  "2d6";//  10;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d8  ) return  "2d8";//  11;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d4  ) return  "2d4";//  12;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d10 ) return  "2d10";//  13;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d12 ) return  "1d12";//  14;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d12 ) return  "2d12";//  15;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_6    ) return  "6";//  16;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_7    ) return  "7";//  17;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_8    ) return  "8";//  18;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_9    ) return  "9";//  19;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_10   ) return  "10";//  20;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_3d10	) return  "3d10";//  51;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_3d12	) return  "3d12";//  52;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_4d6  ) return  "4d6";//  53;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_4d8  ) return  "4d8";//  54;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_4d10	) return  "4d10";// 55;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_4d12 ) return  "4d12";// 56;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_5d6  ) return  "5d6";// 57;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_5d12	) return  "5d12";//  58;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_6d12	) return  "6d12";//  59;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_3d6  ) return  "3d6";// 60;
	if (nDamageBonus==IP_CONST_DAMAGEBONUS_6d6  ) return  "6d6";//  61;
	return "MissDamBonus" + IntToString(nDamageBonus);
}

string CSLIPDamagetypeToString(int iDamageType)
{
	if (iDamageType==IP_CONST_DAMAGETYPE_ACID)       return "Acid";
	if (iDamageType==IP_CONST_DAMAGETYPE_NEGATIVE)   return "Negative";
	if (iDamageType==IP_CONST_DAMAGETYPE_COLD)       return "Cold";
	if (iDamageType==IP_CONST_DAMAGETYPE_POSITIVE)   return "Positive";
	if (iDamageType==IP_CONST_DAMAGETYPE_DIVINE)     return "Divine";
	if (iDamageType==IP_CONST_DAMAGETYPE_SONIC)      return "Sonic";
	if (iDamageType==IP_CONST_DAMAGETYPE_ELECTRICAL) return "Electrical";
	if (iDamageType==IP_CONST_DAMAGETYPE_BLUDGEONING)return "Blunt";
	if (iDamageType==IP_CONST_DAMAGETYPE_FIRE)       return "Fire";
	if (iDamageType==IP_CONST_DAMAGETYPE_PIERCING)   return "Piercing";
	if (iDamageType==IP_CONST_DAMAGETYPE_MAGICAL)    return "Magical";
	if (iDamageType==IP_CONST_DAMAGETYPE_SLASHING)   return "Slashing";
	return "MissDamageType" + IntToString(iDamageType);
}

itemproperty ipProperty =  GetFirstItemProperty(oItem);
while (GetIsItemPropertyValid(ipProperty))
{
// get the items properties
int iPropType = GetItemPropertyType(ipProperty);
    int  iSubType=GetItemPropertySubType(ipProperty);
      int iBonus = GetItemPropertyCostTableValue(ipProperty);
      int iParam1 = GetItemPropertyParam1Value(ipProperty);

string sDamageType = CSLIPDamagetypeToString(iSubType);
string sDamageDesc = CSLDamageBonusToString(iBonus);
// do smething with the sDamageDesc

// obviously you need to rewrite the damage description.

ipProperty =  GetNextItemProperty(oItem);
}

// here is a function that increments a damage bonus to the next best value

int StoneNextDamageBonus(int nDamageBonus)
{
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d6) return -1; // AT MAX!
   // REPLACE INVALID TYPES WITH SIMILIAR VALID TYPE
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_1   ) nDamageBonus = IP_CONST_DAMAGEBONUS_1d4;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_2   ) nDamageBonus = IP_CONST_DAMAGEBONUS_1d4;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_3   ) nDamageBonus = IP_CONST_DAMAGEBONUS_1d6;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_4   ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d4;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d8 ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d4;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_5   ) nDamageBonus = IP_CONST_DAMAGEBONUS_1d10;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_6   ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d6;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d12) nDamageBonus = IP_CONST_DAMAGEBONUS_2d6;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_7   ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d6;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_8   ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d8;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_9   ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d8;
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_10  ) nDamageBonus = IP_CONST_DAMAGEBONUS_2d10;
   // ROTATE UP TO THE NEXT AMOUNT
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d4)  return IP_CONST_DAMAGEBONUS_1d6;   // 6
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d6)  return IP_CONST_DAMAGEBONUS_2d4;   // 8
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d4)  return IP_CONST_DAMAGEBONUS_1d10;  // 10
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_1d10) return IP_CONST_DAMAGEBONUS_2d6;   // 12
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d6)  return IP_CONST_DAMAGEBONUS_2d8;   // 16
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d8)  return IP_CONST_DAMAGEBONUS_3d6;   // 18
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_3d6)  return IP_CONST_DAMAGEBONUS_2d10;  // 20
   if (nDamageBonus==IP_CONST_DAMAGEBONUS_2d10) return IP_CONST_DAMAGEBONUS_2d12;  // 24
   return IP_CONST_DAMAGEBONUS_1d4;
}



Modifié par painofdungeoneternal, 10 octobre 2011 - 08:31 .


#3
ghowriter

ghowriter
  • Members
  • 21 messages
Okay. I don't know what I was expecting but this is a lot to wrap my head around. It resembles the x2 smith script from NWN1 HOTU (Rizolver). What I was having issue with was where the variable nDamageBonus was pulled from to pass into the last function. I cannot find a function that will return this value to me so I can use it to compare. I had thought it was the GetItemPropertyType but that points to the type of item property (ie.: Damage Bonue, Ability Bonus, etc...). This, naturally led me to GetItemPropertySubType but, of course, I determined that this simply specified what kind of bonus the type was (ie.: For DamageBonus type, the SubType can be Fire, Acid, etc...). I was unable to pull the GetItemPropertyParam1Value from the weapon (it returned a 0 for a longsword with +1d6 Fire Damage); or was that simply GetItemPropertyParam1?! Okay I now retest to see if I used the former or latter function and check the return value against the constants.

In the meantime, why is 2d6 the "max"? Is this some unwritten rule? If I apply 4d6 will it bomb out or is that considered too overpowered?

Thanks for the input.

#4
ghowriter

ghowriter
  • Members
  • 21 messages

ghowriter wrote...

I was unable to pull the GetItemPropertyParam1Value from the weapon (it returned a 0 for a longsword with +1d6 Fire Damage); or was that simply GetItemPropertyParam1?! Okay I now retest to see if I used the former or latter function and check the return value against the constants.

In the meantime, why is 2d6 the "max"? Is this some unwritten rule? If I apply 4d6 will it bomb out or is that considered too overpowered?

Thanks for the input.



A retest confirmed it. I used GetItemPropertyParam1Value and it returned a 0 so it is definately not the value I am looking for.

#5
ghowriter

ghowriter
  • Members
  • 21 messages
I got it. It was right there in your script. GetItemPropertyCostTableValue(ItemProperty) returns the value I am looking for... I just assumed that this returned the cost in gold added to an item that had this property...

Got it!! Thanks a million!