modded class PlayerBase { protected bool RTisLinked; protected bool RTshouldLink; protected Object RTlinkParent; protected bool m_RTWantEnterVehicle; int m_Linkbuffer; protected Object m_RTObject; protected int m_RTSimStep; override void Init() { super.Init(); RegisterNetSyncVariableBool("m_RTWantEnterVehicle"); SetWantEnterVehicle(false); } override bool IsInVehicle() { if (RTisLinked) { return false; } return super.IsInVehicle(); //return m_MovementState.m_CommandTypeId == DayZPlayerConstants.COMMANDID_VEHICLE || (GetParent() != null && GetParent().IsInherited(Transport) && !RTisLinked ); } bool WantEnterVehicle() { return m_RTWantEnterVehicle; } void SetWantEnterVehicle(bool wantenter) { m_RTWantEnterVehicle = wantenter; SetSynchDirty(); } void RTLinkPlayer(Object obj) { vector tmPlayer[4]; vector tmTarget[4]; vector tmLocal[4]; GetTransform( tmPlayer ); obj.GetTransform( tmTarget ); Math3D.MatrixInvMultiply4( tmTarget, tmPlayer, tmLocal ); if (!this.GetParent()) { LinkToLocalSpaceOf( obj, tmLocal ); //Print("LINK " + GetSimulationTimeStamp()); RTisLinked = true; RTConfig config = GetDayZGame().GetRoadTripConfig(); if (config.Debugging) { GetGame().GetMission().OnEvent(ChatMessageEventTypeID, new ChatMessageEventParams(CCDirect, "", "LinkPlayer", "")); } } } void RTUnlinkPlayer() { if (this.GetParent()) { UnlinkFromLocalSpace(); RTConfig config = GetDayZGame().GetRoadTripConfig(); if (config.Debugging) { GetGame().GetMission().OnEvent(ChatMessageEventTypeID, new ChatMessageEventParams(CCDirect, "", "UNLinkPlayer", "")); } RTisLinked = false; } } //Before override bool ModCommandHandlerBefore(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished) { if (GetGame().IsServer()) { if (m_RTObject && GetSimulationTimeStamp() == m_RTSimStep) { RTLinkPlayer(m_RTObject); } return super.ModCommandHandlerInside(pDt, pCurrentCommandID, pCurrentCommandFinished); } if (GetGame().IsClient()) { if (pCurrentCommandID == DayZPlayerConstants.COMMANDID_CLIMB ) { return super.ModCommandHandlerBefore(pDt, pCurrentCommandID, pCurrentCommandFinished); } Object obj; ScriptInputUserData ctx; RTshouldLink = RTNeedLink(obj); //RTshouldLink = RTIsColliding(obj); RTConfig config = GetDayZGame().GetRoadTripConfig(); m_Linkbuffer++; if (RTshouldLink && CanLinkToVehicle(config, obj)) { if (!RTisLinked && obj) { if (m_Linkbuffer>=40 && ScriptInputUserData.CanStoreInputUserData()) { //GetGame().GetMission().OnEvent(ChatMessageEventTypeID, new ChatMessageEventParams(CCDirect, "", "ShouldLink " + RTshouldLink + " x " + obj, "")); m_Linkbuffer = 0; //Print("BEFORE LINK " + GetSimulationTimeStamp()); RTLinkPlayer(obj); ctx = new ScriptInputUserData; ctx.Write(ROADTRIP_SYNCHRO_LINK); ctx.Write(obj); ctx.Write(GetSimulationTimeStamp()); ctx.Send(); //ctx.Reset(); } } } else { if (RTisLinked && !obj) { if (m_Linkbuffer>60 && ScriptInputUserData.CanStoreInputUserData()) { m_Linkbuffer = 0; ctx = new ScriptInputUserData; ctx.Write(ROADTRIP_SYNCHRO_UNLINK); ctx.Send(); //ctx.Reset(); RTUnlinkPlayer(); } } } } return super.ModCommandHandlerBefore(pDt, pCurrentCommandID, pCurrentCommandFinished); } override bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx) { if( super.OnInputUserDataProcess(userDataType, ctx) ) return true; if (userDataType == ROADTRIP_SYNCHRO_LINK) { ctx.Read(m_RTObject); ctx.Read(m_RTSimStep); /* EntityAI target = null; if (m_RTObject) { RTLinkPlayer(m_RTObject); return true; } */ return false; //false } else if (userDataType == ROADTRIP_SYNCHRO_UNLINK) { RTUnlinkPlayer(); return true; } return false; } bool RTIsColliding(out Object object) { object = null; array excluded = new array; array collided = new array; excluded.Insert(this); //IsBush() GetGame().IsBoxColliding(this.ModelToWorld(Vector(0,-0.5,0)), this.GetOrientation(), "0.5 0.5 0.5", excluded, collided); if (collided.Count() > 0) { /* if (collided.Count() == 1 && collided[0].IsBush()) { return true; } if (collided.Count() == 2 && collided[0].IsBush() && collided[1].IsBush()) { return true; } if (collided.Count() == 3 && collided[0].IsBush() && collided[1].IsBush() && collided[2].IsBush()) { return true; } */ GetGame().GetMission().OnEvent(ChatMessageEventTypeID, new ChatMessageEventParams(CCDirect, "", "collided " + collided.Count() + " x " + collided[0], "")); object = collided[0]; return (true && object); } return (false && NULL); } bool RTNeedLink(out Object object) { if (WantEnterVehicle()) return (false && NULL); object = null; set objects = new set; vector from = GetPosition() + "0 0.3 0"; vector to = from - "0 1 0"; vector contact_pos; vector contact_dir; int contact_component; Transport vehicle; RTConfig config = GetDayZGame().GetRoadTripConfig(); array hit_proxy_objects = new array; RaycastRVParams ray_input = new RaycastRVParams( from, to, this, 0.125 ); DayZPhysics.RaycastRVProxy( ray_input, hit_proxy_objects ); if (hit_proxy_objects != null) { if (hit_proxy_objects.Count() > 0) { if (hit_proxy_objects[0].parent != NULL) { Object veh = hit_proxy_objects[0].parent; if (veh.IsTransport()) { object = veh; return (true && object); } /* if (config.AllowOther) { for ( int i = 0; i < config.OtherClasses.Count(); i++ ) { if (veh.IsKindOf(config.OtherClasses.Get(i))) { object = veh; return (true && object); } } } */ } //add other classes condition } } /* bool boo = DayZPhysics.RaycastRV( from, to, contact_pos, contact_dir, contact_component, objects, this, this, false, false, ObjIntersectView, 0.005 ); if (objects[0] && (Class.CastTo(vehicle, objects[0]) || Class.CastTo(vehicle, objects[0].GetParent())) ) { object = vehicle; } return (boo && object); */ auto objs = GetObjectsAt( from, to, this, 0.125 ); if( objs != null && objs.Count() > 0 ) { if (Class.CastTo(vehicle,objs[0])) { object = objs[0]; //Print("XXXXXXX Object XXXXXX " + object); return (true && object); } //add other classes too if (config.AllowOther) { for ( int j = 0; j < config.OtherClasses.Count(); j++ ) { if (objs[0].IsKindOf(config.OtherClasses.Get(j))) { object = objs[0]; return (true && object); } } } } return (false && null); } set< Object > GetObjectsAt( vector from, vector to, Object ignore = NULL, float radius = 0.6, Object with = NULL ) { vector contact_pos; vector contact_dir; int contact_component; set< Object > geom = new set< Object >; set< Object > view = new set< Object >; DayZPhysics.RaycastRV( from, to, contact_pos, contact_dir, contact_component, geom, with, this, false, false, ObjIntersectGeom, radius, CollisionFlags.ALLOBJECTS ); DayZPhysics.RaycastRV( from, to, contact_pos, contact_dir, contact_component, view, with, this, false, false, ObjIntersectView, radius, CollisionFlags.ALLOBJECTS ); //GetGame().GetMission().OnEvent(ChatMessageEventTypeID, new ChatMessageEventParams(CCDirect, "", "raycast " + geom + " x " + view, "")); for ( int i = 0; i < geom.Count(); i++ ) { view.Insert( geom[i] ); } if ( view.Count() > 0 ) return view; return NULL; } protected static bool CanLinkToVehicle (RTConfig config, Object vehi) { if (!config.OnlySelected) { return true; } if (config.Vehicles.Count()>0) { for ( int i = 0; i < config.Vehicles.Count(); i++ ) { if (vehi.IsKindOf(config.Vehicles.Get(i))) return true; } } return false; } };