Randomising Help (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios



Message


butch4343 -> Randomising Help (4/18/2021 6:27:21 PM)

Arrrgh this is driving me bonkers [8|]

Can anyone possibly help, my scenario works on the basis of at the loading each time, a number of countries decide one of three paths,

Siding with NATO, in which cases there ships and bases are assigned to the US/NATO
Staying Neutral in that case the country is removed completely
or third joining the USSR in combat operations in which case the forces join that side.

So I created a script that gives the player a wee message at scenario start confirming what the country had decided. I have done this for Egypt, Tunisia and Albania thus far, I click and pasted the script and changed the unit names and sides to suit.

Now for the frustrating part, every time I load the scenario what happens is all three sides follow the same course either all 3 are for NATO, all 3 neutral or all 3 against NATO. Ive loaded the scenario 20 times so it cant be coincidence.

I wondered if some kind soul might load the below scenario and advise me if the same thing happens ? And secondly if anyone has any idea why thats happening and if theres a way around this I would be so grateful, Ill post the screenshots below as well.

The aim is to have a scenario where each time the load happens the player might have a different list of allies and enemies, to make the scenario dynamic.



Kind Regards

Butch




Whicker -> RE: Randomising Help (4/19/2021 3:17:13 AM)

you have to seed the random function or else you keep getting the same random number. Add this before your function that has the random number in it:

math.randomseed(os.time())

that said I don't think I quite ever figured it all out:

https://www.matrixgames.com/forums/tm.asp?m=4583853




butch4343 -> RE: Randomising Help (4/19/2021 7:56:33 AM)

Whicker

Thanks for this mate. I do have the function in my script as per below, but still get the same result , like the thread you linked too, the console works fine when I run each script individually I get any of the three results specified below, but when I run them in the scenario they are matched to the same three results , perhaps am misunderstanding what you mean by seeding?

Regards

Butch

math.randomseed( os.time() )

a = math.random(1,12)

if a<4 then
ScenEdit_SetUnitSide({side='Albania', name='FLOTI A', newside='US/NATO'})
ScenEdit_SetUnitSide({side='Albania', name='FLOTI B', newside='US/NATO'})
ScenEdit_SetUnitSide({side='Albania', name='WH1', newside='US/NATO'})
ScenEdit_SetUnitSide({side='Albania', name='WH2', newside='US/NATO'})
ScenEdit_SetUnitSide({side='Albania', name='Tirana', newside='US/NATO'})

ScenEdit_SpecialMessage('playerside','FROM:CINCSOUTH:-GOV ALBANIA INDICATES INTENTON TO CONDUCT OPERATIONS AGAINST WP. ALBANIA NAVAL FORCES PLACED UNDER YOUR COMMAND')

elseif a>=5 and a <9 then

ScenEdit_RemoveSide({side='Albania'})
ScenEdit_SpecialMessage('playerside',' FROM:CINCSOUTH:-GOV ALBANIA HAVE ANNOUNCED INTENTION TO REMAIN NEUTRAL AND UPHOLD NAVAL AND AIRSPACE INTERGRITY OF PEOPLES SOCIAL REPUBLIC OF ALBANIA')

elseif a>9 then

ScenEdit_SetUnitSide({side='Albania', name='FLOTI A', newside='USSR/WP'})
ScenEdit_SetUnitSide({side='Albania', name='FLOTI B', newside='USSR/WP'})
ScenEdit_SetUnitSide({side='Albania', name='WH1', newside='USSR/WP'})
ScenEdit_SetUnitSide({side='Albania', name='WH2', newside='USSR/WP'})
ScenEdit_SetUnitSide({side='Albania', name='Tirana', newside='USSR/WP'})


ScenEdit_SpecialMessage('playerside',' FROM:CINCSOUTH:-GOV ALBANIA HAVE ANNOUNCED IT WILL STAND BESIDE ITS SOCIALIST BROTHERS IN THE DEFENCE AGAINST THE ATTACK BY THE FASCIST IMPERIALISTS, EXPECT ALBANIAN FORCES TO CONDUCT OFFENSIVE OPERATIONS AGAINST NATO UNITS WITHOUT WARNING')
end




Whicker -> RE: Randomising Help (4/20/2021 6:10:47 PM)

I think the problem is that the way random works - it needs a better seed, os.time is only seconds and that means that each second the seed is the same? something like that.

One thing you can try is to call random a handful of times before you actually use it - like:
math.random()
math.random()
math.random()

then do
local a = math.random(1,12)

and maybe on each one don't use the same range of 1,12.

The frustrating part is that random works great in the console, but for whatever reason in the game it is different.

Another and perhaps better idea is to call the triggers with a time trigger - so one happens at 1 second, another at 1 minute and another at 5 minutes. Then it would work well I think.

As it is my guess is that they are all running in parallel and executing within the same second and that results in the same random number for all 3 which isn't very random for what you want.

You could also try using your own seed for each one - just put any number in where os.time is - and do that with a different number before each one - like:
math.randomseed(43212) << this is probably a bad idea, seed should be unique or it will probably be the same number each time.
Not sure what that would do to other random numbers though, probably not the best idea.




butch4343 -> RE: Randomising Help (4/21/2021 12:34:26 PM)

Whicker

Thanks for this, I suspected the trigger might be an issue , so I tested it last night with 20 second gaps between each trigger firing event and I seemed to get much better results, next thing am gona try is as you say different numbers in the random math seed so one script will be 1-6 one 1-9 and so forth.

Thanks for the help [:)]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.339844