Display MoreHi All,
Thanks for your hard work on all the great community mods.
I worked on a script in python to modify the trader assorts to disable cash trading. Since I really like hardcore, but wanted to use SVM and SPTrealism mods at the same time, and i could not use the other DanW's hardcore mode due to some issues with that one.
So yeah, im not a modder but i wanted to put this somewhere online for people who might be helped by it. Unfortunately reddit doesnt want anyone posting anything related SP for some reason, so i thought maybe here is a good enough place for people to find it when they search on google.
Maybe katto might find it useful if they wanna include that feature later on. I know their mod is mostly geared towards making the game more casual and just tweaking configs but i would love to see integration of the standard hardcore options too.
Not trying to hijack but just share my work and suggestions.
CodeDisplay Moreimport json import os.path #dim the file name for quick editing #you have to specify the file path for each trader and run the script seperately for each one. #I just right click the assort json file and make a shortcut, then copy that path. # After the first one, just copy the folder name filename = 'C:\\Users\\example\\example\\traders\\id#\\assort.json' #open the file, only opens but does not load any data 'r' for read mode file = open(filename, 'r+') #load the data into a new variable called data data = json.load(file) dataorig = data.copy() #close the file, the data remains in the data variable file.close() #find all entries in the assort json that are barters for cash and delete those entries # data structure: file-> barter_scheme -> 'id#' -> key-value pair with the count "count" and item id "_tpl" # basically, for every entry with a key value pair that has currency id as the "_tpl", we need to remove those entries rouble = "5449016a4bdc2d6f028b456f" euro = "569668774bdc2da2298b4568" usd = "5696686a4bdc2da3298b456a" print('data is ' + str(type(data))) barter_scheme = data.get("barter_scheme", []) llitems = data.get("loyal_level_items", []) itemlist = data.get("items", []) barter_scheme_copy = barter_scheme.copy() llitems_copy = llitems.copy() itemlist_copy = itemlist.copy() print('barter_scheme is ' + str(type(barter_scheme)) + ": " + str(len(barter_scheme)) + " items") print(barter_scheme) print('llitems is ' + str(type(llitems)) + ": " + str(len(llitems)) + " items") print(barter_scheme) print('items is ' + str(type(itemlist)) + ": " + str(len(itemlist)) + " items") print(barter_scheme) print('\n\n') #this is crazy. So, the data from the file includes items, barter_schemes, and loyal level items #barter schemes contains an id for each barter scheme, which is a 1d list that includes a 1d list with the dict inside #the dict inside is what contains the key-values to define what the qty and item id that will be accepted is #so we have to access each entry as the barter_scheme[key][0][0].get(whatever key-value we wanna change) #test '63d385bfb3eba6c95d0ef3d6' keys = [] item = 0 for key in barter_scheme_copy.keys(): keys.append(key) for key in keys: item = 0 if barter_scheme[key][0][0].get("_tpl") == (usd): del(barter_scheme[key]) del(llitems[key]) while item < len(itemlist): if itemlist[item]['_id'] == key: del (itemlist[item]) item = item - 1 item = item + 1 elif barter_scheme[key][0][0].get("_tpl") == (rouble): del(barter_scheme[key]) del (llitems[key]) while item < len(itemlist): if itemlist[item]['_id'] == key: del (itemlist[item]) item = item - 1 item = item + 1 elif barter_scheme[key][0][0].get("_tpl") == (euro): del (barter_scheme[key]) del (llitems[key]) while item < len(itemlist): if itemlist[item]['_id'] == key: del (itemlist[item]) item = item - 1 item = item + 1 print('barter_scheme is ' + str(type(barter_scheme)) + ": " + str(len(barter_scheme)) + " items") print(barter_scheme) print('llitems is ' + str(type(llitems)) + ": " + str(len(llitems)) + " items") print(barter_scheme) print('items is ' + str(type(itemlist)) + ": " + str(len(itemlist)) + " items") print(barter_scheme) #open the file again, but in write mode and dump the data into the file, then close file = open(filename, 'w') json.dump(data, file, indent=4) if not os.path.isfile(filename + "_copy.json"): file2 = open(filename + "_copy.json", 'w') json.dump(dataorig, file2, indent=4) else: print("backup not created, there was already a file there or error occurred") file.close()
Man you went such a hard way to pull this off, idk where to even start from.
First: There is dedicated SPT reddit channel - https://www.reddit.com/r/SPTarkov/
Second: Katto doesn't have any development relation to SVM, he's only a publisher.
Third: since you know Python, might as well check how mods in AKI works, you could've just create a simple 3 cycle func to just clear the trades off the server load, with no need to override the files, this way you could always revert the changes without using backup files.
I've wrote it up real quick, sorting ain't perfect but it works.
const DB = container.resolve("DatabaseServer").getTables();
const traders = DB.traders;
for (let CurTrader in traders)
{
if (CurTrader !== "ragfair" && CurTrader !== "638f541a29ffd1183d187f57" && CurTrader !== "579dc571d53a0658a154fbec") //avoid ragfair, peacekeeper and fence
{
for(let assortment in traders[CurTrader].assort.barter_scheme)
{
if( traders[CurTrader].assort.barter_scheme[assortment][0][0]._tpl == "5449016a4bdc2d6f028b456f")
//That's for roubles, add more currency if needed
{
for(let DeletElem in traders[CurTrader].assort.items)
{
if(traders[CurTrader].assort.items[DeletElem]._id == assortment )
{
traders[CurTrader].assort.items.splice(DeletElem,1) //splice instead of delete is important - you can't have blank space in array or it will cause exception with ragfair generation
break;//generally inefficient way of search, break makes it less painful since we know there's only 1 element possible.
}
}
for(let DeletLoyal in traders[CurTrader].loyal_level_items)
{
if(traders[CurTrader].assort.loyal_level_items.DeletLoyal == assortment )
{
delete traders[CurTrader].assort.loyal_level_items.DeletLoyal
break;
}
}
delete traders[CurTrader].assort.barter_scheme[assortment] //delete is fine here though
}
}
}
}
You can insert that straight into traders section in SVM if you ignore first 2 lines, otherwise you can check quick tutorials (or search for blank mod presets) to just insert that and it will work.
(Might as well add this thing inside experimental, since I wrote it anyway)
The only thing I've missed is more currency (i made a comment about it) and catcher of trades that has roubles as not a first requested item (aka if there is an item and only then roubles - it won't be caught on) because there is no barter like that