Larian Banner: Baldur's Gate Patch 9
Previous Thread
Next Thread
Print Thread
#525597 23/07/14 04:31 AM
Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014
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]


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-
Code
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-

Code
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.zip



Scripts 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-

Code
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-

Code
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)

Last edited by Rhidian; 23/07/14 11:15 PM.
Joined: Jun 2013
addict
Offline
addict
Joined: Jun 2013
Thank you very very much for explaining and sharing this.

However, I just can't believe we need to do all this just to add something like a potion ?


Un chemin de 1000 lieues commence par un premier pas.

Project:
Steam workshop Frontiere
Joined: Jul 2014
stranger
Offline
stranger
Joined: Jul 2014
Very useful information, lucidly described. Cheers for this!


My name is Ahnion, dammit---with a grave accent on the i!
Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014
Now that I've thought about it some more, it's likely that I was mistaken about the Script. The script is most likely what is necessary for NPCs to use the item mid-combat, since the script details conditions on when they should take the potion.

So the script shouldn't be necessary for normal player use. The functions should be based off of the Stats file.

Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014
Yep, the script isn't necessary. There's still a lot to learn about item scripting I suppose.

On the flip side, making OP potions is incredibly simple. I mean, with just a few additions to my earlier Stat file...


Code
new entry "POTION_Rhidian_Healing_Potion"
type "Potion"
using "Potion"
data "Act part" "9"
data "StackId" "AwesomeStuff"
data "ComboCategory" "PotionHealing"
data "Value" "4"
data "Vitality" "5"
data "FireResistance" "100"
data "EarthResistance" "100"
data "WaterResistance" "100"
data "AirResistance" "100"
data "PoisonResistance" "100"
data "Duration" "-1"



Then all of a sudden I have a potion capable of giving a *permanent* boost to all resistances to the tune of 100%. Looking through the other Potion descriptions, it should be easily possible to make OP stat increase potions as well.

Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014
laugh I managed to get a Script working with an item.

Behold-

Before
[Linked Image]

After (Book was added to inventory due to consuming the Potion)
[Linked Image]


And here is the Item Script that I attached to my Potion's RootTemplate-

Code
INIT

ITEM:__Me

EVENTS

EVENT RhidianItem
VARS
CHARACTER:_Char
ON
	OnUseItem(_Char, __Me)
ACTIONS
	CombatLogText(_Char,"Hello World", 0, 2)
	CharacterAddToInventory (_Char, "SKILLBOOK_AbilityPoint")



The CombatLogText command didn't do anything, but the adding to inventory command most definitely had an effect.

Edit:
Updated first post

Last edited by Rhidian; 23/07/14 09:15 PM.
Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014
Zombies can go eat their hearts out laugh

[Linked Image]

Code
INIT

ITEM:__Me

EVENTS

EVENT RhidianStatus
VARS
CHARACTER:_Char
ON
	OnUseItem(_Char, __Me)
ACTIONS
	CharacterApplyStatus(_Char, POISONED, -1)



Permanent status effects like Poison and Burning.


[Linked Image]

Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014
I found something cool while looking through the Main Potion.txt file. laugh


[Linked Image]

Code
new entry "Stats_Burning"
type "Potion"
data "Act" "1"
data "Act part" "6"
data "WaterResistance" "100"
data "FireResistance" "100"
data "EarthResistance" "100"
data "AirResistance" "100"
data "Duration" "-1"



It turns out all of the effects of Status effects are listed in the Potion.txt file. Better yet, it's modifyable, meaning we can change how status effects work. The duration apparently can be overwritten by the items and such that call them forth (the Potion in the above picture inflicted the Burning for 3 rounds).

Status effects also include the Shields, Slow (like from that Sandstorm/Oil), and much more laugh

Edit:
I changed my Potion slightly as well. Potions (and by extension Status effects) are capable of changing Skill values like Man-At-Arms and mess around with AP. The APMaximum change didn't appear to work though.


new entry "POTION_Rhidian_Healing_Potion"
type "Potion"
using "Potion"
data "Act part" "9"
data "StackId" "AwesomeStuff"
data "ComboCategory" "PotionHealing"
data "Value" "4"
data "Vitality" "5"
data "FireResistance" "100"
data "EarthResistance" "100"
data "WaterResistance" "100"
data "AirResistance" "100"
data "PoisonResistance" "100"
data "APStart" "10"
data "APRecovery" "10"
data "APMaximum "15"
data "Duration" "-1"


Edit 2:
I stand slightly corrected. That Duration "-1" I had for my modified Burning effect actually does something. It gives a permanent increase *every* time that the character becomes burned. I didn't notice it earlier because the effect is capped at 200%, even though the boost can go higher (I got the boost up to 600% just from entering the fire a few times).

Last edited by Rhidian; 24/07/14 01:19 AM.
Joined: Jul 2014
R
Rhidian Offline OP
addict
OP Offline
addict
R
Joined: Jul 2014

[Linked Image]
[Linked Image]

Code
INIT

ITEM:__Me

EVENTS

EVENT RhidianItem
VARS
CHARACTER:_Char
ON
	OnUseItem(_Char, __Me)
ACTIONS
	CharacterAddToInventory (_Char, "SourceStone_Potion")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")
	CharacterAddToInventory (_Char, "Quest_Stone_Blood_B")

Note: "SourceStone_Potion" is the name of another potion I made.


I think I'll let the pictures speak for themselves laugh

Joined: Dec 2013
old hand
Offline
old hand
Joined: Dec 2013
Good work, thanks for sharing the code. smile


DOS2 Mods: Happily Emmie After and The Noisy Crypt

Steam Workshop
Nexus Mods

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.5