[Script] Vehicle cost adjustment – Train Fever /forums/topic/script-vehicle-cost-adjustment/feed/ Wed, 30 Apr 2025 12:12:19 +0000 https://bbpress.org/?v=2.6.13 en-US /forums/topic/script-vehicle-cost-adjustment/#post-8040 <![CDATA[[Script] Vehicle cost adjustment]]> /forums/topic/script-vehicle-cost-adjustment/#post-8040 Sat, 13 Sep 2014 23:54:49 +0000 trainjunkie 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 do

if 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
end

break
end
if k == Catlen then
break
br = true
end
k = k+1

end

j=j+1
end

i = i+1

end

i = 1

— if backup exists: remove original rename backup to original
— rename original to backup
while true do

local 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)
end

if i == expllen then break end
i = i+1
end

i = 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
end

local fh,err = io.open(filenamebkp)
if err then print(“OOps”); return; end

local 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
end

]]>
/forums/topic/script-vehicle-cost-adjustment/#post-8041 <![CDATA[Reply To: [Script] Vehicle cost adjustment]]> /forums/topic/script-vehicle-cost-adjustment/#post-8041 Sat, 13 Sep 2014 23:57:37 +0000 trainjunkie Oh 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

]]>
/forums/topic/script-vehicle-cost-adjustment/#post-8117 <![CDATA[Reply To: [Script] Vehicle cost adjustment]]> /forums/topic/script-vehicle-cost-adjustment/#post-8117 Sun, 14 Sep 2014 09:43:17 +0000 trainjunkie Haha 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

]]>