Divinity Banner
Previous Thread
Next Thread
Print Thread
Add item found by IterateItemsNear #549750
02/09/14 04:34 PM
02/09/14 04:34 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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.

Re: Add item found by IterateItemsNear [Re: Thoro] #549751
02/09/14 04:41 PM
02/09/14 04:41 PM
Joined: Apr 2013
Posts: 465
N
Norbyte Offline
addict
Norbyte  Offline
addict
N

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

Re: Add item found by IterateItemsNear [Re: Thoro] #549762
02/09/14 06:24 PM
02/09/14 06:24 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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.
Re: Add item found by IterateItemsNear [Re: Thoro] #549771
02/09/14 07:18 PM
02/09/14 07:18 PM
Joined: Jul 2014
Posts: 204
Noaloha Offline
enthusiast
Noaloha  Offline
enthusiast

Joined: Jul 2014
Posts: 204
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.
Re: Add item found by IterateItemsNear [Re: Thoro] #549776
02/09/14 08:52 PM
02/09/14 08:52 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
I try to write a script and not a story goal. Maybe that's the catch?

Re: Add item found by IterateItemsNear [Re: Thoro] #549777
02/09/14 09:05 PM
02/09/14 09:05 PM
Joined: Jul 2014
Posts: 459
R
Rhidian Offline
addict
Rhidian  Offline
addict
R

Joined: Jul 2014
Posts: 459
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)

Re: Add item found by IterateItemsNear [Re: Thoro] #549778
02/09/14 09:13 PM
02/09/14 09:13 PM
Joined: Jul 2014
Posts: 204
Noaloha Offline
enthusiast
Noaloha  Offline
enthusiast

Joined: Jul 2014
Posts: 204
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.
Re: Add item found by IterateItemsNear [Re: Thoro] #549779
02/09/14 09:27 PM
02/09/14 09:27 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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

Re: Add item found by IterateItemsNear [Re: Thoro] #549786
02/09/14 11:20 PM
02/09/14 11:20 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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.
Re: Add item found by IterateItemsNear [Re: Thoro] #549789
03/09/14 12:38 AM
03/09/14 12:38 AM
Joined: Aug 2014
Posts: 20
S
Saishy Offline
stranger
Saishy  Offline
stranger
S

Joined: Aug 2014
Posts: 20
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.

Re: Add item found by IterateItemsNear [Re: Saishy] #549988
03/09/14 10:20 AM
03/09/14 10:20 AM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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...

Re: Add item found by IterateItemsNear [Re: Thoro] #550064
03/09/14 02:19 PM
03/09/14 02:19 PM
Joined: Jul 2014
Posts: 204
Noaloha Offline
enthusiast
Noaloha  Offline
enthusiast

Joined: Jul 2014
Posts: 204
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.
Re: Add item found by IterateItemsNear [Re: Thoro] #550076
03/09/14 03:34 PM
03/09/14 03:34 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
Nope, it has the same behaviour with containers.

Re: Add item found by IterateItemsNear [Re: Thoro] #551329
08/09/14 04:37 PM
08/09/14 04:37 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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?

Re: Add item found by IterateItemsNear [Re: Thoro] #551517
09/09/14 04:15 PM
09/09/14 04:15 PM
Joined: Oct 2005
Posts: 67
T
Thoro Offline OP
journeyman
Thoro  Offline OP
journeyman
T

Joined: Oct 2005
Posts: 67
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?


Powered by UBB.threads™ PHP Forum Software 7.6.2