Script help request: itemFound activate, else deactivate

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Paul
Posts: 15
Joined: Wed Apr 03, 2013 1:44 am
Location: Detroit, MI

Script help request: itemFound activate, else deactivate

Post by Paul »

Scratching my head reading through the "Check alcove for item thread" and reference scripts. If someone has a minute to look at this script it would be much appreciated. I've tried multiple iterations and only get bits and pieces to work correctly.

Scenario... Using an altar that has custom item already added (power_ore_1), I then activate a particle effect (lightning_ore_1) when the custom object is present and deactivate particle effect when the item is removed. Initial state is the item is already on the altar (using add new item) with particle effect active.

The initial state works, but when the item is removed, the particle effect remains or I can place any item on the altar (torch) and the particle effect activates. I can switch the particle effect off with a connector, but the script should be able to interpret the custom item. I've also tried different altar states (always active, event activate/deactivate/any, etc.)

I also intend to add sound as well, but haven't gotten that far yet. I'm assuming I can just add "playSound ()" after "if itemFound then" and after "else"

Here's the code:

Code: Select all

    function oreCheckno()
       local itemFound = true

       for i in checkOre1:containedItems() do
          if i.name == "power_ore_1" then
             itemFound = true
          end
       end

       if itemFound then
          lightning_ore_1:activate()
       else
          lightning_ore_1:deactivate()
       end
    end
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: Script help request: itemFound activate, else deactivat

Post by Xanathar »

The first line has a typo, it should be:

local itemFound = false

otherwise, seems fine :)

Apart from that, you should likely also check that the alcove has "activate always" checked.
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: Script help request: itemFound activate, else deactivat

Post by Damonya »

power_ore_1 must be the name, not the ID.
lightning_ore_1 must be the ID, not the name

Otherwise, perhaps an other way (not tested):

Code: Select all

    function oreCheckno()
       local itemFound = nil
       for i in checkOre1:containedItems() do
          if i.name == "power_ore_1" then
      itemFound = i.id
    end
  end
  if itemFound ~= nil then
  lightning_ore_1:activate()
       else
          lightning_ore_1:deactivate()
       end
  end
Orwak - MOD - Beta version 1.0
Paul
Posts: 15
Joined: Wed Apr 03, 2013 1:44 am
Location: Detroit, MI

Re: Script help: itemFound activate, else deactivate- SOLVED

Post by Paul »

Thank you Damonya, Xanathar. Working just fine now.

For those looking to use a similar script, the setup went as follows. Hope this helps...

Add Altar, select Altar and choose "Add New Item" option. The item I added was a custom object defined in the "objects" script (see below). Make sure you have the associated model defined in "models" folder. In this case I used a model named power_ore_fbx which was created with GMT and saved in my mod_assets/models folder.

defineObject{
name = "power_ore",
class = "Item",
uiName = "Ore",
model = "mod_assets/models/power_ore.fbx",
lightRange = 6,
lightColor = vec(1, 1, 1),
brightness = 0,
castShadow = true,
particleEffect = "lightning_bolt_greater",
gfxIndex = 96,
weight = 20.0,
}

Then add a connector from the Altar to your Lua script code. Enable the "Always Active" checkbox for the Altar, then Set "Event" to (any). The "Target" should show the (script ID) name that the connector from the Altar is pointing towards. The "Action" should show the function that was defined in the script. In this case it was called oreCheckno() as you can see below.

I'm still experimenting with the effects by trial and error... but making progress. :D

Thanks again! -Paul

Code: Select all

        function oreCheckno()
           local itemFound = nil
           for i in checkOre1:containedItems() do
              if i.name == "power_ore" then
          itemFound = i.id
        end
      end
      if itemFound ~= nil then
      lightning_ore_1:activate()
           else
              lightning_ore_1:deactivate()
           end
      end
Post Reply