Disable creeper attacks, spawning, buildings

Place to get help with not working mods / modding interface.
User avatar
metzyn
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Tue Mar 19, 2013 10:49 pm
Contact:

Disable creeper attacks, spawning, buildings

Post by metzyn »

I'd like to either make or use a mod that disables all creeper attacks, spawning, and buildings. Kinda like a "peaceful" mode. I am unsure as how to go about doing this for the control.lua file. Any help?
Factorio Modder
Solar Expansion

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: Disable creeper attacks, spawning, buildings

Post by ficolas »

Needs to edit the freeplay.lua in the core folder, read the code and u may be able to know how to do it.

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: Disable creeper attacks, spawning, buildings

Post by slpwnd »

The core should not be edited because then the mod is not portable. Mod needs to be a self standing package.

The creeper spawners generation can't be disabled at the moment becaused it is hardcoded in the map generator. This will change soon and it will be possible to set the rate of creeper spawners in the map generation gui in the same fashion as the frequency of resources is set, etc.

On the other hand, the regular creeper attacks can be disabled. Creeper attacks logic is coded in the core/lualib/freeplay.lua. The freeplay.lua exposes an interface to manipulate the attacking logic. The script interfaces are described on the wiki: https://forums.factorio.com/wiki/inde ... interfaces

In this case you are probably looking for something like this (not tested - check the freeplay.lua for the interface definition):

Code: Select all

local attackdata = remote.call("freeplay", "getattackdata")
attackdata.enabled = false
remote.call("freeplay", "setattackdata", attackdata)

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Disable creeper attacks, spawning, buildings

Post by FreeER »

slpwnd wrote:In this case you are probably looking for something like this (not tested - check the freeplay.lua for the interface definition):

Code: Select all

    local attackdata = remote.call("freeplay", "getattackdata")
    attackdata.enabled = false
    remote.call("freeplay", "setattackdata", attackdata)
Since I tried something like this last night (but wasn't sure I wasn't making a silly mistake from being tired) I figured I'd test this but I got the same error as before which is
attackdata.png
attackdata.png (27.21 KiB) Viewed 5174 times
As for disabling the creeper spawners...If you just want to disable them from spawning creepers you can use

Code: Select all

    if data.raw["unit-spawner"] then
          data.raw["unit-spawner"].maximum_count_of_owned_units = 0
    end
I tried simply setting data.raw.unit and data.raw["unit-spawner"] to nil so that they don't get generated at all but then you get an error (due to the hard coded generation probably).

For peaceful mode could maybe do something along the lines of

Code: Select all

creepers_destroyed=creepers_destroyed or game.findentities{{game.player.character.position.x,game.player.character.position.y},{game.player.character.position.x,game.player.character.position.y}} --I've had issues with oninit sometimes

game.onevent(defines.events.onchunkgenerated, function(event)
    creepers_destroyed=game.findentities{{event.area.x,event.area.y},{event.area.x,event.area.y}}
end)

for k,v in pairs(creepers_destroyed) do
    if v.type == "unit-spawner" or v.type == "unit" or not v.force.equals(game.player.force) then if v.health v.die() else v.destroy() end end --probably don't need the v.health test but better safe than sorry
end
I think that the for loop would run several times, if not then simply copy/paste it into the onevent function as well. I have not tested it but it is probably the closest you can get to peaceful mode right now...If you wanted a creative mode then you would need to unlock all technologies at the start of the game as well as replacing all recipes with either nothing for requirement (if that wouldn't throw an error) or make them insanely cheap (say a piece of wood).
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: Disable creeper attacks, spawning, buildings

Post by slpwnd »

FreeER wrote: Since I tried something like this last night (but wasn't sure I wasn't making a silly mistake from being tired) I figured I'd test this but I got the same error as before which is

attackdata.png (27.21 KiB) Viewed 8 times
So I tried it as well. I was getting the same error as long as I had the code for changing attackdata in the global scope. Once moved to the onload function it works just fine. That makes sense because in the freeplay.lua script the glob.attackdata is nil in the global scope. It "comes to existence" only in the oninit / onload function. So it works well but can be a bit confusing.

As for the solutions to eliminating existing creepers. Good job - they are nice workarounds. I haven't thought of that.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Disable creeper attacks, spawning, buildings

Post by FreeER »

slpwnd wrote:So I tried it as well. I was getting the same error as long as I had the code for changing attackdata in the global scope. Once moved to the onload function it works just fine. That makes sense because in the freeplay.lua script the glob.attackdata is nil in the global scope. It "comes to existence" only in the oninit / onload function. So it works well but can be a bit confusing.
I guess this means it would be difficut to create a mod that would allow you to become 'friendly' with the creepers by turning the waves off midgame (though i suppose you could have the oninit code check the glob table for an isfriendly value before turning the wave off and then simply telling the player to save the game and reload it to give the creepers time to spread the word lol)
As for the solutions to eliminating existing creepers. Good job - they are nice workarounds. I haven't thought of that.
Why thank you :D


I'll try to work some of these into the tutorial I've got on the wiki for everyone else as well.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

kovarex
Factorio Staff
Factorio Staff
Posts: 8194
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Disable creeper attacks, spawning, buildings

Post by kovarex »

FreeER wrote:
slpwnd wrote:So I tried it as well. I was getting the same error as long as I had the code for changing attackdata in the global scope. Once moved to the onload function it works just fine. That makes sense because in the freeplay.lua script the glob.attackdata is nil in the global scope. It "comes to existence" only in the oninit / onload function. So it works well but can be a bit confusing.
I guess this means it would be difficut to create a mod that would allow you to become 'friendly' with the creepers by turning the waves off midgame (though i suppose you could have the oninit code check the glob table for an isfriendly value before turning the wave off and then simply telling the player to save the game and reload it to give the creepers time to spread the word lol)
You understood him wrong, as I did first.
He said, that you can't do it in the global context (outside function onload, ontick etc).
But you can access it midgame.

Post Reply

Return to “Modding help”