[Help] Remove torch from holder script?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
chaoscommencer
Posts: 119
Joined: Sun Jan 05, 2014 7:48 pm

Re: [Help] Remove torch from holder script?

Post by chaoscommencer »

Try this on for size:

Code: Select all

function extinguishWallTorches(torchHolders)
	for i = 1, #torchHolders do
		if torchHolders[i].name == "torch_holder" then
			local id, level, x, y, facing = torchHolders[i].id, torchHolders[i].level, torchHolders[i].x, torchHolders[i].y, torchHolders[i].facing
			print(id, x, y, facing)
			torchHolders[i]:destroy()
			spawn("torch_holder", level, x, y, facing, id)
		end
	end
end
Pass a table of torch holders (by id) to the function and it should destroy then recreate the torch holders in the same locations with the same ids as they originally had, effectively extinguishing the wall torches without destroying them or eliminating their fuel. This will help if you have other scripts which might reference a given torch holder by id.

Example usage:

Code: Select all

function pressurePlateTriggered()
	local torchHolders = {torch_holder_1, torch_holder_2, torch_holder_3,}
	script_entity_1.extinguishWallTorches(torchHolders)
end
To truly surprise a player and throw them into complete darkness, you can use the extinguishWallTorches function above in conjunction with the douse torches function by Lmaoboat found here:
viewtopic.php?p=37513#p37513

Hope this helps!
Working on a dungeon that displays a massive collection of assets while sorting them into convenient reusable plugin format (concept from some of leki's mods). Will contribute some of my own models as well eventually and follow that with custom dungeon.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: [Help] Remove torch from holder script?

Post by AdrTru »

Hi,
I create script for managing torches in player inventory, But I have problem with autonatic detection finding items where it is container.
Becouse this torches may be inside containes (normaly sack, wooden crate, motar but in some mods may be creted another).

Known somebody how detect if item is it container?
(All of my ideas ended by crash :) and I thing that pcall() dont worked.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
User avatar
DesperateGames
Posts: 90
Joined: Sun Oct 06, 2013 1:54 pm

Re: [Help] Remove torch from holder script?

Post by DesperateGames »

Hi AdrTru,

the only way I know to do this is to check for the item name. In Vanilla Grimrock there are only 3 container types:

Code: Select all

if item.name == "sack" or item.name == "mortar" or item.name == "wooden_box" then
This should work fine as long as you don't have any additional container type items defined in your mod.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Help] Remove torch from holder script?

Post by JohnWordsworth »

I think you can call item:containedItems() on any item in the inventory (even if it's not a container). If it doesn't contain any items, this will return nil? If this isn't true, I'm more confident that you can call 'getItem(slot)' on any item and it will return nil or an item.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: [Help] Remove torch from holder script?

Post by AdrTru »

Yes, thank you this worked

Code: Select all

function TestContained(container)
  local i
  for i in container:containedItems() do 
    return true
  end
  return false
end
Full working code for destroy all torches from party inventory

Code: Select all

function DestroyTorches()
local count = itemDestroy("torch")
  hudPrint("You feel touch of dark shadow")
  if count > 0 then 
    hudPrint("All "..count.." of your torches is missed.")
  end
end

function TestContainer(container)
local count = 0
local i
for i in container:containedItems() do 
  count = count + 1
end
return count
end

function itemDestroy(thisItem)
local thisPlayer,itemSlot,currItem,Champion
local count = 0
  for thisPlayer=1,4 do
    Champion = party:getChampion(thisPlayer)
    for itemSlot=1,31 do
      if Champion:getItem(itemSlot) ~= nil then 
        currItem = Champion:getItem(itemSlot)
        if currItem.name == thisItem then
          Champion:removeItem(itemSlot)
          count = count + 1
        else
          count = count + TestContained(thisItem,currItem)
        end
      end 
    end
  end
  currItem = getMouseItem()
  if currItem ~= nil and currItem.name == thisItem then
    count = count + 1
    setMouseItem(nil)
  end
  return count
end

function TestContained(thisItem,container)
local count,p,slot = 0,0,0
local citem,i,c
  c = TestContainer(container)
  while ((p<c) or (slot>31)) do
    slot = slot + 1
    citem = container:getItem(slot)
    if citem ~= nil then
      p = p + 1
      if citem.name == thisItem then
        count = count + 1
        container:removeItem(slot)
      else
        count = count + TestContained(thisItem,citem) 
      end
    end
  end
  return count
end

My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
User avatar
Eleven Warrior
Posts: 736
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: [Help] Remove torch from holder script?

Post by Eleven Warrior »

Hi yo

Now that is some impressive Coding AdrTru well done.. :)
Post Reply