ItsMods

Full Version: [HELP] pm's message
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Where an error?
The message comes together without blanks
Quote:[PM]: hihowareyou


Code:
//pm's a player with supplied message
        void personalMessage(ServerClient issuer, String message)
        {
            String[] split = message.Split(' ');
            ServerClient target;
            if (!(split.Length > 1))
            {
                TellClient(issuer.ClientNum, "Please provide a receiver", true);
                return;
            }
            else if (!(split.Length > 2))
            {
                TellClient(issuer.ClientNum, "Please provide a message", true);
                return;
            }
            target = findClient(split[1]);
            if (target == null)
            {
                TellClient(issuer.ClientNum, "Player could not be found, or multiple were found", true);
                return;
            }
            else
            {
                String pmessage = "";
                for (int i = 2; i < split.Length; i++)
                {
                    pmessage += split[i];
                }
                TellClient(target.ClientNum, "^1[PM]^2" + issuer.Name + ":^7 " + pmessage, true);
            }
        }
(12-15-2012, 11:51)korsika Wrote: [ -> ]Where an error?
The message comes together without blanks
Quote:[PM]: hihowareyou


Code:
//pm's a player with supplied message
        void personalMessage(ServerClient issuer, String message)
        {
            String[] split = message.Split(' ');
            ServerClient target;
            if (!(split.Length > 1))
            {
                TellClient(issuer.ClientNum, "Please provide a receiver", true);
                return;
            }
            else if (!(split.Length > 2))
            {
                TellClient(issuer.ClientNum, "Please provide a message", true);
                return;
            }
            target = findClient(split[1]);
            if (target == null)
            {
                TellClient(issuer.ClientNum, "Player could not be found, or multiple were found", true);
                return;
            }
            else
            {
                String pmessage = "";
                for (int i = 2; i < split.Length; i++)
                {
                    pmessage += split[i];
                }
                TellClient(target.ClientNum, "^1[PM]^2" + issuer.Name + ":^7 " + pmessage, true);
            }
        }

You are splitting by the blanks => All blanks get "deleted"
So you have to add them again:
Use this:
pmessage += split[i] + " ";
instead of this:
pmessage += split[i];