1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Guest, PO has ceased our separate tiering and adopted Smogon tiers for SM. More information and updates here.

    Dismiss Notice

[Client Scripting] afterChannelMessage problem

Discussion in 'Server and Client Scripting' started by SongSing, Jun 24, 2013.

  1. SongSing

    SongSing KILLL

    Joined:
    Jan 2, 2013
    Messages:
    641
    Likes Received:
    191
    PO Trainer Name:
    SongSing
    Hi. I was wondering how to send a message whenever someone said a specific phrase (sortof like what waehofen does... lol)

    I thought:

    Code (text):
    1.  
    2. ({
    3.     afterChannelMessage: function(message, channel, html) {
    4.     if (message == "abc") {
    5.         client.network().sendChanMessage(channel, "def");
    6.     }  
    7. }
    8. });
    9.  
    would work, but it doesn't seem to. Any idea what I'm doing wrong? :c
     
  2. Crystal Moogle

    Crystal Moogle Ayaya~

    Joined:
    Jul 19, 2010
    Messages:
    3,204
    Likes Received:
    530
    PO Trainer Name:
    Hanako
    Because the message isn't "abc", it's "Playername: abc". Message includes the player's name as well, you'll have to remove that part.
     
  3. SongSing

    SongSing KILLL

    Joined:
    Jan 2, 2013
    Messages:
    641
    Likes Received:
    191
    PO Trainer Name:
    SongSing
    Oh, I didn't realize that. So to get the message could I just do like, message.split(':')[1]?
     
    Last edited: Jun 24, 2013
  4. Wanderer M

    Wanderer M Dancer

    Joined:
    Sep 14, 2011
    Messages:
    36
    Likes Received:
    0
    PO Trainer Name:
    Wanderer M
    If I'd say 'There are three great things on this planet: life, water and me', then message.split(":")[1] would return just ' There are three great things on this planet'.

    Better would it be to use:
    Code (text):
    1. variable = message.split(":");
    2. variable.splice(0,1);
    3. variable = variable.join(":");
    where .splice(0,1) removes the first item from an array, and .join(":") adds the items in the array back together with a : between them.
     
  5. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    You're wrong. Arrays start at 0, so it would return "life, water and me".

    @SongSing: if (message.indexOf(':') >= 0) { message = message.substr(message.indexOf(':') + 2); }
     
  6. Wanderer M

    Wanderer M Dancer

    Joined:
    Sep 14, 2011
    Messages:
    36
    Likes Received:
    0
    PO Trainer Name:
    Wanderer M
    I said "If I'd say ...", therefore, the variable message would be Wanderer M: There are three great things on this planet: life, water and me. That means message.split(":")[1] would return ' There are three great things on this planet'.
     
  7. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    oh, right :x
     
  8. SongSing

    SongSing KILLL

    Joined:
    Jan 2, 2013
    Messages:
    641
    Likes Received:
    191
    PO Trainer Name:
    SongSing
    Okay, I think I'll use coyo's method. I dunno how I didn't think of that lol.
     
  9. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    I don't know if this thread still needs help but. This is what I use, but I have it under beforeChannelMessage, but should work exactly the same in afterChannelMessage unless ya need to sys.stopEvent() for something:
    Code (JavaScript):
    1. var vUserSentName = message.substring(0, message.indexOf(':'));
    2. var vUserSentMessage = message.substr(message.indexOf(':') + 2);
    Now ya can simply:
    Code (JavaScript):
    1. if (vUserSentMessage === "trigger") {
    2.     client.network().sendChanMessage(channel, "Hello.");
    3.     }
     
  10. SongSing

    SongSing KILLL

    Joined:
    Jan 2, 2013
    Messages:
    641
    Likes Received:
    191
    PO Trainer Name:
    SongSing
    yea
     
    Fuzzysqurl likes this.