Beispiel #1
0
        public IWavePlayer PlayKillStreak(string sfxName, string ext = "wav")
        {
            if (!RPGSettings.PlayKillstreaks)
            {
                return(null);
            }

            KillStreakDevice = KillStreakDevice ?? new WaveOutEvent();

            var path = SFXPath + sfxName + "." + ext;

            Wait(250);
            if (!File.Exists(path))
            {
                RPGLog.Log("Did not find killstreak SFX to play");
                return(KillStreakDevice);
            }
            AudioFileReader audioFileReader = new AudioFileReader(path);

            audioFileReader.Volume = 0.6f * Volume;

            KillStreakDevice.Stop();
            KillStreakDevice.Init(audioFileReader);
            KillStreakDevice.Play();
            return(KillStreakDevice);
        }
Beispiel #2
0
        protected override void Dispose(bool A_0)
        {
            if (!A_0)
            {
                return;
            }

            if (!RPG.GameLoaded)
            {
                RPGLog.Log("Game ended.");
                return;
            }

            RPG.Audio.DisposeAll();


            int objDestroyed = 0;
            var count        = RPG.WorldData.AllObjects.Count;

            while (RPG.WorldData.AllObjects.Any())
            {
                RPG.WorldData.AllObjects.First().Destroy();
                objDestroyed++;
            }

            RPGLog.Log("Cleaned up " + objDestroyed + "/" + count + " objects");
            RPGLog.Log("Thread ended.");
            RPGLog.Log("");

            base.Dispose(true);
        }
Beispiel #3
0
        protected override void Start()
        {
            RPGLog.Clear();
            string str;

            CheckStatus(out str);
            RPGLog.Log("Starting GTARPG Log:");
            RPGLog.Log("Date: " + DateTime.Now.ToLongDateString());
            RPGLog.Log("OS: " + FriendlyName());
            RPGLog.Log("GTAV Path: " + Application.StartupPath);
            RPGLog.Log("ScriptHook V v1.0.393.4: " + (hasScriptHookV ? "Found" : "Not Found"));
            RPGLog.Log("ScriptHookVNET v1.1: " + (hasScriptHookDotNet ? "Found" : "Not Found"));
            RPGLog.Log(".NET v4.5: " + (hasNet45 ? "Found" : "Not Found"));
            RPGLog.LogRaw("");
            RPGLog.Log("Waiting to start rpg mode...");

            Function.Call(Hash.DISPLAY_HUD, 1);
            Function.Call(Hash.DISPLAY_RADAR, 1);
            World.RenderingCamera = null;
            Function.Call(Hash.SET_TIME_SCALE, 1.0f);
            Function.Call(Hash.SET_TIMECYCLE_MODIFIER, "");
            Game.Player.CanControlCharacter = true;


            Function.Call(Hash.SET_PLAYER_WEAPON_DAMAGE_MODIFIER, Game.Player, 1.0f);
            Function.Call(Hash.SET_AI_WEAPON_DAMAGE_MODIFIER, 1.0f);

            if (RPGSettings.AutostartRPGMode)
            {
                Wait(500);
                StartRPGMode();
            }
        }
Beispiel #4
0
        public static void Initialise()
        {
            RPGLog.Log("Initialising RPG Mod.");
            RPG.GameMode = GameMode.FullRPG;
            Loading      = true;
            Script.Wait(1);


            //Game.FadeScreenOut(500);
            Script.Wait(500);

            Function.Call(Hash.DISPLAY_HUD, 1);
            Function.Call(Hash.DISPLAY_RADAR, 1);
            World.RenderingCamera = null;
            Function.Call(Hash.SET_TIME_SCALE, 1.0f);
            Function.Call(Hash.SET_TIMECYCLE_MODIFIER, "");
            Game.Player.CanControlCharacter = true;

            //load data
            bool NeedToCreateCharacter;

            LoadAllData(out NeedToCreateCharacter);

            if (NeedToCreateCharacter)
            {
                RPGLog.Log("Character not found. Will be starting character creation.");
            }


            if (!LoadedSuccessfully)
            {
                RPGLog.Log("Failed to load game successfully.");
                UI.Notify("Failed loading RPGMod. See Error 000");
                Game.FadeScreenIn(500);
                Loading         = false;
                RPGInit.Enabled = true;
                return;
            }

            if (NeedToCreateCharacter)
            {
                RPGLog.Log("Loaded successfully with no character found. Starting character creation.");

                CharCreationNew.Enabled = true;
            }
            else
            {
                RPGLog.Log("Loaded successfully with character found.");
                GameLoaded = true;
            }

            //Game.FadeScreenIn(500);
            Loading = false;
        }
