Author Topic: Item Modification Script  (Read 566 times)

Legacy_AllieSyn

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Item Modification Script
« on: November 17, 2011, 08:42:34 pm »


               Hello everyone! I am making an attempt to help out my builder for a ZS I play on. I am also attempting to learn basic scripting. As such I would like to ask for help in the developing of a script that would allow the below to work. On the same note, If at all possible would it be a problem tohave the guts of the script commented so I can look them over to attempt to have a higher understanding of the script as a whole.

I would appreciate any and all help!

I would like the four items below
EnchStoneCold, EnchStoneFire, EnchStoneAcid, EnchStoneElec

This item will be an on use/activate item that will enchant an item equipped in the players right hand ( or a targeted item)

This item will have a 90% chance of granting a permanant +1 cold dmg bonus to the item.
This item will have a 10% chance of eating the item that it was used on.

When the EnchStoneCold is used it is destroyed from the players inventory.

--- now that much doesn't seem to hard. But I would also like it to do the following.

If the item already has a +1 dmg bonus then
This item will have a 70% chance of granting an additional +1 cold bonus ( IE +2) to the item
This item will have a 30% chance of eating the item it was used on.

When EnchStoneCold is used it is destroyed from the players inventory.

--- And a little harder...

If the item already has a +2 dmg bonus then
This item will have a 50% chance of granting an additional +1 cold bonus ( IE +3) to the item
This item will have a 50% chance of eating the item it was used on.

When EnchStoneCold is used it is destroyed from the players inventory.

--- and one more time ....

If the item already has a +3 dmg bonus then
This item will have a 30% chance of granting an additional +1 cold bonus ( IE +4) to the item
This item will have a 70% chance of eating the item it was used on.

When EnchStoneCold is used it is destroyed from the players inventory.

--- and for the final time

If the item already has a +4 dmg bonus then
This item will have a 10% chance of granting an additional +1 cold bonus ( IE +5) to the item
This item will have a 90% chance of eating the item it was used on.

When EnchStoneCold is used it is destroyed from the players inventory.


--- Now to make it even more difficult which is where i think the problem comes in...

This particular item offers a Cold bonus to damage. I would like to then duplicate the script to allow for a stone for Fire, Acid, Electricty, Positive, and negative.

I would like the % to be universal.

Example

Masterwork Longsword that has been enchanted with a cold stone (+1 cold) and a Fire stone (+1 Fire)

The player wants to use a EnchStoneElec

I would like it to roll at the 50%/50% level.   ( being that it is on the 3rd upgrade path)

Let me know your thoughts
Agian - Thank you for any and all help!
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Item Modification Script
« Reply #1 on: November 17, 2011, 11:34:11 pm »


               Okay... Bear with me. '^_^'

  • You must loop through the items properties

    GetFirstItemProperty
    GetNextItemProperty

  • In the loop check if the type is a damage bonus.

    GetItemPropertyType == ITEM_PROPERTY_DAMAGE_BONUS

  • Now you must check what the damage bonus type is.

    GetItemPropertySubType



    To make sense of the values returned by this, you'l need nwn explorer from the vault. Now don't be startled, it's not all complex as I might make it sound like...



    With the explorer you can explore the game's resources, including .2da's. Open the explorer and go "NWN:HotU patch data -> xp2.bif -> Game Data -> itempropdef.2da" You'll notice it isn't there. Always check patch first to ensure you refer to the most up to date version of the .2da. Go to "NWN:HotU main data -> ...", you'll find it there.



    Find the line with "Damage" (damage bonus property). You'll notice that in the column SubTypeResRef the damage property has IPRP_DAMAGETYPE. This is the .2da that handles subtypes for the damage bonus item property. Now lets open that one (iprp_damagetype.2da)



    Here you'll see the values returned by the above function (the very first column)

    e.g.

    6 = acid

    10 = fire

  • So now we have checked that the property is damage bonus, and it's of the wanted damage type, so now we must check its power / amount of damagebonus.

    GetItemPropertyCostTableValue



    First we need to find the cost tables for damage bonus property from the .2da's. Go to "iprp_costtable.2da" and find Damage. You'll notice it points to IPRP_DAMAGECOST, so let's open that .2da.



    The first column is again the value returned by the above function, and the "Label" column tells you how much the damage bonus really is.

    e.g.

    5 = +5

    10 = +2d6

    16 = +6



    Since it seems your stones can only enchant up to +5, you can directly use values returned by this function.

    1 = 1 ... 5 = 5, if its something else, you might not want to count the property to the %'s, or you might not want to allow enchanting the item at all, whatever, that's for you to figure out. (balancing that is)

So again, in a nutshell:
Go through all item properties on the equipped item.
For each item property:
-Check if it's type is  damage bonus
--Check if it's subtype is fire or cold or ... damage type
---Check if it's cost table value is 1..5
----Add the cost value to an integer.

This integer*20% + 10% = chance to fail enchanting.
If >100%, cant enchant.



Hope this helps, do ask if im unclear on something. There's a chance im wrong about something too since it's been a while since I meddled with this stuff... There propably are other ways to do this aswell.
':huh:'


