SOLVED - item check script

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

SOLVED - item check script

Post by Drakkan »

If somebody will have some time to help me with this one I will definitely credit him :)

1. I have button (button1) opening door (door1). When pushed, party is killed by ton of spawned fireballs.
2. There are 4 items (lets call them Orb1-Orb4)
3. What i need script to do, is if you have all 4 orbs (idealy each member of party should have one, but if that would be too much complicated one inventory is fine) party is not killed after pushing button, but instead get teleported
Last edited by Drakkan on Fri Jan 11, 2013 11:44 pm, edited 1 time in total.
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: item check script help pls

Post by Komag »

that's definitely doable and not too much more complex to require they each have one separately. check the script repository for some example "search/check inventory for an item" scripts, then it's just a couple more steps to check for four and require one each champion
Finished Dungeons - complete mods to play
hyteria
Posts: 266
Joined: Sat Dec 29, 2012 8:22 pm

Re: item check script help pls

Post by hyteria »

what do you mean by doable?
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: item check script help pls

Post by Neikun »

doable->do-able->Can be done
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: item check script help pls

Post by Drakkan »

ok spent about one hour with it, but at the end its woriking how I wanted. Perhaps solution is not the best one, but does not matter, it is working :d

I have set counter for 4 and button connect to checkOrb function. When every character has orb in its hand, teleport is activated and party escape. if not fireball kill all.

Code: Select all

function itemCheck(item)
   -- checks for the item in champions hands
   for champ = 1,2 do
   for slot = 7,8 do
      x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
      if x.name == item then
      orbcounter:decrease ()
      end
        end   
   end   
   end   
end


function itemCheck(item)
   -- checks for the item in champions hands
   for champ = 1,2 do
   for slot = 7,8 do
      x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
      if x.name == item then
      orbcounter:decrement ()
      end
        end   
   end   
   end   
end


function itemCheck(item)
   -- checks for the item in champions hands
   for champ = 3,4 do
   for slot = 7,8 do
      x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
      if x.name == item then
      orbcounter:decrement ()
      end
        end   
   end   
   end   
end

function itemCheck(item)
   -- checks for the item in champions hands
   for champ = 3,4 do
   for slot = 7,8 do
      x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
      if x.name == item then
      orbcounter:decrement ()
      end
        end   
   end   
   end   
end

function checkOrb()
   itemCheck("water_orb")
end
Breath from the unpromising waters.
Eye of the Atlantis
hyteria
Posts: 266
Joined: Sat Dec 29, 2012 8:22 pm

Re: item check script help pls

Post by hyteria »

thx neikun )
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: item check script help pls

Post by Komag »

Why do you have so many repetitions? You can only have one function of the same name, you probably want:
for champ = 1,4 do

Also, if only one person has one but you press the button four times, it will trigger the counter, so you probably should reset the counter at the start of the function so that it has to be all at once:

Code: Select all

function itemCheck(item)
  orbcounter:reset()
  for champ = 1,4 do
    for slot = 7,8 do
      local x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
        if x.name == item then
          orbcounter:decrement()
        end
      end
    end
  end
end
Finished Dungeons - complete mods to play
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

SOLVED item check script

Post by Drakkan »

Komag wrote:Why do you have so many repetitions? You can only have one function of the same name, you probably want:
for champ = 1,4 do

Also, if only one person has one but you press the button four times, it will trigger the counter, so you probably should reset the counter at the start of the function so that it has to be all at once:

Code: Select all

function itemCheck(item)
  orbcounter:reset()
  for champ = 1,4 do
    for slot = 7,8 do
      local x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
        if x.name == item then
          orbcounter:decrement()
        end
      end
    end
  end
end
wonderfull thanks, will use this one.
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply