Raised This Month: $51 Target: $400
 12% 

Storing a list of int values in a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RoflCakesInUrFace
Junior Member
Join Date: Jul 2017
Location: Somewhere in Canada
Old 07-12-2017 , 17:32   Storing a list of int values in a file
Reply With Quote #1

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.

Last edited by RoflCakesInUrFace; 07-12-2017 at 17:33. Reason: Formatting
RoflCakesInUrFace is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 07-12-2017 , 19:20   Re: Storing a list of int values in a file
Reply With Quote #2

What are you trying to accomplish?
headline is offline
RoflCakesInUrFace
Junior Member
Join Date: Jul 2017
Location: Somewhere in Canada
Old 07-12-2017 , 19:35   Re: Storing a list of int values in a file
Reply With Quote #3

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.

Last edited by RoflCakesInUrFace; 07-12-2017 at 19:35.
RoflCakesInUrFace is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 07-13-2017 , 03:09   Re: Storing a list of int values in a file
Reply With Quote #4

Quote:
Originally Posted by RoflCakesInUrFace View Post
I am storing a list of weapon item indexes
Like, weapon names in an array or actual entity indexes?

Can we see some code

Last edited by headline; 07-13-2017 at 03:10.
headline is offline
RoflCakesInUrFace
Junior Member
Join Date: Jul 2017
Location: Somewhere in Canada
Old 07-13-2017 , 14:58   Re: Storing a list of int values in a file
Reply With Quote #5

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
    },
};

Last edited by RoflCakesInUrFace; 07-13-2017 at 15:00.
RoflCakesInUrFace is offline
ofir753
Senior Member
Join Date: Aug 2012
Old 07-13-2017 , 15:47   Re: Storing a list of int values in a file
Reply With Quote #6

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.
ofir753 is offline
RoflCakesInUrFace
Junior Member
Join Date: Jul 2017
Location: Somewhere in Canada
Old 07-13-2017 , 16:45   Re: Storing a list of int values in a file
Reply With Quote #7

Quote:
Originally Posted by ofir753 View Post
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.

Last edited by RoflCakesInUrFace; 07-13-2017 at 17:08.
RoflCakesInUrFace is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 07-13-2017 , 19:53   Re: Storing a list of int values in a file
Reply With Quote #8

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.

Last edited by headline; 07-13-2017 at 19:55.
headline is offline
RoflCakesInUrFace
Junior Member
Join Date: Jul 2017
Location: Somewhere in Canada
Old 07-13-2017 , 23:03   Re: Storing a list of int values in a file
Reply With Quote #9

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.
RoflCakesInUrFace is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-14-2017 , 03:34   Re: Storing a list of int values in a file
Reply With Quote #10

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.
Fyren is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:58.


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