Can i use someone else's "say" messages to trigger stuff?



  • Hello!

    I have a neighbour who aasked me to turn a rampart into public. However it could be a problem if someone else comes around. He told me that i could also detect his creeps near my ramparts, make them public for a few ticks, and turn them into private after he passes through. The idea of having my ramparts looking for nearby creeps looks heavy to me, in cpu terms, so i thought it would be easier if he could have his creeps saying "Hey!! I need to pass!" and the i could have my rooms just listening to a key message to allow him to pass.

    Is that possible?



  • It really isn't heavy to use Room.find(FIND_HOSTILE_CREEPS)... since it only returns something if there is anything.

    But yes you can use the creep.say(msg, true) (the true makes it public) and the field creep.saying for inter-creep communication but you have to find it anyways xD
    That basically makes the conversation unneccesary.



  • //Note: this function allows allied to pass ONE specific rampart
    function PassAllied(Rampart, Allies) {
        let Pos = Rampart.pos;
        let look = Pos.room.lookForAtArea(LOOK_CREEPS, Pos.x - 1, Pos.y - 1, Pos.x + 1, Pos.y + 1, true);
        let open = look.every(function (result) {
            let isAllied = Allies.some(allied => result.creep.owner == allied);
            return isAllied;
        });
        if (Rampart.isPubilic != open) {
            Rampart.setPublic(open);
        }
    }
    

    Rampart is the Rampart object and Allies is a array containing the allowed users

    Since it is a useful snippet I made it just for you 😏
    Haven't tested it but debuggin is up to you.



  • WTF is his creep doing anyway?
    It just went through your room and did a u-turn immediately after it disappeared into the room to the left 😆



  • @mrfaul hahhaha i don't know what that creeps does, but my neighbour asked me to open the rampart, so i made it public xDD

    Thanksssss a lot for that snippet!! It's just a few lines but i'm reading and reading it, trying to understand everything and how it does.

    Really really appreciate it!!