Is it possilbe to get the specific enhancement bonus of an item in a script?
I need to write a script that will check for an item's enhancment bonus, and then if it is a +1 do something, if it is a +2 do something else, +3 something else, +4 ect.
Is this possible? If so how?
Get Item Property enhancment bonus
Débuté par
Quilistan
, déc. 05 2010 10:35
#1
Posté 05 décembre 2010 - 10:35
#2
Posté 06 décembre 2010 - 05:43
take a look at this...
( this is inside _CSLCore_Items.nss which can be found here link which would have any dependencies, and be formatted much better )
( this is inside _CSLCore_Items.nss which can be found here link which would have any dependencies, and be formatted much better )
/**
* Returns the current enhancement bonus of a weapon (+1 to +20), 0 if there is
* no enhancement bonus. You can test for a specific type of enhancement bonus
* by passing the appropritate ITEM_PROPERTY_ENHANCEMENT_BONUS* constant into
* nEnhancementBonusType
* @author
* @param
* @see
* @replaces XXXIPGetWeaponEnhancementBonus
* @return
*/
int CSLGetWeaponEnhancementBonus(object oWeapon, int nEnhancementBonusType = ITEM_PROPERTY_ENHANCEMENT_BONUS)
{
itemproperty ip = GetFirstItemProperty(oWeapon);
int nFound = 0;
while (nFound == 0 && GetIsItemPropertyValid(ip))
{
if (GetItemPropertyType(ip) ==nEnhancementBonusType)
{
nFound = GetItemPropertyCostTableValue(ip);
}
ip = GetNextItemProperty(oWeapon);
}
return nFound;
}
/**
* Shortcut function to set the enhancement bonus of a weapon to a certain bonus
* Specifying bOnlyIfHigher as TRUE will prevent application of the bonus if the bonus is lower than currently present. Valid values for nBonus are 1 to 20.
* @author
* @param
* @see
* @replaces XXXIPSetWeaponEnhancementBonus
* @return
*/
void CSLSetWeaponEnhancementBonus(object oWeapon, int nBonus, int bOnlyIfHigher = TRUE)
{
int nCurrent = CSLGetWeaponEnhancementBonus(oWeapon);
if (bOnlyIfHigher && nCurrent > nBonus)
{
return;
}
if (nBonus 20 )
{
return;
}
itemproperty ip = GetFirstItemProperty(oWeapon);
while (GetIsItemPropertyValid(ip))
{
if (GetItemPropertyType(ip) ==ITEM_PROPERTY_ENHANCEMENT_BONUS)
{
RemoveItemProperty(oWeapon,ip);
}
ip = GetNextItemProperty(oWeapon);
}
ip = ItemPropertyEnhancementBonus(nBonus);
AddItemProperty(DURATION_TYPE_PERMANENT,ip,oWeapon);
}
/**
* Shortcut function to upgrade the enhancement bonus of a weapon by the
* number specified in nUpgradeBy. If the resulting new enhancement bonus
* would be out of bounds (>+20), it will be set to +20
* @author
* @param
* @see
* @replaces XXXIPUpgradeWeaponEnhancementBonus
* @return
*/
void CSLUpgradeWeaponEnhancementBonus(object oWeapon, int nUpgradeBy)
{
int nCurrent = CSLGetWeaponEnhancementBonus(oWeapon);
itemproperty ip = GetFirstItemProperty(oWeapon);
int nNew = nCurrent + nUpgradeBy;
if (nNew
{
nNew = 1;
}
else if (nNew >20)
{
nNew = 20;
}
while (GetIsItemPropertyValid(ip))
{
if (GetItemPropertyType(ip) ==ITEM_PROPERTY_ENHANCEMENT_BONUS)
{
RemoveItemProperty(oWeapon,ip);
}
ip = GetNextItemProperty(oWeapon);
}
ip = ItemPropertyEnhancementBonus(nNew);
AddItemProperty(DURATION_TYPE_PERMANENT,ip,oWeapon);
}
Modifié par painofdungeoneternal, 06 décembre 2010 - 05:44 .
#3
Posté 06 décembre 2010 - 06:12
Basically you use GetItemHasItemProperty() with ITEM_PROPERTY_ENHANCEMENT_BONUS to determine it has an enhancement and then for a weapon use IPGetWeaponEnhancementBonus() to get the value. For armor and shields you need to specify ITEM_PROPERTY_AC_BONUS when using the IPGetWeaponEnhancementBonus() function to get the AC bonus.
For a simple example script look at this Item Level Restriction script.
Regards
For a simple example script look at this Item Level Restriction script.
Regards
#4
Posté 07 décembre 2010 - 05:24
Hey guys thank your for the replies. I have made some headway on a system I was thinking about for a rust monster's attack.
Script compiles, but is not working correctly
It doesn't seem to be firing the section that gets the creature's size (which also sets the DC and Max enhancment it can hit), nor I am seeing the item's enhancment bonus.
I am sure there are probably a couple of things I am doing that don't make sense. Every script I write is an adventure of learning for me. I think I explained everything in the script. Any help to get this fixed and running would be much appreciated, at least by DM's!
rust_monster onhit script:
/* RUST_MONSTER onhit script by Quilistan
Thanks to painofdungeoneternal and Kaldor Silverwand for help with getting the enhancment bonus of an item.
This script is a modified system of rules for a rust monster's hit.
The size of the creature determines the DC of it's hit and also determines the level of magic it can effect.
An Item with a powerful enough enchantment can resist this effect out right.
If the creature can affect the item, then the item gets to make a saving throw vs the DC of the monster's hit,
the saving throw is d20 + the item's enchantment bonus.
If the save is made nothing happens, if the save fails the items is destroyed and devoured.
If the creature is slain, an essence from a recently destroy magic item can be found in the belly of the creature.
The item is randomly selected from selected equiped slot on the character.
*/
#include "x2_inc_switches"
#include "ginc_item"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
if(nEvent != X2_ITEM_EVENT_ONHITCAST)
return;
object oCreature = GetItemPossessor(OBJECT_SELF);
object oTarget = GetSpellTargetObject();
string nSize = GetTag(oCreature);
int nDC;
int nMaxHit;
//check size of monster from its blueprint, then set DC of the hit and set the Max Magic Bonus it can hit
if(nSize == "rust_monster_sml")
{
int nDC = 6;
int nMaxHit = 1;
}
if(nSize == "rust_monster_med")
{
int nDC = 8;
int nMaxHit = 2;
}
if(nSize == "rust_monster_lrg")
{
int nDC = 10;
int nMaxHit = 3;
}
if(nSize == "rust_monster_hge")
{
int nDC = 12;
int nMaxHit = 4;
}
if(nSize == "rust_monster_grg")
{
int nDC = 14;
int nMaxHit = 5;
}
if(nSize == "rust_monster_col")
{
int nDC = 16;
int nMaxHit = 6;
}
//check for which item is hit, random selection of select equiped items
int nInventorySlot;
switch(nInventorySlot)
{
case 1: nInventorySlot = INVENTORY_SLOT_RIGHTHAND;
case 2: nInventorySlot = INVENTORY_SLOT_LEFTHAND;
case 3: nInventorySlot = INVENTORY_SLOT_RIGHTRING;
case 4: nInventorySlot = INVENTORY_SLOT_LEFTRING;
case 5: nInventorySlot = INVENTORY_SLOT_HEAD;
case 6: nInventorySlot = INVENTORY_SLOT_ARMS;
case 7: nInventorySlot = INVENTORY_SLOT_NECK;
case 8: nInventorySlot = INVENTORY_SLOT_CHEST;
}
SendMessageToAllDMs("Item is: " + IntToString(nInventorySlot) + " - Creature Size is: " + nSize + " - Max Enchanment creature can hit: " + IntToString(nMaxHit));
//check for items enchantment bonus type: Enchantment, AC, Abiity Score bonus, Saving Throw bonus
//Get Bonus Amount
object oItem = GetItemInSlot(nInventorySlot, oTarget);
int nEnhBonus = 0;
int nSaveBonus = 0;
if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_ENHANCEMENT_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
else if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_AC_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem, ITEM_PROPERTY_AC_BONUS);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
else if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_ABILITY_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem, ITEM_PROPERTY_ABILITY_BONUS);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
else if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_SAVING_THROW_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem, ITEM_PROPERTY_SAVING_THROW_BONUS);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
//Check to see if the creature can beat the item's enhancment bonus
if (nMaxHit < nEnhBonus)
{
SendMessageToPC(oTarget, "The creature's bite hits an item of yours, but the weapon's magic protects it.");
SendMessageToAllDMs("The item's magic protected it from the creature.");
return;
}
//roll the save
int nRoll = d20();
int nRollTotal = nRoll + nSaveBonus;
if (nRollTotal >= nDC)
{
SendMessageToPC(oTarget, "Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " SUCCESS!");
SendMessageToAllDMs("Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " SUCCESS!");
return;
}
//execute hit: apply vfx, destroy item, send message, create essence on creature
effect eVis = EffectNWN2SpecialEffectFile("sp_necromancy_hit");
//Send Message
SendMessageToPC(oTarget, "Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " FAILURE!");
SendMessageToAllDMs("Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " FAILURE!");
//apply vfx
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
//destroy item
DestroyObject(oItem);
//create essence
if (nEnhBonus == 1)
{
CreateItemOnObject("cft_ess_power1", oCreature);
}
if (nEnhBonus == 2)
{
CreateItemOnObject("cft_ess_power2", oCreature);
}
if (nEnhBonus == 3)
{
CreateItemOnObject("cft_ess_power3", oCreature);
}
if (nEnhBonus == 4)
{
CreateItemOnObject("cft_ess_power4", oCreature);
}
if (nEnhBonus == 5)
{
CreateItemOnObject("cft_ess_power4", oCreature);
}
}
Script compiles, but is not working correctly
It doesn't seem to be firing the section that gets the creature's size (which also sets the DC and Max enhancment it can hit), nor I am seeing the item's enhancment bonus.
I am sure there are probably a couple of things I am doing that don't make sense. Every script I write is an adventure of learning for me. I think I explained everything in the script. Any help to get this fixed and running would be much appreciated, at least by DM's!
rust_monster onhit script:
/* RUST_MONSTER onhit script by Quilistan
Thanks to painofdungeoneternal and Kaldor Silverwand for help with getting the enhancment bonus of an item.
This script is a modified system of rules for a rust monster's hit.
The size of the creature determines the DC of it's hit and also determines the level of magic it can effect.
An Item with a powerful enough enchantment can resist this effect out right.
If the creature can affect the item, then the item gets to make a saving throw vs the DC of the monster's hit,
the saving throw is d20 + the item's enchantment bonus.
If the save is made nothing happens, if the save fails the items is destroyed and devoured.
If the creature is slain, an essence from a recently destroy magic item can be found in the belly of the creature.
The item is randomly selected from selected equiped slot on the character.
*/
#include "x2_inc_switches"
#include "ginc_item"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
if(nEvent != X2_ITEM_EVENT_ONHITCAST)
return;
object oCreature = GetItemPossessor(OBJECT_SELF);
object oTarget = GetSpellTargetObject();
string nSize = GetTag(oCreature);
int nDC;
int nMaxHit;
//check size of monster from its blueprint, then set DC of the hit and set the Max Magic Bonus it can hit
if(nSize == "rust_monster_sml")
{
int nDC = 6;
int nMaxHit = 1;
}
if(nSize == "rust_monster_med")
{
int nDC = 8;
int nMaxHit = 2;
}
if(nSize == "rust_monster_lrg")
{
int nDC = 10;
int nMaxHit = 3;
}
if(nSize == "rust_monster_hge")
{
int nDC = 12;
int nMaxHit = 4;
}
if(nSize == "rust_monster_grg")
{
int nDC = 14;
int nMaxHit = 5;
}
if(nSize == "rust_monster_col")
{
int nDC = 16;
int nMaxHit = 6;
}
//check for which item is hit, random selection of select equiped items
int nInventorySlot;
switch(nInventorySlot)
{
case 1: nInventorySlot = INVENTORY_SLOT_RIGHTHAND;
case 2: nInventorySlot = INVENTORY_SLOT_LEFTHAND;
case 3: nInventorySlot = INVENTORY_SLOT_RIGHTRING;
case 4: nInventorySlot = INVENTORY_SLOT_LEFTRING;
case 5: nInventorySlot = INVENTORY_SLOT_HEAD;
case 6: nInventorySlot = INVENTORY_SLOT_ARMS;
case 7: nInventorySlot = INVENTORY_SLOT_NECK;
case 8: nInventorySlot = INVENTORY_SLOT_CHEST;
}
SendMessageToAllDMs("Item is: " + IntToString(nInventorySlot) + " - Creature Size is: " + nSize + " - Max Enchanment creature can hit: " + IntToString(nMaxHit));
//check for items enchantment bonus type: Enchantment, AC, Abiity Score bonus, Saving Throw bonus
//Get Bonus Amount
object oItem = GetItemInSlot(nInventorySlot, oTarget);
int nEnhBonus = 0;
int nSaveBonus = 0;
if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_ENHANCEMENT_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
else if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_AC_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem, ITEM_PROPERTY_AC_BONUS);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
else if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_ABILITY_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem, ITEM_PROPERTY_ABILITY_BONUS);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
else if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_SAVING_THROW_BONUS))
{
int nEnhBonus = IPGetWeaponEnhancementBonus(oItem, ITEM_PROPERTY_SAVING_THROW_BONUS);
//calculate save bonus
int nSaveBonus = nEnhBonus;
}
//Check to see if the creature can beat the item's enhancment bonus
if (nMaxHit < nEnhBonus)
{
SendMessageToPC(oTarget, "The creature's bite hits an item of yours, but the weapon's magic protects it.");
SendMessageToAllDMs("The item's magic protected it from the creature.");
return;
}
//roll the save
int nRoll = d20();
int nRollTotal = nRoll + nSaveBonus;
if (nRollTotal >= nDC)
{
SendMessageToPC(oTarget, "Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " SUCCESS!");
SendMessageToAllDMs("Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " SUCCESS!");
return;
}
//execute hit: apply vfx, destroy item, send message, create essence on creature
effect eVis = EffectNWN2SpecialEffectFile("sp_necromancy_hit");
//Send Message
SendMessageToPC(oTarget, "Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " FAILURE!");
SendMessageToAllDMs("Your item makes a saving throw - " + IntToString(nRoll) + " + " + IntToString(nSaveBonus) + " = " + IntToString(nRollTotal) + " vs DC" + IntToString(nDC) + " FAILURE!");
//apply vfx
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
//destroy item
DestroyObject(oItem);
//create essence
if (nEnhBonus == 1)
{
CreateItemOnObject("cft_ess_power1", oCreature);
}
if (nEnhBonus == 2)
{
CreateItemOnObject("cft_ess_power2", oCreature);
}
if (nEnhBonus == 3)
{
CreateItemOnObject("cft_ess_power3", oCreature);
}
if (nEnhBonus == 4)
{
CreateItemOnObject("cft_ess_power4", oCreature);
}
if (nEnhBonus == 5)
{
CreateItemOnObject("cft_ess_power4", oCreature);
}
}
#5
Posté 07 décembre 2010 - 06:21
There is a rust monster with scripts somewhere on the vault that you might want to look at. I've plans to use it in my King's Festival+Queen's Harvest campaign.
When I have used on hit scripts they have been hc scripts defined on a weapon. The script itself runs on the creature wielding the item. Not exactly what you seem to be doing though. Looks like your script is old NWN style instead.
A couple of scripting things though you should fix. First the naming convention for string variables is to start their name with "s". Variables that start with "n" are used with integer variables. You are using nSize to store a string. It should really be something like sTag rather than nSize.
Second, when you define a variable you only need to assign its type once. After that you just set the variable to values. You define nDC and nMaxHit as int variables, but then in your if clauses you keep redefining them as int again. Instead all of the lines in the if statements should not have int specified.
You may want to consider reading over Knightmare's Scripting for Noobs. It covers the basics of scripting.
Regards
When I have used on hit scripts they have been hc scripts defined on a weapon. The script itself runs on the creature wielding the item. Not exactly what you seem to be doing though. Looks like your script is old NWN style instead.
A couple of scripting things though you should fix. First the naming convention for string variables is to start their name with "s". Variables that start with "n" are used with integer variables. You are using nSize to store a string. It should really be something like sTag rather than nSize.
Second, when you define a variable you only need to assign its type once. After that you just set the variable to values. You define nDC and nMaxHit as int variables, but then in your if clauses you keep redefining them as int again. Instead all of the lines in the if statements should not have int specified.
You may want to consider reading over Knightmare's Scripting for Noobs. It covers the basics of scripting.
Regards
Modifié par Kaldor Silverwand, 07 décembre 2010 - 06:33 .
#6
Posté 07 décembre 2010 - 03:54
Thanks again for the advice. I have read quite a few of the scripting tuts, but I just don't script all the time. So the retention doesn't always stick.
Also this system I thought up my self after reading the 3.5 and 4.0 descriptions of the rust monster, so I am hoping to get this working.
- This is the rust monster from the vault
- This script is for a creature item that fires on hit i_rust_monster_hc is my script name.
I will fix the names, and fix the redefining of the variables (I totally overlooked that). Maybe that is my issue for it not working correctly?
Is there any discription of the default system that comes with the rust monster? I haven't found one yet.
Also this system I thought up my self after reading the 3.5 and 4.0 descriptions of the rust monster, so I am hoping to get this working.
- This is the rust monster from the vault
- This script is for a creature item that fires on hit i_rust_monster_hc is my script name.
I will fix the names, and fix the redefining of the variables (I totally overlooked that). Maybe that is my issue for it not working correctly?
Is there any discription of the default system that comes with the rust monster? I haven't found one yet.
Modifié par Quilistan, 07 décembre 2010 - 04:08 .
#7
Posté 07 décembre 2010 - 04:15
Your script is written the NWN way, not NWN2, so I can't really say whether it works or not. I write all of my item scripts NWN2 style. Look at the hc script for my Bastard Sword of Ruin in the vault. It is similar to what you are trying to do.
Regards
Regards





Retour en haut






