Page 1 of 1
Random placement possible?
Posted: Mon Jul 31, 2017 1:30 am
by PoorOldSpike
Hi, I got CMANO 1.12.5 last week, sorry to start a new thread but I've been stuck all weekend on a couple of things-
1- When creating scens, is there any way to place AI ships so that when the game begins they'll appear at
random locations in the area of operations so that I won't know where they are and will have the fun of hunting them down?
2- I can't figure out how to set the 'event/trigger' routines to make my home-made scens automatically end when my (or the AI's) last ship is sunk.
For example if I BOL-launch ASM's at his suspected position it'd give me a warm fuzzy feeling if the game ended shortly afterwards so I'd know I'd nailed him..

RE: Random placement possible?
Posted: Mon Jul 31, 2017 1:43 am
by Rory Noonan
Hi Spike,
You're in luck, both of these are possible and easy to do.
To start in a random position, I usually use Lua scripting as it is much more customisable. However, the easiest way is to place your units in the editor, then create an area with reference points where you'd like the random position to be and then set up an event as follows:
Trigger: Time-Game start time +1s
Action: Teleport selected units to selected area.
This will teleport the selected units to a random position within the selected area at game start time +1s.
To end a scenario automatically, set up an event as follows:
Trigger: Unit destroyed (in your example; could be any trigger you like)
Action: End scenario
RE: Random placement possible?
Posted: Mon Jul 31, 2017 10:09 am
by kevinkins
last ship is sunk.
By "last" I think you may need a "counter". I have set up a dummy "side" called "shipcounter" and incremented its score by +1 as each ship is sunk. Then you can evaluate the score in an Side Score event to end the scenario using the End Scenario action when the final ship goes down. The dummy side is sort of a global variable within the context of Command and lua. Dummy sides can hold a lot of valuable housekeeping info.
Kevin
RE: Random placement possible?
Posted: Sat Aug 05, 2017 2:12 pm
by ExNusquam
I know this is a week old- but for doing randomization you really should be using a non-repeatable "Scenario Is Loaded" trigger. This means you can randomize the location of player units cleanly as well.
RE: Random placement possible?
Posted: Sat Aug 05, 2017 11:20 pm
by tjhkkr
ORIGINAL: Poor Old Spike
Hi, I got CMANO 1.12.5 last week, sorry to start a new thread but I've been stuck all weekend on a couple of things-
1- When creating scens, is there any way to place AI ships so that when the game begins they'll appear at random locations in the area of operations so that I won't know where they are and will have the fun of hunting them down?
Listen, I cannot help you with number 2, but I can help you with this one.
Would you like me to PM you a script that would accomplish this?

Or I can put it out on this group of messages.
I am also working on a way to randomly set units to one side or another... that should be operational in the next day or so...
The biggest problem I have had with that is that you cannot change WHOLE groups... the LUA script chokes on the scenedit command.
RE: Random placement possible?
Posted: Sun Aug 06, 2017 7:37 pm
by tjhkkr
This LUA script was meant to add randomly located oil rigs....
Some are enemy.
The 'Neutral 1' will not fire on the opponent, but will report the position
Neutral was truly neutral.
The latitudes and longitudes were within a specific geographical area in the Persian Gulf.
the variable 'b' is the number of platforms I wanted.
So if you wanted to place say, random submarines, and wanted 7, b would be 7.
====
a = 0
b = 25
repeat
a = a + 1
string.name = 'Oil Platform EOP.' .. a
UnitProf = math.random(1,5); UnitProf = UnitProf - 1
r = math.random(1, 85) - 1
r = r / 100
lati = 25.5 + r
r = math.random(1, 175) - 1
r = r / 100
longi = 52.05 + r
string.strLati = lati; string.strLongi = longi
r = math.random(1, 12)
if r >= 1 and r <= 5 then
string.sidename = 'Neutral 1'
rr = math.random(1, 3)
if rr == 1 or rr == 2 then
numdbid = 1869
else
numdbid = 1239
end
elseif r >= 6 and r <= 10 then
string.sidename = 'Neutral'
rr = math.random(1, 3)
if rr == 1 or rr == 2 then
numdbid = 1869
else
numdbid = 1239
end
elseif r > 10 then
string.sidename = 'ISIS/Al Quaida'
numdbid = 1239
if UnitProf < 4 then
UnitProf = UnitProf + 1
end
end
ScenEdit_AddUnit({type = 'ship', name = string.name, heading = 0, dbid = numdbid, side = string.sidename, Latitude= string.strLati ,Longitude= string.strLongi, autodetectable="false",holdfire="false",proficiency=UnitProf})
if string.sidename == 'ISIS/Al Quaida' then
ScenEdit_AssignUnitToMission(string.name, 'YankeeGoHome')
end
until a >= b
RE: Random placement possible?
Posted: Tue Aug 08, 2017 4:42 am
by tjhkkr
math.randomseed(1471)
subscr = 0
string.UnitMissionName = 'YankeeGoHome'
string.SiteName = {'Radar (Alfa)', 'Radar (Bandur Abbas)', 'SAM Bty I-HAWK (Bandar-E Bushehr)',
'SAM Grp SA-5 (Bandar-E Bushehr)', 'Radar (Bandar-E Bushehr)', 'Emplacement 1',
'Emplacement 2', 'Emplacement 4','Emplacement 8', 'Emplacement 9a', 'Emplacement 9b', 'eof'}
repeat
subscr = subscr + 1
if string.SiteName[subscr] == 'eof' then
print(subscr)
else
print(subscr)
junkvar = math.random(1,3)
if junkvar > 1 then
ScenEdit_SetUnitSide({side='Neutral', name=string.SiteName[subscr], newside='Iran'})
ScenEdit_AssignUnitToMission(string.SiteName[subscr], string.UnitMissionName)
end
end
until string.SiteName[subscr] == 'eof'
First of all, many of you many not understand the need for such a script, but I love fog of war.
This Script takes single units and randomly assigns it to a nation...
It only takes SINGLE units, it does not work on groups because the Scenedit_SetUnitSide chokes on groups.
The script makes use of subscripted variables. string.SiteName is loaded... obviously you have need to make sure you have the names of the units you wish to run through this process both unique AND must be present or the script ABENDs.
You can have as many units as you want but the last unit must be EOF. That is how the script knows to end.
So I take the sites/units that I want to assign randomly either to Neutral or Iran.
I assign them then to a Mission.
*** WARNING ***
Make sure you save the scenario BEFORE running the script. The change is permanent...
ALSO: the randomseed number should be changed from game to game to that you have some 'randomness'
RE: Random placement possible?
Posted: Tue Aug 08, 2017 8:56 am
by michaelm75au
To randomize whenever it runs.
math.randomseed( os.time() )
RE: Random placement possible?
Posted: Tue Aug 08, 2017 10:29 am
by kevinkins
I read in lua forums that there is an issue with the language generating random numbers and it's best to seed a few times before accepting the number, e.g.
https://stackoverflow.com/questions/201 ... ers-in-lua
https://stackoverflow.com/questions/323 ... generation
These are rather old posts. But I wanted to mention it to make sure everyone's code runs the way they want.
Kevin
RE: Random placement possible?
Posted: Tue Aug 08, 2017 11:07 am
by tjhkkr
ORIGINAL: michaelm
To randomize whenever it runs.
math.randomseed(os.time() )
Thank you very much! That is EXTREMELY helpful!
RE: Random placement possible?
Posted: Tue Aug 08, 2017 11:08 am
by tjhkkr
Thank you, that is VERY good to know.