I have run into another problem, when I run my base.lua that has auto spawns it will re run them again upon load. On my stairs up and stairs down I do have them removing supports, pillars and the ground slope. But when I save and load all the things are reloaded because of my auto spawning in the base.lua. How would get the the following script to only run once or have the stairs remove them every time? Would I have to make all the objects local?
Code: Select all
do
-- Automatically make floor dirt if on solid ground and dirt is not already
-- present. Platforms are not considered floor!
local autoDecoEdgeCave = function(self)
local g = self.go
if g.map:getElevation(g.x,g.y) == g.elevation then
local choice = math.random()
if choice >= 0.85 then
g:spawn("rc_edge_support_01")
elseif choice >= 0.7 then
g:spawn("rc_edge_support_02")
elseif choice >= 0.55 then
g:spawn("rc_edge_support_03")
elseif choice >= 0.4 then
g:spawn("rc_edge_support_04")
end
end
if g.map:getElevation(g.x,g.y) == g.elevation then
local choice = math.random()
if choice >= 0.85 then
g:spawn("rc_edge_support_01b")
elseif choice >= 0.7 then
g:spawn("rc_edge_support_02b")
elseif choice >= 0.55 then
g:spawn("rc_edge_support_03b")
elseif choice >= 0.4 then
g:spawn("rc_edge_support_04b")
end
end
if g.map:getElevation(g.x,g.y) == g.elevation then
local choice = math.random()
if choice >= 0.8 then
g:spawn("rc_rocks_trim_01")
elseif choice >= 0.6 then
g:spawn("rc_rocks_trim_02")
elseif choice >= 0.4 then
g:spawn("rc_rocks_trim_03")
else
g:spawn("rc_wall_slope",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
end
end
local autoDecoFloorDetailAll = function(self)
local g = self.go
local choice = math.random()
local choice2 = math.random()
local choice3 = math.random()
if choice >= 0.6 then
spawn("rc_grass_01a",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice >= 0.4 then
spawn("rc_grass_01b",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice >= 0.2 then
spawn("rc_grass_01c",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
if choice2 >= 0.94 then
spawn("rc_ground_tiles_01",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice2 >= 0.88 then
spawn("rc_ground_tiles_02",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice2 >= 0.82 then
spawn("rc_ground_tiles_03",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice2 >= 0.76 then
spawn("rc_ground_tiles_04",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice2 >= 0.7 then
spawn("rc_ground_tiles_05",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
if choice3 >= 0.8 then
spawn("rc_ground_pebbles_04",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice3 >= 0.6 then
spawn("rc_ground_pebbles_01",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice3 >= 0.4 then
spawn("rc_ground_pebbles_02",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice3 >= 0.2 then
spawn("rc_ground_pebbles_03",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
end
defineObject{
name = "base_cave_wall",
baseObject = "base_wall",
components = {
{
class = "Null",
onInit = autoDecoEdgeCave,
},
},
minimalSaveState = true,
}
defineObject{
name = "base_cave_ground",
baseObject = "base_floor",
components = {
{
class = "Null",
onInit = autoDecoFloorDetailAll,
},
},
minimalSaveState = true,
}
end