View Full Version : Need help with some case commands
Bass-Driver
12th December 2009, 08:08
hi everyone
I'm a Noob in programming but
i'm trying to make a insim Just for practising programming with C#
i have lil problems with 2 case commands
1st
case "!ban":
try
{
if (StrMsg.Length > 2)
{
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
{
int Days = int.Parse(StrMsg[1]);
foreach (clsConnection C in Connections)
{
if (C.Username == Msg.Remove(0,9 + StrMsg[1].Length))
{
InSim.Send_MST_Message("/msg " + C.PlayerName + "^7 is ^1Banned ^7by ");
InSim.Send_MST_Message("/msg " + Connections[GetConnIdx(MSO.UCID)].PlayerName);
InSim.Send_MST_Message("/msg ^7" + Days + "^7 Days");
InSim.Send_MST_Message("/ban " + C.Username + (Days));
}
else
{
InSim.Send_MTC_MessageToConnection("^1User Not Found!!!", (MSO.UCID), 0);
}
}
}
else if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 0)
{
InSim.Send_MTC_MessageToConnection("^3^1U are not an admin", (MSO.UCID), 0);
}
}
}
catch (Exception EX)
{
MessageBox.Show("!BanCommand - " + EX.Message);
}
break;
i get an error
case "!insimrestart":
if (StrMsg.Length >= 1)
{
if (Connections[GetConnIdx(MSO.UCID)].Username == "Bass-Driver")
{
System.Diagnostics.Process.Start("LFS_External_Client.exe");
InSim.Send_MST_Message("/msg ^3^1WARNING ^7Insim Reboot!!!!");
InSim.Send_MST_Message("/msg ^3^7Insim Reboot in 5 Seconds!!!!");
System.Threading.Thread.Sleep(50000);
InSim.Close();
System.Threading.Thread.Sleep(1000);
InSim.Connect();
InSim.Send_MST_Message("/msg ^3^7 Connections: " + Connections.Count);
}
}
break;
System.Threading.Thread.Sleep() doesnt work
is there anyone who can help me
thx
Bass-Driver
Azzano62
12th December 2009, 10:16
Well for the thread sleep just do Thread.Sleep(50000); dont add system threading.
for the ban command try this instead of your code case "!ban":
if (StrMsg.Length > 2)
{
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
{
int Days = int.Parse(StrMsg[1]);
foreach (clsConnection C in Connections)
{
if (C.Username == Msg.Remove(0, 9 + StrMsg[1].Length))
{
InSim.Send_MST_Message("/msg " + C.PlayerName + "^7 is ^1Banned ^7by ");
InSim.Send_MST_Message("/msg " + Connections[GetConnIdx(MSO.UCID)].PlayerName);
InSim.Send_MST_Message("/msg ^7" + Days + "^7 Days");
InSim.Send_MST_Message("/ban " + C.Username + (Days));
}
else
{
InSim.Send_MTC_MessageToConnection("^1User Not Found!!!", (MSO.UCID), 0);
}
}
}
else
{
InSim.Send_MTC_MessageToConnection("^3^1U are not an admin", (MSO.UCID), 0);
}
}
break;
and if that does not work could you tell me what type of error message you get for the ban command.
amp88
12th December 2009, 10:23
hi everyone
I'm a Noob in programming but
i'm trying to make a insim Just for practising programming with C#
i have lil problems with 2 case commands
1st
InSim.Send_MST_Message("/ban " + C.Username + (Days));
i get an error
Looks like you're missing a space here between the player's username and the number of days.
Bass-Driver
12th December 2009, 13:46
Well for the thread sleep just do Thread.Sleep(50000); dont add system threading.
for the ban command try this instead of your code case "!ban":
if (StrMsg.Length > 2)
{
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
{
int Days = int.Parse(StrMsg[1]);
foreach (clsConnection C in Connections)
{
if (C.Username == Msg.Remove(0, 9 + StrMsg[1].Length))
{
InSim.Send_MST_Message("/msg " + C.PlayerName + "^7 is ^1Banned ^7by ");
InSim.Send_MST_Message("/msg " + Connections[GetConnIdx(MSO.UCID)].PlayerName);
InSim.Send_MST_Message("/msg ^7" + Days + "^7 Days");
InSim.Send_MST_Message("/ban " + C.Username + (Days));
}
else
{
InSim.Send_MTC_MessageToConnection("^1User Not Found!!!", (MSO.UCID), 0);
}
}
}
else
{
InSim.Send_MTC_MessageToConnection("^3^1U are not an admin", (MSO.UCID), 0);
}
}
break;
and if that does not work could you tell me what type of error message you get for the ban command.
Doesnt work, still get the same errormessage
Code:
InSim.Send_MST_Message("/ban " + C.Username + (Days));
Looks like you're missing a space here between the player's username and the number of days.
i have removed that line for testing but still get the same error
Error Message ( See Attachment)
Translation:
it says
the lay-out of the inputcharacterline ( or something like that ) is wrong
Bass-Driver
12th December 2009, 14:50
hi
i have fixed the error
Bold thing are changed
int Days = int.Parse(StrMsg[2]);
foreach (clsConnection C in Connections)
{
if (C.Username == Msg.Remove(StrMsg[1].Length))
thx for helping guys
edit
and for Thread.Sleep()
i need to add : using System.Threading statement
but it still doesnt work
PoVo
19th December 2009, 18:29
hi
i have fixed the error
Bold thing are changed
int Days = int.Parse(StrMsg[2]);
foreach (clsConnection C in Connections)
{
if (C.Username == Msg.Remove(StrMsg[1].Length))
thx for helping guys
edit
and for Thread.Sleep()
i need to add : using System.Threading statement
but it still doesnt work
If a username contains a space, this code will not work
Bass-Driver
25th December 2009, 20:20
Looks like you're missing a space here between the player's username and the number of days.
yes the code works but lfs gives an message : This command need 2 parameters.
case "!ban":
if (StrMsg.Length > 2)
{
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
{
int Days = int.Parse(StrMsg[2]);
String UserName = (StrMsg[1]);
foreach (clsConnection C in Connections)
{
if (C.Username == UserName)
{
InSim.Send_MST_Message("/msg ^1^7 " + C.PlayerName + "^7 is ^1Banned,");
InSim.Send_MST_Message("/msg ^3^7by " + Connections[GetConnIdx(MSO.UCID)].PlayerName);
InSim.Send_MST_Message("/ban " + C.Username + Days);
}
}
}
else if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 0)
{
InSim.Send_MTC_MessageToConnection("^1U are not an admin", (MSO.UCID), 0);
}
else
{
InSim.Send_MTC_MessageToConnection("^1Username Not Found", (MSO.UCID), 0);
}
}
else
{
InSim.Send_MTC_MessageToConnection("^1Invalid Command!!", (MSO.UCID), 0);
}
break;
and the code will not work when someone has a space in his/her Username
Bass-Driver
27th December 2009, 10:47
hi i have a lil problem with this code below
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
{
for (int i = 0; i < MSO.UCID; i++)
{
InSim.Send_MST_Message("/spec " + i);
InSim.Send_MTC_MessageToConnection("^3^7ALL PLAYERS ARE SPECTATED", (MSO.UCID), 0);
}
}
break;
it does /spec 1
/spec 2
/spec 3
enc
MariusMM
27th December 2009, 11:59
Well, if you want to spec all, why not just make it easier for yourself, and do something like this:
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
foreach (clsConnection c in Connections)
{
InSim.Send_MST_Message("/spec " + c.Username);
InSim.Send_MTC_MessageToConnection("^3^7ALL PLAYERS ARE SPECTATED", (MSO.UCID), 0);
}
break;
Haven't tested it, but it should work.
Bass-Driver
27th December 2009, 13:12
Well, if you want to spec all, why not just make it easier for yourself, and do something like this:
if (Connections[GetConnIdx(MSO.UCID)].IsAdmin == 1)
foreach (clsConnection c in Connections)
{
InSim.Send_MST_Message("/spec " + c.Username);
InSim.Send_MTC_MessageToConnection("^3^7ALL PLAYERS ARE SPECTATED", (MSO.UCID), 0);
}
break;
Haven't tested it, but it should work.
it works but it says ("^3^7ALL PLAYERS ARE SPECTATED) for each connection
so for 3 players = 3 connections = 3 * ("^3^7ALL PLAYERS ARE SPECTATED)
amp88
27th December 2009, 13:52
it works but it says ("^3^7ALL PLAYERS ARE SPECTATED) for each connection
so for 3 players = 3 connections = 3 * ("^3^7ALL PLAYERS ARE SPECTATED)
If you can't understand why you're getting the message printed 3 times then do you think you should be trying to modify your own InSim application?
The reason why it's being printed is because the following line is within the "for" loop (so it's going to be executed for each connection there is):
InSim.Send_MTC_MessageToConnection("^3^7ALL PLAYERS ARE SPECTATED", (MSO.UCID), 0);
You need to move this command outside of the for loop (after the for loop has executed).
Bass-Driver
27th December 2009, 14:59
If you can't understand why you're getting the message printed 3 times then do you think you should be trying to modify your own InSim application?
The reason why it's being printed is because the following line is within the "for" loop (so it's going to be executed for each connection there is):
InSim.Send_MTC_MessageToConnection("^3^7ALL PLAYERS ARE SPECTATED", (MSO.UCID), 0);
You need to move this command outside of the for loop (after the for loop has executed).
ye ofcourse
stupid me
i did the same when i edit a cruise insim.
thx
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.