Hi 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.
import 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()
Display More