Requesting items from NPCs

hey,
i’m trying to get an NPC to give me an item they’re carrying, using a command like tim, give me the phone.
i know that i can use the ask for syntax with an appropriate topic object, but i’d also like this alternative to work.
so far i’m stumped, and always end up with Tim does not respond (having set obeyCommand to always return true).
any ideas?

collin

I’m assuming you are using adv3Lite, as you shouldn’t be having this problem in adv3.

Eric Eve, a very long time ago, made an extension for adv3 called TCommand, which he incorporated into adv3Lite. Included with that extension was code to convert X, Give Me Y to Ask X for Y. Below is the code that came with that extension, with only the include lines changed.

#charset "us-ascii"
#include <tads.h>
#include "advlite.h"

/* Converts X, GIVE ME Y into ASK X FOR Y */

StringPreParser
    runOrder = 90
    
    doParsing(str, which)
    {
        local workStr = str.toLower;
        local iGive = workStr.find('give');
        if(iGive == nil)
            return str;
        
        local iComma = workStr.find(',');
        local iGiveMe = workStr.find('give me');        
        local iToMe = workStr.find('to me');
        local objectName; 
        
        if(iComma == nil || (iGiveMe == nil && iToMe == nil))
            return str;
        
        local npcName = workStr.substr(1, iComma-1);        
        
        if(iGiveMe)    
            objectName = workStr.substr(iGiveMe + 8);
        else
        {
            
            if(iGive == nil || iGive > iToMe || iGive < iComma)
                return str;
            
            objectName = workStr.substr(iGive + 5, iToMe - iGive - 6);
        }
        
        str = 'ask ' + npcName + ' for ' + objectName;
        
        str = rexReplace(pat, str, npcName + '\'s', ReplaceAll); 
        
        return str;
    }

    pat = static new RexPattern('%<your%>')
;

This should work as long as the player refers to themself as me in the command.

1 Like

hey david,
i actually am using adv3, and not adv3lite. and i’m also using TCommand, which is the reason that i’m a bit embarrassed about having forgotten about the code you posted, which i just recently went over again.
so this of course works. now my question is, should it have also worked beforehand, as you yourself think it should?

thanks for your reply!

Adv3 has a feature called Global Remapping that allows you to remap a command before the parser has decided the items in the command. The only defined global remap in the library is a GiveTo TO AskFor remapper [actions.t Line:2174].

That remap makes it so BOB, GIVE ME THE GUN will be seen as if ASK BOB FOR THE GUN was typed instead. Meaning you only need to code for the AskFor version of the command. If you have code for both commands, try removing the GiveTo code.

adv3Lite doesn’t appear to have a remap for this command so that is why I assumed you were using Lite.