Larian Banner: Baldur's Gate Patch 9
Previous Thread
Next Thread
Print Thread
Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
I am successfully iterating over items near a character via IterateItemsNear(GAMEOBJECT source, FLOAT radius, FIXEDSTRING eventname). Now I want to add the found items to the characters inventory but unfortunately I cant see a way how to do this.
The problem is that the OnIterateItem(ITEM:source, FIXEDSTRING:eventId) function returns ITEM objects but to add items to a characters inventory I have to use the itemStatsID (CharacterAddToInventory(CHARACTER character, FIXEDSTRING itemStatsObject[, INT amount]))...

Do you guys know a way how to accomplish my goal? Is it possible to extract the ID from the ITEM object?

A workaround I had in mind is to use CharacterPickUpItem(ITEM item). But I would like to avoid waiting for the character to go to the item and playing the pickup animation.

Joined: Apr 2013
N
addict
Offline
addict
N
Joined: Apr 2013
If you have an ITEM object already, you need to call ItemToCharacter((ITEM)_Item, (CHARACTER)_Character)

Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
Hmmm... Doesnt seem to work for me. I used the following part:
Code
DisplayText(_Item, "CYS_ChickenRunning_Script_0", 0.1)
ItemToCharacter(_Item,__Me)

The text is showing up on the item but it doesnt get transferred to the characters inventory. Any idea whats happening?

Edit: Where did you get this command from? Couldn't find it in the engine wiki.

Edit2: If I try to compile the script in the Editor it gives me the following error: Failed to parse the action 'ItemToCharacter'. Looks like the game doesnt recognise it at all.

Last edited by Thoro; 02/09/14 06:35 PM.
Joined: Jul 2014
enthusiast
Offline
enthusiast
Joined: Jul 2014
That may be an issue on your end.

Search 'ItemToCharacter' via windows key (or whatever the comparable process is on Mac) -- if you have main.pak unpacked somewhere, you'll see that call's used in dozens of main campaign story goals. It's recognised and works fine in my mod.


Escape From Smalcatraz: Steam/Nexus. Forum thread.
Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
I try to write a script and not a story goal. Maybe that's the catch?

Joined: Jul 2014
R
addict
Offline
addict
R
Joined: Jul 2014
It seems to me that you're writing a charScript (using info on the Wiki). Norbyte's response was a Story script call, which for the most part are separate from charScripts. A list of Story Editor functions can be found here: http://www.larian.com/forums/ubbthreads.php?ubb=showflat&Number=531151#Post531151

As for your question, the reason why CharacterAddToInventory isn't working is because that command attempts to add a completely new item to the inventory, rather than transferring the item that you have found already. Looking through the charScript functions, I don't think charScripts alone can do what you want. You will probably want to involve a Story script as well.

In your charScript, you could have something like this:
Code
CharacterItemEvent (__Me, _item, "PhaseItemToInventory")

With _item being the item nearby that you have iterated to find.

Then in the Story Editor, you could make a Story script like so:
Code
IF
CharacterItemEvent(_Char, _item, "PhaseItemToInventory")
THEN
ItemToCharacter(_item, _Char);

(If CharacterItemEvent in the Story is indeed an Event that can be responded to. I can't recall at the moment; if it's not then it should be one of the related functions)

Joined: Jul 2014
enthusiast
Offline
enthusiast
Joined: Jul 2014
Originally Posted by Thoro
I try to write a script and not a story goal. Maybe that's the catch?

Ha, yes. Sorry for the misunderstanding. That's the eleventy-second time I've mixed up story scripting and char.script/item.script scripting.


Escape From Smalcatraz: Steam/Nexus. Forum thread.
Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
Originally Posted by Noaloha
Ha, yes. Sorry for the misunderstanding. That's the eleventy-second time I've mixed up story scripting and char.script/item.script scripting.

Alrighty almighty. No problem. laugh

I will try Rhidians solution then. Thanks alot so far. smile

Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
Okay. Here we go with the next problem. I have the following code snippet in _GLOBAL_ItemInteraction.txt:

Code
IF
	CharacterItemEvent(_Char, _item, "PhaseItemToInventory")
THEN
	ItemToCharacter(_item, _Char);
	CharacterAddGold(_Char, 2000);


And, surprise, surprise, the gold gets added but the item still wont move or get added to the inventory...

Edit: Nope, I lied! The problem is that only some items get picked up. For example the shells and skulls at the Cyseal start wont get picked up but the chests in the tutorial dungeon. Weapons are also not picked up. Any idea why?

Last edited by Thoro; 02/09/14 11:50 PM.
Joined: Aug 2014
S
stranger
Offline
stranger
S
Joined: Aug 2014
Originally Posted by Thoro
Okay. Here we go with the next problem. I have the following code snippet in _GLOBAL_ItemInteraction.txt:

Code
IF
	CharacterItemEvent(_Char, _item, "PhaseItemToInventory")
THEN
	ItemToCharacter(_item, _Char);
	CharacterAddGold(_Char, 2000);


And, surprise, surprise, the gold gets added but the item still wont move or get added to the inventory...

Edit: Nope, I lied! The problem is that only some items get picked up. For example the shells and skulls at the Cyseal start wont get picked up but the chests in the tutorial dungeon. Weapons are also not picked up. Any idea why?


I suspect that has do to with what the game consider as an "Item"
In the teleport and feather fall's description it says it works on "Items" as well, but only works with chests, barrels, crates... Not those items that you say (skulls, shells, keys, weapons)

Just my two cents tho.

Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
Originally Posted by Saishy
I suspect that has do to with what the game consider as an "Item"
In the teleport and feather fall's description it says it works on "Items" as well, but only works with chests, barrels, crates... Not those items that you say (skulls, shells, keys, weapons)

Just my two cents tho.


Good two cents. wink
I think this is hard coded (which item is an "item"), unfortunately. I tried messing around with ItemHandle and ItemTemplate but still no luck...
I also tried to use CharacterPickUpItem(_Item) in a script action but it wont work either. Strangely on no item tho...

Joined: Jul 2014
enthusiast
Offline
enthusiast
Joined: Jul 2014
Just a thought (raised because I'm trying to reconcile what you're describing with how my mod's goals work), does your code work if you use ItemToContainer instead? Will the shells and skulls move to a bag instead of a character?


Escape From Smalcatraz: Steam/Nexus. Forum thread.
Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
Nope, it has the same behaviour with containers.

Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
OK, a little update on this end. I played around with the editor. I created a new level, placed some shells and books and tried this again. What I found is that items that are Global will be transferred to the inventory but items that are not global will not.
Any ideas how to bypass this?
And what does "Global" mean exactly in the editor?

Joined: Oct 2005
T
Thoro Offline OP
journeyman
OP Offline
journeyman
T
Joined: Oct 2005
I think I understand now what "Global" means.
If you want to use items/characters/etc. in story scripts they have to be "Global". So even if you get the item from another source (in my example from a CharacterItemEvent send from a charScript) it wont be recognised in the story script at all. Is there any way to have a look into the item (like debugging) in the story script?


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