View Full Version : First InSim move
M.M.L.
20th June 2011, 22:01
Hello. This year I finish high school and I got the title of technician for computer. I studied programming for 4 years (Pascal, C, C++ and C#) and I want to make my first Insim aplication that should make server statistics. (For each player: Top speed at diferent track, total laps, laps on each track... One file for each player). I read a bit about it on the forum and I was able to connect to server but still unable to manage with statistics. Help me to make first insim moves. Thank you very much
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InSimDotNet;
using InSimDotNet.Packets;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create new InSim object
InSim insim = new InSim();
// Initailize InSim
insim.Initialize(new InSimSettings {
Host = "127.0.0.1", // Host where LFS is runing
Port = 29999, // Port to connect to LFS through
Admin = "xxx", // Optional game admin password
});
// Send message to LFS
insim.Send("/msg Hello, InSim!");
}
}
}
MadCatX
21st June 2011, 11:21
You should read the InSim.txt file shipped with LFS. It's basically a C header file and it describes in detail all the packets used by InSim. This file itself shoud provide you with enough info.
You'll have a bit of a hard time getting telemetry readings for InSim. InSim is more oriented at automated server administration and race control. To get some real telemetry data you'd have to use OutGauge/OutSim, but that has its own limitations too. InSim provides only basic info like speed, position and heading in CompCar structure in IS_MCI packet.
M.M.L.
18th August 2011, 15:31
I continued my work... and now have problem... want to make commands like $exit... I talked with EQWorry and he said that i need to define $ as special char. How to do that? Then $exit would be a special text and LFS will report it as such
MadCatX
18th August 2011, 17:32
You've got to specify prefix to use commands starting with specific characters. Something like this:
//Initailize InSim
insim.Initialize(new InSimSettings {
Host = "127.0.0.1",
Port = 29999,
Prefix = '$',
});
M.M.L.
18th August 2011, 18:25
Ok... I do that...
insim.Initialize(new InSimSettings
{
Host = "127.0.0.1",
Port = 29999,
Admin = "",
Prefix='$',
});
static void MessageOut(InSim insim, IS_MSO mso)
{
// Print out the message content.
Console.WriteLine(mso.Msg);
string a;
a=mso.Msg;
if (a=="$exit")
{
insim.Send("/msg OK");
}
}
And this not working... I guees that problem is in second code.
MadCatX
18th August 2011, 19:14
I'm not entirely sure about this at the moment, but I guess that LFS truncates the prefix so the message your app receives is just "exit".
M.M.L.
18th August 2011, 19:46
Withaout $ same think... Maybe I need to remove first part of message, (for example SERT•Fangio: $exit)
MadCatX
18th August 2011, 20:24
Or you could do
if(a.Contains("$exit"))
insim.Send("/msg OK");
DarkTimes
18th August 2011, 21:39
It doesn't truncate the prefix, it's probably the player's name, as was stated. I normally do something like this:
if (mso.UserType == UserType.MSO_PREFIX) {
var commands = mso.Msg.Substring(mso.TextStart).Split();
if (commands.Any()) {
var command = commands.First().ToLower();
switch (command) {
case "$exit":
// Handle command
break;
}
}
}
M.M.L.
18th August 2011, 21:55
Both ways works ok... Another question... How to send message just to one player... I can not figure out
DarkTimes
18th August 2011, 21:59
You use the IS_MTC (message to connection) packet:
insim.Send(new IS_MTC { UCID = ucid, PLID = plid, Msg = "Hello, InSim!" });
But InSim.NET contains a couple of little convenience method for doing it.
To send a message to a specific connection:
insim.Send(ucid, "Hello, InSim!");
Or to send to a specific player:
insim.Send(0, plid, "Hello, InSim!");
M.M.L.
18th August 2011, 23:00
This has helped a lot... What about buttons. I guess starting like this insim.Send(new IS_BTN....
M.M.L.
19th August 2011, 13:39
static void newconnection(InSim insim, IS_NCN ncn)
{
insim.Send(ncn.UCID,"^7Dobro dosao na server");
IS_BTN btn = new IS_BTN();
btn.H = 100;
btn.L = 100;
btn.T = 100;
btn.Text = "OKKK";
btn.UCID = ncn.UCID;
btn.W = 100;
btn.ClickID = 5;
btn.ReqI = 245;
btn.BStyle = ButtonStyles.ISB_CLICK;
insim.Send(btn);
}
static void deletebutton(InSim insim, IS_BTC btc)
{
IS_BFN bfn=new IS_BFN();
bfn.ClickID = btc.ClickID;
bfn.UCID=btc.UCID;
bfn.ReqI = btc.ReqI;
insim.Send(bfn);
}
I want to delete button, where i am wrong
MadCatX
19th August 2011, 14:47
You're not telling LFS what do to in the IS_BFN packet. You have to specify the SubT to tell LFS that you want to delete a button. Also the ReqI is supposed to be 0, but I guess LFS wouldn't mind about that.
M.M.L.
19th August 2011, 20:25
Is there shorter way to sending buttons?
DarkTimes
19th August 2011, 22:48
No, buttons are bit too varied to simplify into a couple of method calls. Maybe I'll think about adding something to help with them in the future.
The only thing different I would do is to send them like this, as I think this looks a lot neater. But it's just a preference thing.
insim.Send(new IS_BTN {
H = 100,
L = 100,
T = 100,
W = 100,
Text = "OKKK",
UCID = ncn.UCID,
ClickID = 5,
ReqI = 245,
BStyle = ButtonStyles.ISB_CLICK
});
M.M.L.
20th August 2011, 20:32
Ok...
static void MessageOut(InSim insim, IS_MSO mso)
{
// Print out the message content.
Console.WriteLine(mso.Msg);
if (mso.UserType == UserType.MSO_PREFIX)
{
var commands = mso.Msg.Substring(mso.TextStart).Split();
if (commands.Any())
{
var command = commands.First().ToLower();
switch (command)
{
case "!exit":
insim.Send("/msg ^3Program se gasi!");
System.Threading.Thread.Sleep(1000);
insim.Disconnect();
Environment.Exit(0);
break;
}
}
}
}
I use this function for commands. I want to limit who can use this command. Think that I need to use PLID, but how PLID to connect with username? And how to send two or more flags in InSim setting vecause I want car contact reports and i need to set ISF_CON flag in the IS_ISI to receive car contact reports
insim.Initialize(new InSimSettings
{
Host = "127.0.0.1",
Port = 29999,
Admin = "",
Prefix='!',
IName="Fangio",
Flags = InSimFlags.ISF_MCI,
Interval = 1000, // The interval at which updates are sent (milliseconds)
});
DarkKostas
21st August 2011, 08:22
Now you are getting into more complicated things. You have to add "directories" and add each player at NCN(NewConnection), CNL(ConnectionLeave) packets.
class Connections//Somewhere at the top of your code
{
public byte UCID;
public string UName;
public string PName;
public bool IsAdmin;
}
//Before "insim.Initialize(new InSimSettings blablabla"
insim.Bind<IS_NCN>(OnConnectionJoin);
insim.Bind<IS_CNL>(OnConnectionLeave);
//Add these anywhere you want
private void OnConnectionJoin(InSim insim, IS_NCN NCN)
{
try
{
_connections.Add(NCN.UCID, new Connections
{
UCID = NCN.UCID,
UName = NCN.UName,
PName = NCN.PName,
IsAdmin = NCN.Admin,
});
}
catch (Exception EX) { LogTextToFile("packetError", "NCN - " + EX.Message); }
}
private void OnConnectionLeave(InSim insim, IS_CNL CNL)
{
try { _connections.Remove(CNL.UCID); }
catch (Exception EX) { LogTextToFile("packetError", "CNL - " + EX.Message); }
}
LogTextToFile is a function i made to log text "type"(packetError in this case) to a file. PM me if you want it. You can just replace it for now to add the error to a richtextbox(just an example)
EDIT:
I forgot about flags. You can use more than one by using |
Example: Flags = InSimFlags.ISF_MCI | InSimFlags.ISF_MSO_COLS,
EDIT2:
Here is an example at MSO on how to use first code in case you don't know
case "!ialwaysforget":
insim.Send("/msg ^3" + _connections[mso.UCID].PName + " always forget his username which is " + _connections[mso.UCID].UName);
break;
M.M.L.
21st August 2011, 11:22
I get this error "The name '_connections' does not exist in the current context"
How to connect PLID and PlayerName? I have PLID in car contact, but i want player name. And yes, send me code for logging. Thank you very much
Edit: Also need code for reading config files if you have?
DarkKostas
21st August 2011, 12:55
I forgot to tell that after creating the class you will need to create the dictionary
private Dictionary<byte, Connections> _connections = new Dictionary<byte, Connections>();
About PLID you will have to do the same as UCID but with different packets, NPL and PLL.
LogTextToFile
const string SaveDataFolder = "files";
private void LogTextToFile(string file, string text, bool AdminMessage = true)
{
//Console.WriteLine(file + ": {0}", text); You dont need this one as you use form application.
if (AdminMessage == true) MessageToAdmins("There was a " + file + " : " + text);
if (System.IO.File.Exists(SaveDataFolder + "/" + file + ".log") == false) { FileStream CurrentFile = System.IO.File.Create(SaveDataFolder + "/" + file + ".log"); CurrentFile.Close(); }
StreamReader TextTempData = new StreamReader(SaveDataFolder + "/"+ file + ".log");
string TempText = TextTempData.ReadToEnd();
TextTempData.Close();
StreamWriter TextData = new StreamWriter(SaveDataFolder + "/" + file + ".log");
TextData.WriteLine(TempText + DateTime.Now + ": " + text);
TextData.Flush();
TextData.Close();
}
And MessageToAdmins which is used by LogTextToFile
private void MessageToAdmins(string Message)
{
foreach (var CurrentConnection in _connections.Values)
{
if (CurrentConnection.IsAdmin == true) MessageToUCID(CurrentConnection.UCID, Message);
}
}
MadCatX
21st August 2011, 13:02
You have to declare the _connections (or whatever you name it) variable first. InSim doesn't provide any PLID - UCID - Name matching, you've got to do this yourself. InSim.NET probably has some classes and functions to make the job easier...
M.M.L.
21st August 2011, 17:16
now I get this error "An object reference is required for the non-static field, method, or property 'ConsoleApplication1.Program._connections'
"
namespace ConsoleApplication1
{
class Connections//Somewhere at the top of your code
{
public byte UCID;
public string UName;
public string PName;
public bool IsAdmin;
}
class Program
{
private Dictionary<byte, Connections> _connections = new Dictionary<byte, Connections>();
static void Main()
{
static void OnConnectionLeave(InSim insim, IS_CNL cnl)
{
try { _connections.Remove(cnl.UCID); }
catch (Exception EX) { };
}
static void Novakonekcija(InSim insim, IS_NCN ncn)
{
try
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
});
}
catch (Exception EX) { }
MadCatX
21st August 2011, 17:46
You're accessing _connections from a static function which requires _connections to be declared as static too (if C# is anything like C++ or Java).
M.M.L.
21st August 2011, 18:25
Ok. I fix that but I have trouble with PLID and Pname
This is for car contact
static void Kontakt(InSim insim, IS_CON con)
{
insim.Send("/msg " + _connections[con.A.PLID].PName);
insim.Send("/msg "+_connections[con.B.PLID].PName);
}
This is race joining
static void PrikljucenjeTrci(InSim insim, IS_NPL npl)
{
insim.Send("/msg "+npl.PName+" ^8je izasao sa "+npl.CName);
try
{
_connections.Add(npl.UCID, new Connections
{
PName=npl.PName,
PLID = npl.PLID,
});
}
catch { }
}
When there is car contact insim disconects from server. Can I use one class sonnections for everything or I need to separate?
DarkKostas
21st August 2011, 21:25
Here is my npl and pll and cpr a bit modified for you. You will have to bind and create dictionary/class for this to work. But this is how packets are.
private void OnPlayerJoin(InSim insim, IS_NPL NPL)
{
try
{
if (_players.ContainsKey(NPL.PLID))
{
// Leaving pits, just update NPL object.
_players[NPL.PLID].PLID = NPL.PLID;
_players[NPL.PLID].PName = NPL.PName;
}
else
{
// Add new player.
_players.Add(NPL.PLID, new Players
{
PLID = NPL.PLID,
PName = NPL.PName
});
}
}
catch (Exception EX) {}
}
private void OnPlayerSpectate(InSim insim, IS_PLL PLL)
{
try { _players.Remove(PLL.PLID); }
catch (Exception EX) {}
}
private void OnPlayerRename(InSim insim, IS_CPR CPR)
{
try
{
_connections[CPR.UCID].PName = CPR.PName;
foreach (var CurrentPlayer in _players.Values) if (CurrentPlayer.UCID == CPR.UCID) CurrentPlayer.PName = CPR.PName;
}
catch (Exception EX) {}
}
Im sure "takeover" packet is needed too. But haven't managed(tested yet) on how to do it. Someone could help here for this too.
Anyway, usage of the code
_players[con.A.PLID].PName//This is the player name.
M.M.L.
22nd August 2011, 15:03
I have trouble with admins... Admins are defined in admin.txt and that looks like this
#Ovde se definisu admini
Admin=nesrulz
Admin=M.M.L.
Admin=gagag
My code for reading admin.txt:
string[] lines = System.IO.File.ReadAllLines("admin.txt");
foreach (string line in lines)
{
//Do something with line
if (line.StartsWith("#", false, System.Globalization.CultureInfo.InvariantCulture) )
{
}
else
{
if (line.ToLower().Contains("admin="))
{
try
{
string medjuvr = line.Remove(0, 6);
Console.WriteLine(medjuvr);
if (medjuvr == ncn.UName)
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 1,
});
}
else
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 0,
});
}
}
catch
{
}
}
}
}
This is for buttons:
if (_connections[ncn.UCID].ServerAdmin == 1)
{
insim.Send(new IS_BTN
{
H = 10,
W = 20,
L = 25,
T = 25,
Text = "^2SHOW GREEN FLAG",
UCID = ncn.UCID,
ClickID = 1,
ReqI = 255,
BStyle = ButtonStyles.ISB_CLICK
});
....................
....................
....................
MadCatX
22nd August 2011, 15:23
You're converting the username to lowercase with this line
line.ToLower().Contains("admin=")
If you're trying the server with yourself as the admin, it obviously won't work as string comparison is case sensitive. Also avoid using == to compare strings (or any other non-primitive types). In Java using == compares pointers to the objects, not the objects themselves, I suppose C# is the same in this respect. Use CompareTo() function.
M.M.L.
22nd August 2011, 15:32
It works only for the first admin in the list. Also works with ToLower and withuot.
MadCatX
22nd August 2011, 15:51
It's impossible to help without better description of the problem, "it doesn't work" really doesn't give us much to go with. By any chance, does this work?
string[] lines = System.IO.File.ReadAllLines("admin.txt");
foreach (string line in lines)
{
//Do something with line
if (!line.StartsWith("#", false, System.Globalization.CultureInfo.InvariantCulture) )
{
int delimiterIdx = line.IndexOf("="); //Find first "=" on the line
//Extract text from the beginning of the line to the last character before the first "="
string lineKey = line.Substring(0, delimiterIdx - 1).ToLower();
if (lineKey.Equals("admin"))
{
try
{
//Get the name of the admin
string medjuvr = line.Substring(delimiterIdx + 1);
Console.WriteLine(medjuvr);
if (medjuvr.Equals(ncn.UName))
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 1,
});
}
else
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 0,
});
}
}
catch
{
}
}
}
}
DarkTimes and co. compatible version (don't use for educational purposes) :D
string[] lines = System.IO.File.ReadAllLines("admin.txt");
foreach (string line in lines)
{
//Do something with line
if (!line.StartsWith("#", false, System.Globalization.CultureInfo.InvariantCulture) )
{
int delimiterIdx = line.IndexOf("=");
if (line.Substring(0, delimiterIdx - 1).ToLower().Equals("admin"))
{
try
{
if (line.Substring(delimiterIdx + 1).Equals(ncn.UName))
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 1,
});
}
else
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 0,
});
}
}
catch
{
}
}
}
}
I don't have a C# compiler set up here (nor the knowledge of the language) so minor modifications might be required to get it compiled.
M.M.L.
22nd August 2011, 16:04
foreach (string line in lines)
{
if (line.StartsWith("#", false, System.Globalization.CultureInfo.InvariantCulture) )
{
} //Skiping the lines if start with #
else
{
if (line.Contains("Admin="))
{
try
{
string medjuvr = line.Remove(0, 6); //medjuvr is username of admin
Console.WriteLine(medjuvr);
if (medjuvr == ncn.UName) //if medjuvr match with ncn.UName
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 1,
});
}
else //if not match
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 0,
});
}
}
catch
{
}
}
}
}
If in txt I have three admins, console.writeline(medjuwr); prints 3times muliply 3admins and insim disconnects. I added comments.
I get exception "KeyNot found" the given key is not present in the dictionary
MadCatX
22nd August 2011, 16:05
Can you post the actual output of your program? Also LFS usually gives error messages when it terminates connection to an InSim app.
M.M.L.
22nd August 2011, 16:15
I change function and now works ok... Thanks for help
string[] lines = System.IO.File.ReadAllLines("admin.txt");
foreach (string line in lines)
{
if (line.StartsWith("#", false, System.Globalization.CultureInfo.InvariantCulture) )
{
} //Skiping the lines if start with #
else
{
if (line.Contains("Admin="))
{
try
{
string medjuvr = line.Remove(0, 6); //medjuvr is username of admin
Console.WriteLine(medjuvr);
if (medjuvr == ncn.UName) //if medjuvr match with ncn.UName
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 1,
});
}
}
catch { }
}
}
}
if (_connections.ContainsKey(ncn.UCID))
{
}
else
{
_connections.Add(ncn.UCID, new Connections
{
UCID = ncn.UCID,
UName = ncn.UName,
PName = ncn.PName,
IsAdmin = ncn.Admin,
ServerAdmin = 0,
});
}
M.M.L.
22nd August 2011, 18:18
When is contact between cars, i want to only admins see message about that.
static void Kontakt(InSim insim, IS_CON con)
{
insim.Send("/msg ^1Kontakt izmedju: ^8"+_players[con.A.PLID].PName+" i "+_players[con.B.PLID].PName);
}
So I need to edit this function... Do I need to create one new class Admin where will be ucid and how to read all ucid and send message to all admins?
MadCatX
22nd August 2011, 20:04
Wouldn't something like
foreach(Connections conn in _connections) {
if(conn.IsAdmin == 1)
insim.Send(new IS_MTC {ucid = conn.UCID,
Msg = "blah" });
}
do?
M.M.L.
22nd August 2011, 20:17
Cannot convert type 'System.Collections.Generic.KeyValuePair<byte,ConsoleApplication1.Connections>' to 'ConsoleApplication1.Connections' C:\Users\Damir\documents\visual studio 2010\Projects\insimmm\insimmm\Program.cs
Underline foreach
MadCatX
22nd August 2011, 20:30
I have no knowledge of C#, so pardon my occasional ignorance, apparently the correct syntax is
foreach(KeyValuePair<byte, Connections> kvp in _connections) {
if(kvp.Value.IsAdmin == 1) ....
M.M.L.
22nd August 2011, 20:36
Now its good... Thanks
DarkKostas
22nd August 2011, 21:54
My much much smaller code for admins
private bool GetUserAdmin(string Username)
{
StreamReader CurrentFile = new StreamReader(SaveDataFolder + "/admins.ini");
string line = null;
while ((line = CurrentFile.ReadLine()) != null)
{
if (line.Trim() == Username)
{
CurrentFile.Close();
return true;
}
}
CurrentFile.Close();
return false;
}
private void OnConnectionJoin(InSim insim, IS_NCN NCN)
{
try
{
_connections.Add(NCN.UCID, new Connections
{
UCID = NCN.UCID,
UName = NCN.UName,
PName = NCN.PName,
IsAdmin = NCN.Admin,
IsCustomAdmin = GetUserAdmin(NCN.UName)
});
}
catch (Exception EX) {}
}
A useful function to combine real admin and .ini admin
private bool IsConnectionAdmin(Connections CurrentConnection)
{
if (CurrentConnection.IsAdmin == true || CurrentConnection.IsCustomAdmin == true) return true;
return false;
}
And an in-game command to add admins(you will need to modify it a bit because im using if statements for each command instead of break.
else if (command[0] == "!makeadmin")
{
if (!IsConnectionAdmin(_connections[MSO.UCID]))
{
MessageToUCID(MSO.UCID, "You are not an admin");
return;
}
if (command.Length == 1)
{
MessageToUCID(MSO.UCID, "Invalid Format. ^7!makeadmin [username]");
return;
}
bool UsernameFound = false;
string Username = Text.Remove(0, command[0].Length + 1);
foreach (var CurrentConnection in _connections.Values)
{
if (CurrentConnection.UName.ToLower() == Username.ToLower())
{
UsernameFound = true;
if (IsConnectionAdmin(CurrentConnection)) MessageToUCID(MSO.UCID, "^7" + CurrentConnection.PName + " ^3is already an admin");
else
{
CurrentConnection.IsCustomAdmin = true;
StreamReader ApR = new StreamReader(SaveDataFolder + "/admins.ini");
string TempAPR = ApR.ReadToEnd();
ApR.Close();
StreamWriter Ap = new StreamWriter(SaveDataFolder + "/admins.ini");
Ap.WriteLine(TempAPR + CurrentConnection.UName);
Ap.Flush();
Ap.Close();
}
break;
}
}
if (UsernameFound == false) MessageToUCID(MSO.UCID, Username + " ^3not found");
}
You can replace MessageToUCID with your message function or the default way.(anything you like to use)
M.M.L.
24th August 2011, 12:20
Thanks...
When I click on button
insim.Send("/rcm GREEN FLAG");
insim.Send("/rcm_all");
System.Threading.Thread.Sleep(5000);
insim.Send("/rcc_all");
But then, program is sleaping for 5sec, and will not accept any command until it passes 5sec.
PoVo
24th August 2011, 14:16
Thanks...
When I click on button
insim.Send("/rcm GREEN FLAG");
insim.Send("/rcm_all");
System.Threading.Thread.Sleep(5000);
insim.Send("/rcc_all");
But then, program is sleaping for 5sec, and will not accept any command until it passes 5sec.
http://www.lfsforum.net/showthread.php?p=1626816#post1626816
M.M.L.
27th August 2011, 16:58
I get this error....http://fangio.eu5.org/files/Slike_razne/insimerror.png
DarkTimes
28th August 2011, 08:32
All I can imagine is that at some point in the fifteen seconds it takes the timer to elapse, the connection with LFS has been lost. Perhaps it would be better to place the IsConnected check in the anonymous method.
timer.Elapsed += delegate {
if (insim.IsConnected) {
insim.Send(TinyType.TINY_RST, 5);
}
}
Also just a tip, instead of using anonymous methods, it's generally recommended to use lambdas these days, but I guess it doesn't make much difference in this instance.
timer.Elapsed += (sender, e) => {
};
Jonathon.provost
25th October 2011, 09:51
Right I have tried to make a sort of like gui program where i have green flag yellow ect in a form this is the code i have so far.
public partial class Form1 : Form
{
// Create new InSim object
InSim insim = new InSim();
public Form1()
{
InitializeComponent();
// Create new InSim object
InSim insim = new InSim();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create new InSim object
InSim insim = new InSim();
// Initailize InSim
insim.Initialize(new InSimSettings
{
Host = "127.0.0.1", // Host where LFS is runing
Port = 29999, // Port to connect to LFS through
Admin = "xxx", // Optional game admin password
});
}
private void button1_Click(object sender, EventArgs e)
{
// Send message to LFS
insim.Send("/msg Hello, I am a InSim!");
// Send RCM to LFS
insim.Send("/rcm Hello PPL");
insim.Send("/rcm_all");
}
private void button2_Click(object sender, EventArgs e)
{
//Say's Hello
insim.Send("/msg ^7Hia All!");
}
And if i click button 1 or 2 then it says insim not connected is there anyway i can make it work??
cheers
DarkTimes
25th October 2011, 16:34
Try this...
public partial class Form1 : Form
{
// Create new InSim object
InSim insim = new InSim();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Initailize InSim
insim.Initialize(new InSimSettings
{
Host = "127.0.0.1", // Host where LFS is runing
Port = 29999, // Port to connect to LFS through
Admin = "xxx", // Optional game admin password
});
}
private void button1_Click(object sender, EventArgs e)
{
// Send message to LFS
insim.Send("/msg Hello, I am a InSim!");
// Send RCM to LFS
insim.Send("/rcm Hello PPL");
insim.Send("/rcm_all");
}
private void button2_Click(object sender, EventArgs e)
{
//Say's Hello
insim.Send("/msg ^7Hia All!");
}
}
Jonathon.provost
25th October 2011, 17:34
Cheers worked perfect :D
_________________________
Just made my 1st insim. not the best but i still need to learn how to make buttons in lfs so i just made a app gui.
I have attached the files.
Please read readme.txt
Kind Regards,
J.Provost
M.M.L.
11th February 2012, 10:41
How to calculate drift points?
MadCatX
11th February 2012, 11:22
It depends on what you consider a drift and I can see that it would take a bit of work to get it right, but a very simple algorithm could work like this
if (car.Speed > MIN_SPEED) {
unsigned short driftAngle = abs(car.Direction - car.Heading);
if (driftAngle > MIN_DANGLE && driftAngle < MAX_DANGLE)
driftPoints[PLID] += COEFF * car.Speed * driftAngle;
}
This would of course require quite high sample rate to get any useful data.
simeon_shumen
19th February 2012, 12:26
може ли да ми дадете cruis мод за lfs 0.6B плс. много :)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.