コード例 #1
0
ファイル: StorageManager.cs プロジェクト: TICG/vMenu
 /// <summary>
 /// Saves an (old/nomral) ped data to storage.
 /// </summary>
 /// <param name="saveName"></param>
 /// <param name="pedData"></param>
 /// <param name="overrideExisting"></param>
 /// <returns></returns>
 public static bool SavePedInfo(string saveName, PedInfo pedData, bool overrideExisting)
 {
     if (overrideExisting || (GetResourceKvpString(saveName) ?? "NULL") == "NULL")
     {
         SetResourceKvp(saveName, JsonConvert.SerializeObject(pedData));
         return(GetResourceKvpString(saveName) == JsonConvert.SerializeObject(pedData));
     }
     return(false);
 }
コード例 #2
0
        /// <summary>
        /// Load the saved ped and spawn it.
        /// </summary>
        /// <param name="savedName">The ped saved name</param>
        public static async void LoadSavedPed(string savedName, bool restoreWeapons)
        {
            if (savedName != "vChar_tmp_saved_ped")
            {
                PedInfo pi = StorageManager.GetSavedPedInfo("ped_" + savedName);
                Log(JsonConvert.SerializeObject(pi));
                await SetPlayerSkin(pi.model, pi, restoreWeapons);
            }
            else
            {
                PedInfo pi = StorageManager.GetSavedPedInfo(savedName);
                Log(JsonConvert.SerializeObject(pi));
                await SetPlayerSkin(pi.model, pi, restoreWeapons);

                DeleteResourceKvp("vChar_tmp_saved_ped");
            }
        }
コード例 #3
0
        /// <summary>
        /// Sets the player's model to the provided modelHash.
        /// </summary>
        /// <param name="modelHash">The model hash.</param>
        public static async Task SetPlayerSkin(uint modelHash, PedInfo pedCustomizationOptions, bool keepWeapons = true)
        {
            if (IsModelInCdimage(modelHash))
            {
                if (keepWeapons)
                {
                    Log("saved from SetPlayerSkin()");
                }
                RequestModel(modelHash);
                while (!HasModelLoaded(modelHash))
                {
                    await Delay(0);
                }

                if ((uint)GetEntityModel(Game.PlayerPed.Handle) != modelHash) // only change skins if the player is not yet using the new skin.
                {
                    // check if the ped is in a vehicle.
                    bool        wasInVehicle = Game.PlayerPed.IsInVehicle();
                    Vehicle     veh          = Game.PlayerPed.CurrentVehicle;
                    VehicleSeat seat         = Game.PlayerPed.SeatIndex;

                    int maxHealth = Game.PlayerPed.MaxHealth;
                    int maxArmour = Game.Player.MaxArmor;
                    int health    = Game.PlayerPed.Health;
                    int armour    = Game.PlayerPed.Armor;

                    // set the model
                    SetPlayerModel(Game.Player.Handle, modelHash);

                    Game.Player.MaxArmor     = maxArmour;
                    Game.PlayerPed.MaxHealth = maxHealth;
                    Game.PlayerPed.Health    = health;
                    Game.PlayerPed.Armor     = armour;

                    // warp ped into vehicle if the player was in a vehicle.
                    if (wasInVehicle && veh != null && seat != VehicleSeat.None)
                    {
                        FreezeEntityPosition(Game.PlayerPed.Handle, true);
                        int tmpTimer = GetGameTimer();
                        while (!Game.PlayerPed.IsInVehicle(veh))
                        {
                            // if it takes too long, stop trying to teleport.
                            if (GetGameTimer() - tmpTimer > 1000)
                            {
                                break;
                            }
                            ClearPedTasks(Game.PlayerPed.Handle);
                            await Delay(0);

                            TaskWarpPedIntoVehicle(Game.PlayerPed.Handle, veh.Handle, (int)seat);
                        }
                        FreezeEntityPosition(Game.PlayerPed.Handle, false);
                    }
                }

                // Reset some stuff.
                SetPedDefaultComponentVariation(Game.PlayerPed.Handle);
                ClearAllPedProps(Game.PlayerPed.Handle);
                ClearPedDecorations(Game.PlayerPed.Handle);
                ClearPedFacialDecorations(Game.PlayerPed.Handle);

                if (pedCustomizationOptions.version == 1)
                {
                    var ped = Game.PlayerPed.Handle;
                    for (var drawable = 0; drawable < 21; drawable++)
                    {
                        SetPedComponentVariation(ped, drawable, pedCustomizationOptions.drawableVariations[drawable],
                                                 pedCustomizationOptions.drawableVariationTextures[drawable], 1);
                    }

                    for (var i = 0; i < 21; i++)
                    {
                        int prop        = pedCustomizationOptions.props[i];
                        int propTexture = pedCustomizationOptions.propTextures[i];
                        if (prop == -1 || propTexture == -1)
                        {
                            ClearPedProp(ped, i);
                        }
                        else
                        {
                            SetPedPropIndex(ped, i, prop, propTexture, true);
                        }
                    }
                }
                else if (pedCustomizationOptions.version == -1)
                {
                    // do nothing.
                }
                else
                {
                    // notify user of unsupported version
                    //Notify.Error("This is an unsupported saved ped version. Cannot restore appearance. :(");
                }
                if (modelHash == (uint)GetHashKey("mp_f_freemode_01") || modelHash == (uint)GetHashKey("mp_m_freemode_01"))
                {
                    //var headBlendData = Game.PlayerPed.GetHeadBlendData();
                    if (pedCustomizationOptions.version == -1)
                    {
                        SetPedHeadBlendData(Game.PlayerPed.Handle, 0, 0, 0, 0, 0, 0, 0.5f, 0.5f, 0f, false);
                        while (!HasPedHeadBlendFinished(Game.PlayerPed.Handle))
                        {
                            await Delay(0);
                        }
                    }
                }
                SetModelAsNoLongerNeeded(modelHash);
            }
            else
            {
                //Notify.Error(CommonErrors.InvalidModel);
            }
        }
