ItsMods
[HELP] pm's message - Printable Version

+- ItsMods (https://www.itsmods.com)
+-- Forum: Archive (https://www.itsmods.com/Forum-Archive.html)
+--- Forum: Archive (https://www.itsmods.com/Forum-Archive--64.html)
+--- Thread: [HELP] pm's message (/Thread-HELP-pm-s-message.html)



[HELP] pm's message - korsika - 12-15-2012

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); } }



RE: [HELP] pm's message - Ich1994 - 12-15-2012

(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];