I have been working on figuring out how Item Scripts work and how they can be used. I have been using a custom potion to test the effect, since it can be easily manipulated.
Steps on how I created a custom Potion template here (ie the old version of this post)-
![[Linked Image]](http://i.imgur.com/E2rU6TK.jpg)
Creating a custom potion takes a couple of steps. Here's how I made my first functional potion-
1. Create a new RootTemplate for the custom potion from an existing Potion Template. This is the RootTemplate for the custom item.
2. In the Stats/Generated/Potion.txt for the mod, create the stats for the potion. In my case, it was this-
new entry "Potion"
type "Potion"
data "Act" "1"
data "Weight" "250"
data "Value" "3"
data "UseAPCost" "3"
data "InventoryTab" "Consumable"
new entry "POTION_Rhidian_Healing_Potion"
type "Potion"
using "Potion"
data "Act part" "9"
data "StackId" "Healing"
data "ComboCategory" "PotionHealing"
data "Value" "4"
data "Vitality" "9"
The name here is quite important, as it is used elsewhere.
3. Link the RootTemplate to the Stats entry by creating a new entry in the Stats/Generated/Links/Potion.txt file-
object itemstat "POTION_Rhidian_Healing_Potion","6cdb1340-d893-43c4-9eae-dd89a311eee8","",0,0,"HealingPotion",1,1,2,0,-1,20
Then in the Editor set the Stats of the RootTemplate to the name of the Stats that you created in the txt file
4. Then I had a way of getting the item into the game to test it (even though it should be buyable at the merchant due to how I set it's stats). I changed the Witch class preset equipment so that I could get it after character creation.
Proof of Concept mod here-
http://www.mediafire.com/download/3sw6oasco38cjcs/CustomPotion1.zipScripts can be added to Items, which can let them have custom effects beyond those stated in their Stats.
Here is my basic script that shows how the item can check when it's been used-
INIT
ITEM:__Me
EVENTS
EVENT RhidianItem
VARS
CHARACTER:_Char
ON
OnUseItem(_Char, __Me)
ACTIONS
CharacterAddToInventory (_Char, "SKILLBOOK_AbilityPoint")
The name that comes after EVENT can be anything you want really, so long as it doesn't overlap with something else.
The stuff after the ACTIONS can be any of the commands that the game can accept. I used the AddToInventory command because it clearly demonstrates an effect when used.
Scripts can also access Global characters/items, like so-
INIT
ITEM:__Me
EXTERN CHARACTER:%player1=Player1_dac1443f-a866-4ab3-b240-e705c0b20ec5
EXTERN CHARACTER:%player2=Player2_a0af7520-57ac-4f1c-b9d7-197bceebeade
EVENTS
EVENT CoolItem1
ON
OnUseItem(%player1, __Me)
ACTIONS
CharacterAddToInventory (%player1, "SKILLBOOK_StatPoint")
CharacterAddToInventory (%player1, "SKILLBOOK_StatPoint")
EVENT CoolItem2
ON
OnUseItem(%player2, __Me)
ACTIONS
CharacterAddToInventory (%player2, "SKILLBOOK_StatPoint")
CharacterAddToInventory (%player2, "SKILLBOOK_StatPoint")
Take a look at this line, as it has several important features-
EXTERN CHARACTER:%player1=Player1_dac1443f-a866-4ab3-b240-e705c0b20ec5
This line imports the Player 1 character. The syntax after the equals sign is <Name in Editor>_<GUID>. You can right click the appropriate Global in the Editor and copy Name <GUID> to clipboard and adjust it from there.
From what I can tell Scripts must actually be present on an item in-game to have any sort of effect. More testing is forthcoming (and will be further on in this topic depending on when I can't edit this anymore)