Preventing Objects From Being Placed In Containers

Darkweaver
24 Sept 2014, 19:52
Pretty much what the title says. I want certain containers (not all of them) to not be able to have items placed in them.

For example, I have a pedestal that you can open to reveal a book. However, you can place your sword in there which obviously, a sword wouldn't fit inside a pedestal, nor would most of the items the character carries. So, I want to prevent the player from putting any items inside the pedestal.

I'm very new and I know next to nothing about coding. I "script" using the GUI (I'm just now learning the "if" this is like this "then" this happens, etc) so any help would be much grateful!

jaynabonne
24 Sept 2014, 20:37
You can use "limited containers" to do it:

Click on the game object and then its Features tab. Then make sure "Inventory limits: limit items that can be carried or contained by specifying a volume" is checked.

Then click on your pedestal object. On its Container tab, set the Container Type to "Limited Container". Set the maximum number of objects to 0. If you want it to say something specific when someone tries to put on object on the pedestal (e.g. You can't put things here.), put that text in the "Full container message" field.

That should do it! You can put objects in the container yourself either in the game setup or programmatically. But the player can't via the "put in/on" command.

Darkweaver
24 Sept 2014, 20:42
Much, much thanks! I got it to work!

I downloaded your code and got it to work before you edited your post but I will try that too! Thank you.

jaynabonne
24 Sept 2014, 20:48
I wasn't fast enough. :) I think the limited container is easier to go with, but feel free to try the other if you wish.

Darkweaver
24 Sept 2014, 20:58
jaynabonne wrote:I wasn't fast enough. :) I think the limited container is easier to go with, but feel free to try the other if you wish.

One more pesterous question.

Let's say I have a bag that devours objects (yes cruel, but I don't.... yet :twisted:) and I wanted objects put in them to disappear or if the player places an object inside, something bad happens (like the bag pulls the player in and kills them lol)

So, I figure I got to Verbs tab and use the Place or Put In but they're not on the pull down list. Now I know you can use Place or Put In when playing the game but for some reason, those Verbs do not appear on the list. Otherwise, I figure it's something like Put In or Place and then Remove Object and Print Message.

I'll try and have this be my last question of the day. :oops:

jaynabonne
24 Sept 2014, 21:59
The problem is that "put X in/on Y" is a command, not a verb. So it's not handled via the verb mechanism.

The solution gets back to the code I had posted before but removed. A container can have an "addscript" attribute, which is a script called when an object is added to the container (put in/on). Unfortunately, it's not a script - it's something called a "delegate", which is sort of like a script with extra information added that makes it almost like a function. Probably more than you need to know, but the downside of delegates is that you can't edit them in the GUI. The delegate type for this attribute is "AddScript".

So if you had this attribute in your object:

    <addscript type="AddScript">
msg ("You can't put things here.")
</addscript>

then it would print out that message instead of adding to the container. If instead, you had:

    <addscript type="AddScript">
msg ("The object is vaporized! Bwa ha ha ha!")
object.parent = null
</addscript>

then the object would disappear along with a sinister message.

But you'd have to edit this all in code view, which might be a bit much. If you can let me know the behaviors, I could create a library with some types with the right delegate implementations that you could derive your special containers from. Inheritance you can do easily in the GUI. :)

jaynabonne
24 Sept 2014, 22:09
Actually, there's another way to do it...

If the container is limited to a room (e.g. you can't pick it up and move it around), then you can create a custom command in the room where the container is. It's pattern would be like "put #object# in incinerator". And then the script would just do whatever you want. Commands in rooms take precedence (as far as I know) over general commands - that's worth a try, btw, to verify... (sorry, it's late. I'm not totally coherent).

It might be something else to try. Then you could code the script yourself.

Darkweaver
24 Sept 2014, 23:11
jaynabonne wrote:Actually, there's another way to do it...

If the container is limited to a room (e.g. you can't pick it up and move it around), then you can create a custom command in the room where the container is. It's pattern would be like "put #object# in incinerator". And then the script would just do whatever you want. Commands in rooms take precedence (as far as I know) over general commands - that's worth a try, btw, to verify... (sorry, it's late. I'm not totally coherent).

It might be something else to try. Then you could code the script yourself.

Thanks.

All the containers I am referring to would be in the room (not being able to be taken by the player) like a book shelf or a swirling black hole of death on the floor. Not sure where or how I would place the code you mention in the room, although.

Sorry if I'm very dense. I'm a slow learner and I'm only starting to play with the "IF" and "ELSE IF" with things right now.

Dave Lebling I am not.