1. So i have managed to Create and add information to a dictionary and then alter the already existing data in there, however how would i achieve or is it possible to add new information to an existing key ?

    So for exapmple i wanted to add to the end of this key bellow PID, lets say "rotation" : "13.93" ?

    Something like #
    if (key = 18814540){
    add rotation
    }
    Thanks loads

    Code:
    {
      "Dictionary": {
        "18814540": {
          "DisplayName": "[MD] SniperSpool",
          "PlayerLocationx": "1298.168",
          "PlayerLocationy": "13.931",
          "PlayerLocationz": "975.916",
          "CID": "2822330",
          "PID": "76561198126816619"
        }
      }
    }
     
  2. Simple guide how to work with Dictionary.
    Create dictionary:
    Code:
    Dictionary<ulong, string> nameDictionary = new Dictionary<ulong, string>();
    Add value to key:
    Code:
    nameDictionary.Add(key, value);
    Better to check is key added already
    Code:
    if (!nameDictionary.ContainsKey(key))
    {
    nameDictionary.Add(key, value);
    }
    Changing value of dictionary with key
    Better to check is key added already
    Code:
    if (nameDictionary.ContainsKey(key))
    {
    nameDictionary[key] = value;
    }
    if tValue of dictionary is List<string> for example, than you can add value with ~ way:
    Better to check is key added already
    [/CODE]if (nameDictionary.ContainsKey(key))
    {
    nameDictionary[key].Add(value);
    }[/CODE]

    Cause tValue of this Dictionary is List you should add value with same method. If you want to change value in dictionary which tValue is List, for e.x.
    Code:
    nameDictionary[key][0] = "teststring";
    Where 0 - number of string in list that should be changed.

    -------------
    In your situation tValue of your Dictionary is custom Class with info, something like
    Code:
    class Custom {
    string PlayerLocationx;
    string PlayerLocationy;
    string PlayerLocationz;
    string CID;
    string PID;
    }
    If you want to add Rotation - you should modify main Class, so add new string Rotation.
    Code:
    class Custom {
    string PlayerLocationx;
    string PlayerLocationy;
    string PlayerLocationz;
    string PlayerRotation;
    string CID;
    string PID;
    }
    And than you can add Rotation to each player, just example of code:
    Code:
    foreach (var check in BasePlayer.activePlayerList)
    {
    if (nameDictionary.ContainsKey(check.userId)
    nameDictionary[check.userId].PlayerRotation = check.transform.rotation.ToString();
    }
    From my experience, ofc, maybe, someone can say it is bad, but when i need to save player position i prefer to use just one string:
    Code:
    class Save{
    string position;
    }
    something[someKey].position = player.transform.position.ToString();
    Later you can easy convert string to Vector3.
    Code:
    player.Teleport(something[someKey].position.ToVector3());
    if i am not mistaken.
     
    Last edited by a moderator: Jan 14, 2018
  3. Is there a way to List the tValue's of the key ?

    Probably better for me to describe what im trying to do.

    save a number of signs based on there NET.ID's. so i can for example.


    "DisplayName": "[MD] SniperSpool",
    "PlayerLocationx": "1298.168",
    "PlayerLocationy": "13.931",
    "PlayerLocationz": "975.916",
    "CID": "2822330",
    "PID": "76561198126816619"
    --
    "IMG1" : "NET ID , IMGINFO"
    "IMG2" : "NET ID, IMGINFO"
    --
    i can then go through the list splitting the NET ID and Image info, looking at img1 to see if the NET id of save, matches the Net ID of the current component, if it does then do what i need it to do
     
  4. Ehrm, sorry here i can't help you, never worked hard on Signs. One questions, your final target see amount of signs? If yes - you dont need anything from this.
     
  5. foreach (var check in myDictionary)
    {
    List<string> ItemKeys = check.Keys.ToList();
    }

    Anyway i can't understand why do you need list of Keys :/
    Sorry, maybe language barrier.
     
  6. Save info

    Code:
                var UniqueID = chairmount.net.ID;
                var ItemKey = Convert.ToInt32(Math.Round(Convert.ToDouble(UnityEngine.Random.Range(Convert.ToSingle(0), Convert.ToSingle(99999999))))).ToString();
                           
                    if (!ChopperCache.ContainsKey(ItemKey))
                    {
                        ChopperCache.Add(ItemKey, new ChopperInformation {
                             DisplayName = player.displayName.ToString(),
                             PlayerLocationx = player.transform.position.x.ToString(),
                             PlayerLocationy = player.transform.position.y.ToString(),
                             PlayerLocationz = player.transform.position.z.ToString(),
                             ChopperID = UniqueID.ToString(),
                             PID = player.userID.ToString()
                        });
                            SaveData();
                    } 
    Update info

    Code:
                var UniqueID = mountable.net.ID.ToString();
                List<String> ItemKey = ChopperCache.Keys.ToList();
                        foreach (var ChopKey in ItemKey)
                            {
                            if (ChopperCache[ChopKey].ChopperID == UniqueID)
                                {                  
                                     ChopperCache[ChopKey].PlayerLocationx = player.transform.position.x.ToString();
                                     ChopperCache[ChopKey].PlayerLocationy = player.transform.position.y.ToString();
                                     ChopperCache[ChopKey].PlayerLocationz = player.transform.position.z.ToString();               
                                     SaveData();          
                                }
                            }
    Does that make any more sence now ?


    ---- ADDED ----

    Forgot to add the bit when i spawn the new gyro

    Code:
                List<String> ItemKeys = ChopperCache.Keys.ToList();
                foreach (var ChopKey in ItemKeys)
                    {                    var locxa = ChopperCache[ChopKey].PlayerLocationx;
                        var locya = ChopperCache[ChopKey].PlayerLocationy;
                        var locza = ChopperCache[ChopKey].PlayerLocationz;
                        
                            float locx = float.Parse(locxa);
                            float locy = float.Parse(locya);
                            float locz = float.Parse(locza);
                        
                var spawnpos = new Vector3(locx,locy,locz);            var PID = ChopperCache[ChopKey].PID;
                var OwnID = Convert.ToUInt64(PID);
                newCopter.OwnerID = OwnID;
                newCopter.Spawn();       
                ChopperCache[ChopKey].ChopperID = chairmount.net.ID.ToString();            SaveData();               
                }
    Obv ive Removed the acctual chopper spawn bits
     
    Last edited by a moderator: Jan 14, 2018