mirror of
https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git
synced 2024-12-12 10:13:58 +02:00
Add autofill softmod
This commit is contained in:
parent
e5e0baf53a
commit
b07742d74b
14
config.lua
14
config.lua
@ -12,12 +12,13 @@ GAME_MODE_MSG = "In the current game mode, a satellite must be launched from an
|
||||
MODULES_ENABLED = "Mods Enabled: Separate Spawns, RSO, Gravestone Chests, Long-Reach"
|
||||
-- MODULES_ENABLED = "Mods Enabled: Gravestone-Chests"
|
||||
|
||||
|
||||
WELCOME_MSG_TITLE = "[INSERT SERVER OWNER MSG HERE!]"
|
||||
-- WELCOME_MSG_TITLE = "Welcome to Oarc's Server"
|
||||
WELCOME_MSG1 = "Rules: Be polite. Ask before changing other players's stuff. Have fun!"
|
||||
WELCOME_MSG2 = "This server is running a custom scenario that changes spawn locations."
|
||||
|
||||
OTHER_MSG1 = "Latest updates in this scenario version (0.2.2):"
|
||||
OTHER_MSG2 = "Long-reach soft mod, random silo position, limited # players joining a spawn."
|
||||
OTHER_MSG1 = "Latest updates in this scenario version (0.2.4):"
|
||||
OTHER_MSG2 = "Autofill (turrets + vehicles)."
|
||||
|
||||
|
||||
WELCOME_MSG3 = "Due to the way this scenario works, it may take some time for the land"
|
||||
@ -36,10 +37,10 @@ SPAWN_MSG3 = "Resources are spread out far apart but are quite rich."
|
||||
-- will probably break the frontier rocket silo mode
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Separate spawns
|
||||
-- Frontier style rocket silo mode
|
||||
FRONTIER_ROCKET_SILO_MODE = true
|
||||
|
||||
-- Frontier style rocket silo mode
|
||||
-- Separate spawns
|
||||
ENABLE_SEPARATE_SPAWNS = true
|
||||
|
||||
-- Enable Scenario version of RSO
|
||||
@ -57,6 +58,9 @@ ENABLE_TAGS = true
|
||||
-- Enable Long Reach
|
||||
ENABLE_LONGREACH = true
|
||||
|
||||
-- Enable Autofill
|
||||
ENABLE_AUTOFILL = true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Spawn Options
|
||||
--------------------------------------------------------------------------------
|
||||
|
13
control.lua
13
control.lua
@ -96,6 +96,12 @@ script.on_init(function(event)
|
||||
if FRONTIER_ROCKET_SILO_MODE then
|
||||
ChartRocketSiloArea(game.forces[MAIN_FORCE])
|
||||
end
|
||||
|
||||
-- local entityTest = game.surfaces["nauvis"].create_entity({name = "big-ship-wreck-1", position = {0, 0}, force = "neutral", direction = 0})
|
||||
-- game.surfaces["nauvis"].create_entity({name="flying-text", position={0,0}, text="Hello world", color={r=0.5,g=1,b=1}})
|
||||
-- local entityEnvTest = entityTest.get_inventory(defines.inventory.chest)
|
||||
-- entityEnvTest.insert{name="iron-plate", count=3}
|
||||
|
||||
end)
|
||||
|
||||
|
||||
@ -202,6 +208,13 @@ script.on_event(defines.events.on_player_left_game, function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_built_entity, function(event)
|
||||
if ENABLE_AUTOFILL then
|
||||
Autofill(event)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- On Research Finished
|
||||
|
@ -50,6 +50,7 @@ my_spacer_style = {
|
||||
my_small_button_style = {
|
||||
font = "default-small-semibold"
|
||||
}
|
||||
my_color_red = {r=1,g=0.1,b=0.1}
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -64,6 +65,17 @@ function DebugPrint(msg)
|
||||
end
|
||||
end
|
||||
|
||||
-- Prints flying text.
|
||||
-- Color is optional
|
||||
function FlyingText(msg, pos, color)
|
||||
local surface = game.surfaces["nauvis"]
|
||||
if color == nil then
|
||||
surface.create_entity({ name = "flying-text", position = pos, text = msg })
|
||||
else
|
||||
surface.create_entity({ name = "flying-text", position = pos, text = msg, color = color })
|
||||
end
|
||||
end
|
||||
|
||||
-- Broadcast messages
|
||||
function SendBroadcastMsg(msg)
|
||||
for name,player in pairs(game.connected_players) do
|
||||
@ -410,7 +422,76 @@ function SetFixedSiloPosition()
|
||||
end
|
||||
end
|
||||
|
||||
-- Transfer Items Between Inventory
|
||||
-- Returns the number of items that were successfully transferred.
|
||||
-- Returns -1 if item not available.
|
||||
-- Returns -2 if can't place item into destInv (ERROR)
|
||||
function TransferItems(srcInv, destEntity, itemStack)
|
||||
-- Check if item is in srcInv
|
||||
if (srcInv.get_item_count(itemStack.name) == 0) then
|
||||
return -1
|
||||
end
|
||||
|
||||
-- Check if can insert into destInv
|
||||
if (not destEntity.can_insert(itemStack)) then
|
||||
return -2
|
||||
end
|
||||
|
||||
-- Insert items
|
||||
local itemsRemoved = srcInv.remove(itemStack)
|
||||
itemStack.count = itemsRemoved
|
||||
return destEntity.insert(itemStack)
|
||||
end
|
||||
|
||||
-- Attempts to transfer at least some of one type of item from an array of items.
|
||||
-- Use this to try transferring several items in order
|
||||
-- It returns once it successfully inserts at least some of one type.
|
||||
function TransferItemMultipleTypes(srcInv, destEntity, itemNameArray, itemCount)
|
||||
local ret = 0
|
||||
for _,itemName in pairs(itemNameArray) do
|
||||
ret = TransferItems(srcInv, destEntity, {name=itemName, count=itemCount})
|
||||
if (ret > 0) then
|
||||
return ret -- Return the value succesfully transferred
|
||||
end
|
||||
end
|
||||
return ret -- Return the last error code
|
||||
end
|
||||
|
||||
function AutofillTurret(player, turret)
|
||||
local mainInv = player.get_inventory(defines.inventory.player_main)
|
||||
|
||||
-- Attempt to transfer some ammo
|
||||
local ret = TransferItemMultipleTypes(mainInv, turret, {"piercing-rounds-magazine","firearm-magazine"}, 25)
|
||||
|
||||
-- Check the result and print the right text to inform the user what happened.
|
||||
if (ret > 0) then
|
||||
-- Inserted ammo successfully
|
||||
FlyingText("Inserted ammo x" .. ret, turret.position, my_color_red)
|
||||
elseif (ret == -1) then
|
||||
FlyingText("Out of ammo!", turret.position, my_color_red)
|
||||
elseif (ret == -2) then
|
||||
FlyingText("Autofill ERROR! - Report this bug!", turret.position, my_color_red)
|
||||
end
|
||||
end
|
||||
|
||||
function AutoFillVehicle(player, vehicle)
|
||||
local mainInv = player.get_inventory(defines.inventory.player_main)
|
||||
|
||||
-- Attempt to transfer some fuel
|
||||
if ((vehicle.name == "car") or (vehicle.name == "tank") or (vehicle.name == "diesel-locomotive")) then
|
||||
TransferItemMultipleTypes(mainInv, vehicle, {"raw-wood", "coal", "solid-fuel"}, 50)
|
||||
end
|
||||
|
||||
-- Attempt to transfer some ammo
|
||||
if ((vehicle.name == "car") or (vehicle.name == "tank")) then
|
||||
TransferItemMultipleTypes(mainInv, vehicle, {"piercing-rounds-magazine","firearm-magazine"}, 100)
|
||||
end
|
||||
|
||||
-- Attempt to transfer some tank shells
|
||||
if (vehicle.name == "tank") then
|
||||
TransferItemMultipleTypes(mainInv, vehicle, {"explosive-cannon-shell", "cannon-shell"}, 100)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -448,6 +529,19 @@ function PlayerSpawnItems(event)
|
||||
GivePlayerStarterItems(game.players[event.player_index])
|
||||
end
|
||||
|
||||
-- Autofill softmod
|
||||
function Autofill(event)
|
||||
local player = game.players[event.player_index]
|
||||
local eventEntity = event.created_entity
|
||||
|
||||
if (eventEntity.name == "gun-turret") then
|
||||
AutofillTurret(player, eventEntity)
|
||||
end
|
||||
|
||||
if ((eventEntity.name == "car") or (eventEntity.name == "tank") or (eventEntity.name == "diesel-locomotive")) then
|
||||
AutoFillVehicle(player, eventEntity)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- UNUSED CODE
|
||||
|
Loading…
Reference in New Issue
Block a user