Add item to alcove

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
User avatar
Kuro01
Posts: 36
Joined: Tue Jun 23, 2015 2:05 pm

Add item to alcove

Post by Kuro01 »

Hello, I'm trying to spawn an item(key) on and alcove or an altar after triggered by lever. Can someone help.
What I got so far but not sure what else to add.

Code: Select all

function gearkey()
   spawn("gear_key",1,0,0,0,0,"test")
end   
or

function gearkey()
addItem:ledgerack_3("gear_key",3,7,1,0,0,"test")
end
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Add item to alcove

Post by minmay »

1. Your method call syntax is backwards: the function goes on the right side, and the table it belongs to goes on the left side. http://www.lua.org/manual/5.2/manual.html Also, the addItem function belongs to the SurfaceComponent, not the GameObject.
2. You need to actually spawn the gear key, and pass its ItemComponent to SurfaceComponent:addItem().
3. There is no need to add the gear key to the map yourself if you are going to put it on a surface anyway.

This is what you wanted:

Code: Select all

function gearkey()
  ledgerack_3.surface:addItem(spawn("gear_key",nil,nil,nil,nil,nil,"test").item)
end
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Kuro01
Posts: 36
Joined: Tue Jun 23, 2015 2:05 pm

Re: Add item to alcove

Post by Kuro01 »

Thanks
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Add item to alcove

Post by Azel »

Kuro01 wrote:Hello, I'm trying to spawn an item(key) on and alcove or an altar after triggered by lever. Can someone help.
What I got so far but not sure what else to add.

Code: Select all

function gearkey()
   spawn("gear_key",1,0,0,0,0,"test")
end   
or

function gearkey()
addItem:ledgerack_3("gear_key",3,7,1,0,0,"test")
end
I like to cheat with stuff like this. I will use the Editor to place the gear key inside of the Alcove, and simply "hide" it using the regular user interface by "unchecking" the ITEM and MODEL properties. Then, when a lever/button/trigger is activated, I have a Counter that decrements from 0 to 1, and onActivate of the counter, simply call a basic function:

function ShowGearKey()

gear_key_1.item:enable()
gear_key_1.model:enable()

end

I did this with a secret note; I assume it would work for a key :?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Add item to alcove

Post by minmay »

don't do that, it will mess up anything that checks the alcove's contents
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Add item to alcove

Post by Azel »

minmay wrote:don't do that, it will mess up anything that checks the alcove's contents
Not true. Just exclude the hidden item during the contents loop check.

I allow a user to enter a gem in to the Alcove, and when a lever is pulled, the gem is removed and a hidden note is revealed. The user can place their entire armor and weapon set in the Alcove if they like, nothing "messes up."
User avatar
Kuro01
Posts: 36
Joined: Tue Jun 23, 2015 2:05 pm

Re: Add item to alcove

Post by Kuro01 »

Hey me again, I got the item to spawn the way i want on the ledge but having trouble using a combination alcove thing. I have 4 alcoves, I want 3 of them with items on surface and 1 of them without to spawn the key. I been trying these but I get errors. How would i set the ledge connector if no toggle available.Is it both insert and remove, decrement andincrement?

Code: Select all

function checkAlcove()
    if hunger_ledge_alcove_1a.surface:isActivated() and 
       hunger_ledge_alcove_2a.surface:isActivated() and
       hunger_ledge_alcove_3a.surface:isActivated() and not
       hunger_ledge_alcove_4a.surface:isActivated() then

       hunger_ledge_alcove_1a.surface:addItem(spawn("gear_key",3,7,1,0,1,"test").item)
    end
end
another

Code: Select all

function checkAlcove()
 if hunger_ledge_alcove_1a.surface:getValue() == 1 and
 hunger_ledge_alcove_1a.surface:getValue() == 0 and
 hunger_ledge_alcove_1a.surface:getValue() == 0 and
 hunger_ledge_alcove_1a.surface:getValue() == 0 then

 hunger_ledge_alcove_1a.surface:addItem(spawn("gear_key",3,7,1,0,1,"test").item)
    end
end
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Add item to alcove

Post by Azel »

Hi Kuro,

I made you a dungeon that lets you put items in any 3 Alcoves, and the 4th Alcove will spawn the Gear Key if it is empty.

I put the entire dungeon file on my Mod Website: http://mystrock.com/files/Alcoves.zip

It is a perfectly safe download; I have a few other dungeon files that I share from that location :D

I'm going to link this Alcoves dungeon file in Eleven Warriors Modding thread as well. If anyone else has any fun Alcove requests then let me know and I can try to add them.
User avatar
Kuro01
Posts: 36
Joined: Tue Jun 23, 2015 2:05 pm

Re: Add item to alcove

Post by Kuro01 »

Thanks, Can I get the adress to your mod page, curiouse
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Add item to alcove

Post by Azel »

Mod info is on the main site: http://www.mystrock.com

Currently only a Demo is available. The full version will be released in about 5 weeks (at the end of September).

Steam download: http://steamcommunity.com/sharedfiles/f ... =369773173
Nexus Download: http://www.nexusmods.com/legendofgrimrock2/mods/31/?
Direct Download: http://www.mystrock.com/files/pathdemo/ ... elease.zip

This is my first Mod, but the feedback has been quite good so far :mrgreen:
Post Reply