Radom position for surf unit initaite

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Parel803
Posts: 607
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Radom position for surf unit initaite

Post by Parel803 »

Good evening,
I'm trying to do some with random. Small steps.
I got something from another thread, thx.
I made somthing and the random position is the same for both units, no doubt logical.

Is there a way to give both a different position?

local Side = 'Civilian'
local EnvType = 'ship'
local Spd = math.random(1,10)
local Hdg = math.random(1,360,3)

local lat_var = math.random(1,(10^13))
local lon_var = math.random(1,(10^13))
v_lat = math.random(-6,8) + (lat_var/(10^13))
v_lon = math.random(90,125) + (lon_var/(10^13))

ScenEdit_AddUnit({side=Side, type=EnvType, name='test1', DBID=2355, speed=Spd, heading=Hdg, latitude=v_lat, longitude=v_lon})
ScenEdit_AddUnit({side=Side, type=EnvType, name='test2', DBID=1787, speed=Spd, heading=Hdg, latitude=v_lat, longitude=v_lon})

local u1 = ScenEdit_GetUnit({side='Civilian', name='test1'})
print (u1.latitude)
print (u1.longitude)

best regards GJ
LettuceTurnipTheBeet
Posts: 7
Joined: Sat Dec 18, 2021 12:09 pm

RE: Radom position for surf unit initaite

Post by LettuceTurnipTheBeet »

I think you need to seed your rng before calling math.random, with os.time for example, like this:

math.randomseed(os.time())
Parel803
Posts: 607
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: Radom position for surf unit initaite

Post by Parel803 »

Lettuce, thank you. Gonna try it.
regards GJ
Post Reply

Return to “Lua Legion”