Making an Inventory/Equipped Item Disappear

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
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Making an Inventory/Equipped Item Disappear

Post by David Ward »

Something we've put together recently is a spell that spawns a magic weapon that can be equipped, like a magic sword. Thing is, it is supposed to disappear after a certain amount of time, or if that is simply not workable, after a number of uses, but we haven't been able to figure out how to use a timer in this way.

Is there a way to make an item like this disappear after a certain amount of time, whether it is equipped or not?
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Making an Inventory/Equipped Item Disappear

Post by Eburt »

As discussed in this thread this is very difficult due to the possibility of the weapon being in places like in a container. If you can be sure it will be in certain places, it's not so bad... would forcing the party member to keep it equipped until the duration expires be an option? I think that might be doable...
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Making an Inventory/Equipped Item Disappear

Post by cameronC »

Eburt wrote:As discussed in this thread this is very difficult due to the possibility of the weapon being in places like in a container. If you can be sure it will be in certain places, it's not so bad... would forcing the party member to keep it equipped until the duration expires be an option? I think that might be doable...
If that is the largest hurdle then it's pretty doable...
ItemComponent:setFitContainer(boolean) Set whether the item fits inside containers such as sacks or wooden boxes (default true)
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Making an Inventory/Equipped Item Disappear

Post by minmay »

Yep, if you stop it from fitting in containers you only have to:
- store its id, then use FindEntity() to find it if it's on the map
- if that returns nil, it's not on the map so it must be in an inventory; iterate through all champions' slots to find it.
- don't include any ways for it to get into a monster's inventory (you would have to avoid using giant frogs for example) unless you are willing to also iterate through all monster inventories
You do need to worry about the implications of destroying the item while it's in a SocketComponent or SurfaceComponent; it will trigger onRemoveItem connectors for example.
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
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Making an Inventory/Equipped Item Disappear

Post by David Ward »

Thank you all for the input. Looking into it now~
Post Reply