I'm trying to create a FFA scenario to play with my friends. This mode will allow us to have our own bases, our own research all seperatly but a non-hostile faction treatie.
For this mode I'd like to have the following setup:
-Random Faction (based on player name - works)
-Random Spawn (doesn't work)
Here's the current code that I use:
Code: Select all
script.on_event(defines.events.on_player_created, function(event)
local player = game.get_player(event.player_index)
player.insert{name="iron-plate", count=8}
player.insert{name="pistol", count=1}
player.insert{name="basic-bullet-magazine", count=10}
player.insert{name="burner-mining-drill", count = 1}
player.insert{name="stone-furnace", count = 1}
setForce(player)
end)
d = 32*3
bd = d*3
function setForce(player)
pforces = {};
for _, player in ipairs(game.players) do
local fname = "player_" .. player.name;
local force = game.forces[fname] or game.create_force(fname);
player.force = force;
for _, pforce in ipairs(pforces) do
pforce.set_cease_fire(force.name, true);
force.set_cease_fire(pforce.name, true)
end;
pforces[#pforces+1] = force
end
setForcespawn(force,player)
end
function setForcespawn(force,player)
s = game.surfaces.nauvis
local x = math.random(320,960)
local y = math.random(320,960)
local pos ={x, y}
game.forces["player"].chart(s,{{ x - bd, y -bd}, { x + bd, y + bd}} )
local position = s.find_non_colliding_position("player",pos, 64,4)
player.teleport(pos,s)
if position ~= nil then
for k, p in pairs (game.players) do
p.print(position.x.." "..position.y)
end
force.set_spawn_position({position.x,position.y},s)
player.teleport(position,s)
for k, entity in pairs(s.find_entities_filtered({area={{position.x - bd, position.y -bd}, {position.x + bd, position.y + bd}}, force= "enemy"})) do
entity.destroy()
end
else for k, p in pairs (game.players) do
p.print("Map unsutitable, please restart")
end
end
end
I hope that you know why the method returns nil and how I can solve this issue.
Thanks in advance
Also I'd like to have some general tips on how to debug in LUA. I'm a java developper myself and I can't seem to log any data anywhere (except for messaging players, but when nill, it terminates the game).