LUA script unit/group variable start points

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
trevor999
Posts: 59
Joined: Sun Jun 01, 2008 9:19 pm

LUA script unit/group variable start points

Post 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
User avatar
blu3s
Posts: 992
Joined: Fri Jul 08, 2022 9:45 am

Re: LUA script unit/group variable start points

Post 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
trevor999
Posts: 59
Joined: Sun Jun 01, 2008 9:19 pm

Re: LUA script unit/group variable start points

Post 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.
User avatar
blu3s
Posts: 992
Joined: Fri Jul 08, 2022 9:45 am

Re: LUA script unit/group variable start points

Post 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
Post Reply

Return to “Lua Legion”