1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-20 03:29:26 +02:00

Change train_saviour to use 'player-port' instead of 'small-plane'.

This commit is contained in:
James Gillham 2020-11-15 20:53:32 +00:00
parent dd0ddd131e
commit 0b95a25f1d
4 changed files with 47 additions and 12 deletions

View File

@ -49,7 +49,7 @@ global.config = {
player_colors = {
enabled = true
},
-- saves players' lives if they have a small-plane in their inventory, also adds the small-plane to the market and must therefor be loaded first
-- saves players' lives if they have a player-port in their inventory, also adds the player-port to the market and must therefor be loaded first
train_saviour = {
enabled = true
},
@ -209,7 +209,7 @@ global.config = {
{name = 'substation', count = 50},
{name = 'roboport', count = 10},
{name = 'infinity-chest', count = 10},
{name = 'small-plane', count = 2},
{name = 'player-port', count = 2},
{name = 'coin', count = 20000},
{name = 'rocket-part', count = 2},
{name = 'computer', count = 2},

View File

@ -420,7 +420,7 @@ local pages = {
}
market_label.style.single_line = false
grid.add {type = 'sprite', sprite = 'item/small-plane'}
grid.add {type = 'sprite', sprite = 'item/player-port'}
local train_savior = grid.add {type = 'label', caption = {'info.softmods_saviour_label'}}
local train_savior_style = train_savior.style
train_savior_style.font = 'default-listbox'

View File

@ -3,16 +3,19 @@ local market_items = require 'resources.market_items'
local Global = require 'utils.global'
local DonatorPerks = require 'resources.donator_perks'
local Donator = require 'features.donator'
local Task = require 'utils.task'
local Token = require 'utils.token'
local train_perk_flag = DonatorPerks.train
local saviour_token_name = 'small-plane' -- item name for what saves players
local saviour_token_name = 'player-port' -- item name for what saves players
local saviour_entity_token_name = 'player-port' -- entity name for the saviour_token_name, or nil if the item cannot be placed.
local saviour_timeout = 180 -- number of ticks players are train immune after getting hit (roughly)
table.insert(market_items, 3, {
price = 100,
name = saviour_token_name,
name_label = 'Train Immunity (1x use)',
description = 'Each ' .. saviour_token_name .. ' in your inventory will save you from being killed by a train once.',
description = 'Each ' .. saviour_token_name .. ' in your inventory will save you from being killed by a train once.'
})
local remove_stack = {name = saviour_token_name, count = 1}
@ -22,12 +25,7 @@ Global.register(saved_players, function(tbl)
saved_players = tbl
end)
local train_names = {
['locomotive'] = true,
['cargo-wagon'] = true,
['fluid-wagon'] = true,
['artillery-wagon'] = true
}
local train_names = {['locomotive'] = true, ['cargo-wagon'] = true, ['fluid-wagon'] = true, ['artillery-wagon'] = true}
local function save_player(player)
player.character.health = 1
@ -85,4 +83,41 @@ local function on_pre_death(event)
game.print(player_name .. ' has been saved from a train death. One of their Train Immunity items has been consumed.')
end
--- Cleans the players cursor to prevent from spamming saviour_entity_token_name
-- Somehow required to have a 1 tick delay before cleaning the players cursor
local delay_clear_cursor = Token.register(function(param)
param.player.clean_cursor()
end)
local function built_entity(event)
local entity = event.created_entity
if not entity or not entity.valid then
return
end
local name = entity.name
local ghost = false
if name == 'entity-ghost' then
name = entity.ghost_name
ghost = true
end
if name ~= saviour_entity_token_name then
return
end
local index = event.player_index
local player = game.get_player(index)
local stack = event.stack
entity.destroy()
if player and player.valid and not ghost and stack.valid then
player.insert(stack)
end
Task.set_timeout_in_ticks(1, delay_clear_cursor, {player = player})
end
Event.add(defines.events.on_pre_player_died, on_pre_death)
Event.add(defines.events.on_built_entity, built_entity)

View File

@ -785,7 +785,7 @@ local function init(config)
{name = 'utility-science-pack', price = 125},
{
price = 100,
name = 'small-plane',
name = 'player-port',
name_label = 'Train Immunity (1x use)',
description = 'Each small plane in your inventory will save you from being killed by a train once.'
}