Quest's "Take" Script

Forgewright
23 Dec 2018, 03:58I wanted to be able to look at and at least try to take an object carried by an NPC or monster.
(it also requires the NPC or monster to be an open and transparent container in said object's feature menu)
I added the third and fourth line to Quest's "take" command after copying it.
took_something = false
foreach (obj, object) {
if (obj.parent.dead = false) {
msg ("I don't think "+ obj.parent.prefix + " " + obj.parent.alias + " is willing to to give it up.")
}
else if (not multiple or (not Contains(game.pov, obj.parent) and not DoesInherit(obj.parent, "npc_type"))) {
DoTake (obj, multiple)
took_something = true
}
// if this is multiple then we should skip anything in a container that has already been taken
// (always earlier in the list) and anything held by an NPC .
// Scenery and anything flagged "not_all" will already be excluded
}
if (multiple and not took_something) {
msg ("Nothing here to take.")
}
Anybody foresee any grief off the top of their head?
or
A better way to do it?
đź‘€

Dcoder
24 Dec 2018, 01:25It would be easier (and less messy) to just add the NPC/monsters to the scope of your take command.
mrangel
24 Dec 2018, 11:21I think it's possible to do this without modifying any functions.
Give each NPC an attribute Dave.transparent = true
.
When he's killed, set Dave.isopen = true
.
And modify the message for trying to take an item out of a closed container:
<dynamictemplate name="ObjectNotOpen">CapFirst(GetDisplayAlias(object)) + " " + Conjugate(object, "be") + " not {either Equal("+object.name+".dead, false):willing to give it up:open}."</dynamictemplate>
.
That's off the top of my head, but I think it should work.
Basically just turns the NPC into a transparent container, and changes the "Is not open" message depending if the object has a dead
attribute.

Forgewright
24 Dec 2018, 12:48I am wanting the player to be able to look at and try and take objects carried by living npc and monsters. Not just when they are dead. They may or may not be able to take the items but should always be able to look at them.
mrangel
24 Dec 2018, 14:52That's why I suggested making the NPCs transparent containers; the player can always look at an object, but whether they can take it depends on the NPC's isopen
attribute.
I'm sure there's a way to get it to behave as you want while only modifying the dynamic template; though might need a combination of code and text processor markup. Actually… I think the one I posted above should work. If the container is a living NPC, it says "Dave is not willing to give it up."; otherwise it says "The wardrobe is not open.". And if the NPC's isopen
attribute is true, you can take items out of them.
XanMag
24 Dec 2018, 15:09You don’t want to hear my answer, but... here it is.
I’d use an IF script to describe the NPC differently. I’d just put the object the NPC is carrying in the room. If the object is visible and you try to take it, print message saying NPC won’t give it up. If object isn’t visible, print message “I’m not sure where you’re looking, but I don’t see that here.” (Or something like that)
It’s clumsy, but it works. I do it all the time. Good luck.

Forgewright
25 Dec 2018, 00:30mrangel said:
That's why I suggested making the NPCs transparent containers; the player can always look at an object, but whether they can take it depends on the NPC's isopen attribute.
Had the transparent part. The isopen
is what I was looking for!
Thanks mrangel
Xanmag, That is something I have done also. I run into issues if the player is allowed to take the object and then drops it. Not anything I couldn't fix mind you. Just more work. Hopefully mrangel's way doesn't produce issues down the road also.
Thanks for the input!