AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Storing a list of int values in a file (https://forums.alliedmods.net/showthread.php?t=299378)

RoflCakesInUrFace 07-12-2017 17:32

Storing a list of int values in a file
 
I recently started with sourcemod and I ran into a bit of a problem with the limited file I/O available in sourcemod plugins.
I need to store several lists (basically in categories) of int values in a file and retrieve them into several arrays or a single lookup table but I don't know how I would go about doing this correctly (as in not a horrible hack).
Any help getting me on the right track would be appreciated.

headline 07-12-2017 19:20

Re: Storing a list of int values in a file
 
What are you trying to accomplish?

RoflCakesInUrFace 07-12-2017 19:35

Re: Storing a list of int values in a file
 
I am storing a list of weapon item indexes (Separated into categories) that the plugin will trigger on. I was testing with a hardcoded lookup table.

headline 07-13-2017 03:09

Re: Storing a list of int values in a file
 
Quote:

Originally Posted by RoflCakesInUrFace (Post 2534977)
I am storing a list of weapon item indexes

Like, weapon names in an array or actual entity indexes?

Can we see some code

RoflCakesInUrFace 07-13-2017 14:58

Re: Storing a list of int values in a file
 
The plugin was created with the intent of messing with my friends, it does something to them if certain weapons are equipped.

I want to populate this table from an external file so I don't have to recompile it when I want to change something.

I intend to add more to it once I have the config feature working.

Code:


// Lookup table for weapon definition indexes
// TODO: Replace with an external list/config
int ItemLookup[][] = {

    {        // Remove all the player's weapons if they equip these
               
        415,
        231
               
    },
       
    { // Slows down the player if these are equipped
                       
        30667,
        163,
        44
    },
};


ofir753 07-13-2017 15:47

Re: Storing a list of int values in a file
 
Read about sorting, if you are not experienced with sorting try use bubble sort or insertion sort, if you want more efficency use merge sort.

RoflCakesInUrFace 07-13-2017 16:45

Re: Storing a list of int values in a file
 
Quote:

Originally Posted by ofir753 (Post 2535110)
Read about sorting, if you are not experienced with sorting try use bubble sort or insertion sort, if you want more efficency use merge sort.

Sorry, but you may have misread. I want to store the values in an external file and retrieve them(in a non hackish way) to populate the table posted above. I am very aware of sorting algorithms and their differences.

headline 07-13-2017 19:53

Re: Storing a list of int values in a file
 
Best way in my opinion would probably be a simple KeyValues file. Consider this

KeyValues file


You can edit the file as needed, but just parse the file every time the map starts with something like this.

Code


Just be sure to male slowWeapons and removeWeapons global variables.

RoflCakesInUrFace 07-13-2017 23:03

Re: Storing a list of int values in a file
 
Completely overlooked keyvalues. Whoops. Anyways, that code was really easy to integrate into the plugin with some very minor modification and it works great. Thanks for the help.

Fyren 07-14-2017 03:34

Re: Storing a list of int values in a file
 
There isn't really a reason to not flatten out the keyvalues data if you're going to do it that way:
Code:

"root"
{
  "slow" "foo"
  "slow" "bar"
  "remove" "baz"
  "remove" "quux"
}

But the code to parse it will be different.

Two separate files with one number per line can be parsed with just a ReadFileLine loop and StringToInt.


All times are GMT -4. The time now is 12:59.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.