Author Topic: /lib/sentient.c bugfix  (Read 1323 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
/lib/sentient.c bugfix
« on: March 04, 2012, 01:50:30 PM »
bit of code in eventAsk() prevents NPCs from responding to commands with two words:
Code: [Select]
    if( sscanf(str, "%s %s", cmd, args) != 2 ){
        cmd = str;
        args = 0;
    }
    if( !CommandResponses[cmd] ){
        if( !CommandResponses["default"] ) return 0;
        else if( stringp(CommandResponses["default"]) ){
            eventForce("speak " + CommandResponses["default"]);
            return 1;
        }
        else return evaluate(CommandResponses["default"], who, cmd, args);
    }
    if( stringp(CommandResponses[cmd]) ){
        eventForce("speak " + CommandResponses[cmd]);
        return 1;
    }
    return evaluate(CommandResponses[cmd], who, cmd, args);

if sscanf() is splitting the str, the mapping's key, into components, it will naturally never be able to find that key in the mapping, and will always fail...

change I made was as follows:
Code: [Select]
    if( sscanf(str, "%s %s", cmd, args) != 2 ){
        cmd = str;
        args = 0;
    }
    if( !CommandResponses[str] ){
        if( !CommandResponses["default"] ) return 0;
        else if( stringp(CommandResponses["default"]) ){
            eventForce( CommandResponses["default"] );
            return 1;
        }
        else return evaluate(CommandResponses["default"], who, cmd, args);
    }
    if( stringp(CommandResponses[str]) ){
        eventForce(CommandResponses[str]);
        return 1;
    }
    return evaluate(CommandResponses[str], who, cmd, args);

(also made the mapping values, when strings, themselves the eventForce() rather than just a speech, so that the NPCs can be a little more robust.  can still use 'say xyz' as the mapping value, of course)