"can_place_entity" question
Posted: Tue Jul 18, 2017 6:34 pm
Hi,
I'm using "can_place_entity", but still I'm getting units spawned on water tiles. (I thought it would check for water tiles)
This is the code:
Next I tried looking at the tile, to see if it's a water tile, but I can't seem to get "get_tile" working during "script.on_init"
Last question for now.
Besides using "surface = game.surfaces['nauvis']" is there a better surface to use? I've had some issues in the past with hard coding the surface in my other mods, but can't use event or created_entity or any of those here.
I've attached the file in question and full mod.
Thanks.
I'm using "can_place_entity", but still I'm getting units spawned on water tiles. (I thought it would check for water tiles)
This is the code:
Code: Select all
while Dens_Spawned < 10 do
local surface = game.surfaces['nauvis']
local pos_x = math.random(-200,200)
local pos_x = math.random(-200,200)
if surface.can_place_entity({ name="alien-army-26", position={pos_x, pos_y}, force = game.forces.alien}) then
local lords = surface.create_entity({name="alien-army-26", position={pos_x, pos_y},force = game.forces.alien})
Dens_Spawned = Dens_Spawned + 1
Scatter = Scatter + 100
end
end
Next I tried looking at the tile, to see if it's a water tile, but I can't seem to get "get_tile" working during "script.on_init"
Code: Select all
script.on_init(on_initialize)
local waterTiles =
{
["deepwater"] = true,
["deepwater-green"] = true,
["water"] = true,
["water-green"] = true
}
function Initial_Spawn(surface)
local spawn_zone = 100
local Dens_Spawned = 0
local Scatter = 0
local chart_radius = 10
local radius_from_player = settings.startup["Alien_Distance"].value
while Dens_Spawned < 20 do
local surface = surface
local pos_x = math.random(-200,200)
local pos_y = math.random(-200,200)
local currentTilename = game.surfaces[1].get_tile(pos_x,pos_y).name
if surface.can_place_entity({ name="alien-army-26", position={pos_x, pos_y}, force = game.forces.alien}) and not waterTiles[currentTilename] then
local lords = surface.create_entity({name="alien-army-26", position={pos_x, pos_y},force = game.forces.alien})
nd
Dens_Spawned = Dens_Spawned + 1
Scatter = Scatter + 100
else
Dens_Spawned = Dens_Spawned
end
end
return lords
end
Last question for now.
Besides using "surface = game.surfaces['nauvis']" is there a better surface to use? I've had some issues in the past with hard coding the surface in my other mods, but can't use event or created_entity or any of those here.
I've attached the file in question and full mod.
Thanks.