insertItem into inventory?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
[SMUG]Ipecac
Posts: 28
Joined: Tue Oct 21, 2014 5:51 am

insertItem into inventory?

Post by [SMUG]Ipecac »

Hey guys,

I'm trying to spawn an item in my players inventory.

When i do this:

function doThing()
party.party:getChampion(1):insertItem(11,dagger_1.item)
end

it compiles and runs, but nothing...

If I call it (11,dagger.item) or anything other than an actual dagger already placed, it says the item is a nill.

What's up here?
User avatar
jxjxjf
Posts: 33
Joined: Fri Oct 24, 2014 6:26 am

Re: insertItem into inventory?

Post by jxjxjf »

I think your issue is just the index you're using. I guess there are 2 more equipment slots now, so backpack spaces start at 13. 11 should be your champion's "second" left hand.

I just tested it now and it worked, somewhat, although I was having issues with the item occupying both its original position and the new position in inventory until I picked the item up [edit: from either its original position or the new backpack slot]. Also, it would do nothing if there was already an item in that slot, so that could also be your issue.

I know it's not a solution, but hopefully that helps in the right direction. :)
[SMUG]Ipecac
Posts: 28
Joined: Tue Oct 21, 2014 5:51 am

Re: insertItem into inventory?

Post by [SMUG]Ipecac »

jxjxjf you delicious bastard!! It works! Thanks a million!
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: insertItem into inventory?

Post by NutJob »

jxjxjf wrote: I just tested it now and it worked, somewhat, although I was having issues with the item occupying both its original position and the new position in inventory until I picked the item up [edit: from either its original position or the new backpack slot]. Also, it would do nothing if there was already an item in that slot, so that could also be your issue.
My solution was to spawn the item to a 1x1 room (basically not accessible by the party, I call the Trash Room heh) then add it to the characters inventory. When you pick up the item for the first time (in Inventory) the item in the "Trash Room" disappears (being it was the same ID).
TheLegendaryNarwhal
Posts: 12
Joined: Sat Oct 25, 2014 3:26 pm

Re: insertItem into inventory?

Post by TheLegendaryNarwhal »

If backpack spaces start at 13 what are the other spaces designated as? I've tried addItem into 13 and it works fine but things like 12,14 don't seem to do anything.

Edit: Also, and I've posted in a different post about spawning entities about this same thing, how would you addItem into your inventory in the case of something like a pellet_box since they have a count. So instead of just adding a single "pellet_box" to your bag, how would you add 5,10,or 100? Just seems like the only way I can get to the count easily is by placing the entity down and then just modifying that, which is more steps then I really want to go through.
Last edited by TheLegendaryNarwhal on Sun Oct 26, 2014 5:19 am, edited 1 time in total.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: insertItem into inventory?

Post by NutJob »

Can give my script a whirl. I'll be here for a short while longer if you need help.
Post Reply