Beispiel #5
0
        public static T GetPopup <T>() where T : class
        {
            var x = Popups.All.FirstOrDefault(p => p is T);
            var r = x == null ? null : x as T;

            if (r == null)
            {
                RPGLog.Log("Could not find popup");
            }
            return(r);
        }
Beispiel #6
0
 public override void Update()
 {
     try
     {
         UpdateX();
     }
     catch (Exception ex)
     {
         RPGLog.Log("UIHandler Err.");
         RPGLog.Log(ex);
     }
 }
Beispiel #7
0
        public static void InitCharacter()
        {
            LoadTutorial();
            RPG.GameMode = GameMode.FullRPG;

            //Settings
            RPGLog.Log("Setting model:");
            Model m = PlayerData.ModelHash;

            RPGLog.Log("Setting model to: " + m.Hash);
            m.Request(5000);
            if (m.IsValid && m.IsLoaded)
            {
                Function.Call(Hash.SET_PLAYER_MODEL, Game.Player.Handle, m.Hash);
                Script.Wait(500);
            }

            //remember we can control max health/ /useful for skills later on
            RPGLog.Log("Setting player HP");
            Game.Player.Character.MaxHealth = 100;
            Game.Player.Character.Health    = 100;

            RPGLog.Log("Init Cooldowns");
            var cooldowns = RPG.PlayerData.Inventory.Where(i => i.Usable).Select(i => i.CoolDownTimer)
                            .Concat(RPG.PlayerData.Skills.Where(s => s.Unlocked).Select(s => s.CoolDownTimer));

            foreach (var cooldown in cooldowns)
            {
                cooldown.Current = cooldown.CoolDownMsTime;
            }
            RPGLog.Log("Loading Variations");

            RPGMethods.LoadVariations();
            RPGMethods.LoadVariations();
            RPGMethods.LoadVariations();
            RPGMethods.LoadVariations();
            RPGMethods.LoadVariations();


            //Reload
            RPGLog.Log("Reload quests if needed");
            foreach (var q in PlayerData.Quests.Where(q => q.InProgress))
            {
                q.OnReload();
            }

            RPGLog.Log("Loading Weapons");
            if (m.IsValid && m.IsLoaded && Game.Player.Character != null && Game.Player.Character.Exists())
            {
                RPGMethods.LoadPlayerWeapons();
            }
        }
Beispiel #8
0
        private void QuestUpdates()
        {
            var questsInProgress = PlayerData.Quests.Where(q => q.InProgress).ToList();
            var qNum             = 1;

            foreach (var q in questsInProgress.Where(qu => qu.SpawnTargets && qu.HasSpawnedTargets))
            {
                foreach (var b in q.BlipObjects)
                {
                    if (qNum < 10)
                    {
                        b.Blip.ShowNumber(qNum);
                    }
                }

                var conditionsToFix = q.Conditions.Where(c =>
                                                         !c.Done &&
                                                         (c.Type == ConditionType.Kill || c.Type == ConditionType.Loot) &&
                                                         c.Parameters.ContainsKey("ModelHash"));

                foreach (var c in conditionsToFix)
                {
                    var quest = q;

                    var npcs = WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).ToList();

                    for (int i = 0; i < npcs.Count; i++)
                    {
                        var n = npcs[i];
                        if (n.Ped.Exists() && !n.Ped.IsAlive)
                        {
                            n.Destroy();
                        }
                    }

                    //If no npcs found, or npcs are too high
                    if (WorldData.Npcs.All(n => n.Name != "Quest_" + quest.Name) || WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).All(n => !n.Ped.IsAlive) ||
                        WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).All(w => w.Ped.Exists() && w.Ped.Position.Z > Game.Player.Character.Position.Z + 45) ||
                        WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).All(w => w.Ped.Exists() && w.Ped.Position.Z < Game.Player.Character.Position.Z - 45))
                    {
                        q.HasSpawnedTargets = false;
                        c.Position          = RPGMethods.GetSpawnPoint(200);

                        q.ClearObjectsAndBlips();
                        q.SetupCondition(c, false);
                        RPGLog.Log("Spawning more peds for quest : " + quest.Name);
                    }
                }

                qNum++;
            }
        }
Beispiel #9
0
        public void StartQuest(string questName)
        {
            var quest = Quests.FirstOrDefault(q => q.Name == questName);

            if (quest != null)
            {
                quest.Start(false);
            }
            else
            {
                RPGLog.LogError("Failed to start quest. Quest not found: " + questName);
            }
        }
