Radom position for surf unit initaite (Full Version)

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



Message


Parel803 -> Radom position for surf unit initaite (1/10/2022 4:54:45 PM)

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 -> RE: Radom position for surf unit initaite (1/10/2022 11:11:02 PM)

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

math.randomseed(os.time())




Parel803 -> RE: Radom position for surf unit initaite (1/11/2022 8:53:32 AM)

Lettuce, thank you. Gonna try it.
regards GJ




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
2.65625