jmax
Posts: 59
Joined: 12/5/2016 Status: offline
|
Works well now, though occasionally the event is fired without creating a merchant for reasons unknown. Pretty satisfying watching the shipping lanes fill up with realistic traffic—now I just need to impose some limits so it doesn't overload my CPU after running for a while. math.randomseed( os.time() )
a = math.random(1,4)
if a == 1 then
local PORTTABLE = {'Singapore', 'Singapore', 'Singapore', 'Singapore', 'Manila' }
local PORT = PORTTABLE[math.random( 1, #PORTTABLE)]
local DBIDTABLE = { 259, 275, 275, 339, 339, 339, 145, 145, 145, 144, 144, 2776, 2775, 2774, 2773, 2029, 2030, 2028, 2027, 2023, 222 }
local DBID = DBIDTABLE[math.random( 1, #DBIDTABLE)]
local MISSIONTABLE = {'Ningbo', 'Ningbo', 'Ningbo', 'Busan', 'Busan', 'Hong Kong', 'Shanghai', 'Dalian', 'Yokohama', 'Kaohsiung' }
local MISSION = MISSIONTABLE[math.random( 1, #MISSIONTABLE)]
lastCount = ScenEdit_GetKeyValue('MerchCounter');
lastCountN = tonumber(lastCount);
if lastCountN == nil then
lastCountN = 0;
end
lastCountN = lastCountN +1;
ScenEdit_SetKeyValue('MerchCounter', tostring(lastCountN));
b=ScenEdit_GetKeyValue('MerchCounter');
local new_merch
if b ~= 0 then
local new_merch = ScenEdit_AddUnit({side='Civilian', type='Ship',name='Merchant #'..b, dbid=DBID, base=PORT, long=0, lat=0})
ScenEdit_AssignUnitToMission( new_merch.name, ''..PORT..' to '..MISSION..'')
print (new_merch.name..' with dbid '..DBID..' was assigned route '..PORT..' to '..MISSION..'')
end
end
--^Tanker heavy
if a == 2 then
local PORTTABLE = {'Xiamen', 'Manila', 'Manila'}
local PORT = PORTTABLE[math.random( 1, #PORTTABLE)]
local DBIDTABLE = { 2776, 2775, 2775, 2774, 2774, 2774, 2773, 2773, 2023, 2023, 2030, 2028, 2027, 145, 144 }
local DBID = DBIDTABLE[math.random( 1, #DBIDTABLE)]
local MISSIONTABLE = {'Singapore', 'Singapore', 'Shanghai', 'Shanghai', 'Ningbo', 'Yokohama', 'Kaohsiung', 'Hong Kong', 'Busan' }
local MISSION = MISSIONTABLE[math.random( 1, #MISSIONTABLE)]
lastCount = ScenEdit_GetKeyValue('MerchCounter');
lastCountN = tonumber(lastCount);
if lastCountN == nil then
lastCountN = 0;
end
lastCountN = lastCountN +1;
ScenEdit_SetKeyValue('MerchCounter', tostring(lastCountN));
b=ScenEdit_GetKeyValue('MerchCounter');
local new_merch
if b ~= 0 then
local new_merch = ScenEdit_AddUnit({side='Civilian', type='Ship',name='Merchant #'..b, dbid=DBID, base=PORT, long=0, lat=0})
ScenEdit_AssignUnitToMission( new_merch.name, ''..PORT..' to '..MISSION..'')
print (new_merch.name..' with dbid '..DBID..' was assigned route '..PORT..' to '..MISSION..'')
end
end
--^Bulk heavy
if a == 3 then
local PORTTABLE = {'Shanghai', 'Shanghai', 'Hong Kong', 'Hong Kong', 'Ningbo', 'Busan', 'Kaohsiung' }
local PORT = PORTTABLE[math.random( 1, #PORTTABLE)]
local DBIDTABLE = { 2031, 2029, 2030, 2030, 2030, 2028, 2027, 2774, 2773, 2023, 2023, 2034, 1599 }
local DBID = DBIDTABLE[math.random( 1, #DBIDTABLE)]
local MISSIONTABLE = {'Singapore', 'Singapore', 'Xiamen', 'Manila', 'Yokohama', 'Yokohama' }
local MISSION = MISSIONTABLE[math.random( 1, #MISSIONTABLE)]
lastCount = ScenEdit_GetKeyValue('MerchCounter');
lastCountN = tonumber(lastCount);
if lastCountN == nil then
lastCountN = 0;
end
lastCountN = lastCountN +1;
ScenEdit_SetKeyValue('MerchCounter', tostring(lastCountN));
b=ScenEdit_GetKeyValue('MerchCounter');
local new_merch
if b ~= 0 then
local new_merch = ScenEdit_AddUnit({side='Civilian', type='Ship',name='Merchant #'..b, dbid=DBID, base=PORT, long=0, lat=0})
ScenEdit_AssignUnitToMission( new_merch.name, ''..PORT..' to '..MISSION..'')
print (new_merch.name..' with dbid '..DBID..' was assigned route '..PORT..' to '..MISSION..'')
end
end
--^Container heavy
if a == 4 then
local PORTTABLE = {'Hong Kong', 'Shanghai' }
local PORT = PORTTABLE[math.random( 1, #PORTTABLE)]
local DBIDTABLE = { 2774, 2773, 2023, 2023, 2030, 2027, 2027, 145, 144, 1599 }
local DBID = DBIDTABLE[math.random( 1, #DBIDTABLE)]
local MISSIONTABLE = {'Manila', 'Ningbo', 'Yokohama', 'Xiamen', 'Kaohsiung', 'Busan' }
local MISSION = MISSIONTABLE[math.random( 1, #MISSIONTABLE)]
lastCount = ScenEdit_GetKeyValue('MerchCounter');
lastCountN = tonumber(lastCount);
if lastCountN == nil then
lastCountN = 0;
end
lastCountN = lastCountN +1;
ScenEdit_SetKeyValue('MerchCounter', tostring(lastCountN));
b=ScenEdit_GetKeyValue('MerchCounter');
local new_merch
if b ~= 0 then
local new_merch = ScenEdit_AddUnit({side='Civilian', type='Ship',name='Merchant #'..b, dbid=DBID, base=PORT, long=0, lat=0})
ScenEdit_AssignUnitToMission( new_merch.name, ''..PORT..' to '..MISSION..'')
print (new_merch.name..' with dbid '..DBID..' was assigned route '..PORT..' to '..MISSION..'')
end
end
--^Mixed
|