Page 1 of 1

LUA script unit/group variable start points

Posted: Sat Dec 16, 2023 4:50 pm
by trevor999
Greetings all

First of let me say that I'm here because the last experience with coding/programming was in the 80's - with punch cards, then Basic. A six year old probably knows more about coding than I do. To be honest, it all looks like ancient Greek to me.

I am creating a scenario and would like several of the surface and submarine groups to start at variable points with differing chance percentages on each variable point. For example, Group 123 starts at a point on the map, and has two other points it may start at 33% of the time.

Any help would be most appreciated. Thanks in advance.

Regards

Re: LUA script unit/group variable start points

Posted: Mon Dec 25, 2023 8:58 am
by blu3s
You can use lua function math.random() to get a float number btw 0 and 1, and then use an if statement to create the units in different coordinates

Something like this:

Code: Select all

local dice = math.random()
if dice <0.34 then
--position 1
elseif dice <0.67 then
--position 2
else
-- position 3

end

Re: LUA script unit/group variable start points

Posted: Tue Dec 26, 2023 5:46 pm
by trevor999
Excellent! That's looks like the kind of thing I'm looking for.

Now how do I put the unit ID in there?

Thanks for the help! And, if you celebrate, Happy Holiday's/Merry Christmas.

Re: LUA script unit/group variable start points

Posted: Wed Dec 27, 2023 9:47 pm
by blu3s
My approach would be creating the units with lua so you don't need to pass their ID. If not, you'll need to use the method setunit to change the units positions.https://commandlua.github.io/assets/Fun ... tUnit.html

Merry Christmas