1. Hi guys,
    I'm working on a C# plugin to use on my server for our "events" (such as arena deathmatch). Using a chat command the admin can create an event, using another command he can set currentposition as that event position and then calling another command he can "open" that event enabling the /teleportToEvent command for people who want to partecipate.

    Using the storedData class found in Oxide Docs, I've been able to reach a first functioning result, but it's written really really bad ( :p ).

    The problem is I'm not very familiar with HashSet and after I've stored the first "Event" (with the proper chat command that calls HashSet Add() method) in the datafile, I've got difficulties to search, and eventually retrieve, that specific object in the hashset (e.g. if event "test" is in the hashset then modify test position to "certainVal").

    The question is: how can I find (if I can) a specific object in the hashset? Or maybe I'm going the wrong way, is there a better way to do this?

    Thank you all very much!
     
  2. If you ever only search for a specific key I would use a Dictionary instead. The dict has a TryGetValue function and its super fast.

    If you dont have much data I'd just use a list and iterate the performance will be more than fine.

    In my 20+ years of professional programing the only time I used hashsets was in school. Its a performance tool more than anything that you would use when you have very large amounts of data that do not have a unique id and in which you need to do searches. A phone book with names as key would be a good example..
     
  3. Hi Deicide666ra! Thank you!
    I'm not very expert so, seeing hashset in the docs example and seeing also other plugins using hashsets (Godmode, ZoneManager...) I tried with that. I don't think, even in the prospective of releasing this plugin, that it would need tools for a large amount of data so I think that dictionary and list would be fine (I also prefer them).
    My idea is to create an event with /event create <name> and then set the position with /event <name> setposition. The C# structure do this is already done but i've got problems when I have to "extract" that specific event with name "name".
    If it's not too much, can I ask you an example of how you would write down objects to datafile with a list (identified by a key maybe) and how you could search for them to point the specific object with the name <name> to modify, for example, its position value?

    Thank you very much! In the meantime I'll continue digging into plugins and trying to do something with lists or dictionaries :)
     
  4. I haven't had to save any lists to config files yet, but I read you can simply cast it to object and save it like that.

    As for using keys, use a Dictionnary for this. When you add an element you can provide a key (it can be anything so long as it's unique) in your case probably the event name. Then simply do something like this (freehand code here, might not work as is):

    Code:
    Vector3d position;
    if (yourDict.TryGetValue("myevent", position) == false)
        Puts("Couldn't find myevent");
    else {
        // move player to position or whatever
    }
    If it's a class you're storing in the dict, just replace Vector3d by the class name.
     
  5. I went from HashSet to List and it seems perfect, I am able to add data to the list and then save it to datafile, then retrieve back the data to the list when plugin is reloaded, I'm able to target specific objects in the list (and modify properties if needed) with FirstOrDefault method, great!

    Now I'm wondering if it's convenient to store data as a list of Dictionaries which would have event name as key and the Event object itself as value.
    Now with a simple list of objects the output is somenthing like:

    Code:
    {
      "Events": [
        {
          "playerName": "d3nnib",
          "name": "test",
          "coordX": -1476.10059,
          "coordY": 17.2807274,
          "coordZ": 678.2619
        },
        {
          "playerName": "d3nnib",
          "name": "arena",
          "coordX": -1470.15308,
          "coordY": 19.7896671,
          "coordZ": 675.891357
        },
        {
          "playerName": "d3nnib",
          "name": "Easy Siege",
          "coordX": -1464.6062,
          "coordY": 17.0926476,
          "coordZ": 655.045837
        }
      ]
    }
    I mean if it's a best practice to store that in something like:

    Code:
    {
      "Events": [
        {
        "test" : {
          "playerName": "d3nnib",
          "coordX": -1476.10059,
          "coordY": 17.2807274,
          "coordZ": 678.2619
        },
       "arena" :  {
          "playerName": "d3nnib",
          "name": "arena",
          "coordX": -1470.15308,
          "coordY": 19.7896671,
          "coordZ": 675.891357
        },
        "Easy Siege" : {
          "playerName": "d3nnib",
          "name": "Easy Siege",
          "coordX": -1464.6062,
          "coordY": 17.0926476,
          "coordZ": 655.045837
        }
      ]
    }

    Hope I've understood correctly how this mechanism works, If I used some wrong terminology I apologize :p
     
    Last edited by a moderator: Jul 1, 2015
  6. A list of dictionnaries seems a bit overkill, just store classes in a list or a dict. Only time you'd use a dict instead of a class is if the data is extremely variable both in contents and size.
     
  7. Ok! I've used a list like in the first example, no problems at all there! (I can manage, add, remove or edit events in the list / datafile as I like).

    I'll mark as solved now, thank you very much for your help Deicide666ra!