Beispiel #10
0
        public IWavePlayer PlaySFX(string sfxName)
        {
            IWavePlayer waveOutDevice = new WaveOutEvent();
            var         path          = SFXPath + sfxName + ".mp3";

            if (!File.Exists(path))
            {
                RPGLog.Log("Did not find SFX to play");
                return(waveOutDevice);
            }
            AudioFileReader audioFileReader = new AudioFileReader(path);

            audioFileReader.Volume = Volume;
            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();

            AudioDevices.Add(waveOutDevice);
            return(waveOutDevice);
        }
Beispiel #11
0
        public static void LoadAllData(out bool NeedToCreateCharacter)
        {
            RPGMethods.CleanupObjects();
            NeedToCreateCharacter = false;
            var newDir         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var dir            = Path.Combine(newDir, @"Rockstar Games\GTA V\RPGMod\");
            var playerDataFile = "PlayerData.save";

            var playerDataPath = Path.Combine(dir, playerDataFile);

            if (File.Exists(playerDataPath))
            {
                try
                {
                    var loadedData = File.ReadAllText(playerDataPath);
                    PlayerData = JsonConvert.DeserializeObject <PlayerData>(loadedData, GM.GetSerialisationSettings());
                    var dataVersion = PlayerData.Version;
                    if (dataVersion != RPG.Version)
                    {
                        VersionMigration.Migrate(dataVersion, RPG.Version);
                    }

                    InitCharacter();
                }
                catch (Exception e)
                {
                    LoadedSuccessfully = false;
                    RPGLog.Log(e.ToString());
                    RPGLog.Log("Error Loading or Initialising Player data.");
                }
            }
            else
            {
                NeedToCreateCharacter = true;
            }



            ApplySettings();
        }
Beispiel #12
0
        private void OnTick(object sender, EventArgs e)
        {
            //var s = new Stopwatch();
            //s.Start();

            if (CannotUpdate())
            {
                return;
            }
            try
            {
                if (_emptyUpdate)
                {
                    _emptyUpdate = false;
                    return;
                }

                if (_firstUpdate)
                {
                    Start();
                    _firstUpdate = false;
                }

                Update();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    RPGLog.LogError(ex.GetType() + ": " + ex.Message + "\n" + ex.StackTrace);
                    RPGLog.Log("Terminated script: " + GetType());
                    _running = false;
                }
            }

            //if (s.ElapsedMilliseconds > 0)
            //    RPGLog.Log(GetType() + " took " + s.ElapsedMilliseconds + " to tick.");
        }
