Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Radom position for surf unit initaite

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Radom position for surf unit initaite Page: [1]
Login
Message << Older Topic   Newer Topic >>
Radom position for surf unit initaite - 1/10/2022 4:54:45 PM   
Parel803

 

Posts: 579
Joined: 10/10/2019
From: Netherlands
Status: offline
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
Post #: 1
RE: Radom position for surf unit initaite - 1/10/2022 11:11:02 PM   
LettuceTurnipTheBeet

 

Posts: 7
Joined: 12/18/2021
Status: offline
I think you need to seed your rng before calling math.random, with os.time for example, like this:

math.randomseed(os.time())

(in reply to Parel803)
Post #: 2
RE: Radom position for surf unit initaite - 1/11/2022 8:53:32 AM   
Parel803

 

Posts: 579
Joined: 10/10/2019
From: Netherlands
Status: offline
Lettuce, thank you. Gonna try it.
regards GJ

(in reply to LettuceTurnipTheBeet)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Radom position for surf unit initaite Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

2.484