Good news! To provide faster support and grow the community, we'll be changing the forum to "Read Only" and turn to Discord instead for support.
Join here: https://discord.gg/zjNj5zZ

Reload Equipment & EasySave2(Optional)

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Reload Equipment & EasySave2(Optional)

Postby PeterBibinin » Thu Jul 13, 2017 2:45 pm

Hi there! Below you can get working script for Reload Equipment.

Note: This script should execute after SaveLoad

Code: Select all


public CharacterUI characterUI; //Assign in Inspector
private uint quantity;


public void ReloadEquipment()
        {
            if (characterUI != null)
            {

                for (int i = 0; i < characterUI.Count(); i++)
                {
                    var itemToUnEquip = characterUI[i].item as EquippableInventoryItem;


                    if (itemToUnEquip != null)
                    {
                        quantity = itemToUnEquip.currentStackSize;
                    }

                    Debug.Log("Quantity :" + quantity);
                    if (itemToUnEquip != null)
                    {
                        var itemID = itemToUnEquip.ID;
                        var itemToEquip = ItemManager.database.items[itemID] as EquippableInventoryItem;
                        if (quantity != 0)
                        {
                            itemToEquip.currentStackSize = quantity;
                        }
                        characterUI.UnEquipItem(itemToUnEquip, false);
                        characterUI.EquipItem(characterUI.equippableSlots[i], itemToEquip);
         var itemStats = itemToEquip.stats;
                        characterUI.equippableSlots[i].characterCollection.character.stats.ChangeAll(itemStats, 1f);
                    }
                }
            }
            else
            {
                Debug.LogError("CharackterUI is not assigned! Cant Reload Equipment");
            }
        }




____________ Easy Save 2 Integration ______________

To work with this you need do first step. Look post : viewtopic.php?f=25&t=2898&p=7196&hilit=saving+stats#p7196

And Custome Script:

In my case I have other script where I set variable playerGO and I have stats "Health", "TEST" in category "Default". You need add your category and stats name like me and get player prefab (playerGO).
Also first I ReloadEquipment() and then LoadStats()

Code: Select all

using System;
using UnityEngine;
using System.Collections;
using Devdog.General;
using Devdog.InventoryPro;
using UnityEngine.Assertions;
using PPS_SaveLoadSystem.Player;

/* Created by Myk.
* Edited by PeterBibinin (PPS)
*/


public class PlayerStatsSaver : MonoBehaviour


{
    //Plugin References
    public string filename;
    private InventoryPlayer _player;
    public GameObject playerGO;

    //Player Stats
    private IStat _health;
    private IStat _test;



    void Start()
    {
        //Gets the player.
        _player = playerGO.GetComponent<InventoryPlayer>();
        StartLoadStats();

    }


    public void StartLoadStats()
    {

            //Gets the Player Stats.
        var stat = _player.stats;
        var catagory = "Default";
        _test = stat.Get(catagory, "TEST");
        _health = stat.Get(catagory, "Health");


        using (ES2Reader reader = ES2Reader.Create(filename))
        {
            var health = reader.Read<Stat>();
            var test = reader.Read<Stat>();

            CopyStatValues(health, _health);
            CopyStatValues(test, _test);

        }

        Debug.Log("F5 key - Save Stats");
        Debug.Log("F6 key - Load Stats");
        Debug.Log("Del key - Delete Stats");


    }

    public void SaveStats()
    {

        using (ES2Writer writer = ES2Writer.Create(filename, new ES2Settings() { fileMode = ES2Settings.ES2FileMode.Create }))
        {
            writer.Write((Stat)_health);
            writer.Write((Stat)_test);

            writer.Save(true);
        }
    }

    public void LoadStats()
    {
        if (ES2.Exists(filename) == false)
        {
            Debug.Log("Can't load from file " + filename + " file does not exist.", gameObject);
            return;
        }

        using (ES2Reader reader = ES2Reader.Create(filename))
        {
            var health = reader.Read<Stat>();
            var test = reader.Read<Stat>();

            CopyStatValues(health, _health);
            CopyStatValues(test, _test);
        }
    }

    public void CopyStatValues(IStat from, IStat to)
    {
        to.SetMaxValueRaw(from.currentMaxValue, false, false);
        to.SetFactorMax(from.currentFactorMax, false, false);
        to.SetFactor(from.currentFactor, false);
        to.SetCurrentValueRaw(from.currentValueRaw, true);
    }
}
Last edited by PeterBibinin on Sun Jul 30, 2017 4:06 pm, edited 1 time in total.
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !

hugo.canané
Posts: 129
Joined: Sat Jul 02, 2016 12:28 am

Re: Reload Equipment

Postby hugo.canané » Thu Jul 13, 2017 6:41 pm

MY BRO BIG BOSS
Sos Survival - In steam - Thanks DevDog

http://store.steampowered.com/app/528970

hugo.canané
Posts: 129
Joined: Sat Jul 02, 2016 12:28 am

Re: Reload Equipment

Postby hugo.canané » Fri Jul 21, 2017 5:36 pm

What api is need for stats please all is good but if you have item stats if you quit and joins items reload but no stats ,

thansk for help
Sos Survival - In steam - Thanks DevDog

http://store.steampowered.com/app/528970

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Re: Reload Equipment & EasySave2(Optional)

Postby PeterBibinin » Sun Jul 30, 2017 4:09 pm

Update ................
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Re: Reload Equipment & EasySave2(Optional)

Postby PeterBibinin » Sun Sep 10, 2017 6:52 pm

This is test....
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !


Return to “Share custom components”

Who is online

Users browsing this forum: No registered users and 1 guest