The online racing simulator
Help me please !
Hello i have this code


foreach(clsConn Conn in Connections)
{
// Pit EXIT
if (pathx >= -27 && pathx <= -24 && pathy >= 65 && pathy <= 67)
{
if (Conn.ExitZone == 0)
{
if (direction > 330 || direction < 20)
{
MessageToAll(_players[car.PLID].PName + " was fined ^1€500 ^7for wrong exit");
Conn.Cash -= 500;
Conn.ExitZone = 1;
}
if (Conn.ExitZone == 1)
{
MessageToUCID(_players[car.PLID].UCID, " ^1!!! Next time you will be kicked ^1!!!");
}
}
else // (Conn.ExitZone == 2)
{
SpecID(_players[car.PLID].PName);
}
}
else
{
if (Conn.ExitZone == 1)
{
Conn.ExitZone = 0;
}
}
}

..well, the code works but no how i want. When i go to wrong exit insim send messages 3 times

"plyerName" was fined $800 for wrong exit
!!! Next time you will be kicked !!!
"plyerName" was fined $800 for wrong exit
!!! Next time you will be kicked !!!
"plyerName" was fined $800 for wrong exit
!!! Next time you will be kicked !!!

I will be happy if someone want to help me Smile

EDIT: insim send messages 3 times becuse on server is 2 conn + host
Is the direction from a connection? It looks like some kind of global variable now.

And pathy and pathx as well?
Oh yeah, i forgot that

foreach (CompCar car in MCI.Info)
{
Players NPL;
if (_players.TryGetValue(car.PLID, out NPL))
{
var pathx = car.X / 196608;
var pathy = car.Y / 196608;
var direction = car.Direction / 180;
}

foreach(clsConn Conn in Connections)
{
// Pit EXIT
if (pathx >= -27 && pathx <= -24 && pathy >= 65 && pathy <= 67)
{
if (Conn.ExitZone == 0)
{
if (direction > 330 || direction < 20)
{
MessageToAll(_players[car.PLID].PName + " was fined ^1€500 ^7for wrong exit");
Conn.Cash -= 500;
Conn.ExitZone = 1;
}
if (Conn.ExitZone == 1)
{
MessageToUCID(_players[car.PLID].UCID, " ^1!!! Next time you will be kicked ^1!!!");
}
}
else // (Conn.ExitZone == 2)
{
SpecID(_players[car.PLID].PName);
}
}
else
{
if (Conn.ExitZone == 1)
{
Conn.ExitZone = 0;
}
}
}
}

It's been a while since I've done an InSim app with things like this, but it doesn't sound logical that you have the foreach for the connections in the CompCar plugin. Aren't you now handling something for all connections at every car update? I don't think that will be fast in terms of performance with a lot of people in the server.

Anyway, the things you now run shouldn't be in the second (Connections) loop I think. From the top of my head you can define a connection on the hand of the car, right? Maybe you can try that.
#6 - heawy
// MCI Update
private void MCI_Update(int PLID)
{
try
{
#region ' UniqueID Loader '
int IDX = -1;
for (int i = 0; i < Connections.Count; i++)
{
if (Connections[i].PlayerID == PLID)
{
IDX = i;
break;
}
}
if (IDX == -1)
return;

clsConnection Conn = Connections[IDX];
clsConnection ChaseCon = Connections[GetConnIdx(Connections[IDX].Chasee)];
clsConnection TowCon = Connections[GetConnIdx(Connections[IDX].Towee)];
#endregion

#region ' Cruise '

decimal SpeedMS = (decimal)(((Conn.CompCar.Speed / 32768f) * 100f) / 2);
decimal Speed = (decimal)((Conn.CompCar.Speed * (100f / 32768f)) * 3.6f);

Conn.TotalDistance += Convert.ToInt32(SpeedMS);
Conn.TripMeter += Convert.ToInt32(SpeedMS);
Conn.BonusDistance += Convert.ToInt32(SpeedMS);
Conn.HealthDist += Convert.ToInt32(SpeedMS);
Conn.UpgradeLicence += Convert.ToInt32(SpeedMS);

#endregion

#region ' CompCar Details '

var kmh = Conn.CompCar.Speed / 91;
var mph = Conn.CompCar.Speed / 146;
var direction = Conn.CompCar.Direction / 180;

var node = Conn.CompCar.Node;
var pathx = Conn.CompCar.X / 196608;
var pathy = Conn.CompCar.Y / 196608;
var pathz = Conn.CompCar.Z / 98304;
var angle = Conn.CompCar.AngVel / 30;
string Car = Conn.CurrentCar;



#endregion

#region ' Track B '

switch (TrackName)
{
case "BL1":

#region ' Wrong Exit fines '

{
// Pit EXIT
if (pathx >= -27 && pathx <= -24 && pathy >= 65 && pathy <= 67)
{
if (Conn.ExitZone == 0)
{
if ((!Conn.IsOfficer || !Conn.IsCadet) && !Conn.InChaseProgress)
{
if (direction > 330 || direction < 20)
{
MsgAll("^6»^7 " + Conn.NoColPlyName + " was fined ^1€500 ^7for wrong exit");
MsgPly("^6»^7 Next time you'll be kicked!", Conn.UniqueID);
Conn.Cash -= 500;
Conn.WrongWay += 1;
Conn.ExitZone = 2;
}
if (Conn.WrongWay == 2)
{
MsgPly("^6»^1 You are kicked for using WRONG exit!", Conn.UniqueID);
KickID(Conn.Username);
}
}
}
}
else
{
if (Conn.ExitZone == 2)
{
Conn.ExitZone = 0;
}
}

// Pit ENTRY

if (pathx >= -23 && pathx <= -21 && pathy >= -39 && pathy <= -35)
{
if (Conn.ExitZone == 0)
{

if (direction < 100)
{
MsgAll("^6»^7 " + Conn.NoColPlyName + " was spec & fined ^1€500 ^7for wrong entry");
Conn.Cash -= 500;
SpecID(Conn.PlayerName);
SpecID(Conn.Username);
Conn.WrongWay += 1;
Conn.ExitZone = 1;
}
if (Conn.WrongWay == 2)
{
MsgPly("^6»^7 You are kicked for using WRONG entry!", Conn.UniqueID);
KickID(Conn.Username);
}
}
}
else
{
if (Conn.ExitZone == 1)
{
Conn.ExitZone = 0;
}
}
}
#endregion

break;
}
#endregion
}
catch { }
}

For example, used in MCI update void. No need to foreach CompCar and Conn again.
This code work for you ? In my insim nothing happens Fap
Still waiting :|
#9 - heawy
It works in MY insim, its not code to be copied and pasted...
Quote from heawy : its not code to be copied and pasted...

I know but i don't know why don't work :/

FGED GREDG RDFGDR GSFDG