Exemple #1
0
 public static void StopPhone()
 {
     PhoneAppStarter.Stop();
     PhoneState.IsShown = false;
     API.DestroyMobilePhone();
     phoneScaleform.Dispose();
 }
        /// <summary>
        /// Loads the scaleform.
        /// </summary>
        /// <returns></returns>
        private async Task LoadScale()
        {
            if (scale != null)
            {
                for (var i = 0; i < maxClients * 2; i++)
                {
                    scale.CallFunction("SET_DATA_SLOT_EMPTY", i);
                }
                scale.Dispose();
            }
            scale = null;
            while (!HasScaleformMovieLoaded(RequestScaleformMovie("MP_MM_CARD_FREEMODE")))
            {
                await Delay(0);
            }
            scale = new Scaleform("MP_MM_CARD_FREEMODE");
            var titleIcon      = "2";
            var titleLeftText  = "FiveM";
            var titleRightText = $"Players {NetworkGetNumConnectedPlayers()}/{maxClients}";

            scale.CallFunction("SET_TITLE", titleLeftText, titleRightText, titleIcon);
            await UpdateScale();

            scale.CallFunction("DISPLAY_VIEW");
        }
Exemple #3
0
        private async Task OnMissionScaleFormTick()
        {
            try
            {
                if (!_isNear)
                {
                    if (_dropOffMarkerScaleform.IsLoaded)
                    {
                        _dropOffMarkerScaleform.Dispose();
                    }
                    return;
                }

                var playerPed = Game.PlayerPed;

                _dropOffMarkerScaleform.CallFunction("SET_MISSION_INFO", "Drop Off", "Action", "Player Info", "", "", true, 1,
                                                     999, 9999, "");
                _dropOffMarkerScaleform.Render3D(playerPed.GetOffsetPosition(new Vector3(0, 2f, 0)), -playerPed.Rotation, Vector3.One);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            await Task.FromResult(0);
        }
Exemple #4
0
        public void Dispose()
        {
            var h = _sc.Handle;

            SetScaleformMovieAsNoLongerNeeded(ref h);
            _sc.Dispose();
            _sc = null;
        }
Exemple #5
0
 static void ResetCamera()
 {
     World.RenderingCamera = null;
     camera.Delete();
     camera             = null;
     Game.ThermalVision = false;
     Game.Nightvision   = false;
     heliScaleform.Dispose();
 }
        public void ClosePlayerList()
        {
            if (cardScaleform != null)
            {
                cardScaleform.Dispose();
                cardScaleform = null;
            }

            Audio.PlaySoundFrontend("CLOSE_SOUND_NAME");
        }
Exemple #7
0
        private async Task OnTick()
        {
            try
            {
                var playerPed = Game.PlayerPed;

                if (!playerPed.IsInVehicle() &&
                    GetPedInVehicleSeat(playerPed.CurrentVehicle.Handle, -1) != playerPed.Handle)
                {
                    return;
                }

                _isNearTimeTrial = false; // Reset boolean before check

                foreach (var timetrial in TimeTrials)
                {
                    if (playerPed.Position.DistanceToSquared(timetrial.Item4) < 10)
                    {
                        Screen.Effects.Start(ScreenEffect.RaceTurbo, 0, true); // Or something else
                        Screen.DisplayHelpTextThisFrame($"Press ~INPUT_CONTEXT~ to Start TimeTrial ({timetrial.Item2})");

                        // TODO Scaleform.Dispose() is performed trashy. Find another way
                        _timetrialMarkerScaleform.CallFunction("SET_MISSION_INFO", $"{timetrial.Item2}", "Time Trial", $"{timetrial.Item3}", "", "", true, 1,
                                                               999, 9999, "");
                        _timetrialMarkerScaleform.Render3D(timetrial.Item4, -playerPed.Rotation, Vector3.One);
                        _isNearTimeTrial = true;

                        if (!Game.IsControlJustReleased(0, Control.Context))
                        {
                            continue;
                        }

                        Screen.Fading.FadeOut(500);
                        playerPed.CurrentVehicle.PositionNoOffset = timetrial.Item5;
                        _hasStarted        = true;
                        _selectedTimeTrial = timetrial.Item1;
                        Screen.Fading.FadeIn(500);
                    }
                }

                if (!_isNearTimeTrial)
                {
                    if (!Screen.Effects.IsActive(ScreenEffect.RaceTurbo))
                    {
                        Screen.Effects.Stop(ScreenEffect.RaceTurbo);
                    }
                    _timetrialMarkerScaleform.Dispose();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            await Task.FromResult(0);
        }
        public async void Loop()
        {
            if (Game.IsControlJustPressed(0, Control.MultiplayerInfo))
            {
                playerListCurPage = DEFAULT_PAGE;

                if (playerListOpen)
                {
                    Debug.WriteLine("Close Player List");
                    if (cardScaleform != null)
                    {
                        cardScaleform.Dispose();
                        cardScaleform = null;
                    }

                    Audio.PlaySoundFrontend(CLOSE_SOUND_NAME);
                }
                else
                {
                    Debug.WriteLine("Open Player List");
                    playerList = new PlayerList();
                    await GetPlayerHeadshots(playerList);

                    playerListMaxPage = (int)Math.Ceiling((double)playerList.Count() / PLAYERS_PER_PAGE);

                    cardScaleform = new Scaleform("mp_mm_card_freemode");
                    while (!cardScaleform.IsLoaded)
                    {
                        await BaseScript.Delay(0);
                    }
                    Debug.WriteLine($"IsScaleformLoaded: {cardScaleform}");

                    UpdateTitle();
                    UpdateCard();

                    Audio.PlaySoundFrontend(OPEN_SOUND_NAME);
                }

                playerListOpen = !playerListOpen;
            }

            if (playerListOpen)
            {
                API.SetScriptGfxAlign(76, 84);
                API.DrawScaleformMovie(cardScaleform.Handle, 0.122f, 0.3f, 0.28f, 0.6f, 255, 255, 255, 255, 0);
                API.ResetScriptGfxAlign();
            }
        }
Exemple #9
0
        /// <summary>
        /// Draws menu to screen, if any are open. Activated with interaction menu
        /// </summary>
        protected override void DrawMenu(List <Events.TickNametagData> nametags)
        {
            if (Pad.IsControlJustPressed(0, (int)Control.InteractionMenu))
            {
                if (_debug)
                {
                    Chat.Output("Player just pressed interactive key");
                }

                if (!_ply.IsSittingInAnyVehicle())
                {
                    if (!MenuPool.IsAnyMenuOpen())
                    {
                        if (_instructionLayer != null)
                        {
                            _instructionLayer.Dispose();
                            _instructionLayer = null;
                        }
                        OnShowSkinSelector(null);
                    }
                }
                else
                {
                    Chat.Output("Try outside of the vehicle");
                }
            }

            if (MenuPool.IsAnyMenuOpen())
            {
                MenuPool.ProcessMenus();
            }
            else
            {
                if (_instructionLayer != null)
                {
                    int x = 0; int y = 0;
                    RAGE.Game.Graphics.GetScreenResolution(ref x, ref y);
                    var size = new System.Drawing.Point(x, y);

                    //Needs minus values if you want to move the buttons elsewhere on screen
                    //var point = new System.Drawing.Point(-(int)(x * 0.9), -(int)(y * 0.5));

                    //Should be bottom right
                    var point = new System.Drawing.Point(0, 0);
                    _instructionLayer.Render2DScreenSpace(point, size);
                }
            }
        }
        public static async Task DrawCenterBar(string message, string subMessage, int colId = 5, int duration = 1000 * 10)
        {
            var scaleform = new Scaleform("MP_BIG_MESSAGE_FREEMODE");

            while (!scaleform.IsLoaded)
            {
                await Delay(100);
            }
            var now = API.GetGameTimer();

            scaleform.CallFunction("SHOW_SHARD_WASTED_MP_MESSAGE", message, subMessage, colId);
            while (API.GetGameTimer() - now <= duration)
            {
                scaleform.Render2D();
                await Delay(0);
            }
            scaleform.Dispose();
        }
        private async Task OnScaleformTick()
        {
            await Task.FromResult(0);

            if (organizationUpdateScaleform != null)
            {
                if (--organizationUpdateScaleformTime == 0)
                {
                    organizationUpdateScaleform.Dispose();
                    organizationUpdateScaleform = null;
                }
                else
                {
                    organizationUpdateScaleform.CallFunction("SHOW_SHARD_CENTERED_TOP_MP_MESSAGE");
                    organizationUpdateScaleform.CallFunction("SHARD_SET_TEXT", organizationUpdateScaleformMessage, "", 1);
                    organizationUpdateScaleform.Render2D();
                }
            }
        }
Exemple #12
0
        private async Task OnTick()
        {
            await Delay(100);

            if (Game.PlayerPed.IsDead)
            {
                wastedScaleform = new Scaleform("MP_BIG_MESSAGE_FREEMODE");
                died            = true;
                Screen.Effects.Start(ScreenEffect.DeathFailMpIn);
                Audio.PlaySoundFrontend("Bed", "WastedSounds");
                await Delay(10000);

                Screen.Fading.FadeOut(500);
                await Delay(3000);

                Game.PlayerPed.Position = WorldUtil.GetClosestImmersiveStreetSpawn(Game.PlayerPed.Position, 100f);
                Game.PlayerPed.Resurrect();
                Screen.Fading.FadeIn(500);
                Screen.Effects.Stop(ScreenEffect.DeathFailMpIn);
                died = false;
                wastedScaleform.Dispose();
            }
        }
Exemple #13
0
        private async Task OnIsDead()
        {
            await Task.FromResult(0);

            if (_isDead)
            {
                _deadMessage.CallFunction("SHOW_SHARD_WASTED_MP_MESSAGE", "~r~Wasted", "Press ~INPUT_CONTEXT~ to respawn", -1, true, true);
                _deadMessage.Render2D();

                if (Game.IsControlJustReleased(0, Control.Context))
                {
                    var playerPed = Game.PlayerPed;
                    SetEntityVisible(playerPed.Handle, true, true);
                    FreezeEntityPosition(playerPed.Handle, false);
                    Screen.Fading.FadeOut(500);
                    playerPed.Position = PlayerHousePosition;
                    playerPed.Resurrect();
                    Screen.Effects.Stop(ScreenEffect.DeathFailMpIn);
                    _isDead = false;
                    _deadMessage.Dispose();
                }
            }
        }
        /// <summary>
        /// Pre-loads the (new) page and sets up all images and grid titles. This is required before a page can be shown.
        /// </summary>
        /// <param name="pageIndex">The page to (re)load.</param>
        /// <param name="selectedIndex">The index of the item to select (add checkmark + 1 vote) on this page.</param>
        /// <param name="hoverIndex">The index of the item you want to highlight this page.</param>
        /// <param name="maxPages">The total amount of pages to display in the top right corner.</param>
        /// <returns></returns>
        public static async Task LoadPage(int pageIndex, int selectedIndex, int hoverIndex, int maxPages)
        {
            _scale.CallFunction("CLEANUP_MOVIE");
            _scale.Dispose();

            Scaleform newScaleformHandle = new Scaleform("MP_NEXT_JOB_SELECTION");

            if (!newScaleformHandle.IsLoaded)
            {
                RequestScaleformMovie("MP_NEXT_JOB_SELECTION");
                while (newScaleformHandle.IsLoaded)
                {
                    await Delay(0);
                }
            }
            newScaleformHandle.CallFunction("SET_TITLE", "Sumo - Select A Vehicle", $"Page {pageIndex + 1}/{maxPages}");
            var page = GridPages[pageIndex];

            for (var i = 0; i < 9; i++)
            {
                var item = page.items[i];
                if (item.textureDict != "" && item.textureName != "")
                {
                    if (!HasStreamedTextureDictLoaded(item.textureDict))
                    {
                        RequestStreamedTextureDict(item.textureDict, false);
                        while (!HasStreamedTextureDictLoaded(item.textureDict))
                        {
                            await Delay(0);
                        }
                    }
                }
                if (i < 6)
                {
                    newScaleformHandle.CallFunction("SET_GRID_ITEM", i, GetVehicleName(item.title), item.textureDict, item.textureName, 0,
                                                    0, -1, false, 0.0, 0.0, !item.enabled, -1);
                }
                else
                {
                    newScaleformHandle.CallFunction("SET_GRID_ITEM", i, item.title, item.textureDict, item.textureName, -1, 0, -2, false,
                                                    0.0, 0.0, !item.enabled, -1);
                }
            }
            if (selectedIndex > -1 && selectedIndex < 9)
            {
                newScaleformHandle.CallFunction("SET_GRID_ITEM_VOTE", selectedIndex, 1, 0, true, true);
            }

            if (selectedIndex < 6)
            {
                newScaleformHandle.CallFunction("SET_SELECTION", hoverIndex, GetVehicleName(GridPages[pageIndex].items[hoverIndex].title),
                                                GridPages[pageIndex].items[hoverIndex].description, false);
            }
            else
            {
                newScaleformHandle.CallFunction("SET_SELECTION", hoverIndex, GridPages[pageIndex].items[hoverIndex].title,
                                                GridPages[pageIndex].items[hoverIndex].description, false);
            }

            _scale = newScaleformHandle;
            return;
        }
Exemple #15
0
        public void ProcessControls()
        {
            if (!Visible || TemporarilyHidden)
            {
                return;
            }
            API.DisableAllControlActions(0);

            if (Game.IsControlJustPressed(2, Control.PhoneLeft) && FocusLevel == 0)
            {
                Tabs[Index].Active  = false;
                Tabs[Index].Focused = false;
                Tabs[Index].Visible = false;
                Index = (1000 - (1000 % Tabs.Count) + Index - 1) % Tabs.Count;
                Tabs[Index].Active  = true;
                Tabs[Index].Focused = false;
                Tabs[Index].Visible = true;

                Game.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
            }

            else if (Game.IsControlJustPressed(2, Control.PhoneRight) && FocusLevel == 0)
            {
                Tabs[Index].Active  = false;
                Tabs[Index].Focused = false;
                Tabs[Index].Visible = false;
                Index = (1000 - (1000 % Tabs.Count) + Index + 1) % Tabs.Count;
                Tabs[Index].Active  = true;
                Tabs[Index].Focused = false;
                Tabs[Index].Visible = true;

                Game.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
            }

            else if (Game.IsControlJustPressed(2, Control.FrontendAccept) && FocusLevel == 0)
            {
                if (Tabs[Index].CanBeFocused)
                {
                    Tabs[Index].Focused    = true;
                    Tabs[Index].JustOpened = true;
                    FocusLevel             = 1;
                }
                else
                {
                    Tabs[Index].JustOpened = true;
                    Tabs[Index].OnActivated();
                }

                Game.PlaySound("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
            }

            else if (Game.IsControlJustPressed(2, Control.PhoneCancel))
            {
                if (FocusLevel == 1)
                {
                    Tabs[Index].Focused = false;
                    FocusLevel          = 0;
                    Game.PlaySound("BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                }
                else if (FocusLevel == 0 && CanLeave)
                {
                    Visible = false;
                    Game.PlaySound("BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                    OnMenuClose?.Invoke(this, EventArgs.Empty);
                    _loaded = false;
                    _header.CallFunction("REMOVE_MENU", true);
                    _header.Dispose();
                    _header = null;
                }
            }

            if (!HideTabs)
            {
                if (Game.IsControlJustPressed(0, Control.FrontendLb))
                {
                    Tabs[Index].Active  = false;
                    Tabs[Index].Focused = false;
                    Tabs[Index].Visible = false;
                    Index = (1000 - (1000 % Tabs.Count) + Index - 1) % Tabs.Count;
                    Tabs[Index].Active  = true;
                    Tabs[Index].Focused = false;
                    Tabs[Index].Visible = true;

                    FocusLevel = 0;

                    Game.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                }

                else if (Game.IsControlJustPressed(0, Control.FrontendRb))
                {
                    Tabs[Index].Active  = false;
                    Tabs[Index].Focused = false;
                    Tabs[Index].Visible = false;
                    Index = (1000 - (1000 % Tabs.Count) + Index + 1) % Tabs.Count;
                    Tabs[Index].Active  = true;
                    Tabs[Index].Focused = false;
                    Tabs[Index].Visible = true;

                    FocusLevel = 0;

                    Game.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                }
            }

            if (Tabs.Count > 0)
            {
                Tabs[Index].ProcessControls();
            }
        }
Exemple #16
0
        /// <summary>
        /// Shows the end round animation. (TODO)
        /// </summary>
        /// <returns></returns>
        public static async Task ShowIntroScaleform()
        {
            var bg = new Scaleform("MP_CELEBRATION_BG");
            var fg = new Scaleform("MP_CELEBRATION_FG");
            var cb = new Scaleform("MP_CELEBRATION");

            RequestScaleformMovie("MP_CELEBRATION_BG");
            RequestScaleformMovie("MP_CELEBRATION_FG");
            RequestScaleformMovie("MP_CELEBRATION");
            while (!bg.IsLoaded || !fg.IsLoaded || !cb.IsLoaded)
            {
                await Delay(0);
            }

            // Setting up colors.
            bg.CallFunction("CREATE_STAT_WALL", "ch", "HUD_COLOUR_BLACK", -1);
            fg.CallFunction("CREATE_STAT_WALL", "ch", "HUD_COLOUR_RED", -1);
            cb.CallFunction("CREATE_STAT_WALL", "ch", "HUD_COLOUR_BLUE", -1);

            // Setting up pause duration.
            bg.CallFunction("SET_PAUSE_DURATION", 3.0f);
            fg.CallFunction("SET_PAUSE_DURATION", 3.0f);
            cb.CallFunction("SET_PAUSE_DURATION", 3.0f);

            bool   won      = new Random().Next(0, 2) == 0;
            string win_lose = won ? "CELEB_LOSER" : "CELEB_WINNER";

            bg.CallFunction("ADD_WINNER_TO_WALL", "ch", win_lose, GetPlayerName(PlayerId()), "", 0, false, "", false);
            fg.CallFunction("ADD_WINNER_TO_WALL", "ch", win_lose, GetPlayerName(PlayerId()), "", 0, false, "", false);
            cb.CallFunction("ADD_WINNER_TO_WALL", "ch", win_lose, GetPlayerName(PlayerId()), "", 0, false, "", false);

            // Setting up background.
            bg.CallFunction("ADD_BACKGROUND_TO_WALL", "ch");
            fg.CallFunction("ADD_BACKGROUND_TO_WALL", "ch");
            cb.CallFunction("ADD_BACKGROUND_TO_WALL", "ch");

            // Preparing to show the wall.
            bg.CallFunction("SHOW_STAT_WALL", "ch");
            fg.CallFunction("SHOW_STAT_WALL", "ch");
            cb.CallFunction("SHOW_STAT_WALL", "ch");

            // Drawing the wall on screen for 3 seconds + 1 seconds (for outro animation druation).
            var timer = GetGameTimer();

            DisableDrawing = true;
            while (GetGameTimer() - timer <= (3000 + 1000))
            {
                await Delay(0);

                DrawScaleformMovieFullscreenMasked(bg.Handle, fg.Handle, 255, 255, 255, 255);
                DrawScaleformMovieFullscreen(cb.Handle, 255, 255, 255, 255, 0);
                HideHudAndRadarThisFrame();
            }
            DisableDrawing = false;

            // Playing effect when it's over.
            StartScreenEffect("MinigameEndNeutral", 0, false);
            PlaySoundFrontend(-1, "SCREEN_FLASH", "CELEBRATION_SOUNDSET", false);

            // Cleaning up.
            bg.CallFunction("CLEANUP");
            fg.CallFunction("CLEANUP");
            cb.CallFunction("CLEANUP");

            bg.Dispose();
            fg.Dispose();
            cb.Dispose();
        }
Exemple #17
0
 public void Dispose()
 {
     _sc.Dispose();
     _sc = null;
 }
Exemple #18
0
        internal async Task MainTick()
        {
            Ped player = Game.PlayerPed;

            if (IsPlayerInHeli() && player.CurrentVehicle.HeightAboveGround > 2.5f)
            {
                Vehicle heli = player.CurrentVehicle;

                if (Game.IsControlJustPressed(0, CAM_TOGGLE) && config.AllowCamera && !Game.IsControlPressed(0, Control.Aim))
                {
                    PlayManagedSoundFrontend("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                    _helicam = true;
                }

                if (Game.IsControlJustPressed(0, REPEL) && config.AllowRappel)
                {
                    if (heli.GetPedOnSeat(VehicleSeat.LeftRear) == player || heli.GetPedOnSeat(VehicleSeat.RightRear) == player)
                    {
                        if (_shouldRappel)
                        {
                            PlayManagedSoundFrontend("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                            TaskRappelFromHeli(player.Handle, 1);
                        }
                        else
                        {
                            Screen.ShowNotification("Press again to rappel from helicopter.");
                            _shouldRappel = true;
                        }
                    }
                    else
                    {
                        Screen.ShowNotification("~r~Can't rappel from this seat!", true);
                        PlayManagedSoundFrontend("5_Second_Timer", "DLC_HEISTS_GENERAL_FRONTEND_SOUNDS");
                    }
                }
            }
            else
            {
                _shouldRappel = false;
            }

            if (_helicam)
            {
                SetTimecycleModifier("heliGunCam");
                SetTimecycleModifierStrength(0.3f);
                Scaleform scaleform = new Scaleform("HELI_CAM");
                while (!scaleform.IsLoaded)
                {
                    await Delay(1);
                }

                Vehicle heli = player.CurrentVehicle;
                Camera  cam  = new Camera(CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true));
                cam.AttachTo(heli, new Vector3(0f, 0f, -1.5f));
                cam.FieldOfView = _fov;
                cam.Rotation    = new Vector3(0f, 0f, heli.Heading);
                RenderScriptCams(true, false, 0, true, false);

                SendNuiMessage(JsonConvert.SerializeObject(new
                {
                    shown = true,
                    heli  = heli.Model.IsHelicopter,
                    plane = !heli.Model.IsHelicopter
                }));

                TriggerEvent("HideHud");
                Entity lockedEntity = null;

                Vector3 hitPos = Vector3.Zero;
                Vector3 endPos = Vector3.Zero;

                Blip speedBlip  = null;
                Blip crosshairs = World.CreateBlip(heli.Position);
                crosshairs.Sprite   = (BlipSprite)123;
                crosshairs.Color    = BlipColor.Red;
                crosshairs.Scale    = 0.5f;
                crosshairs.Name     = "Current Crosshair Position";
                crosshairs.Rotation = 0;

                DateTime lastLosTime = DateTime.Now;
                DateTime lockedTime  = DateTime.Now;
                DateTime enterTime   = DateTime.Now;

                SetNetworkIdExistsOnAllMachines(heli.NetworkId, true);

                while (_helicam && player.IsAlive && player.IsSittingInVehicle() && player.CurrentVehicle == heli && player.CurrentVehicle.HeightAboveGround > 2.5f)
                {
                    float zoomValue = 1.0f / (config.FovMax - config.FovMin) * (_fov - config.FovMin);

                    Game.DisableControlThisFrame(0, Control.NextCamera);
                    Game.DisableControlThisFrame(0, Control.VehicleSelectNextWeapon);
                    Game.DisableControlThisFrame(0, Control.VehicleCinCam);
                    Game.DisableControlThisFrame(0, Control.VehicleHeadlight);
                    Game.DisableControlThisFrame(0, REPEL);
                    Game.DisableControlThisFrame(0, TOGGLE_SPOTLIGHT);
                    Game.DisableControlThisFrame(0, Control.Phone);
                    heli.IsRadioEnabled = false;


                    if (Game.IsControlJustPressed(0, CAM_TOGGLE))
                    {
                        PlayManagedSoundFrontend("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                        _helicam = false;
                    }

                    if (Game.IsControlJustPressed(0, VISION_TOGGLE))
                    {
                        PlayManagedSoundFrontend("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                        ChangeVision();
                    }

                    if (Game.IsControlJustPressed(0, Control.ContextSecondary))
                    {
                        cam.Rotation = new Vector3(0f, 0f, heli.Heading);
                        _fov         = 80f;
                    }

                    if (Game.IsControlJustPressed(0, Control.NextCamera))
                    {
                        _roadOverlay = !_roadOverlay;
                        if (_roadOverlay && _streetOverlay.Count == 0)
                        {
                            SendNuiMessage(JsonConvert.SerializeObject(new
                            {
                                type    = "alert",
                                message = "Street overlay failed to load. Contact the server owner(s)."
                            }));
                        }
                    }

                    if (lockedEntity != null)
                    {
                        if (Entity.Exists(lockedEntity))
                        {
                            if ((lockedEntity.Model.IsPed && !config.AllowPedLocking) || lockedEntity.IsInWater)
                            {
                                lockedEntity = null;
                            }
                            else
                            {
                                if (HasEntityClearLosToEntity(heli.Handle, lockedEntity.Handle, 17))
                                {
                                    lastLosTime = DateTime.Now;
                                }

                                RenderInfo(lockedEntity);
                                hitPos = endPos = lockedEntity.Position;
                                string lockedTimeString = DateTime.Now.Subtract(lockedTime).ToString(@"mm\:ss");
                                RenderText(0.2f, 0.4f, $"~g~Locked ~w~{lockedTimeString}");

                                if (World.GetDistance(lockedEntity.Position, heli.Position) > config.MaxDist || Game.IsControlJustPressed(0, TOGGLE_ENTITY_LOCK) || DateTime.Now.Subtract(lastLosTime).Seconds > 5)
                                {
                                    Debug.WriteLine($"LOS: {DateTime.Now.Subtract(lastLosTime).Seconds}. Dist: {Math.Round(World.GetDistance(lockedEntity.Position, heli.Position))}");
                                    lockedEntity = null;
                                    lockedTime   = new DateTime();
                                    cam.StopPointing();
                                    PlayManagedSoundFrontend("5_Second_Timer", "DLC_HEISTS_GENERAL_FRONTEND_SOUNDS");
                                }
                            }
                        }
                        else
                        {
                            lockedEntity = null;
                        }
                    }
                    else
                    {
                        RenderText(0.2f, 0.4f, $"~r~Unlocked");
                        CheckInputRotation(cam, zoomValue);
                        Tuple <Entity, Vector3, Vector3> detected = GetEntityInView(cam);
                        endPos = detected.Item3;
                        if (Entity.Exists(detected.Item1))
                        {
                            RenderInfo(detected.Item1);
                            if (Game.IsControlJustPressed(0, TOGGLE_ENTITY_LOCK))
                            {
                                PlayManagedSoundFrontend("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                                lockedEntity = detected.Item1;
                                lockedTime   = DateTime.Now;
                                cam.PointAt(lockedEntity);
                                lastLosTime = DateTime.Now;
                            }
                        }
                        if (!detected.Item2.IsZero)
                        {
                            hitPos = detected.Item2;
                        }
                    }

                    if (hitPos.IsZero)
                    {
                        crosshairs.Alpha = 0;
                    }
                    else
                    {
                        crosshairs.Alpha    = 255;
                        crosshairs.Position = hitPos;
                    }

                    if (Game.IsControlJustPressed(0, Control.ReplaySnapmaticPhoto) && config.AllowSpeedCalculations)
                    {
                        if (hitPos.IsZero)
                        {
                            SendNuiMessage(JsonConvert.SerializeObject(new
                            {
                                type    = "alert",
                                message = "You are not aiming at anything!"
                            }));
                        }
                        else
                        {
                            _calculateSpeed = !_calculateSpeed;
                            if (_calculateSpeed)
                            {
                                hitPos.Z        += 0.1f;
                                speedBlip        = World.CreateBlip(hitPos);
                                speedBlip.Color  = BlipColor.MichaelBlue;
                                speedBlip.Sprite = BlipSprite.PoliceCar;
                                speedBlip.Name   = $"Speed Marker {DateTime.Now.ToString("HH:MM:SS")}";
                                SetBlipDisplay(speedBlip.Handle, 2);
                                _speedMarker = new Tuple <int, Vector3>(Game.GameTime, speedBlip.Position);
                            }
                            else
                            {
                                if (speedBlip != null)
                                {
                                    speedBlip.Delete();
                                }
                                speedBlip    = null;
                                _speedMarker = null;
                            }
                        }
                    }

                    TimeSpan timeInCam = DateTime.Now.Subtract(enterTime);
                    RenderText(0.01f, config.TextY - 0.1f, $"{DateTime.UtcNow.ToString($"MM/dd/yyyy\nHH:mm:ssZ")}\n~y~{timeInCam.ToString(@"mm\:ss")}", 0.3f);

                    float  latPos  = heli.Position.Y;
                    float  lonPos  = heli.Position.X;
                    string latText = "N";
                    string lonText = "E";
                    if (latPos < 0f)
                    {
                        latText = "S";
                        latPos  = Math.Abs(latPos);
                    }
                    if (lonPos < 0f)
                    {
                        lonText = "W";
                        lonPos  = Math.Abs(lonPos);
                    }
                    double aircraftHdg = 360 - Math.Round(heli.Heading);
                    RenderText(0.075f, config.TextY - 0.1f, $"Aircraft:\n{latText} {Math.Round(latPos, 2)}\n{lonText} {Math.Round(lonPos, 2)}\n{aircraftHdg}°  {Math.Ceiling(heli.HeightAboveGround * 3.2808f)}ft", 0.3f);

                    HandleZoom(cam);
                    RenderTargetPosInfo(hitPos);
                    if (config.AllowMarkers)
                    {
                        HandleMarkers(hitPos);
                    }
                    RenderRotation(heli, hitPos.IsZero ? endPos : hitPos, cam.Rotation);

                    if (_roadOverlay && _streetOverlay.Count > 0)
                    {
                        RenderStreetNames(hitPos == Vector3.Zero ? heli.Position : hitPos);
                    }

                    if (Game.IsDisabledControlJustPressed(0, TOGGLE_SPOTLIGHT) && config.AllowSpotlights)
                    {
                        _spotlightActive = !_spotlightActive;

                        if (!_spotlightActive)
                        {
                            TriggerServerEvent("helicam:spotlight:kill");
                        }
                        else
                        {
                            SendNuiMessage(JsonConvert.SerializeObject(new
                            {
                                type    = "info",
                                message = $"Spotlight turned on"
                            }));
                        }
                    }

                    if (_spotlightActive && config.AllowSpotlights)
                    {
                        Vector3 spotlightDest = Entity.Exists(lockedEntity)
                            ? lockedEntity.Position - cam.Position
                            : (!hitPos.IsZero ? hitPos - cam.Position : endPos - cam.Position);
                        spotlightDest.Normalize();
                        TriggerServerEvent("helicam:spotlight:draw", heli.NetworkId, cam.Position, spotlightDest, 5f);
                    }

                    scaleform.CallFunction("SET_ALT_FOV_HEADING", heli.Position.Z, zoomValue, cam.Rotation.Z);
                    scaleform.Render2D();

                    hitPos = Vector3.Zero;
                    await Delay(0);
                }

                // No longer in cam
                if (_spotlightActive)
                {
                    _spotlightActive = false;
                    TriggerServerEvent("helicam:spotlight:kill");
                }

                SendNuiMessage(JsonConvert.SerializeObject(new
                {
                    shown = false
                }));

                TriggerEvent("ShowHud");
                _helicam = false;
                if (speedBlip != null)
                {
                    speedBlip.Delete();
                }
                crosshairs.Delete();
                _speedMarker    = null;
                _calculateSpeed = false;
                ClearTimecycleModifier();
                _visionState = 0;
                _fov         = (config.FovMax + config.FovMin) * 0.5f; // Reset to default zoom level
                RenderScriptCams(false, false, 0, true, false);
                scaleform.Dispose();
                cam.Delete();
                Game.Nightvision = false;
            }
        }
Exemple #19
0
 public static void Dispose()
 {
     Main.GetInstance().UnregisterTickHandler(DisplayScaleform);
     _sc.Dispose();
     _sc = null;
 }
Exemple #20
0
        private async Task OnTimeTrialTick()
        {
            try
            {
                if (_hasStarted)
                {
                    var playerPed = Game.PlayerPed;

                    if (!_countDownDone)
                    {
                        var countdownTime = 10;

                        while (countdownTime != 0)
                        {
                            Game.DisableControlThisFrame(0, Control.VehicleSubTurnHardLeft);
                            Game.DisableControlThisFrame(0, Control.VehicleSubTurnHardRight);
                            SetVehicleForwardSpeed(playerPed.CurrentVehicle.Handle, 0f);

                            Audio.PlaySoundFrontend("CHECKPOINT_AHEAD", "HUD_MINI_GAME_SOUNDSET");
                            _timetrialCountdownScaleform.CallFunction("SET_MESSAGE", $"{countdownTime}", 255, 255, 255,
                                                                      true);
                            _timetrialCountdownScaleform.Render2D();
                            countdownTime--;

                            await Delay(1000);
                        }
                        _timetrialCountdownScaleform.CallFunction("SET_MESSAGE", "GO!", 255, 255, 255, true);
                        _timetrialCountdownScaleform.Render2D();


                        _gameTimeAtStart = GetGameTimer();

                        _countDownDone = true;
                    }

                    if (_timetrialCountdownScaleform.IsLoaded)
                    {
                        _timetrialCountdownScaleform.Dispose();
                    }

                    while (playerPed.CurrentVehicle.Position.DistanceToSquared(TimeTrials[_selectedTimeTrial].Item6) < 1)
                    {
                        _currentTime = GetGameTimer() - _gameTimeAtStart;

                        // TODO Draw RaceTimer Scaleform
                        Screen.ShowSubtitle($"Time: {_currentTime}"); // Temp solution

                        if (!Game.IsControlJustReleased(0, Control.SelectCharacterMichael))
                        {
                            continue;
                        }

                        Screen.ShowNotification("Cancelled Time Trial");
                        _hasStarted      = false;
                        _countDownDone   = false;
                        _currentTime     = 0;
                        _gameTimeAtStart = 0;
                        return;
                    }

                    _finalTime = GetGameTimer() - _gameTimeAtStart;

                    // TODO RaceComplete Scaleform _timetrialCompletedScaleform
                    // Perhaps need to draw scaleform EVERY FRAME so create separate Tick
                    Audio.PlaySoundFrontend("TREVOR_BIG_01");
                    _timetrialCompletedScaleform.CallFunction("SHOW_MISSION_PASSED_MESSAGE", $"Time Trial Completed in {_finalTime}ms", "", 100, true, 0, true);
                    _timetrialCompletedScaleform.Render2D();

                    _hasStarted    = false;
                    _countDownDone = false;
                    _currentTime   = 0;

                    await Delay(5000);

                    _timetrialCompletedScaleform.Dispose();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            await Task.FromResult(0);
        }