Mod to turn peaceful_mode OFF after X minutes?

This is the place to request new mods or give ideas about what could be done.
Post Reply
Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Mod to turn peaceful_mode OFF after X minutes?

Post by Peter34 »

Say, 180 minutes. PeaceOff180M.zip

Upon gamestart, peaceful_mode is set to ON, regardless of game setup choice settings.

After 120 minutes, the mod sends a warning text to console output. "1 hour until Biter aggression!"
After 150 minutes, a sterner warning text: "WARNING: 30 minutes to combat"
165, sterner still. 175 a very insisting text...
At 180, peaceful_mode is set to OFF, and the console notifies all players.

Can someone make such a mod, please? Obviously it'd have to count time from true_gamestart, in order to work in multipayer. So there needs to be a world age variable of some kind. If there isn't, it probably can't be done.

I know players can already do this manually. Even in a coop MP game, the players can agree to, say, 2.5 or 4 hours of peaceful, then one player sets his phone on a timer, and when the phone beeps, he is supposed to tell the other player and then use the console command. But will he? Doing this kind of thing manually, there can be all sorts of temptations to give oneself (or the team) 5 or 10 more minutes. Maybe something happened earlier that felt unfair.

Having it all as an automated process that just works, proceeeding with machine-like mercilessness, would be preferable. Plus someone might forget to set his phone's timer. Honestly.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by prg »

Code: Select all

function print_all(text)
    for _, v in pairs(game.players) do v.print(text) end
end

script.on_init(function()
    game.peaceful_mode = true
    game.forces.enemy.kill_all_units()
end)

script.on_event(defines.events.on_tick, function(event)
    if event.tick == 60 * 60 * 120 then print_all("warning1")
    elseif event.tick == 60 * 60 * 150 then print_all("warning2")
    elseif event.tick == 60 * 60 * 180 then
        print_all("omg they're coming")
        game.peaceful_mode = false
        game.forces.enemy.kill_all_units()
    end
end)
Not tested.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Lerrrtaste
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Mar 23, 2016 12:09 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Lerrrtaste »

+++ - Supporting that!

Another Suggestion by myself is to add a command to activate/deactivate the peacful mode manually.

Lerrrtaste
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Mar 23, 2016 12:09 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Lerrrtaste »

prg wrote:

Code: Select all

function print_all(text)
    for _, v in pairs(game.players) do v.print(text) end
end

script.on_init(function()
    game.peaceful_mode = true
    game.forces.enemy.kill_all_units()
end)

script.on_event(defines.events.on_tick, function(event)
    if event.tick == 60 * 60 * 120 then print_all("warning1")
    elseif event.tick == 60 * 60 * 150 then print_all("warning2")
    elseif event.tick == 60 * 60 * 180 then
        print_all("omg they're coming")
        game.peaceful_mode = false
        game.forces.enemy.kill_all_units()
    end
end)
Not tested.

How to add this to the game :D?

Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Peter34 »

Lerrrtaste wrote: How to add this to the game :D?
I don't understand it at all, either. He skipped far too many steps in the procedure.

Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Peter34 »

I still need to know which file to put that script into. I'm a very inexperienced modder. So far I've only made mods to change item recipes, or made changes to other people's mods (for my personal use) to change the stats of items (e.g. range, recipe costs).

Where do scripts go, in a mod?

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Ranakastrasz »

Peter34 wrote:I still need to know which file to put that script into. I'm a very inexperienced modder. So far I've only made mods to change item recipes, or made changes to other people's mods (for my personal use) to change the stats of items (e.g. range, recipe costs).

Where do scripts go, in a mod?
control.lua

Suggest you look at other mods, and use that as a starting point. Thats how I learned Factorio Specific modding. Actually, Thats how I learned Warcraft 3 Modding, Fate Modding, and a few other games as well. find a mod, pull it apart, and figure out how it works....

Also Why I totally failed at modding Starcraft 2, (Aside from, the horrid editer) as well as a few others. Lack of examples.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

credomane
Filter Inserter
Filter Inserter
Posts: 278
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by credomane »

So I was bored. Made this a mod.

Simple mod. Mostly took prg's code snippet, patched it to work with Factorio 0.13 added my own surprise and made the attached Factorio 0.13 mod.

Mod only works with the games default surface. Probably all you wanted any how.
Only enables and gives three hour warning on news games.
ALL games with mod will get the count down warnings and peaceful mode turned off after 3 hours of game ticks.

Warnings are 3 hours at start then 2 hours, 1 hour, 30 minutes, 15 minutes , 10 minutes, and a final warning at 5 minutes.
Then "They awaken..." when the mod turns off peaceful. Depending on pollution attacks could be quick or take awhile. :P

[edit]
The license on the mod is MIT except for my little surprise. The license on that is in the text file of the same name.
Attachments
PeaceOff180M_0.0.1.zip
(60.91 KiB) Downloaded 88 times

Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Peter34 »

Thanks a lot! I wasn't able to decipher control.lua sufficiently to figure out what the "surprise" is (unless it's the kill_all thing which I suspect would be a necessary component of such a mod anyway, but wasn't sure about), but the rest of it looks very good!

I'll be testing the mod in a MP game, starting maybe 2 weeks and a few days from now.

credomane
Filter Inserter
Filter Inserter
Posts: 278
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by credomane »

When the game switches from peace to non-peaceful and visa-versa the biters don't switch modes. Didn't in 0.12 and older anyways. So a kill all on them is needed to "force" them to mode switch but the surprise is nothing bad or even hidden. You should have seen it when you dug about the mod. Probably didn't realize that is was the surprise is all. So even better. Consider it an extra warning to the console print out when peaceful mod turns off. :)

Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by Peter34 »

Sorry for not reporting back earlier. This mod works fine in MP 0.13, and updating it to 0.14 is as simple as editing the relevant data file and changing "0.13" to "0.14".

Thanks!

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Mod to turn peaceful_mode OFF after X minutes?

Post by aubergine18 »

This might also be of interest - it limits evolution of enemies based on your current research: https://mods.factorio.com/mods/Telemak/ ... nEvolution
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Post Reply

Return to “Ideas and Requests For Mods”