コード例 #4
0
        /// <summary>
        /// Saves the current player ped.
        /// </summary>
        public static async Task <bool> SavePed(string forceName = null, bool overrideExistingPed = false)
        {
            string name = forceName;

            if (string.IsNullOrEmpty(name))
            {
                // Get the save name.
                name = await GetUserInput(windowTitle : "Enter a ped save name", maxInputLength : 30);
            }

            // If the save name is not invalid.
            if (!string.IsNullOrEmpty(name))
            {
                // Create a dictionary to store all data in.
                PedInfo data = new PedInfo();

                // Get the ped.
                int ped = Game.PlayerPed.Handle;

                data.version = 1;
                // Get the ped model hash & add it to the dictionary.
                uint model = (uint)GetEntityModel(ped);
                data.model = model;

                // Loop through all drawable variations.
                var drawables        = new Dictionary <int, int>();
                var drawableTextures = new Dictionary <int, int>();
                for (var i = 0; i < 21; i++)
                {
                    int drawable         = GetPedDrawableVariation(ped, i);
                    int textureVariation = GetPedTextureVariation(ped, i);
                    drawables.Add(i, drawable);
                    drawableTextures.Add(i, textureVariation);
                }
                data.drawableVariations        = drawables;
                data.drawableVariationTextures = drawableTextures;

                var props        = new Dictionary <int, int>();
                var propTextures = new Dictionary <int, int>();
                // Loop through all prop variations.
                for (var i = 0; i < 21; i++)
                {
                    int prop        = GetPedPropIndex(ped, i);
                    int propTexture = GetPedPropTextureIndex(ped, i);
                    props.Add(i, prop);
                    propTextures.Add(i, propTexture);
                }
                data.props        = props;
                data.propTextures = propTextures;

                data.isMpPed = (model == (uint)GetHashKey("mp_f_freemode_01") || model == (uint)GetHashKey("mp_m_freemode_01"));
                if (data.isMpPed)
                {
                    //Notify.Alert("Note, you should probably use the MP Character creator if you want more advanced features. Saving Multiplayer characters with this function does NOT save a lot of the online peds customization.");
                }

                // Try to save the data, and save the result in a variable.
                bool saveSuccessful;
                if (name == "vChar_tmp_saved_ped")
                {
                    saveSuccessful = StorageManager.SavePedInfo(name, data, true);
                }
                else
                {
                    saveSuccessful = StorageManager.SavePedInfo("ped_" + name, data, overrideExistingPed);
                }

                //if (name != "vChar_tmp_saved_ped") // only send a notification if the save wasn't triggered because the player died.
                //{
                //    // If the save was successfull.
                //    if (saveSuccessful)
                //    {
                //        //Notify.Success("Ped saved.");
                //    }
                //    // Save was not successfull.
                //    else
                //    {
                //        Notify.Error(CommonErrors.SaveNameAlreadyExists, placeholderValue: name);
                //    }
                //}

                return(saveSuccessful);
            }
            // User cancelled the saving or they did not enter a valid name.
            else
            {
                //Notify.Error(CommonErrors.InvalidSaveName);
            }
            return(false);
        }
コード例 #5
0
 /// <summary>
 /// Sets the player's model to the provided modelName.
 /// </summary>
 /// <param name="modelName">The model name.</param>
 public static async Task SetPlayerSkin(string modelName, PedInfo pedCustomizationOptions, bool keepWeapons = true) => await SetPlayerSkin((uint)GetHashKey(modelName), pedCustomizationOptions, keepWeapons);