Try re-arranging the braces around "if (c.IsTrainer == 1)", like above. As it is, it executes the "Trainer Chat:" message from the if statement correctly, and the curly braces after it will end the if statement, so it sends it regardless of if c.IsTrainer is true. Also using bool instead of int for TrainerFound would be slightly better practice, with either true or false. But that's just nit-picking
Well, you have some funky code in there..
First, item 1. What is TrainerFound supposed to do? You declared it outside the for loop so it seems like some kind of tracker for all items of the for loop. I think your intention was to set it when isTrainer is true but its not working like that. Just use isTrainer and an else block or something.
2. Using isTrainer is nice but it returns a boolean right? is* usually do. Its better practice to either check for true/false and not 1 or 0. Best to leave it off altogether. eg: if (c.isTrainer)
3. This is the only line that will be executed if c is a trainer. I think your intention was to execute the lines within the curly braces below but that will not happen.
4. The curly braces here have no effect. It is not part of the if statement. #3 is but since you left out the curly braces before that, only the next statement is executed and thats it.
5. TrainerFound will never be == 0. Because the curly braces on #4 have no effect, TrainerFound is always set to 1.
6. Why send "No permission ." when there is no message? Tell them no message not no permission..
Anyway, I think this is what you want.. Also, check the params for that Send_MTC_MessageToConnection function. I'm not sure of this but it seems like its all going to whoever sent the MSO, not everyone connected. Maybe something like: InSim.Send_MTC_MessageToConnection("Trainer Chat: " + MSO.Msg, c.UCID, 0);
case "!tr": if (StrMsg.Length > 1) { foreach (clsConnection c in Connections) { if (c.IsTrainer) InSim.Send_MTC_MessageToConnection("Trainer Chat: " + MSO.Msg, MSO.UCID, 0); else InSim.Send_MTC_MessageToConnection("No Permission :).", MSO.UCID, 0); } } else { InSim.Send_MTC_MessageToConnection("What am I going to send?", MSO.UCID, 0); } break;
StrMsg is an array. By setting it to check if it's less than 16, it won't work if there's more than 16 words in the message. If you still have the rest of the MSO code from the cruise tutorial, try changing it to Msg. Msg is a normal string