Could someone fix this simple Control.lua.

Place to get help with not working mods / modding interface.
User avatar
StoneLegion
Filter Inserter
Filter Inserter
Posts: 687
Joined: Fri Sep 05, 2014 7:34 pm
Contact:

Could someone fix this simple Control.lua.

Post by StoneLegion »

This was not written by me besides the top portion of the code. It seems at least the top part does not work anymore I'm not actually much of a coder it was more grabbing and changing configs + the Starting areas for Multiplayer.

Code: Select all

-- Thanks to Loren1350 for helping me learn some of these settings!

      -- constant amount of PUs that are eaten by the chunk
game.mapsettings.pollution.ageing = 1/256
      -- this much PUs must be on the chunk to start diffusing
game.mapsettings.pollution.min_to_diffuse = 10
      -- amount that is diffused to neighboring chunk
      -- (possibly repeated for other directions as well)
game.mapsettings.pollution.diffusion_ratio = 5/256
      -- percentual increase in the evolve factor for every second (60 ticks)
game.mapsettings.enemy_evolution.time_factor = 0
      -- percentual increase in the evolve factor for every destroyed spawner
game.mapsettings.enemy_evolution.destroy_factor = 0
      -- percentual increase in the evolve factor for 1000 PU
game.mapsettings.enemy_evolution.pollution_factor = 0.00001
      -- Minimal distance of expansion point in chunks from player base
game.mapsettings.enemy_expansion.min_player_base_distance=0


require "defines"

function init()
  if not glob.deadPlayers then
    glob.deadPlayers = {}
  end
end
game.oninit(init)
game.onload(init)

game.onevent(defines.events.onentitydied, function(event)
  if event.entity.type == "player" then
    for index, player in ipairs(game.players) do
      if not player.character and not glob.deadPlayers[index] then
        glob.deadPlayers[index] = true
        break
      end
    end
  end
end)

game.onevent(defines.events.ontick, function(event)
	for playerIndex, value in pairs(glob.deadPlayers) do
	local player = game.players[playerIndex]
   		if player.character then
			if playerIndex % 2 == 0 then
   				local position = game.findnoncollidingposition("player", {-63,67}, 50, 1)
	   			if position ~= nil then player.teleport(position) end
	   		else
   				local position = game.findnoncollidingposition("player", {-159,-8105}, 50, 1)
	   			if position ~= nil then player.teleport(position) end
			end
   			glob.deadPlayers[playerIndex] = nil
   		end
	end
end)

game.onevent(defines.events.onplayercreated, function(event)
	local player = game.players[event.playerindex]
   		if player.character then
			if event.playerindex % 2 == 0 then
   				local position = game.findnoncollidingposition("player", {-63,67}, 50, 1)
	   			if position ~= nil then player.teleport(position) end
	   		else
   				local position = game.findnoncollidingposition("player", {-159,-8105}, 50, 1)
	   			if position ~= nil then player.teleport(position) end
			end
   		end
end)
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Could someone fix this simple Control.lua.

Post by Choumiko »

All i did was rename according to the 0.12 changes, not tested

Code: Select all

    -- Thanks to Loren1350 for helping me learn some of these settings!

          -- constant amount of PUs that are eaten by the chunk
    game.map_settings.pollution.ageing = 1/256
          -- this much PUs must be on the chunk to start diffusing
    game.map_settings.pollution.min_to_diffuse = 10
          -- amount that is diffused to neighboring chunk
          -- (possibly repeated for other directions as well)
    game.map_settings.pollution.diffusion_ratio = 5/256
          -- percentual increase in the evolve factor for every second (60 ticks)
    game.map_settings.enemy_evolution.time_factor = 0
          -- percentual increase in the evolve factor for every destroyed spawner
    game.map_settings.enemy_evolution.destroy_factor = 0
          -- percentual increase in the evolve factor for 1000 PU
    game.map_settings.enemy_evolution.pollution_factor = 0.00001
          -- Minimal distance of expansion point in chunks from player base
    game.map_settings.enemy_expansion.min_player_base_distance=0


    require "defines"

    function init()
      if not global.deadPlayers then
        global.deadPlayers = {}
      end
    end
    game.on_init(init)
    game.on_load(init)

    game.on_event(defines.events.on_entity_died, function(event)
      if event.entity.type == "player" then
        for index, player in ipairs(game.players) do
          if not player.character and not global.deadPlayers[index] then
            global.deadPlayers[index] = true
            break
          end
        end
      end
    end)

    game.on_event(defines.events.on_tick, function(event)
       for playerIndex, value in pairs(global.deadPlayers) do
       local player = game.players[playerIndex]
             if player.character then
             if playerIndex % 2 == 0 then
                   local position = player.surface.find_non_colliding_position("player", {-63,67}, 50, 1)
                   if position ~= nil then player.teleport(position) end
                else
                   local position = player.surface.find_non_colliding_position("player", {-159,-8105}, 50, 1)
                   if position ~= nil then player.teleport(position) end
             end
                global.deadPlayers[playerIndex] = nil
             end
       end
    end)

    game.on_event(defines.events.on_player_created, function(event)
       local player = game.players[event.player_index]
             if player.character then
             if event.player_index % 2 == 0 then
                   local position = player.surface.find_non_colliding_position("player", {-63,67}, 50, 1)
                   if position ~= nil then player.teleport(position) end
                else
                   local position = player.surface.find_non_colliding_position("player", {-159,-8105}, 50, 1)
                   if position ~= nil then player.teleport(position) end
             end
             end
    end)
User avatar
StoneLegion
Filter Inserter
Filter Inserter
Posts: 687
Joined: Fri Sep 05, 2014 7:34 pm
Contact:

Re: Could someone fix this simple Control.lua.

Post by StoneLegion »

Thank you friend :) And thanks for keeping up with Farl as well into 0.12. It seem to all work I will test the MP Starting area's tomorrow with my mate.
Post Reply

Return to “Modding help”