################################################################## #OBH PACKET #Made by Bass-Driver version V0.1 ################################################################## ###################### #Insim4.cs ###################### enum obh //Flags { OBH_LAYOUT, //1 // an added object OBH_CAN_MOVE, //2 // a movable object OBH_WAS_MOVING, //4 // was moving before this hit OBH_ON_SPOT //8 // object in original position } enum ISF { OBH = 128, // bit 7 : set to receive OBH packets } enum TypePack { ISP_OBH, // 51 - info : contact car + object (collision report) } public byte[] ISI(string adminPass, int portNum, byte mciSeconds, string nameApp, bool local) { byte[] packet = new byte[44]; packet[0] = 44; packet[1] = (byte)TypePack.ISP_ISI; packet[2] = 1; packet[3] = 0; // Port packet[4] = (byte)(portNum % 256); // LSB packet[5] = (byte)(portNum / 256); // MSB // Flags if (local) packet[6] = (byte)ISF.MCI | (byte)ISF.LOCAL | (byte)ISF.OBH; // LSB else packet[6] = ( byte )ISF.MCI | (byte)ISF.OBH; // LSB packet[7] = 0; // MSB packet[8] = 0; packet[9] = (byte)'!'; // Number of milli seconds between NLP or MCI packets (0=none) packet[10] = 100; // LSB packet[11] = 0; // MSB System.Text.Encoding.ASCII.GetBytes(adminPass, 0, Math.Min(adminPass.Length, 16), packet, 12); System.Text.Encoding.ASCII.GetBytes(nameApp, 0, Math.Min(nameApp.Length, 16), packet, 28); return packet; } public class CarContOBJ // 8 bytes : car in a contact with an object { public int Direction; // car's motion if Speed > 0 : 0 = world y direction, 128 = 180 deg public int Heading; // direction of forward axis : 0 = world y direction, 128 = 180 deg public int Speed; // m/s public int PlayerPosZ; // position (1 metre = 4) public int PlayerPosX; // position (1 metre = 16) public int PlayerPosY; // position (1 metre = 16) } // OK For Insim 6 public class OBH // 24 Byte size Object Collision between Car > Object { public CarContOBJ CarCont = new CarContOBJ(); public readonly int PLID; // player's unique id public readonly int SpClose; // closing speed (10 = 1 m/s) public readonly int ObjectHitTime; // looping time stamp public readonly int ObjectPosX; // as in ObjectInfo public readonly int ObjectPosY; // as in ObjectInfo public readonly int ObjectPosZ; // as in ObjectInfo public readonly int Sp1; //spare1 public readonly int Index; // AXO_x as in ObjectInfo or zero if it is an unknown object public readonly int OBHFlags; public OBH(byte[] packet) { PLID = pakGetByte(packet, 3); //1 Byte SpClose = pakGetWord(packet, 4); //2 Bytes ObjectHitTime = pakGetWord(packet, 6); //2 Bytes CarCont.Direction = pakGetByte(packet, 8); //1 Byte CarCont.Heading = pakGetByte(packet, 9); //1 Byte CarCont.Speed = pakGetByte(packet, 10); //1 Byte CarCont.PlayerPosZ = pakGetByte(packet, 11); //1 Byte CarCont.PlayerPosX = pakGetShort(packet, 12); //2 Bytes CarCont.PlayerPosY = pakGetShort(packet, 14); //2 Bytes ObjectPosX = pakGetShort(packet, 16); //2 Bytes ObjectPosY = pakGetShort(packet, 18); //2 Bytes ObjectPosZ = pakGetByte(packet, 20); //1 Byte Sp1 = pakGetByte(packet, 21); //1 Byte Index = pakGetByte(packet, 22); //1 Byte OBHFlags = pakGetByte(packet, 23); //1 Byte } } ###################### #managePacket.cs ###################### //Global Var bool ExecuteEvent = false; private string Objects(int ObjectIndex) { string[] Object = new string[193]; //193 objects in LFS (lyt format) https://www.lfs.net/programmer/lyt Object[0] = "Scenery Object"; //Scenery Object Object[1] = ""; Object[2] = ""; Object[3] = ""; Object[4] = "Long Chalk Line"; Object[5] = "Short Chalk Line"; //Chalk Lines Object[6] = "Short Ahead Arrow"; Object[7] = "Long Ahead Arrow"; // Ahead Arrows Object[8] = "Short Left Curve Arrow"; Object[9] = "Left Turn Arrow"; Object[10] = "Long Left Curve Arrow"; // Left Arrows Object[11] = "Short Right Curve Arrow"; Object[12] = "Right Turn Arrow"; Object[13] = "Long Right Curve Arrow"; // Right Arrows Object[14] = ""; Object[15] = ""; Object[16] = ""; Object[17] = ""; Object[18] = ""; Object[19] = ""; Object[20] = "Red/White Cone"; Object[21] = "Red Cone"; Object[22] = "Striped Code"; // Types of Red Cones Object[23] = "Striped Blue Cone"; Object[24] = "Blue Cone"; // Types of Blue Cones Object[25] = "Striped Green Cone"; Object[26] = "Green Cone"; // Types of Green Cones Object[27] = "Orange Cone"; Object[28] = "White Cone"; // Types of White Cones Object[29] = "Striped Yellow Cone"; Object[30] = "Yellow Cone"; // Types of Yellow Cones Object[31] = ""; Object[32] = ""; Object[33] = ""; Object[34] = ""; Object[35] = ""; Object[36] = ""; Object[37] = ""; Object[38] = ""; Object[39] = ""; Object[40] = "Red Cone Pointer"; Object[41] = "Blue Cone Pointer"; Object[42] = "Green Cone Pointer"; Object[43] = "Yellow Cone Pointer"; //Pointer Cones Object[44] = ""; Object[45] = ""; Object[46] = ""; Object[47] = ""; Object[48] = "Small Single Tyre"; Object[49] = "Small 2 Stack Tyre"; Object[50] = "Small 3 Stack Tyre"; Object[51] = "Small 4 Stack Tyre"; // Small Tirestacks Object[52] = "Big Single Tyre"; Object[53] = "Big 2 Stack Tyre"; Object[54] = "Big 3 Stack Tyre"; Object[55] = "Big 4 Stack Tyre"; //Big Tirestacks Object[56] = ""; Object[57] = ""; Object[58] = ""; Object[59] = ""; Object[60] = ""; Object[61] = ""; Object[62] = ""; Object[63] = ""; Object[64] = "Left Curve Marker"; Object[65] = "Right Curve Marker"; Object[66] = "Left Turn Marker"; Object[67] = "Right Turn Marker"; Object[68] = "Hard Left Turn Marker"; Object[69] = "Hard Right Turn Marker"; Object[70] = "Left-Right Turn Marker"; Object[71] = "Right-Left Turn Marker"; Object[72] = "U-Turn >> Right Turn Marker"; Object[73] = "U-Turn >> Left Turn Marker"; Object[74] = "Left Winding Turn Marker"; Object[75] = "Right Winding Turn Marker"; Object[76] = "Left U-Turn Marker"; Object[77] = "Right U-Turn Marker"; Object[78] = ""; Object[79] = ""; Object[80] = ""; Object[81] = ""; Object[82] = ""; Object[83] = ""; Object[84] = "25m Sign"; Object[85] = "50m Sign"; Object[86] = "100m Sign"; Object[87] = "125m Sign"; Object[88] = "150m Sign"; Object[89] = "200m Sign"; Object[90] = "250m Sign"; Object[91] = ""; Object[92] = ""; Object[93] = ""; Object[94] = ""; Object[95] = ""; Object[96] = "Short Railing"; Object[97] = "Medium Railing"; Object[98] = "Long Railing"; // Not moveable Railing Object[99] = ""; Object[100] = ""; Object[101] = ""; Object[102] = ""; Object[103] = ""; Object[104] = "Long Barrier"; Object[105] = "Short Barrier Red"; Object[106] = "Short Barrier White"; //Barriers Object[107] = ""; Object[108] = ""; Object[109] = ""; Object[110] = ""; Object[111] = ""; Object[112] = "Banner"; Object[113] = "Banner"; // 2 Banners Object[114] = ""; Object[115] = ""; Object[116] = ""; Object[117] = ""; Object[118] = ""; Object[119] = ""; Object[120] = "Small Ramp"; Object[121] = "Big Ramp";// Ramps Object[122] = ""; Object[123] = ""; Object[124] = ""; Object[125] = ""; Object[126] = ""; Object[127] = ""; Object[128] = "Speed Hump"; Object[129] = "Speed Hump"; // Speedhumbs Object[130] = ""; Object[131] = ""; Object[132] = ""; Object[133] = ""; Object[134] = ""; Object[135] = ""; Object[136] = "Green Post"; Object[137] = "Orange Post"; Object[138] = "Red Post"; Object[139] = "White Post"; // Post Objects Object[140] = ""; Object[141] = ""; Object[142] = ""; Object[143] = ""; Object[144] = "Bale"; Object[145] = ""; Object[146] = ""; Object[147] = ""; Object[148] = "Railing"; Object[149] = "StartLight"; Object[150] = ""; Object[151] = ""; Object[152] = ""; Object[153] = ""; Object[154] = ""; Object[155] = ""; Object[156] = ""; Object[157] = ""; Object[158] = ""; Object[159] = ""; Object[160] = "Keep Left Sign"; Object[161] = "Keep Right Sign"; //Keep side Signs Object[162] = ""; Object[163] = ""; Object[164] = ""; Object[165] = ""; Object[166] = ""; Object[167] = ""; Object[168] = "80 km/h Sign"; Object[169] = "50 km/h Sign"; //Speed Signs Object[170] = ""; Object[171] = ""; Object[172] = "Concrete Slab"; Object[173] = "Concrete Ramp"; Object[174] = "Concrete Wall"; Object[175] = "Concrete Pillar"; Object[176] = "Concrete Slab Wall"; Object[177] = "Concrete Ramp Wall"; Object[178] = "Concrete Short Slab Wall"; Object[179] = "Concrete Wedge"; Object[180] = ""; Object[181] = ""; Object[182] = ""; Object[183] = ""; Object[184] = "Start Position"; Object[185] = "Pit Start Point"; Object[186] = "Pit Stop Box"; // Pit Objects Object[187] = ""; Object[188] = ""; Object[189] = ""; Object[190] = ""; Object[191] = ""; Object[192] = ""; return Object[ObjectIndex]; }//List with objects void managePacket( InSim.Decoder.OBH obh) { #region Detect Type of object detection value if (newCfg.varsLapper.DetectHitObject != "") { if (newCfg.varsLapper.DetectHitObject.Contains("All_Tires") && (obh.Index > 47 && obh.Index < 56)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("All_Cones") && ((obh.Index > 19 && obh.Index < 31) || (obh.Index > 39 && obh.Index < 44))) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("All_Markers") && (obh.Index > 63 && obh.Index < 78)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("All_DistMarkers") && (obh.Index > 83 && obh.Index < 91)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("All_Railings") && (obh.Index > 95 && obh.Index < 99)) { ExecuteEvent = true; } #region Concrete Objects if (newCfg.varsLapper.DetectHitObject.Contains("All_Concrete") && (obh.Index > 171 && obh.Index < 180)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_Slabs") && (obh.Index == 172)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_Ramps") && (obh.Index == 173)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_Walls") && (obh.Index == 174)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_Pillars") && (obh.Index == 175)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_SlabWalls") && (obh.Index == 176)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_RampWalls") && (obh.Index == 177)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_ShortSlabWalls") && (obh.Index == 178)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Concrete_Wedges") && (obh.Index == 179)) { ExecuteEvent = true; } #endregion if (newCfg.varsLapper.DetectHitObject.Contains("Banners") && (obh.Index > 111 && obh.Index < 114)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("SpeedBumps") && (obh.Index > 127 && obh.Index < 130)) { ExecuteEvent = true; } #region BarrierObjects if (newCfg.varsLapper.DetectHitObject.Contains("All_Barriers") && (obh.Index > 103 && obh.Index < 107)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Long_Barrier") && (obh.Index == 104)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Red_Barrier") && (obh.Index == 105)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("White_Barrier") && (obh.Index == 106)) { ExecuteEvent = true; } #endregion #region PostObjects if (newCfg.varsLapper.DetectHitObject.Contains("All_Post") && (obh.Index > 135 && obh.Index < 140)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Green_Post") && (obh.Index == 136)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Orange_Post") && (obh.Index == 137)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Red_Post") && (obh.Index == 138)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("White_Post") && (obh.Index == 139)) { ExecuteEvent = true; } #endregion if (newCfg.varsLapper.DetectHitObject.Contains("KeepSigns") && (obh.Index > 159 && obh.Index < 162)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("SpeedSigns") && (obh.Index > 167 && obh.Index < 170)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("Bale") && (obh.Index == 144)) { ExecuteEvent = true; } if (newCfg.varsLapper.DetectHitObject.Contains("All_Objects")) { ExecuteEvent = true; } } else { ExecuteEvent = false; } #endregion if (ExecuteEvent == true) { string objectHit; infoPlayer currInfoPlayer; currInfoPlayer = listOfPlayers.getPlayerByPLID(obh.PLID); if (currInfoPlayer == null) return; objectHit = Objects(obh.Index); if (currInfoPlayer.unitSpeedKmh) { currInfoPlayer.ObjectContactSpeed = obh.CarCont.Speed; //KMH } else { currInfoPlayer.ObjectContactSpeed = Math.Round(obh.CarCont.Speed * 0.62137, 1);//KMH >> MPH } currInfoPlayer.ObjectContactDir = obh.CarCont.Direction; currInfoPlayer.ObjectContactHead = obh.CarCont.Heading; int ObjectX = obh.ObjectPosX/16; int ObjectY = obh.ObjectPosY/16; int ObjectZ = obh.ObjectPosZ; string[] args = new string[7]; args[0] = currInfoPlayer.userName; args[1] = obh.OBHFlags.ToString(); args[2] = obh.ObjectHitTime.ToString(); args[3] = ObjectX.ToString(); args[4] = ObjectY.ToString(); args[5] = ObjectZ.ToString(); args[6] = objectHit.ToString(); newCfg.executeFunction("OnObjectCollision", currInfoPlayer, args); ExecuteEvent = false; // Event is executed } } ###################### #loop.cs ###################### void Loop(InSim.Connect insimConnection) { #region Manage packet and launch correct action if (recvPacket.Length > 3) { string packetHead = insimConnection.packetHead(recvPacket); uint verifyID = insimConnection.verifyID(recvPacket); // Console.WriteLine(packetHead); switch (packetHead) { case "OBH"://contact car + object (collision report) InSim.Decoder.OBH obh = new InSim.Decoder.OBH(recvPacket); managePacket(obh); break; } } } ###################### #readcfg.cs ###################### DetectHitObject, //New Hit Objects public string DetectHitObject = ""; //New enable Hit Objects eventAllowed["OnObjectCollision"] = new eventProperties("$userName,$ObjectFlag,$ObjectHitTime,$Object_X,$Object_Y,$TypeObject");//New ###################### #infoplayer.cs ###################### //Player Info public int ObjectContactSpeed; public int ObjectContactDir; public int ObjectContactHead; ###################### #GLSPlayerVars.cs ###################### enum playerVars { //Object Hit ObjectContactSpeed, //Speed of player when hitting a object ObjectContactHead, //Heading of player when hitting a object ObjectContactDir, //Direction of player when hitting a object } public void GetVarPlayer(GLScript.unionVal val, string idVar, string userName) { infoPlayer currInfoPlayer = null; if (userName != "") currInfoPlayer = listOfPlayers.getPlayerByUserName(userName); #region Var currInfoPlayer if (currInfoPlayer == null) { val.typVal = GLScript.typVal.str; val.sval = utils.quote(""); return; } else { switch (idVar.ToLower()) { //Object contact Player Vars case "objectcontactspeed": val.typVal = GLScript.typVal.num; val.fval = (float)(currInfoPlayer.ObjectContactSpeed*3.6); break; case "objectcontactdir": val.typVal = GLScript.typVal.num; val.fval = (float)(currInfoPlayer.ObjectContactDir); break; case "objectcontacthead": val.typVal = GLScript.typVal.num; val.fval = (float)(currInfoPlayer.ObjectContactHead); break; } } #endregion } ################################################################## #LFSLAPPER.LPR ################################################################## #Player Vars #GetCurrentPlayerVar("ObjectContactSpeed") //Speed of player when hitting a object #GetCurrentPlayerVar("ObjectContactHead") //Heading of player when hitting a object #GetCurrentPlayerVar("ObjectContactDir") //Direction of player when hitting a object # When $ObjectFlag returns a value. #OBH_LAYOUT, //1 // an added object #OBH_CAN_MOVE, //2 // a movable object #OBH_WAS_MOVING, //4 // was moving before this hit #OBH_ON_SPOT //8 // object in original position $DetectHitObject = ""; #To get objectstrings for detection look at docs/ObjectHit.txt Event OnObjectCollision($userName,$ObjectFlag,$ObjectHitTime,$Object_X,$Object_Y,$Object_Z,$ObjectType) # Player event #Globalmsg("".getplayervar($userName,"NickName")."^8 hit a ^3".$ObjectType." ^8Height: ".$Object_Z); EndEvent Strings for $DetectHitObject = ""; All_Objects //All Objects All_Tires //Small+Big Tires All_Cones //All Type of Cones incl Pointers All_Markers //All Types of Markers All_DistMarkers //Distance Markers All_Post//All Posts (Green/Orange/Red/White) All_Railings // (Short/Medium/Long Railing) All_Concrete // (All Concrete AutoX Objects) Concrete_Slabs Concrete_Ramps Concrete_Walls Concrete_Pillars Concrete_SlabWalls Concrete_RampWalls Concrete_ShortSlabWalls Concrete_Wedges Green_Post Orange_Post Red_Post White_Post All_Barriers // All Types of Barriers Long_Barrier Red_Barrier White_Barrier Banners SpeedBumps Bale KeepSigns SpeedSigns NOTE: You can combine objects, Example: "All_Tires+Red_Post+etc"