The online racing simulator
Need help with some case commands
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!!!!");
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=black]System.Threading.[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Thread[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=black].Sleep[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](50000);[/SIZE]
[SIZE=2]InSim.Close();
[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=black]System.Threading.[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Thread[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=black].[/COLOR][COLOR=black]Sleep[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](1000);
[/SIZE]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

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.
#3 - amp88
Quote from Bass-Driver :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.
Quote from Azzano62 :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


Quote : 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
Attached images
!bancommand failure.jpg
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


#6 - PoVo
Quote from Bass-Driver :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
Quote from amp88 :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
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) DELETED by MariusMM
Quote from MariusMM :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)
Quote from Bass-Driver :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).
Quote from amp88 :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

FGED GREDG RDFGDR GSFDG