require "util" require "defines" require "stdlib/game" require ("config") script.on_init(function() On_Init() end) script.on_configuration_changed(function() On_Init() end) function On_Init() global.character_data = global.character_data or {} for i, player in pairs(game.players) do if player.gui.left.rocket_score and tonumber(player.gui.left.rocket_score.rocket_count.caption) > 0 then player.force.technologies["uplink-station"].enabled = true end end end script.on_event(defines.events.on_gui_click, function(event) local player = game.players[event.element.player_index] local name = event.element.name if (name == "terminate-uplink") then local uplink = player.character if not global.character_data[event.element.player_index] or not global.character_data[event.element.player_index].valid then player.print({"critical-character-error"}) return else if enableSounds then playSoundForPlayer("uplink-deactivate", player) end player.print({"uplink-terminated"}) player.character = global.character_data[event.element.player_index] end uplink.destroy() player.driving = false if (player.gui.top["terminate-uplink"]) then player.gui.top["terminate-uplink"].destroy() end return end end) function playSoundForPlayer(sound, player) player.surface.create_entity({name = sound, position = player.position}) end function isContraband(item) if item.name == "ion-cannon-targeter" or item.name == "deconstruction-planner" or item.name == "filtered-deconstruction-planner" or item.name == "upgrade-planner" or item.name == "resource-monitor" then return false else return true end end script.on_event(defines.events.on_rocket_launched, function(event) local force = event.rocket.force if not force.technologies["uplink-station"].enabled then for i, player in pairs(force.players) do if player.connected then if (player.gui.left.rocket_score and tonumber(player.gui.left.rocket_score.rocket_count.caption) > 0) or event.rocket.get_item_count("satellite") > 0 then player.force.technologies["uplink-station"].enabled = true Game.print_force(force, {"first-satellite-sent"}) break end end end end end) if disableLogisticsWhileUplinked then script.on_event(defines.events.on_tick, function(event) if game.tick % 60 == 2 then for i, player in pairs(game.players) do if player.connected and player.character.name == "orbital-uplink" then for i = 1, #player.get_inventory(defines.inventory.player_quickbar) do if player.get_inventory(defines.inventory.player_quickbar)[i].valid_for_read and isContraband(player.get_inventory(defines.inventory.player_quickbar)[i]) then if player.get_inventory(defines.inventory.player_tools).can_insert(player.get_inventory(defines.inventory.player_quickbar)[i]) then player.get_inventory(defines.inventory.player_tools).insert(player.get_inventory(defines.inventory.player_quickbar)[i]) end if player.get_inventory(defines.inventory.player_guns).can_insert(player.get_inventory(defines.inventory.player_quickbar)[i]) then player.get_inventory(defines.inventory.player_guns).insert(player.get_inventory(defines.inventory.player_quickbar)[i]) end if player.get_inventory(defines.inventory.player_armor).can_insert(player.get_inventory(defines.inventory.player_quickbar)[i]) then player.get_inventory(defines.inventory.player_armor).insert(player.get_inventory(defines.inventory.player_quickbar)[i]) end player.get_inventory(defines.inventory.player_quickbar)[i].clear() end end end end end if game.tick % 30 == 23 then for i, player in pairs(game.players) do if not player.get_inventory(defines.inventory.player_trash).is_empty() then for i = 1, #player.get_inventory(defines.inventory.player_trash) do if player.get_inventory(defines.inventory.player_trash)[i].valid_for_read then player.insert(player.get_inventory(defines.inventory.player_trash)[i]) player.get_inventory(defines.inventory.player_trash)[i].clear() end end end end end end) end script.on_event(defines.events.on_built_entity, function(event) if event.created_entity.name == "uplink-station" then event.created_entity.insert{name="coal", count=1} event.created_entity.operable = false return end end) script.on_event(defines.events.on_preplayer_mined_item, function(event) if event.entity.name == "uplink-station" then return event.entity.clear_items_inside() end end) script.on_event(defines.events.on_player_driving_changed_state, function(event) local player = game.players[event.player_index] if player.vehicle and player.character.name == "orbital-uplink" then player.driving = false return end if player.vehicle and player.vehicle.name == "uplink-station" then player.print({"initiating-uplink"}) if enableSounds then playSoundForPlayer("uplink-activate", player) end -- inventory blueprints local blueprints = {} local hotbar = player.get_inventory(defines.inventory.player_quickbar) local hbcount = # hotbar + 1 local i = 1 while ( i < hbcount ) do if hotbar[i] and hotbar[i].valid and hotbar[i].valid_for_read then if hotbar[i].type == "blueprint" and hotbar[i].is_blueprint_setup() then table.insert(blueprints, { entities = table.deepcopy( hotbar[i].get_blueprint_entities() ) , tiles = table.deepcopy( hotbar[i].get_blueprint_tiles() ) , icons = table.deepcopy( hotbar[i].blueprint_icons ) } ) end end i = i + 1 end -- end of inventory blueprints part 1 local maininv = player.get_inventory(defines.inventory.player_main) local mcount = # maininv + 1 local j = 1 while ( j < mcount ) do if maininv[j] and maininv[j].valid and maininv[j].valid_for_read then if maininv[j].type == "blueprint" and maininv[j].is_blueprint_setup() then table.insert(blueprints, { entities = table.deepcopy( maininv[j].get_blueprint_entities() ) , tiles = table.deepcopy( maininv[j].get_blueprint_tiles() ) , icons = table.deepcopy( maininv[j].blueprint_icons ) } ) end end j = j + 1 end -- end of inventory blueprints part 2 global.character_data[event.player_index] = player.character local uplink = player.surface.create_entity{name="orbital-uplink", position=player.position, force=player.force} player.character = uplink uplink.destructible = false if game.item_prototypes["ion-cannon-targeter"] then player.insert({name="ion-cannon-targeter", count=1}) end if game.item_prototypes["filtered-deconstruction-planner"] then player.insert({name="filtered-deconstruction-planner", count=1}) else player.insert({name="deconstruction-planner", count=1}) end if game.item_prototypes["upgrade-planner"] then player.insert({name="upgrade-planner", count=1}) end if game.item_prototypes["resource-monitor"] then player.insert({name="resource-monitor", count=1}) end -- add blueprints local newbar = player.get_inventory(defines.inventory.player_quickbar) local newbarcount = # newbar + 1 local l = 1 for k, blueprint in ipairs(blueprints) do newbar.insert({name="blueprint", count=1}) while( l < newbarcount ) do if newbar[l] and newbar[l].valid and newbar[l].valid_for_read then if newbar[l].type == "blueprint" then if not (newbar[l].is_blueprint_setup()) then newbar[l].set_blueprint_entities(blueprint["entities"]) newbar[l].set_blueprint_tiles(blueprint["tiles"]) newbar[l].blueprint_icons = table.deepcopy(blueprint["icons"]) break end -- end of if blueprint setup end -- end of if blueprint end -- end of if valid l = l + 1 end -- end of while end -- end add blueprints player.get_inventory(defines.inventory.player_tools).insert({name="dummy-axe", count=1}) player.get_inventory(defines.inventory.player_guns).insert({name="dummy-gun", count=1}) player.get_inventory(defines.inventory.player_guns).insert({name="dummy-gun-2", count=1}) player.get_inventory(defines.inventory.player_guns).insert({name="dummy-gun-3", count=1}) player.get_inventory(defines.inventory.player_armor).insert({name="power-armor-mk2", count=1}) local armor = player.get_inventory(defines.inventory.player_armor)[1] armor.grid.put{name="fusion-reactor-equipment"} armor.grid.put{name="night-vision-equipment"} if not player.gui.top["terminate-uplink"] then player.gui.top.add{type="button", name="terminate-uplink", caption={"terminate-uplink"}} end end end)