PS: what the hell is "boomerang" item property??
               
               

               


                     Modifié par Xardex, 17 novembre 2011 - 11:34 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Item Modification Script
« Reply #2 on: November 18, 2011, 03:24:41 am »


               boomerang, mind blank and few other itemproperties were never implemented unfortunately
               
               

               
            

Legacy_AllieSyn

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Item Modification Script
« Reply #3 on: November 18, 2011, 02:10:06 pm »


               Question - Is there a way to do this without looking through the .2da files?  Or perhaps an alternate method of doing this would modding any of the files that we have for the server?

Sorry if I am being a pain.

Though after asking my scripter he explained how what you have listen would work, I just don't feel comfortable fishing inside of files I have no business being in >.<
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Item Modification Script
« Reply #4 on: November 18, 2011, 02:25:23 pm »


               There is no harm in reading a 2DA, But if you didn't want to you could always look up the information you need in the Lexiocn.  

IP_CONST_DAMAGETYPE_*

IP_CONST_DAMAGEBONUS_*

Or just use the constants that are already built into the gamefor the default Item prop types.
               
               

               
            

Legacy_AllieSyn

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Item Modification Script
« Reply #5 on: November 18, 2011, 05:32:07 pm »


               Okay, playing with the lilac soul - I think I understand how to set up the % for each item, but how would I have the script recognize if it had the previous dmg bonus?

Example that it went from being a +1 acid to a +2 acid?

itemproperty ipAdd;
object oItem;
object oTarget;
/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...&id=4683&id=625    */

#include "x2_inc_itemprop"
void main()
{
object oPC;

if (!GetIsPC(GetItemActivatedTarget())
){

SendMessageToPC(GetItemActivator(), "Improper use of item!");
return;}

if (d100()<=90)
  {
  oPC = GetItemActivator();

  oTarget = oPC;

  oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);

  ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, IP_CONST_DAMAGEBONUS_1);

  IPSafeAddItemProperty(oItem, ipAdd);

  }
else
  {
  oTarget = GetItemActivatedTarget();

  DestroyObject(oTarget, 0.0);

  }

}


Now how would I make an addition to this to possibly give a Universal Tag to the item effected so that the other stones effect it as well?
               
               

               
            

Legacy_AllieSyn

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Item Modification Script
« Reply #6 on: November 18, 2011, 05:45:27 pm »


               .... Question with this... Could we make an addition to this

If ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, IP_CONST_DAMAGEBONUS_*);

Then
if (d100()<=70)
{
oPC = GetItemActivator();

oTarget = oPC;

oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);

ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_*, IP_CONST_DAMAGEBONUS_*+1);

IPSafeAddItemProperty(oItem, ipAdd);

}
else
{
oTarget = GetItemActivatedTarget();

DestroyObject(oTarget, 0.0);

}

}


How would it identify if the previous change was there?
How would it give the specific elemental bonus associated with the stone used?
Example - the first time use was acid, and the second time was fire. so the end bonus should be +1 acid dmg and +1 fire dmg...


Im sorry if I seem rather ignorant. I think I might have bitten off more than i can chew >.<
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Item Modification Script
« Reply #7 on: November 18, 2011, 06:31:39 pm »


               Viewing the .2da's is harmless, and learning how to do it (which isn't hard at all) might be beneficial for you in the long run, so you wouldn't always need to ask here when meddling with these things. After all, you are just checking the return values for the functions
GetItemPropertySubType
and
GetItemPropertyCostTableValue
.

To increase a damage bonus by 1 you once again must look through all the properties. Find property type damage bonus with subtype in the specific damage type. (i.e. fire/cold) and check its costtable value. Then IPSafeAdd the same damage type bonus with costtable+1 damage.

e.g.
ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, iCostTableValue+1);
IPSafeAddItemProperty(oItem, ipAdd);

You can use the .2da line number instead of IP_CONST_DAMAGEBONUS_*, and as we earlier found out it's fairly simple from +1 to +5. (+1 is on line 1, +5 on line 5)

At least try out the explorer once. If you follow my earlier post's instructions you'll see it's really quite simple to check these specific .2da's.
               
               

               


                     Modifié par Xardex, 18 novembre 2011 - 06:35 .
                     
                  


            

Legacy_AllieSyn

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Item Modification Script
« Reply #8 on: November 18, 2011, 07:27:02 pm »


               Okay Xardex I will give it a try when I get home today. At the moment Im playing with lilac's generator while at work lol. Once I get to messing around with the file expect questions lol.

I also think im understanding the iCostTable your explaining.

Now i need to figure out how to make the script acknowledge the existing bonus to properly use the % of success and failure.

Thank you so far though. This is all very new to me and any help that is given is HUGELY appreciated.
               
               

               


                     Modifié par AllieSyn, 18 novembre 2011 - 07:35 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Item Modification Script
« Reply #9 on: November 18, 2011, 08:10:33 pm »


               Oh right, "cost table" is a misleading name. I had just gotten used to it....
Hopefully this clears it up a bit:

http://img534.images...5148/asdfuh.jpg
               
               

               
            

Legacy_AllieSyn

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Item Modification Script
« Reply #10 on: November 18, 2011, 09:22:29 pm »


               See that I recognize!!! ^.^