Created
October 22, 2023 00:11
-
-
Save illuzian/6fd40fb55c3f84eadf10c0b5aa2b9d58 to your computer and use it in GitHub Desktop.
Add Town and Industry Prefixes in Transport Fever 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- run in console with debug enabled or make it a mod or whatevs | |
exists = {} | |
towns = game.interface.getEntities( {radius = 999999}, {type = "TOWN", includeData=true} ) | |
buildings = game.interface.getEntities( {radius = 999999}, {type = "SIM_BUILDING", includeData=true} ) | |
buildings_prefixes = {} | |
for town_id,town in pairs(towns) do | |
print(town.name) | |
print(town_id) | |
town_full_name = town.name | |
name = town.name | |
if string.match(name, "(%w+)|") ~= nil then | |
prefix_name = string.match(name, "(%w+)|"); | |
town_full_name = string.match(town.name,"%w+|(%w+)") | |
exists[prefix_name] = true; | |
goto continue | |
else | |
prefix_name = string.upper( string.sub(name, 0,3)) | |
end | |
if (exists[prefix_name]) ~= nil then | |
print('exists'); | |
for letter in string.gmatch(name,"(%w)") do | |
if letter == '|' then | |
goto continue | |
else | |
new_prefix = prefix_name .. string.upper(letter) | |
if exists[new_prefix] == nil then | |
print("made new name " .. new_prefix) | |
exists[new_prefix] = true | |
break | |
end | |
end | |
end | |
else | |
print("made prefx for " .. name .. " with prefix " .. prefix_name) | |
new_name = prefix_name .. '|' .. name | |
new_name_cmd = api.cmd.make.setName(town_id, new_name) | |
api.cmd.sendCommand(new_name_cmd) | |
exists[prefix_name] = true | |
end | |
::continue:: | |
for building_id, building in pairs(buildings) do | |
prefix = prefix_name | |
if string.match(building.name, '|') ~= nil then | |
goto building_cont | |
end | |
if building ~= nil then | |
if string.match(building.name, town_full_name) then | |
print('yes') | |
print(town_full_name) | |
print(building.name) | |
letters = string.match(building.name, town_full_name .. '(.*)') | |
letters = string.gmatch(string.upper(string.gsub(letters, ' ', '')), '(%w)') | |
print(letters) | |
for letter in letters do | |
new_building_prefix = prefix .. letter | |
if buildings_prefixes[new_building_prefix] == nil then | |
print('new pref '..new_building_prefix) | |
buildings_prefixes[new_building_prefix] = true | |
new_building_name = new_building_prefix .. '|' .. building.name | |
print(new_building_name) | |
new_building_name_cmd = api.cmd.make.setName(building_id, new_building_name) | |
api.cmd.sendCommand(new_building_name_cmd) | |
building[building_id] = nil | |
break | |
end | |
end | |
end | |
end | |
::building_cont:: | |
end | |
::building_done:: | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment