Possible addition for utils.lua

I developed this function to create asteroid fields and mystery clouds... It might be useful for other in the utils.lua script. Note it does limit the max number of objects per call to 1000 as I've found that if you let it go nuts it will crash the server.

function createObjectsOnArc(x,y,radius,arc_deg,offset,spacing,object_type,rings,chance,randomize)
if rings == nil then rings = 1 end
if chance == nil then chance = 100 end
if randomize == nil then randomize = 0 end
local circ_dist = 2*math.pi*radius
local arc_dist=(circ_dist/360)*arc_deg
local deg= arc_deg/(arc_dist/spacing)
local randeg=arc_deg/(arc_dist/randomize)

local total_count = (math.floor((arc_deg/deg),0.5)+1)
if total_count>1000 then
spacing = arc_dist/1000
deg= arc_deg/(arc_dist/spacing)
total_count = arc_dist/spacing
for cnt=0,total_count,1 do
for cnt_ring=0,rings-1,1 do
local cnt_deg = offset+cnt*deg+(random(-randeg,randeg))
local cnt_dist = radius + (random((-cnt_ring*randomize),(cnt_ring*randomize)))
if random(0, 100) < chance then
local dx,dy = vectorFromAngle(cnt_deg,cnt_dist)
object_type():setPosition(x + dx, y + dy)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!