Return to Inventory

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Xzalander
Posts: 62
Joined: Thu Sep 13, 2012 1:27 pm
Location: Yorkshire, United Kingdom

Return to Inventory

Post by Xzalander »

Komag wrote:Steal an item being held or equiped by a party member
(such as removing the torch from Contar Stoneskull's left hand)

example from petri:
Assuming Contar is the first champion in the party:

Code: Select all

party:getChampion(1):removeItem(7)
7 is the slot number of the left hand, defined in Champion:insertItem()'s documentation.
Just wondering is there anyway to get this code to return the item to the affected characters inventory instead of being deleted?
I plan to use it so that characters can carry torches in their packs and place them, but not carry them in hand so as to avoid the player breaking lighting atmosphere.

Or do I need to use a different type of script?
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Return to Inventory

Post by petri »

Xzalander wrote:Just wondering is there anyway to get this code to return the item to the affected characters inventory instead of being deleted?
Sure there is!
User avatar
Xzalander
Posts: 62
Joined: Thu Sep 13, 2012 1:27 pm
Location: Yorkshire, United Kingdom

Re: Return to Inventory

Post by Xzalander »

Ah found it!

Code: Select all

Champion:insertItem(slot, item)
Inserts an item to an equipment slot. Slot must be one of the following: 1 (head), 2 (torso), 3 (legs), 4 (feet), 5 (cloak), 6 (neck), 7 (left hand), 8 (right hand), 9 (gaunlets), 10 (bracers), 11-31 (backpack slots).
So I could simply remove the item then add the item back again. Completed script coming up for the repository soon!
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Return to Inventory

Post by Montis »

Remember to check for free inventory space and if none is available drop the item to the ground. :)
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
Xzalander
Posts: 62
Joined: Thu Sep 13, 2012 1:27 pm
Location: Yorkshire, United Kingdom

Re: Return to Inventory

Post by Xzalander »

Edit: sussed it.

Why is it that if I name this scripts ID to 'checkInventory' it doesnt work, but if I name it anything else it does?

Code: Select all

function itemCheck(thisItem)
   local thisPlayer = 1
   local itemSlot = 1
   local currItem
   
   for thisPlayer=1,4,1 do
      for itemSlot=7,8,1 do
         if party:getChampion(thisPlayer):getItem(itemSlot) ~= nil then 
            currItem = party:getChampion(thisPlayer):getItem(itemSlot).name
            if currItem == "torch" then
               return true
            end
         end   
      itemSlot = itemSlot + 1
      end
   thisPlayer = thisPlayer + 1      
   end   
end


function checkInventory()
   if itemCheck("torch") then
      print("found it!!")
party:getChampion(1):removeItem(7)
        else
      print("no such item in inventory.")
   end 
end
As a final note I have that working thus far to detect items in left and right hand and if detected to remove it, but it only removes it from the left hand, not the right and only on the character in slot 1.
User avatar
Emciel
Posts: 34
Joined: Fri Sep 14, 2012 2:19 am

Re: Return to Inventory

Post by Emciel »

was just trying to figure out a script for this. got a working removal script, but i can't make the insertItem function work

even just testing

Code: Select all

party:getChampion(2):insertItem(11,"torch")
returns an error

"bad argument #2 to 'insertItem' (Item expected, got ???)

is this a bug? or am i doing something wrong? O.o
User avatar
Xzalander
Posts: 62
Joined: Thu Sep 13, 2012 1:27 pm
Location: Yorkshire, United Kingdom

Re: Return to Inventory

Post by Xzalander »

Emciel, I'm suffering the same and Im not sure either.

My focus right now is trying to get the game to remove torches from -any- person hand not just the slot1character.

Ugh I don't think Im being specific enough in that code either. Axe in left torch in right. Trigger script deletes the axe. My brain is fuzzing up.
User avatar
Emciel
Posts: 34
Joined: Fri Sep 14, 2012 2:19 am

Re: Return to Inventory

Post by Emciel »

the working code i've got for removing the torch is:

Code: Select all

function itemCheck(item)
	for champ = 1,4 do
	for slot = 7,8 do
		x = party:getChampion(champ):getItem(slot)
		if x ~= nil then
		if x.name == item then
                        party:getChampion(champ):removeItem(slot)
			print("item removed")
		end
        end   
	end    
	end   
end

function checkTorch()
  itemCheck("torch")
end
then create a timer which is set to running, and connect it on activate to "checkTorch()".
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Return to Inventory

Post by Montis »

Emciel wrote:was just trying to figure out a script for this. got a working removal script, but i can't make the insertItem function work

even just testing

Code: Select all

party:getChampion(2):insertItem(11,"torch")
returns an error

"bad argument #2 to 'insertItem' (Item expected, got ???)

is this a bug? or am i doing something wrong? O.o
An item is program-wise a function, but you inserted a string.
The code that you posted above should have the item as variable "x", so you could try it with that, after removing the item from slot 7 or 8.

Code: Select all

party:getChampion(champ):insertItem(11,x)
Can't test right now but it might work. If it does, you can implement an additional loop to check for free inventory space as I mentioned above.
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
Xzalander
Posts: 62
Joined: Thu Sep 13, 2012 1:27 pm
Location: Yorkshire, United Kingdom

Re: Return to Inventory

Post by Xzalander »

Emciel I cant get that code to work at all if I tie it to a pressure plate (Doing that so I know when to expect a response from the function).

Infact, I can't even get mine to work now, despite it having worked before saving and reloading.

Edit oh god whats wrong with my brain today! I forgot to set the action to the second function!


EDIT: What I have so far.

Insert an extra for stated as Empty. Now I just need to figure out how to get empty to check for an empty slot instead of using =11,31

Code: Select all

function itemCheck(thisItem)



   for champ = 1,4 do
   for slot = 7,8 do
   for empty = 11,31 do
      x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
      if x.name == "torch" then
                        party:getChampion(champ):removeItem(slot)
  		 party:getChampion(champ):insertItem(empty,x)
         print("item removed") 

      end
        end   
   end
   end    
   end   
end
Post Reply