- This topic has 2 replies, 1 voice, and was last updated 10 years, 4 months ago by trainjunkie.
-
AuthorPosts
-
September 14, 2014 at 01:54 #8040trainjunkieParticipant
So I have this lua script that automatically adjusts price/ running costs by vehicle category, how do I post it? It defines categories, then a value adjustment matrix for each category, then it systematically alters the game files. Must be excecuted in the res folder to work, otherwise No chance.
This not intended as a user-friendly tool, just posting it if people might find it useful
Here it is, since there is no attach function in this form, and I do not know where to post it otherwise.
Hope it can be useful to some, I personally intend to make good use of it^^, any feedback appreciated.
The usual disclaimers apply of course, if you accidently blow up your house or start WW3 by excecuting this piece of lua it ain’t my fault.
Reminder: copy/pasting this might not work if you don’t recombine split lines.
Cat = {}
Cat[1] = {“Steamlocs”, “models/model/vehicle/train/”, “a3-5_705”, “borsig_1860”, “lner_class_a4”, “d1_3”, “br89”, “br75_4”, “br53preusg3”}
Cat[2] = {“Eloc”, “models/model/vehicle/train/”, “ae_4-7”, “br_103_1”, “br_185_traxx”, “br_e94”, “c6_8”, “rabde_12_12_front”, “rabde_12_12_waggon”, “re_44i”, “re_450″,”re_450_b”,”re_450_bt”,”re6_6″,”roterpfeil”, “tgv”, “tgv_w1”, “tgv_w2”, “twindexx”, “twindexx_w1”}
Cat[3] = {“Diesel”, “models/model/vehicle/train/”, “br_218”, “db_v100”, “nohab”, “schienenbus”}
Cat[4] = {“Waggons”, “models/model/vehicle/waggon/”,”3axes_person”, “bc4”, “compartment_car”, “d_1_spanischb”, “donnerbuechse”, “ew_ii”, “ew_iv”, “goods_1850”, “hbi1”, “kesselwagen_1860”, “kesselwagen_1910”, “kesselwagen_1950”, “open_1850”, “open_1910”, “open_1975”, “verbandswagen”, “wagen_bayrisch_1865”}
Cat[5] = {“Bus”, “models/model/vehicle/bus/”,”aboag”,”benz_o06600″,”berkhof_duvedec”,”landauer”,”mack_1900″,”obeissante”,”postkutsche”,”saurer_tuescher”,”volvo_5000″}
Cat[6] = {“Tram”, “models/model/vehicle/tram/”, “be4_6mirage”, “be5_6”, “dampftram”, “halle”, “schst”, “strassenbahn1850”, “typ1”}
Cat[7] = {“Trucks”, “models/model/vehicle/truck/”, “40_tons”, “benz1912lkw”, “dmg_cannstatt”, “horsewagon_1850”, “man_19_304_1970”, “opel_blitz_1930”}Catlen = 7
Changes = {}
Changes[1] = {“Steamlocs”,”runningCosts”,1,1,”price”,1,1}
Changes[2] = {“Eloc”,”runningCosts”,1,1,”price”,1,1}
Changes[3] = {“Diesel”,”runningCosts”,1,1,”price”,1,1}
Changes[4] = {“Waggons”,”runningCosts”,1,1,”price”,1,1}
Changes[5] = {“Bus”,”runningCosts”,1,1,”price”,1,1}
Changes[6] = {“Tram”,”runningCosts”,1,1,”price”,1,1}
Changes[7] = {“Trucks”,”runningCosts”,1,1,”price”,1,1}Changeslen = 3
Matexpl = {}
i = 1
j = 0
k = 1
l = 1
expllen = 0
while Changes[i] ~= nil do
j = 0
while Changes[i][3*j+2] ~= nil do
k = 1
while true doif string.match(Changes[i][1],Cat[k][1]) then
l = 1
while Cat[k][l+2] ~= nil do
expllen = expllen + 1
Matexpl[expllen] = {}
Matexpl[expllen][1] = Cat[k][2] .. Cat[k][l+2]
Matexpl[expllen][2] = Changes[i][3*j+2]
Matexpl[expllen][3] = Changes[i][3*j+3]
Matexpl[expllen][4] = Changes[i][3*j+4]
l = l + 1
endbreak
end
if k == Catlen then
break
br = true
end
k = k+1end
j=j+1
endi = i+1
end
i = 1
— if backup exists: remove original rename backup to original
— rename original to backup
while true dolocal filename = Matexpl[i][1] .. “.mdl”
local filenamebkp = Matexpl[i][1] .. “-bkp.mdl”local tempf2 = io.open(filename,”r”)
if tempf2 ~= nil then
io.close(tempf2)local tempf = io.open(filenamebkp,”r”)
if tempf~=nil then
io.close(tempf)
os.remove(filename)
os.rename(filenamebkp, filename)
end
os.rename(filename, filenamebkp)
endif i == expllen then break end
i = i+1
endi = 1
while true do
local rmv = false
local filename = Matexpl[i][1] .. “.mdl”
local filenamebkp = Matexpl[i][1] .. “-bkp.mdl”local tempf3 = io.open(filename,”r”)
if tempf3~=nil then
io.close(tempf3)
filenamebkp = Matexpl[i][1] .. “-w.mdl”
os.rename(filename,filenamebkp)
rmv = true
endlocal fh,err = io.open(filenamebkp)
if err then print(“OOps”); return; endlocal fho,err = io.open(filename,”w”)
local Varname = Matexpl[i][2]
local mult = tonumber(Matexpl[i][3])
local div = tonumber(Matexpl[i][4])
while true do
local line = fh:read()
if line == nil then break end
print (line)
local str,_ = string.find(line,Varname)
if str == nil then
fho:write(line)
fho:write(“\n”)
else
local _, _, key, val, suffix = string.find(line, “(%a+)%s*=%s*(%d+)%s*(%p*)”)
val = math.floor(val * mult / div)
fho:write(key, ” = “,val,suffix)
fho:write(“\n”)
end
end
fh:close()
fho:close()
if rmv == true then
os.remove(filenamebkp)
end
if i == expllen then return end
i = i+1
endSeptember 14, 2014 at 01:57 #8041trainjunkieParticipantOh yeah two more things:
– I intend to include track laying/road building costs in the future
– The script as is will change no value, you need to adjust the Change matrix:
Changes[2] = {“Eloc”,”runningCosts”,1,1,”price”,1,1} does nothing
Changes[2] = {“Eloc”,”runningCosts”,1,6,”price”,3,1} Elocs are 3 times as expensive but cost only a sixth to run
September 14, 2014 at 11:43 #8117trainjunkieParticipantHaha my script doesn’t support typos well: benz_o06600 -> benz_o6600.
In general I’ll work on it a bit and post it in the other forum
-
AuthorPosts
- The forum ‘Modding’ is closed to new topics and replies.