Page 1 of 1

/announcement (CPE Required For Clients)

PostPosted: 17 Jul 2014, 19:01
by AFK_Games
This code only works with versions of classicube that support CPE MessageTypes, enjoy:

Code: Select all
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace MCDzienny
{
    public class CmdAnnouncement: Command
    {
        public override string name { get { return "announcement"; } }
        public override string shortcut { get { return "an"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
        public override void Use(Player p, string message)
        {
            Player.players.ForEachSync(pl =>
            {
                if (pl.Cpe.MessageTypes == 1)
                {
                    pl.SendMessage(Cpe.V1.Announcement, message);
                    return;
                }
                else
                {
                    Player.SendMessage(p, "Player's client does not support CPE MessageTypes.");
                }
            });
           
        }
       
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/announcement - Generate a global server announcement.");
        }
    }
}

Re: /announcement (CPE Required For Clients)

PostPosted: 19 Jul 2014, 07:14
by Leeizazombie
Not bad <ok>

By the way when you use:
Code: Select all
else
                {
                    Player.SendMessage(p, "Player's client does not support CPE MessageTypes.");
                }

There's no real need to send that message to every other user is there? I mean it would cause confusion! :P

Also there's no need to use a return statement inside an if > else block, because even if the player supports CPE, he/she will not receive the message from the else block because that part was not returned true.

Re: /announcement (CPE Required For Clients)

PostPosted: 01 Aug 2014, 14:27
by AFK_Games
Sorry, I made 1 mistake with the command at the start, and to cheer lee up I have fixed the else part :D

Code: Select all
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace MCDzienny
{
    public class CmdAnnouncement : Command
    {
        public override string name { get { return "announcement"; } }
        public override string shortcut { get { return "an"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
        public override void Use(Player p, string message)
        {
            Player.players.ForEachSync(pl =>
            {
                if (pl.Cpe.MessageTypes == 1)
                {
                    pl.SendMessage(Cpe.V1.Announcement, message);
                    return;
                }
            });
           
        }
       
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/announcement - Generate a global server announcement.");
        }
    }
}

Re: /announcement (CPE Required For Clients)

PostPosted: 02 Aug 2014, 18:13
by HETAL
@LeeIzaZombie He didn't send it to all players, he foreached pl but used p when sending the message..

Re: /announcement (CPE Required For Clients)

PostPosted: 03 Aug 2014, 08:03
by _Retaliate_
So basically it would spam whoever used the command every time the command found someone who didn't support cpe

Re: /announcement (CPE Required For Clients)

PostPosted: 25 Aug 2014, 03:30
by AndrewPH
It's also worth noting that the announcement messages are one of the few CPE things that can be sent to people who don't have CPE.

It'll just show up as a normal message if they don't support the extension.