private async Task OnTick() { foreach (var vehicle in World.GetAllVehicles()) { var handle = vehicle.Handle; if (IsSpotlightEnabled(handle)) { var door = API.GetEntityBoneIndexByName(handle, "door_dside_f"); var coords = API.GetWorldPositionOfEntityBone(handle, door); var doorCoords = API.GetWorldPositionOfEntityBone(handle, door); var carHeadingVector = (Vector2)API.GetEntityForwardVector(handle); var carHeadingVectorAngle = AngleConverter(Convert.ToDouble(carHeadingVector.X), Convert.ToDouble(carHeadingVector.Y)); SetSpotlightDefaultsIfNull(handle); var finalVector = new Vector3( new Vector2( Convert.ToSingle(Math.Cos((carHeadingVectorAngle + API.DecorGetFloat(handle, DECOR_NAME_XY)) / 57.2957795131)), Convert.ToSingle(Math.Sin((carHeadingVectorAngle + API.DecorGetFloat(handle, DECOR_NAME_XY)) / 57.2957795131)) ), API.DecorGetFloat(handle, DECOR_NAME_Z) ); API.DrawSpotLight(coords.X, doorCoords.Y, coords.Z + 0.35f, finalVector.X, finalVector.Y, finalVector.Z, 221, 221, 221, 70.0f, API.DecorGetFloat(handle, DECOR_NAME_BRIGHTNESS), 4.3f, 15.0f, 28.6f); } } await Task.FromResult(0); }
private async Task OnTick() { int playerVehicle = API.GetVehiclePedIsIn(API.GetPlayerPed(-1), false); foreach (var vehicle in World.GetAllVehicles()) { var handle = vehicle.Handle; if (IsSpotlightEnabled(handle)) { string baseBone = GetBaseBone(handle); Vector3 baseCoords = GetBaseCoordinates(handle, baseBone); Vector3 directionalCoords = GetDirectionalCoordinates(handle, baseBone); SetSpotlightDefaultsIfNull(handle); if (handle == playerVehicle) { DrawSpotlightLabel(true); } API.DrawSpotLight( baseCoords.X, baseCoords.Y, baseCoords.Z, directionalCoords.X, directionalCoords.Y, directionalCoords.Z, 221, 221, 221, VehicleHasRotatableTargetBone(handle) ? 200f : 70f, // rotatable spotlights have longer max reach API.DecorGetFloat(handle, DECOR_NAME_BRIGHTNESS), 4.3f, 15.0f, 28.6f ); } } await Task.FromResult(0); }
private static Vector3 GetDirectionalCoordinates(int handle, string bone) { if (bone == "door_dside_f") // target bone is not rotatable, use default orientation { Vector2 vehicleHeading = (Vector2)API.GetEntityForwardVector(handle); double vehicleHeadingAngle = Utilities.DirectionToAngle(Convert.ToDouble(vehicleHeading.X), Convert.ToDouble(vehicleHeading.Y)); return(new Vector3( new Vector2( Convert.ToSingle(Math.Cos((vehicleHeadingAngle + API.DecorGetFloat(handle, DECOR_NAME_XY)) / 57.2957795131)), Convert.ToSingle(Math.Sin((vehicleHeadingAngle + API.DecorGetFloat(handle, DECOR_NAME_XY)) / 57.2957795131)) ), API.DecorGetFloat(handle, DECOR_NAME_Z) )); } else // target bone is rotatable, convert to direction { Vector3 boneHeading = API.GetWorldRotationOfEntityBone(handle, API.GetEntityBoneIndexByName(handle, bone)); if (API.GetVehicleClass(handle) == 15) // helicopters retain manual offset { double angle = Utilities.DirectionToAngle((Vector2)Utilities.RotationToDirection(boneHeading)); return(new Vector3( new Vector2( Convert.ToSingle(Math.Cos((angle + API.DecorGetFloat(handle, DECOR_NAME_XY)) / 57.2957795131)), Convert.ToSingle(Math.Sin((angle + API.DecorGetFloat(handle, DECOR_NAME_XY)) / 57.2957795131)) ), API.DecorGetFloat(handle, DECOR_NAME_Z) )); } return(Utilities.RotationToDirection(boneHeading)); } }
private async Task MoveSpotlightVertical(bool up) { var vehicle = API.GetVehiclePedIsIn(API.GetPlayerPed(-1), Config.GetValueBool(Config.REMOTE_CONTROL, true)); var current = API.DecorGetFloat(vehicle, DECOR_NAME_Z); if (up) { if (current <= 0.1f) { await TranslateDecorSmoothly(vehicle, DECOR_NAME_Z, current, current + 0.1f, 10); } } else { if (current >= -1.2f) { await TranslateDecorSmoothly(vehicle, DECOR_NAME_Z, current, current - 0.1f, 10); } } }
private async Task MoveSpotlightHorizontal(bool left) { var vehicle = API.GetVehiclePedIsIn(API.GetPlayerPed(-1), true); var current = API.DecorGetFloat(vehicle, DECOR_NAME_XY); if (left) { if (current <= 90f) { await TranslateDecorSmoothly(vehicle, DECOR_NAME_XY, current, current + 10f, 10); } } else { if (current >= -30f) { await TranslateDecorSmoothly(vehicle, DECOR_NAME_XY, current, current - 10f, 10); } } }
private async Task MoveSpotlightHorizontal(bool left) { var vehicle = API.GetVehiclePedIsIn(API.GetPlayerPed(-1), Config.GetValueBool(Config.REMOTE_CONTROL, true)); var current = API.DecorGetFloat(vehicle, DECOR_NAME_XY); Debug.WriteLine(Config.GetValueFloat(Config.RANGE_LEFT, 90f).ToString()); if (left) { if (current <= Config.GetValueFloat(Config.RANGE_LEFT, 90f)) { await TranslateDecorSmoothly(vehicle, DECOR_NAME_XY, current, current + 10f, 10); } } else { if (current >= -Config.GetValueFloat(Config.RANGE_RIGHT, 30f)) { await TranslateDecorSmoothly(vehicle, DECOR_NAME_XY, current, current - 10f, 10); } } }