bearhunter007
Posts: 23
Joined: 3/11/2017 Status: offline
|
Trying to use three different courses for the modified random merchant script by Apache85 My attempt as coded fails. What did I do wrong? --Random Merchant by Apache85 modified JJM math.random(os.time()) --reset random seed math.random(os.time()) merch_number = math.random(8,16) --random number between 8 and 16 determines number of merchants counter = 0 --counter init --course 1 local courseset_one={{lat=24.55,lon=122.37},{lat=21.56,lon=121.78}, {lat=17.39,lon=117.38},{lat=4.511,lon=106.64},{lat=1.287,lon=104.35}, {lat=1.186,lon=103.84},{lat=4.790,lon=98.906}} --course 2 local courseset_two={{lat=30.37,lon=129.52},{lat=23.03,lon=-164.0}} --course 3 local courseset_three={{lat=30.11,lon=129.42},{lat=18.03,lon=-158.0}} repeat local lat_var = math.random(1,(10^13)) --random number between 1 and 10^13 local long_var = math.random(1,(10^13)) --random number between 1 and 10^13 local pos_lat = math.random(27,32) + (lat_var/(10^13)) --latitude; currently in East China Sea local pos_long = math.random(123,127) + (long_var/(10^13)) --longitude; currently in East China Sea local crse=math.random(1,3) if crse==1 then local crseplot=crourseset_one end if crse==2 then local crseplot=crourseset_two end if crse==3 then local crseplot=crourseset_three end local merch_suffix = math.random(1000,2000) --name suffix local merch_name = ('Merchant ' .. merch_suffix) --adds merchant name with numbered suffix as above local DBIDTABLE = { 775, 2027, 2029, 2028, 2030, 774, 2026, 2031, 384, 2024, 2775, 2023, 773, 2774, 1001, 1374, 2773, 2776, 1006, 222, 1599, 2034, 1002, 1317, 144, 339, 275, 145, 2022, 259 } --defines the possible db choices ScenEdit_AddUnit({ side='Merchant', type='Ship', name=merch_name, heading = 270, speed=10, dbid=DBIDTABLE[math.random( 1, #DBIDTABLE)], latitude=pos_lat, longitude=pos_long, course=crseplot }) --adds the merchant using the variables above --adds the merchant using the variables above print (merch_name) --prints the name of the merchant created; this can be deleted without any detrimental effect this_merch = ScenEdit_GetUnit({ side='Merchant', type='Ship', name=merch_name}) --assigns the unit table from created unit to a variable local fuel_state = (math.random(60,90))/100 --random decimal to reflect 60-90% fuel local current_fuel = (this_merch.fuel[3001].current) --the starting fuel level local f = current_fuel * fuel_state --multiplies starting fuel by fuel state decimal local f = math.floor(f + 0.5) --rounds resulting number to an integer ScenEdit_SetUnit({side='Merchant',name=merch_name, fuel={ {3001, f} } }) --changes the fuel level --ScenEdit_AssignUnitToMission(merch_name, "Vladivostok") --assigns created unit to mission Vladivostok counter = counter + 1 --adds to counter until counter == merch_number --stop when counter reaches merchant number
|