Returning false on PlayerMessage doesn't suppress the message

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761
I tried the following code to test something:
Code: [Select]
SqCore.On().PlayerMessage.Connect(function (player, message)
{
    return false;
});

But it doesn't suppress the message. In the official plugin, this would successfully suppress a message:
Code: [Select]
function onPlayerMessage(player, text)
{
    return false;
}

KAKAN

  • Wiki Contributor
  • Posts: 3,346
Re: Returning false on PlayerMessage doesn't suppress the message
« Reply #1, on May 2nd, 2017, 05:25 PM »
That's because they're so called "Signals". In the official plugin, you get only 1 call, but in SLC's plugin, you can have as many callbacks of the function as you want.
I think there's another way to block it, dunno for sure.

in case you're wondering what the first line meant:
Code: [Select]
SqCore.On().PlayerMessage.Connect(function (player, message)
{
    print("A");
});
SqCore.On().PlayerMessage.Connect(function (player, message)
{
    print("B");
});

Code: [Select]
function onPlayerMessage(player, text)
{
    print("A");
}
function onPlayerMessage(player, text)
{
    print("B");
}
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761
Re: Returning false on PlayerMessage doesn't suppress the message
« Reply #2, on May 2nd, 2017, 05:27 PM »
Quote from KAKAN on May 2nd, 2017, 05:25 PM
That's because they're so called "Signals". In the official plugin, you get only 1 call, but in SLC's plugin, you can have as many callbacks of the function as you want.
I think there's another way to block it, dunno for sure.

in case you're wondering what the first line meant:
Code: [Select]
SqCore.On().PlayerMessage.Connect(function (player, message)
{
    print("A");
});
SqCore.On().PlayerMessage.Connect(function (player, message)
{
    print("B");
});

Code: [Select]
function onPlayerMessage(player, text)
{
    print("A");
}
function onPlayerMessage(player, text)
{
    print("B");
}
I knew all that. Now, how does that help me solve my question?
Re: Returning false on PlayerMessage doesn't suppress the message
« Reply #3, on May 2nd, 2017, 06:58 PM »
Solved:
Code: [Select]
SqCore.On().PlayerMessage.Connect(function (player, message)
{
    SqBroadcast._Message("[#33CC33]User   [#FFFFFF]| [#" + format("%02X%02X%02X", player.Color.r, player.Color.g, player.Color.b) + "]" + player.Name + "[#FFFFFF]: " + message);
   
    SqCore.SetState(0);
});
Browsing through the source isn't all that easy...