Beispiel #13
0
        private void CheckNpcs()
        {
            foreach (var npc in NpcDatas)
            {
                var dist      = npc.Position.DistanceTo(Game.Player.Character.Position);
                var npcStatus = npc.GetNpcStatus();
                var npcBlip   = WorldData.Blips.FirstOrDefault(b => b.Name == "Blip_" + npc.Name);
                if (npcBlip != null)
                {
                    var blipPos = npcBlip.Blip.Position;

                    if (string.IsNullOrEmpty(npcStatus))
                    {
                        if (npcBlip.Blip.Sprite != npc.BlipSprite)
                        {
                            npcBlip.Blip.Remove();
                            npcBlip.Blip        = World.CreateBlip(blipPos);
                            npcBlip.Blip.Sprite = npc.BlipSprite;
                        }
                    }
                    else
                    {
                        var importantMarker = npcStatus[0];
                        switch (importantMarker)
                        {
                        case '!':
                            if (npcBlip.Blip.Sprite != BlipSprite.Information)
                            {
                                npcBlip.Blip.Remove();
                                npcBlip.Blip        = World.CreateBlip(blipPos);
                                npcBlip.Blip.Sprite = BlipSprite.Information;
                            }
                            break;

                        case '?':
                            if (npcBlip.Blip.Sprite != BlipSprite.GTAOMission)
                            {
                                npcBlip.Blip.Remove();
                                npcBlip.Blip        = World.CreateBlip(blipPos);
                                npcBlip.Blip.Sprite = BlipSprite.GTAOMission;
                            }
                            break;

                        case '*':
                            if (npcBlip.Blip.Sprite != BlipSprite.ChatBubble)
                            {
                                npcBlip.Blip.Remove();
                                npcBlip.Blip        = World.CreateBlip(blipPos);
                                npcBlip.Blip.Sprite = BlipSprite.ChatBubble;
                            }
                            break;

                        case '$':
                            if (npcBlip.Blip.Sprite != BlipSprite.Store)
                            {
                                npcBlip.Blip.Remove();
                                npcBlip.Blip        = World.CreateBlip(blipPos);
                                npcBlip.Blip.Sprite = BlipSprite.Store;
                            }
                            break;
                        }
                    }
                }


                if (RPGSettings.ShowUI && RPG.UIHandler.CurrentDialog == null)
                {
                    if (npc.IsQuestNpc && dist < 20)
                    {
                        var pos = npc.Ped != null ? npc.Ped.Position : npc.Position;
                        pos.Z += 1.0f;
                        OutputArgument xArg = new OutputArgument();
                        OutputArgument yArg = new OutputArgument();
                        Function.Call(Hash._WORLD3D_TO_SCREEN2D, pos.X, pos.Y, pos.Z, xArg, yArg);
                        var x = xArg.GetResult <float>();
                        var y = yArg.GetResult <float>();

                        new UIRectangle(new Point((int)(UI.WIDTH * x) - 50, (int)(UI.HEIGHT * y) + 12), new Size(100, 2), Color.DodgerBlue).Draw();
                        new UIText(npc.Name, new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y)), 0.21f, Color.White, 0, true).Draw();

                        if (!string.IsNullOrEmpty(npcStatus))
                        {
                            new UIText(npcStatus, new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y) - 35), 0.8f, Color.Gold, 0, true).Draw();
                        }
                    }
                }
                if (npc.IsQuestNpc && !npc.Spawned)
                {
                    //RPGLog.Log("Found unspawned NPC");
                    if (dist < 100)
                    {
                        RPGLog.Log("Spawning NPC");
                        var model = new Model(npc.ModelName);
                        model.Request(1000);
                        var ped = World.CreatePed(model, npc.Position, npc.Heading);

                        try
                        {
                            ped.RelationshipGroup = Game.Player.Character.RelationshipGroup;
                            ped.IsInvincible      = true;
                            EventHandler.Do(o =>
                            {
                                EventHandler.Wait(1000);
                                ped.FreezePosition = true;
                            });
                            Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, ped.Handle);
                            Function.Call(Hash.SET_PED_CAN_BE_TARGETTED, ped.Handle, false);
                            Function.Call(Hash.SET_PED_CAN_BE_TARGETTED_BY_PLAYER, ped.Handle, false);
                        }
                        catch
                        {
                            RPGLog.Log("Error setting npc and player friendliness.");
                        }
                        npc.SetPed(ped);
                        npc.Spawned = true;
                    }
                }
            }
        }
Beispiel #14
0
        public override void Update()
        {
            Ped player = Game.Player.Character;

            if (player.IsDead || Function.Call <bool>(Hash.IS_PLAYER_BEING_ARRESTED, Game.Player.Handle))
            {
                RPG.PlayerDead = true;
                Wait(3000);
                var deathPosition = Game.Player.Character.Position;
                try
                {
                    RPG.UIHandler.CloseAll();
                    RPGSettings.ShowUI = false;
                    var c = World.CreateCamera(Game.Player.Character.Position + new Vector3(0, 0, 100), new Vector3(0, 0, 90), GameplayCamera.FieldOfView);
                    World.RenderingCamera = c;

                    var oldModel = RPG.PlayerData.ModelHash;

                    Model m = PedHash.Michael;
                    m.Request(1000);
                    Function.Call(Hash.SET_PLAYER_MODEL, Game.Player.Handle, m.Hash);
                    Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, Game.Player.Character.Handle);
                    m.MarkAsNoLongerNeeded();

                    while (Game.Player.Character.IsDead || Function.Call <bool>(Hash.IS_PLAYER_BEING_ARRESTED, Game.Player.Handle))
                    {
                        Wait(0);
                    }

                    var t = 150;
                    while (t > 0)
                    {
                        UI.ShowSubtitle("Loading", 100);
                        Function.Call(Hash.DISPLAY_HUD, 0);
                        Function.Call(Hash.DISPLAY_RADAR, 0);
                        World.RenderingCamera = c;
                        Wait(100);
                        t--;
                    }

                    //Wait(15000);
                    Model oldM = oldModel;
                    oldM.Request(1000);
                    Function.Call(Hash.SET_PLAYER_MODEL, Game.Player.Handle, oldM.Hash);
                    Wait(0);
                    Game.Player.Character.FreezePosition = false;

                    RPGMethods.OnRespawn();
                    RPGSettings.ShowUI = true;
                    Function.Call(Hash.DISPLAY_HUD, 1);
                    Function.Call(Hash.DISPLAY_RADAR, 1);
                    World.RenderingCamera = null;
                    c.Destroy();
                    Game.FadeScreenIn(500);
                    RPG.PlayerDead = false;
                    Wait(15000);
                }
                catch (Exception ex)
                {
                    RPGLog.Log(ex.ToString());
                }
            }
        }